@demiurgejs/core 0.0.0 → 0.1.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 (153) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +75 -2
  3. package/dist/adapter/index.d.ts +20 -0
  4. package/dist/adapter/index.d.ts.map +1 -0
  5. package/dist/browser/file-router.d.ts +30 -0
  6. package/dist/browser/file-router.d.ts.map +1 -0
  7. package/dist/browser/index.d.ts +3 -0
  8. package/dist/browser/index.d.ts.map +1 -0
  9. package/dist/chunks/index-BnX9Qxbm.js +44 -0
  10. package/dist/chunks/index-BnX9Qxbm.js.map +1 -0
  11. package/dist/chunks/ssr-O3d7Q73U.js +273 -0
  12. package/dist/chunks/ssr-O3d7Q73U.js.map +1 -0
  13. package/dist/chunks/streaming-27pwhjGC.js +343 -0
  14. package/dist/chunks/streaming-27pwhjGC.js.map +1 -0
  15. package/dist/chunks/testing-BBnJ5WUR.js +2871 -0
  16. package/dist/chunks/testing-BBnJ5WUR.js.map +1 -0
  17. package/dist/data/cache.d.ts +95 -0
  18. package/dist/data/cache.d.ts.map +1 -0
  19. package/dist/data/idempotency.d.ts +24 -0
  20. package/dist/data/idempotency.d.ts.map +1 -0
  21. package/dist/data/index.d.ts +5 -0
  22. package/dist/data/index.d.ts.map +1 -0
  23. package/dist/data/testing.d.ts +7 -0
  24. package/dist/data/testing.d.ts.map +1 -0
  25. package/dist/data/testing.js +134 -0
  26. package/dist/data/testing.js.map +1 -0
  27. package/dist/document/hydration.d.ts +13 -0
  28. package/dist/document/hydration.d.ts.map +1 -0
  29. package/dist/document/index.d.ts +13 -0
  30. package/dist/document/index.d.ts.map +1 -0
  31. package/dist/document/links.d.ts +17 -0
  32. package/dist/document/links.d.ts.map +1 -0
  33. package/dist/document/metadata.d.ts +62 -0
  34. package/dist/document/metadata.d.ts.map +1 -0
  35. package/dist/document/render.d.ts +28 -0
  36. package/dist/document/render.d.ts.map +1 -0
  37. package/dist/document/scripts.d.ts +24 -0
  38. package/dist/document/scripts.d.ts.map +1 -0
  39. package/dist/document/seo.d.ts +42 -0
  40. package/dist/document/seo.d.ts.map +1 -0
  41. package/dist/index.d.ts +23 -0
  42. package/dist/index.d.ts.map +1 -0
  43. package/dist/index.js +1318 -0
  44. package/dist/index.js.map +1 -0
  45. package/dist/internal/testing.d.ts +3 -0
  46. package/dist/internal/testing.d.ts.map +1 -0
  47. package/dist/internal/testing.js +22 -0
  48. package/dist/internal/testing.js.map +1 -0
  49. package/dist/node/http.d.ts +28 -0
  50. package/dist/node/http.d.ts.map +1 -0
  51. package/dist/node/index.d.ts +45 -0
  52. package/dist/node/index.d.ts.map +1 -0
  53. package/dist/node/index.js +385 -0
  54. package/dist/node/index.js.map +1 -0
  55. package/dist/node/static.d.ts +9 -0
  56. package/dist/node/static.d.ts.map +1 -0
  57. package/dist/node/streaming.d.ts +5 -0
  58. package/dist/node/streaming.d.ts.map +1 -0
  59. package/dist/package-name.d.ts +2 -0
  60. package/dist/package-name.d.ts.map +1 -0
  61. package/dist/platform/analytics.d.ts +20 -0
  62. package/dist/platform/analytics.d.ts.map +1 -0
  63. package/dist/platform/fonts.d.ts +35 -0
  64. package/dist/platform/fonts.d.ts.map +1 -0
  65. package/dist/platform/images.d.ts +49 -0
  66. package/dist/platform/images.d.ts.map +1 -0
  67. package/dist/platform/index.d.ts +9 -0
  68. package/dist/platform/index.d.ts.map +1 -0
  69. package/dist/platform/observability.d.ts +60 -0
  70. package/dist/platform/observability.d.ts.map +1 -0
  71. package/dist/route/action.d.ts +33 -0
  72. package/dist/route/action.d.ts.map +1 -0
  73. package/dist/route/http-error.d.ts +24 -0
  74. package/dist/route/http-error.d.ts.map +1 -0
  75. package/dist/route/index.d.ts +10 -0
  76. package/dist/route/index.d.ts.map +1 -0
  77. package/dist/route/page.d.ts +5 -0
  78. package/dist/route/page.d.ts.map +1 -0
  79. package/dist/route/response.d.ts +100 -0
  80. package/dist/route/response.d.ts.map +1 -0
  81. package/dist/route/types.d.ts +186 -0
  82. package/dist/route/types.d.ts.map +1 -0
  83. package/dist/route/webhook.d.ts +25 -0
  84. package/dist/route/webhook.d.ts.map +1 -0
  85. package/dist/router/index.d.ts +5 -0
  86. package/dist/router/index.d.ts.map +1 -0
  87. package/dist/router/manifest.d.ts +117 -0
  88. package/dist/router/manifest.d.ts.map +1 -0
  89. package/dist/router/navigation-data.d.ts +9 -0
  90. package/dist/router/navigation-data.d.ts.map +1 -0
  91. package/dist/routing/generate.d.ts +14 -0
  92. package/dist/routing/generate.d.ts.map +1 -0
  93. package/dist/routing/index.d.ts +3 -0
  94. package/dist/routing/index.d.ts.map +1 -0
  95. package/dist/routing/types.d.ts +38 -0
  96. package/dist/routing/types.d.ts.map +1 -0
  97. package/dist/security/audit.d.ts +16 -0
  98. package/dist/security/audit.d.ts.map +1 -0
  99. package/dist/security/cors.d.ts +7 -0
  100. package/dist/security/cors.d.ts.map +1 -0
  101. package/dist/security/csrf.d.ts +15 -0
  102. package/dist/security/csrf.d.ts.map +1 -0
  103. package/dist/security/env.d.ts +69 -0
  104. package/dist/security/env.d.ts.map +1 -0
  105. package/dist/security/index.d.ts +17 -0
  106. package/dist/security/index.d.ts.map +1 -0
  107. package/dist/security/policy.d.ts +18 -0
  108. package/dist/security/policy.d.ts.map +1 -0
  109. package/dist/security/rate-limit.d.ts +6 -0
  110. package/dist/security/rate-limit.d.ts.map +1 -0
  111. package/dist/security/report.d.ts +13 -0
  112. package/dist/security/report.d.ts.map +1 -0
  113. package/dist/security/request.d.ts +11 -0
  114. package/dist/security/request.d.ts.map +1 -0
  115. package/dist/security/types.d.ts +137 -0
  116. package/dist/security/types.d.ts.map +1 -0
  117. package/dist/security/upload.d.ts +23 -0
  118. package/dist/security/upload.d.ts.map +1 -0
  119. package/dist/security/websocket.d.ts +13 -0
  120. package/dist/security/websocket.d.ts.map +1 -0
  121. package/dist/server/errors.d.ts +13 -0
  122. package/dist/server/errors.d.ts.map +1 -0
  123. package/dist/server/failure-site.d.ts +2 -0
  124. package/dist/server/failure-site.d.ts.map +1 -0
  125. package/dist/server/fallbacks.d.ts +10 -0
  126. package/dist/server/fallbacks.d.ts.map +1 -0
  127. package/dist/server/index.d.ts +14 -0
  128. package/dist/server/index.d.ts.map +1 -0
  129. package/dist/server/negotiate.d.ts +3 -0
  130. package/dist/server/negotiate.d.ts.map +1 -0
  131. package/dist/server/not-found.d.ts +11 -0
  132. package/dist/server/not-found.d.ts.map +1 -0
  133. package/dist/server/problem.d.ts +18 -0
  134. package/dist/server/problem.d.ts.map +1 -0
  135. package/dist/server/render-tree.d.ts +4 -0
  136. package/dist/server/render-tree.d.ts.map +1 -0
  137. package/dist/server/request-handler.d.ts +40 -0
  138. package/dist/server/request-handler.d.ts.map +1 -0
  139. package/dist/server/request-metadata.d.ts +7 -0
  140. package/dist/server/request-metadata.d.ts.map +1 -0
  141. package/dist/server/ssr.d.ts +17 -0
  142. package/dist/server/ssr.d.ts.map +1 -0
  143. package/dist/static/index.d.ts +23 -0
  144. package/dist/static/index.d.ts.map +1 -0
  145. package/dist/static/index.js +256 -0
  146. package/dist/static/index.js.map +1 -0
  147. package/dist/vite/index.d.ts +4 -0
  148. package/dist/vite/index.d.ts.map +1 -0
  149. package/dist/vite/index.js +580 -0
  150. package/dist/vite/index.js.map +1 -0
  151. package/dist/vite/plugin.d.ts +37 -0
  152. package/dist/vite/plugin.d.ts.map +1 -0
  153. package/package.json +90 -4
package/dist/index.js ADDED
@@ -0,0 +1,1318 @@
1
+ import { jsx as H } from "react/jsx-runtime";
2
+ import { createContext as W, useState as I, useRef as k, useEffect as C, useMemo as _, createElement as f, useContext as V, Component as G } from "react";
3
+ import { e as K, H as Y, f as Z } from "./chunks/ssr-O3d7Q73U.js";
4
+ import { r as mr } from "./chunks/ssr-O3d7Q73U.js";
5
+ import { e as Q, t as X, p as D, s as J, g as ee, c as L, l as te, i as O, j as re, N as z, k as ne, m as ae, n as ie, o as se, H as oe, q as ce, B as ue, u as le, v as fe, w as de, x as he, y as me, R as pe, z as A } from "./chunks/testing-BBnJ5WUR.js";
6
+ import { A as gr, C as wr, D as yr, E as vr, F as br, G as Sr, I as Er, J as Rr, b as $r, K as xr, d as Ar, L as Tr, M as Ir, O as kr, P as Cr, Q as Dr, S as zr, T as Pr, U as Lr, V as Or, W as Nr, h as Ur, X as Mr, Y as Fr, Z as jr, _ as qr, $ as Br, a0 as Hr, a1 as Wr, a2 as _r, a3 as Vr, a4 as Gr, a5 as Kr, a6 as Yr, a7 as Zr, a8 as Qr, a9 as Xr, aa as Jr, ab as en, ac as tn, ad as rn, ae as nn, af as an, ag as sn, ah as on, ai as cn, aj as un, ak as ln, al as fn, am as dn, an as hn, ao as mn } from "./chunks/testing-BBnJ5WUR.js";
7
+ import { a as gn, c as wn, d as yn } from "./chunks/index-BnX9Qxbm.js";
8
+ import "react-dom/server";
9
+ function Nt(e) {
10
+ return {
11
+ entries: e
12
+ };
13
+ }
14
+ function Ut(e) {
15
+ return [
16
+ '<?xml version="1.0" encoding="UTF-8"?>',
17
+ `<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"${e.entries.some((r) => r.alternates?.length) ? ' xmlns:xhtml="http://www.w3.org/1999/xhtml"' : ""}>`,
18
+ ...e.entries.map(we),
19
+ "</urlset>",
20
+ ""
21
+ ].join(`
22
+ `);
23
+ }
24
+ function Mt(e) {
25
+ return e;
26
+ }
27
+ function Ft(e) {
28
+ return e;
29
+ }
30
+ function jt(e) {
31
+ const t = [];
32
+ for (const r of e.rules ?? []) {
33
+ for (const n of b(r.userAgent))
34
+ t.push(`User-agent: ${n}`);
35
+ for (const n of b(r.allow))
36
+ t.push(`Allow: ${n}`);
37
+ for (const n of b(r.disallow))
38
+ t.push(`Disallow: ${n}`);
39
+ t.push("");
40
+ }
41
+ e.host && t.push(`Host: ${e.host}`);
42
+ for (const r of b(e.sitemap))
43
+ t.push(`Sitemap: ${r}`);
44
+ return `${t.join(`
45
+ `).replace(/\n+$/, "")}
46
+ `;
47
+ }
48
+ function ge(e) {
49
+ const t = e.width ?? 1200, r = e.height ?? 630, n = e.background ?? "#101820", a = e.foreground ?? "#ffffff", i = $(e.title, 120), o = e.subtitle ? $(e.subtitle, 160) : void 0, s = e.brand ? $(e.brand, 80) : void 0;
50
+ return be(t, r), [
51
+ `<svg xmlns="http://www.w3.org/2000/svg" width="${t}" height="${r}" viewBox="0 0 ${t} ${r}" role="img" aria-label="${p(i)}">`,
52
+ ` <rect width="100%" height="100%" fill="${p(n)}" />`,
53
+ s ? ` <text x="72" y="96" fill="${p(a)}" font-family="Inter, ui-sans-serif, system-ui, sans-serif" font-size="32" font-weight="700">${w(s)}</text>` : null,
54
+ ` <text x="72" y="${o ? 300 : 340}" fill="${p(a)}" font-family="Inter, ui-sans-serif, system-ui, sans-serif" font-size="76" font-weight="800">${w(i)}</text>`,
55
+ o ? ` <text x="72" y="392" fill="${p(a)}" fill-opacity="0.78" font-family="Inter, ui-sans-serif, system-ui, sans-serif" font-size="38" font-weight="500">${w(o)}</text>` : null,
56
+ "</svg>"
57
+ ].filter((u) => !!u).join(`
58
+ `);
59
+ }
60
+ function qt(e) {
61
+ return new Response(ge(e), {
62
+ headers: {
63
+ "cache-control": "public, max-age=31536000, immutable",
64
+ "content-type": "image/svg+xml; charset=utf-8"
65
+ }
66
+ });
67
+ }
68
+ function we(e) {
69
+ return [
70
+ " <url>",
71
+ ` <loc>${w(e.url)}</loc>`,
72
+ e.lastModified ? ` <lastmod>${w(ye(e.lastModified))}</lastmod>` : null,
73
+ e.changeFrequency ? ` <changefreq>${e.changeFrequency}</changefreq>` : null,
74
+ e.priority !== void 0 ? ` <priority>${ve(e.priority)}</priority>` : null,
75
+ ...(e.alternates ?? []).map(
76
+ (t) => ` <xhtml:link rel="alternate" hreflang="${p(t.hrefLang)}" href="${p(t.href)}" />`
77
+ ),
78
+ " </url>"
79
+ ].filter((t) => !!t).join(`
80
+ `);
81
+ }
82
+ function ye(e) {
83
+ return e instanceof Date ? e.toISOString() : e;
84
+ }
85
+ function ve(e) {
86
+ if (e < 0 || e > 1)
87
+ throw new Error("Sitemap entry priority must be between 0 and 1.");
88
+ return String(e);
89
+ }
90
+ function b(e) {
91
+ return e === void 0 ? [] : Array.isArray(e) ? e : [e];
92
+ }
93
+ function w(e) {
94
+ return e.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
95
+ }
96
+ function p(e) {
97
+ return w(e).replaceAll('"', "&quot;").replaceAll("'", "&apos;");
98
+ }
99
+ function $(e, t) {
100
+ return e.length > t ? `${e.slice(0, t - 3)}...` : e;
101
+ }
102
+ function be(e, t) {
103
+ if (!Number.isSafeInteger(e) || e <= 0)
104
+ throw new Error("OG image width must be a positive integer.");
105
+ if (!Number.isSafeInteger(t) || t <= 0)
106
+ throw new Error("OG image height must be a positive integer.");
107
+ }
108
+ function Bt(e) {
109
+ return Q(
110
+ async (t) => {
111
+ const r = e.input ? await e.input(t) : void 0, n = {
112
+ ...t,
113
+ input: r
114
+ }, a = async () => await Se(
115
+ await e.handler(n),
116
+ t
117
+ );
118
+ if (!e.idempotency)
119
+ return await a();
120
+ const i = typeof e.idempotency.key == "function" ? e.idempotency.key(n) : e.idempotency.key;
121
+ return (await e.idempotency.store.run({
122
+ fn: a,
123
+ key: i,
124
+ ttl: e.idempotency.ttl
125
+ })).value;
126
+ },
127
+ {
128
+ cors: e.cors,
129
+ security: e.security,
130
+ timing: e.timing
131
+ }
132
+ );
133
+ }
134
+ const Ht = {
135
+ async formData({ request: e }) {
136
+ return await e.formData();
137
+ },
138
+ async json({ request: e }) {
139
+ return await e.json();
140
+ },
141
+ async text({ request: e }) {
142
+ return await e.text();
143
+ }
144
+ };
145
+ async function Se(e, t) {
146
+ return e instanceof Response ? e : await X(e, t);
147
+ }
148
+ function Wt(e) {
149
+ return typeof e == "function" ? {
150
+ kind: "page",
151
+ render: { mode: "ssr" },
152
+ view: e
153
+ } : {
154
+ data: e.data,
155
+ kind: "page",
156
+ layout: e.layout,
157
+ render: e.render ?? { mode: "ssr" },
158
+ view: e.view
159
+ };
160
+ }
161
+ const _t = {
162
+ hmac(e) {
163
+ return {
164
+ kind: "response",
165
+ response: async (t) => {
166
+ const r = new Uint8Array(await t.request.arrayBuffer()), n = t.request.headers.get(
167
+ e.header ?? "x-webhook-signature"
168
+ );
169
+ return n ? await Ee(r, n, e) ? await e.handler({
170
+ ...t,
171
+ rawBody: r,
172
+ text: () => new TextDecoder().decode(r)
173
+ }) : new Response("Invalid webhook signature.", {
174
+ status: 401
175
+ }) : new Response("Missing webhook signature.", {
176
+ status: 401
177
+ });
178
+ },
179
+ security: {
180
+ csrf: !1
181
+ }
182
+ };
183
+ }
184
+ };
185
+ async function Ee(e, t, r) {
186
+ const n = r.algorithm ?? "SHA-256", a = r.encoding ?? "hex", i = Re(
187
+ t,
188
+ n,
189
+ r.prefix
190
+ ), o = $e(i, a);
191
+ if (!o)
192
+ return !1;
193
+ const s = await globalThis.crypto.subtle.importKey(
194
+ "raw",
195
+ new TextEncoder().encode(r.secret),
196
+ {
197
+ hash: n,
198
+ name: "HMAC"
199
+ },
200
+ !1,
201
+ ["verify"]
202
+ );
203
+ return await globalThis.crypto.subtle.verify(
204
+ "HMAC",
205
+ s,
206
+ o,
207
+ Uint8Array.from(e).buffer
208
+ );
209
+ }
210
+ function Re(e, t, r) {
211
+ const n = e.trim(), a = r === void 0 ? `${t.toLowerCase().replace("-", "")}=` : r;
212
+ return a !== !1 && n.startsWith(a) ? n.slice(a.length).trim() : n;
213
+ }
214
+ function $e(e, t) {
215
+ if (t === "hex")
216
+ return /^(?:[0-9a-f]{2})+$/i.test(e) ? Uint8Array.from(
217
+ e.match(/.{2}/g) ?? [],
218
+ (r) => Number.parseInt(r, 16)
219
+ ) : null;
220
+ if (!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(
221
+ e
222
+ ))
223
+ return null;
224
+ try {
225
+ const r = typeof atob == "function" ? atob(e) : Buffer.from(e, "base64").toString("binary");
226
+ return Uint8Array.from(r, (n) => n.charCodeAt(0));
227
+ } catch {
228
+ return null;
229
+ }
230
+ }
231
+ const xe = "24h", Ae = 1e4;
232
+ function Vt(e = {}) {
233
+ const t = e.now ?? Date.now, r = e.defaultTtl ?? xe, n = e.maximumEntries ?? Ae;
234
+ if (!Number.isSafeInteger(n) || n <= 0)
235
+ throw new Error(
236
+ "Demiurge idempotency maximumEntries must be a positive integer."
237
+ );
238
+ const a = D(r);
239
+ if (!Number.isFinite(a))
240
+ throw new Error("Demiurge idempotency defaultTtl must be finite.");
241
+ const i = /* @__PURE__ */ new Map();
242
+ return {
243
+ async run(o) {
244
+ const s = J(o.key), u = t();
245
+ Te(i, u);
246
+ const d = i.get(s);
247
+ if (d && (d.pending || d.expiresAt > u))
248
+ return {
249
+ key: s,
250
+ replayed: !0,
251
+ value: await d.value
252
+ };
253
+ if (i.size >= n && Ie(i), i.size >= n)
254
+ throw new Error(
255
+ "Demiurge idempotency store is at capacity with in-flight mutations."
256
+ );
257
+ const g = Promise.resolve().then(o.fn), c = {
258
+ expiresAt: Number.POSITIVE_INFINITY,
259
+ pending: !0,
260
+ value: g
261
+ };
262
+ i.set(s, c);
263
+ try {
264
+ const l = await g;
265
+ return c.pending = !1, c.expiresAt = t() + D(o.ttl ?? r), {
266
+ key: s,
267
+ replayed: !1,
268
+ value: l
269
+ };
270
+ } catch (l) {
271
+ throw i.get(s) === c && i.delete(s), l;
272
+ }
273
+ }
274
+ };
275
+ }
276
+ function Te(e, t) {
277
+ for (const [r, n] of e)
278
+ !n.pending && n.expiresAt <= t && e.delete(r);
279
+ }
280
+ function Ie(e) {
281
+ for (const [t, r] of e)
282
+ if (!r.pending) {
283
+ e.delete(t);
284
+ return;
285
+ }
286
+ }
287
+ function Gt(e, t) {
288
+ return e.run(t);
289
+ }
290
+ function ke(e) {
291
+ const t = L(e.routes), r = e.loadNavigationData ?? U;
292
+ return function() {
293
+ const [a, i] = I(() => S()), [o, s] = I(
294
+ () => e.initialMatch ?? { status: "loading" }
295
+ ), u = k(!!e.initialMatch), d = k(0);
296
+ C(() => {
297
+ function c() {
298
+ i(S());
299
+ }
300
+ return window.addEventListener("popstate", c), () => window.removeEventListener("popstate", c);
301
+ }, []), C(() => {
302
+ let c = !1, l = !1;
303
+ const h = ++d.current, R = new AbortController(), v = () => !c && h === d.current;
304
+ if (u.current && De(e.initialMatch) === a.pathname)
305
+ return u.current = !1, () => {
306
+ c = !0;
307
+ };
308
+ s({ status: "loading" }), te(t, a.pathname).then((m) => {
309
+ v() && !l && m && s({ loading: m, status: "loading" });
310
+ }).catch(() => {
311
+ });
312
+ const T = new Request(a.href, { signal: R.signal });
313
+ return Promise.resolve(r(T)).then(
314
+ (m) => O(
315
+ t,
316
+ a.pathname,
317
+ T,
318
+ m,
319
+ void 0,
320
+ { documentContributions: !1 }
321
+ )
322
+ ).then((m) => {
323
+ l = !0, v() && s(m);
324
+ }).catch(async (m) => {
325
+ if (l = !0, !v() || R.signal.aborted)
326
+ return;
327
+ const B = await re(
328
+ t,
329
+ a.pathname
330
+ );
331
+ v() && s({
332
+ Error: B,
333
+ error: m,
334
+ pathname: a.pathname,
335
+ status: "error"
336
+ });
337
+ }), () => {
338
+ c = !0, R.abort();
339
+ };
340
+ }, [a.pathname, a.search]);
341
+ const g = _(
342
+ () => ({
343
+ navigation: e.navigation ?? "server",
344
+ push(c) {
345
+ const l = S();
346
+ window.history.pushState(null, "", c);
347
+ const h = S();
348
+ i(h), l.pathname === h.pathname && l.search === h.search && l.hash !== h.hash && Oe(h.hash);
349
+ }
350
+ }),
351
+ []
352
+ );
353
+ return f(M.Provider, {
354
+ value: g,
355
+ children: f(ze, {
356
+ key: `${a.pathname}${a.search}`,
357
+ Loading: e.loading,
358
+ NotFound: e.notFound,
359
+ match: o
360
+ })
361
+ });
362
+ };
363
+ }
364
+ function Ce(e, t) {
365
+ const r = t.getAttribute(Z);
366
+ return e.status === "not-found" ? r === "not-found" : e.status === "ready" && r === null;
367
+ }
368
+ function De(e) {
369
+ if (e)
370
+ return e.status === "ready" ? e.match.pathname : e.status === "loading" ? void 0 : e.pathname;
371
+ }
372
+ async function Kt(e) {
373
+ const t = e.root ?? document.getElementById("root");
374
+ if (!t)
375
+ throw new Error(
376
+ "Demiurge expected a #root element in the framework document."
377
+ );
378
+ const r = L(e.routes), n = e.loadNavigationData ?? U, a = e.initialData ?? K(document), i = await O(
379
+ r,
380
+ window.location.pathname,
381
+ new Request(window.location.href),
382
+ a ?? await n(new Request(window.location.href)),
383
+ void 0,
384
+ { documentContributions: !1 }
385
+ ), o = Ce(i, t), s = ke(
386
+ o ? {
387
+ ...e,
388
+ initialMatch: i,
389
+ loadNavigationData: n,
390
+ navigation: a?.navigation ?? e.navigation
391
+ } : {
392
+ ...e,
393
+ loadNavigationData: n,
394
+ navigation: a?.navigation ?? e.navigation
395
+ }
396
+ ), { createRoot: u, hydrateRoot: d } = await import("react-dom/client");
397
+ if (o && t.hasAttribute(Y)) {
398
+ d(t, f(s));
399
+ return;
400
+ }
401
+ t.replaceChildren(), u(t).render(f(s));
402
+ }
403
+ function Yt(e) {
404
+ const t = Ue(), r = ee(e);
405
+ return /* @__PURE__ */ H(
406
+ "a",
407
+ {
408
+ className: e.className,
409
+ href: r,
410
+ onClick: (n) => {
411
+ t.navigation === "server" && Ne(n) && (n.preventDefault(), t.push(r));
412
+ },
413
+ children: e.children
414
+ }
415
+ );
416
+ }
417
+ function ze({
418
+ Loading: e,
419
+ NotFound: t,
420
+ match: r
421
+ }) {
422
+ if (r.status === "loading") {
423
+ const c = r.loading ?? e;
424
+ return c ? f(c) : null;
425
+ }
426
+ if (r.status === "not-found") {
427
+ const c = r.notFound ?? t ?? ue;
428
+ return r.layouts.reduceRight(
429
+ (l, h) => f(h, {
430
+ children: l,
431
+ path: {},
432
+ pathname: r.pathname
433
+ }),
434
+ f(c, { pathname: r.pathname })
435
+ );
436
+ }
437
+ if (r.status === "error")
438
+ return r.Error ? f(r.Error, {
439
+ error: r.error,
440
+ pathname: r.pathname,
441
+ status: N(r.error)
442
+ }) : null;
443
+ const { data: n, error: a, page: i, layouts: o, path: s, pathname: u } = r.match, d = f(i, { data: n, path: s, pathname: u }), g = o.reduceRight(
444
+ (c, l) => f(l, { path: s, pathname: u, children: c }),
445
+ d
446
+ );
447
+ return f(Pe, {
448
+ Error: a,
449
+ children: g,
450
+ pathname: u
451
+ });
452
+ }
453
+ class Pe extends G {
454
+ static getDerivedStateFromError(t) {
455
+ return { error: t };
456
+ }
457
+ state = {};
458
+ componentDidUpdate(t) {
459
+ this.state.error !== void 0 && t.pathname !== this.props.pathname && this.setState({ error: void 0 });
460
+ }
461
+ render() {
462
+ return this.state.error !== void 0 ? this.props.Error ? f(this.props.Error, {
463
+ error: this.state.error,
464
+ pathname: this.props.pathname,
465
+ status: N(this.state.error)
466
+ }) : null : this.props.children;
467
+ }
468
+ }
469
+ function N(e) {
470
+ return le(e) ? e.status : 500;
471
+ }
472
+ function S() {
473
+ return {
474
+ hash: window.location.hash,
475
+ href: window.location.href,
476
+ pathname: window.location.pathname,
477
+ search: window.location.search
478
+ };
479
+ }
480
+ async function U(e) {
481
+ const t = new Headers(e.headers);
482
+ t.set("accept", "application/json"), t.set(z, ne);
483
+ const r = await fetch(new Request(e, {
484
+ credentials: "same-origin",
485
+ headers: t
486
+ })), n = r.headers.get(z);
487
+ if (n === ae) {
488
+ const a = await r.json();
489
+ if (a.hasData !== !0)
490
+ throw new Error("Demiurge received malformed navigation route data.");
491
+ return { data: a.data, hasData: !0 };
492
+ }
493
+ if (n === ie)
494
+ return { hasData: !0 };
495
+ if (n === se || !r.ok) {
496
+ const a = await Le(r), i = oe.includes(
497
+ r.status
498
+ ) ? r.status : 500;
499
+ throw ce(i, {
500
+ detail: typeof a?.detail == "string" ? a.detail : void 0,
501
+ title: typeof a?.title == "string" ? a.title : void 0
502
+ });
503
+ }
504
+ throw new Error(
505
+ "Demiurge expected a navigation data response from the application server."
506
+ );
507
+ }
508
+ async function Le(e) {
509
+ try {
510
+ return await e.json();
511
+ } catch {
512
+ return;
513
+ }
514
+ }
515
+ function Oe(e) {
516
+ queueMicrotask(() => {
517
+ if (!e) {
518
+ window.scrollTo?.(0, 0);
519
+ return;
520
+ }
521
+ let t;
522
+ try {
523
+ t = decodeURIComponent(e.slice(1));
524
+ } catch {
525
+ t = e.slice(1);
526
+ }
527
+ document.getElementById(t)?.scrollIntoView?.();
528
+ });
529
+ }
530
+ function Ne(e) {
531
+ return e.button === 0 && !e.metaKey && !e.altKey && !e.ctrlKey && !e.shiftKey;
532
+ }
533
+ const M = W({
534
+ navigation: "document",
535
+ push(e) {
536
+ window.location.href = e;
537
+ }
538
+ });
539
+ function Ue() {
540
+ return V(M);
541
+ }
542
+ const Me = "/_demiurge/image";
543
+ function Zt(e) {
544
+ return e;
545
+ }
546
+ function Qt(e, t = {}) {
547
+ return F(e, t) !== null;
548
+ }
549
+ function Xt(e, t = {}) {
550
+ const r = F(e.src, t);
551
+ if (!r)
552
+ throw new Error(`Image source "${e.src}" is not allowed by the image policy.`);
553
+ x("width", e.width), x("height", e.height), He(e.quality);
554
+ const n = e.format ?? "auto", i = We(e.width, e.widths).map((s) => {
555
+ const u = Math.round(e.height / e.width * s);
556
+ return {
557
+ format: n,
558
+ height: u,
559
+ src: _e({
560
+ format: n,
561
+ optimizerPath: t.optimizerPath ?? Me,
562
+ quality: e.quality,
563
+ src: e.src,
564
+ width: s
565
+ }),
566
+ width: s
567
+ };
568
+ }), o = i[0];
569
+ return {
570
+ alt: e.alt,
571
+ decoding: "async",
572
+ fetchPriority: e.priority ? "high" : void 0,
573
+ height: e.height,
574
+ loading: e.priority ? "eager" : "lazy",
575
+ sizes: e.sizes,
576
+ source: r,
577
+ src: o.src,
578
+ srcSet: i.map((s) => `${s.src} ${s.width}w`).join(", "),
579
+ variants: i,
580
+ width: e.width
581
+ };
582
+ }
583
+ function F(e, t) {
584
+ if (e.startsWith("/") && !e.startsWith("//"))
585
+ return t.local === !1 ? null : { kind: "local", src: e };
586
+ let r;
587
+ try {
588
+ r = new URL(e);
589
+ } catch {
590
+ return null;
591
+ }
592
+ return r.protocol !== "https:" && r.protocol !== "http:" ? null : Fe(r, t.remote ?? []) ? { kind: "remote", src: r.toString() } : null;
593
+ }
594
+ function Fe(e, t) {
595
+ return t.some(
596
+ (r) => typeof r == "string" ? je(e, r) : qe(e, r)
597
+ );
598
+ }
599
+ function je(e, t) {
600
+ try {
601
+ return e.origin === new URL(t).origin;
602
+ } catch {
603
+ return !1;
604
+ }
605
+ }
606
+ function qe(e, t) {
607
+ return t.protocol && e.protocol !== t.protocol || e.hostname !== t.hostname || t.port !== void 0 && e.port !== t.port ? !1 : t.pathname ? Be(e.pathname, t.pathname) : !0;
608
+ }
609
+ function Be(e, t) {
610
+ return t.endsWith("*") ? e.startsWith(t.slice(0, -1)) : e === t;
611
+ }
612
+ function x(e, t) {
613
+ if (!Number.isInteger(t) || t <= 0)
614
+ throw new Error(`Image ${e} must be a positive integer.`);
615
+ }
616
+ function He(e) {
617
+ if (e !== void 0 && (!Number.isInteger(e) || e < 1 || e > 100))
618
+ throw new Error("Image quality must be an integer between 1 and 100.");
619
+ }
620
+ function We(e, t) {
621
+ const r = t ?? [e, e * 2], n = [...new Set(r)];
622
+ for (const a of n)
623
+ x("width", a);
624
+ return n.sort((a, i) => a - i);
625
+ }
626
+ function _e({
627
+ format: e,
628
+ optimizerPath: t,
629
+ quality: r,
630
+ src: n,
631
+ width: a
632
+ }) {
633
+ const i = new URLSearchParams({
634
+ src: n,
635
+ w: String(a)
636
+ });
637
+ return r !== void 0 && i.set("q", String(r)), e !== "auto" && i.set("f", e), `${t}?${i.toString()}`;
638
+ }
639
+ const Jt = {
640
+ google(e) {
641
+ return {
642
+ display: e.display ?? "swap",
643
+ family: e.family,
644
+ kind: "font",
645
+ source: "google",
646
+ src: e.src,
647
+ style: e.style ?? "normal",
648
+ weight: e.weight ?? 400
649
+ };
650
+ },
651
+ local(e) {
652
+ if (!e.src.trim())
653
+ throw new Error("Local font source must not be empty.");
654
+ return {
655
+ display: e.display ?? "swap",
656
+ family: e.name,
657
+ kind: "font",
658
+ source: "local",
659
+ src: e.src,
660
+ style: e.style ?? "normal",
661
+ weight: e.weight ?? 400
662
+ };
663
+ }
664
+ };
665
+ function er(e) {
666
+ return [...e];
667
+ }
668
+ function tr(e) {
669
+ return e.filter((t) => t.src).map((t) => ({
670
+ as: "font",
671
+ crossOrigin: "anonymous",
672
+ href: t.src,
673
+ kind: "link",
674
+ rel: "preload",
675
+ type: Ve(t.src)
676
+ }));
677
+ }
678
+ function rr(e) {
679
+ return e.filter((t) => t.source === "local" && t.src).map((t) => {
680
+ const r = t.src;
681
+ return [
682
+ "@font-face {",
683
+ ` font-family: "${P(t.family)}";`,
684
+ ` src: url("${P(r)}") format("${Ge(r)}");`,
685
+ ` font-style: ${t.style};`,
686
+ ` font-weight: ${t.weight};`,
687
+ ` font-display: ${t.display};`,
688
+ "}"
689
+ ].join(`
690
+ `);
691
+ }).join(`
692
+ `);
693
+ }
694
+ function Ve(e) {
695
+ return e.split("?")[0].split("#")[0].split(".").pop()?.toLowerCase() === "woff" ? "font/woff" : "font/woff2";
696
+ }
697
+ function Ge(e) {
698
+ return e.split("?")[0].split("#")[0].split(".").pop()?.toLowerCase() === "woff" ? "woff" : "woff2";
699
+ }
700
+ function P(e) {
701
+ return e.replace(/[\\"]/g, "\\$&");
702
+ }
703
+ const nr = {
704
+ plausible(e) {
705
+ const t = Ke(e.domain), r = Ye(e.endpoint ?? "https://plausible.io");
706
+ return {
707
+ connectSrc: r.origin,
708
+ consent: e.consent ?? !1,
709
+ domain: t,
710
+ kind: "analytics",
711
+ provider: "plausible",
712
+ script: fe({
713
+ dataApi: `${r.origin}/api/event`,
714
+ dataDomain: t,
715
+ purpose: "analytics",
716
+ src: `${r.origin}/js/script.js`,
717
+ strategy: e.strategy ?? "afterInteractive"
718
+ })
719
+ };
720
+ }
721
+ };
722
+ function Ke(e) {
723
+ const t = e.trim();
724
+ if (!t || t.includes("/") || t.includes(" "))
725
+ throw new Error("Analytics domain must be a hostname without a path.");
726
+ return t;
727
+ }
728
+ function Ye(e) {
729
+ let t;
730
+ try {
731
+ t = new URL(e);
732
+ } catch {
733
+ throw new Error("Analytics endpoint must be an absolute URL.");
734
+ }
735
+ if (t.protocol !== "https:")
736
+ throw new Error("Analytics endpoint must use HTTPS.");
737
+ return t;
738
+ }
739
+ function ar(e = {}) {
740
+ return {
741
+ async request(t) {
742
+ await E({ kind: "request", signal: t }, e);
743
+ },
744
+ async serverStart(t = {}) {
745
+ await E({ kind: "server-start", signal: t }, e);
746
+ },
747
+ async trace(t) {
748
+ await E({ kind: "trace", signal: t }, e);
749
+ },
750
+ async reportWebVitals(t) {
751
+ await E({ kind: "web-vital", signal: t }, e);
752
+ }
753
+ };
754
+ }
755
+ async function E(e, t) {
756
+ await t.onEvent?.(e), e.kind === "request" ? await t.request?.(e.signal) : e.kind === "server-start" ? await t.serverStart?.(e.signal) : e.kind === "trace" ? await t.trace?.(e.signal) : await t.webVitals?.(e.signal);
757
+ }
758
+ const Ze = /* @__PURE__ */ new Set(["DELETE", "PATCH", "POST", "PUT"]);
759
+ function ir(e = {}) {
760
+ const t = [], r = e.document, n = r ? Je(r.policy, r.headers, t) : {};
761
+ r && Qe(r.policy, t);
762
+ const a = e.route ? ot(e.route, t) : void 0;
763
+ return r?.scripts && (et(
764
+ r.policy.csp,
765
+ r.scripts,
766
+ r.headers,
767
+ t
768
+ ), r.scriptDependencies && t.push(
769
+ ...Xe(
770
+ r.scripts,
771
+ tt(r.scriptDependencies)
772
+ )
773
+ )), {
774
+ findings: t,
775
+ headers: n,
776
+ route: a
777
+ };
778
+ }
779
+ function Qe(e, t) {
780
+ if (!e.trustedTypes || e.trustedTypes.mode !== "report-only")
781
+ return;
782
+ const r = e.csp || void 0, n = !!r?.reportUri?.length, a = e.headers?.reportingEndpoints, i = !!(r?.reportTo && a && a[r.reportTo]);
783
+ !n && !i && t.push({
784
+ code: "report-only-target-missing",
785
+ message: "Trusted Types report-only mode has no deliverable target. Configure CSP reportTo with a matching Reporting-Endpoints member, reportUri for compatibility, or both.",
786
+ severity: "warning"
787
+ });
788
+ }
789
+ function Xe(e, t = {}) {
790
+ const r = t.requirePurpose ?? !0, n = [];
791
+ for (const a of e) {
792
+ const i = lt(a);
793
+ i && (r && !a.purpose && n.push({
794
+ code: "script-purpose-missing",
795
+ message: `Third-party script ${a.src} should declare a purpose for audits and consent flows.`,
796
+ severity: "warning"
797
+ }), t.requireIntegrity && !a.integrity && n.push({
798
+ code: "script-integrity-missing",
799
+ message: `Third-party script ${a.src} should declare an integrity hash or an explicit trust-boundary exception.`,
800
+ severity: "warning"
801
+ }), a.strategy === "beforeInteractive" && !t.allowBeforeInteractiveThirdParty && n.push({
802
+ code: "script-third-party-before-interactive",
803
+ message: `Third-party script ${a.src} runs before the app is interactive and should be justified by policy.`,
804
+ severity: "warning"
805
+ }), ft(i) && n.push({
806
+ code: "script-gtm-wide-trust-boundary",
807
+ message: "Google Tag Manager can load additional scripts at runtime and should be treated as a wide trust boundary.",
808
+ severity: "warning"
809
+ }));
810
+ }
811
+ return n;
812
+ }
813
+ function Je(e, t, r) {
814
+ try {
815
+ return Object.fromEntries(de(e, t));
816
+ } catch (n) {
817
+ return r.push({
818
+ code: "security-header-render-failed",
819
+ message: n instanceof Error ? n.message : "Security headers failed to render.",
820
+ severity: "error"
821
+ }), {};
822
+ }
823
+ }
824
+ function et(e, t, r, n) {
825
+ if (!e)
826
+ return;
827
+ const a = rt(e);
828
+ for (const i of t) {
829
+ if (nt(a) && !i.nonce) {
830
+ n.push({
831
+ code: "csp-script-missing-nonce",
832
+ message: `Document script ${i.src} needs a nonce for the effective script-src policy.`,
833
+ severity: "error"
834
+ });
835
+ continue;
836
+ }
837
+ i.nonce && r?.nonce && i.nonce === r.nonce || at(a, i.src) || n.push({
838
+ code: "csp-script-src-blocked",
839
+ message: `Document script ${i.src} is not allowed by the effective script-src policy.`,
840
+ severity: "error"
841
+ });
842
+ }
843
+ }
844
+ function tt(e) {
845
+ return typeof e == "boolean" ? {} : e;
846
+ }
847
+ function rt(e) {
848
+ return e.scriptSrc ?? e.defaultSrc ?? [];
849
+ }
850
+ function nt(e) {
851
+ return e.some((t) => t.includes("'nonce-{nonce}'"));
852
+ }
853
+ function at(e, t) {
854
+ return e.includes("*") ? !0 : e.includes("'none'") || e.some((r) => r.startsWith("'nonce-")) ? !1 : e.includes("'self'") && it(t) || t.startsWith("https:") && e.includes("https:") || t.startsWith("http:") && e.includes("http:") ? !0 : e.some((r) => st(r, t));
855
+ }
856
+ function it(e) {
857
+ return e.startsWith("/") && !e.startsWith("//");
858
+ }
859
+ function st(e, t) {
860
+ if (e.startsWith("'"))
861
+ return !1;
862
+ try {
863
+ const r = new URL(e), n = new URL(t);
864
+ return n.protocol === r.protocol && n.hostname === r.hostname && n.port === r.port && (r.pathname === "/" || n.pathname.startsWith(r.pathname));
865
+ } catch {
866
+ return !1;
867
+ }
868
+ }
869
+ function ot(e, t) {
870
+ return ct(e.cors, t), ut(e.method, e.security, t), {
871
+ cors: e.cors,
872
+ method: e.method,
873
+ security: e.security
874
+ };
875
+ }
876
+ function ct(e, t) {
877
+ if (e)
878
+ try {
879
+ he(e);
880
+ } catch (r) {
881
+ t.push({
882
+ code: "cors-invalid",
883
+ message: r instanceof Error ? r.message : "CORS policy is invalid.",
884
+ severity: "error"
885
+ });
886
+ }
887
+ }
888
+ function ut(e, t, r) {
889
+ Ze.has(e) && (t?.csrf === !1 && r.push({
890
+ code: "csrf-disabled",
891
+ message: "CSRF protection is explicitly disabled for this unsafe route.",
892
+ severity: "info"
893
+ }), t?.rateLimit || r.push({
894
+ code: "rate-limit-missing",
895
+ message: "Unsafe routes should declare rate limiting.",
896
+ severity: "warning"
897
+ }), t?.request?.maxBodySize || r.push({
898
+ code: "request-body-limit-missing",
899
+ message: "Unsafe routes should declare a request body size limit.",
900
+ severity: "warning"
901
+ }));
902
+ }
903
+ function lt(e) {
904
+ try {
905
+ const t = new URL(e.src);
906
+ if (t.protocol === "http:" || t.protocol === "https:")
907
+ return t;
908
+ } catch {
909
+ return null;
910
+ }
911
+ return null;
912
+ }
913
+ function ft(e) {
914
+ return e.hostname === "www.googletagmanager.com" && (e.pathname === "/gtm.js" || e.pathname === "/ns.html");
915
+ }
916
+ class dt extends Error {
917
+ issues;
918
+ constructor(t) {
919
+ super(vt(t)), this.name = "EnvValidationError", this.issues = t;
920
+ }
921
+ }
922
+ function sr(e) {
923
+ return e;
924
+ }
925
+ function or(e, t) {
926
+ const r = [], n = {};
927
+ for (const a of Object.keys(e)) {
928
+ const i = e[a], o = t[String(a)];
929
+ if (o === void 0 || o === "") {
930
+ if (i.optional) {
931
+ n[a] = void 0;
932
+ continue;
933
+ }
934
+ r.push({
935
+ code: "missing",
936
+ key: String(a),
937
+ message: `Environment variable ${String(a)} is required.`
938
+ });
939
+ continue;
940
+ }
941
+ try {
942
+ n[a] = i.parse(String(a), o);
943
+ } catch (s) {
944
+ r.push({
945
+ code: "invalid",
946
+ key: String(a),
947
+ message: s instanceof Error ? s.message : `Environment variable ${String(a)} is invalid.`
948
+ });
949
+ }
950
+ }
951
+ if (r.length)
952
+ throw new dt(r);
953
+ return n;
954
+ }
955
+ function ht(e = {}) {
956
+ return y(e, !1, (t, r) => {
957
+ if (r === "true" || r === "1")
958
+ return !0;
959
+ if (r === "false" || r === "0")
960
+ return !1;
961
+ throw new Error(`Environment variable ${t} must be true, false, 1, or 0.`);
962
+ });
963
+ }
964
+ function mt(e, t = {}) {
965
+ return y(t, !1, (r, n) => {
966
+ if (e.includes(n))
967
+ return n;
968
+ throw new Error(
969
+ `Environment variable ${r} must be one of: ${e.join(", ")}.`
970
+ );
971
+ });
972
+ }
973
+ function pt(e = {}) {
974
+ return y(e, !1, (t, r) => {
975
+ if (!/^-?\d+$/.test(r))
976
+ throw new Error(`Environment variable ${t} must be an integer.`);
977
+ const n = Number(r);
978
+ if (!Number.isSafeInteger(n))
979
+ throw new Error(`Environment variable ${t} must be a safe integer.`);
980
+ if (e.min !== void 0 && n < e.min)
981
+ throw new Error(
982
+ `Environment variable ${t} must be greater than or equal to ${e.min}.`
983
+ );
984
+ if (e.max !== void 0 && n > e.max)
985
+ throw new Error(
986
+ `Environment variable ${t} must be less than or equal to ${e.max}.`
987
+ );
988
+ return n;
989
+ });
990
+ }
991
+ function gt(e = {}) {
992
+ return y(
993
+ e,
994
+ !0,
995
+ (t, r) => j(t, r, e)
996
+ );
997
+ }
998
+ function wt(e = {}) {
999
+ return y(
1000
+ e,
1001
+ !1,
1002
+ (t, r) => j(t, r, e)
1003
+ );
1004
+ }
1005
+ function yt(e = {}) {
1006
+ return y(e, !1, (t, r) => {
1007
+ let n;
1008
+ try {
1009
+ n = new URL(r);
1010
+ } catch {
1011
+ throw new Error(`Environment variable ${t} must be a valid URL.`);
1012
+ }
1013
+ if (e.protocols?.length && !e.protocols.includes(n.protocol))
1014
+ throw new Error(
1015
+ `Environment variable ${t} must use one of these protocols: ${e.protocols.join(", ")}.`
1016
+ );
1017
+ return n;
1018
+ });
1019
+ }
1020
+ const cr = {
1021
+ boolean: ht,
1022
+ enum: mt,
1023
+ integer: pt,
1024
+ secret: gt,
1025
+ string: wt,
1026
+ url: yt
1027
+ };
1028
+ function y(e, t, r) {
1029
+ return {
1030
+ optional: e.optional ?? !1,
1031
+ parse: r,
1032
+ sensitive: t
1033
+ };
1034
+ }
1035
+ function j(e, t, r) {
1036
+ if (r.minLength !== void 0 && t.length < r.minLength)
1037
+ throw new Error(
1038
+ `Environment variable ${e} must be at least ${r.minLength} characters.`
1039
+ );
1040
+ return t;
1041
+ }
1042
+ function vt(e) {
1043
+ return e.length === 1 ? e[0].message : `Environment validation failed with ${e.length} issues.`;
1044
+ }
1045
+ function ur(e = {}) {
1046
+ return async function(r) {
1047
+ if (r.method.toUpperCase() !== "POST")
1048
+ return new Response(null, {
1049
+ headers: {
1050
+ allow: "POST"
1051
+ },
1052
+ status: 405
1053
+ });
1054
+ const n = St(r);
1055
+ if (n)
1056
+ return n;
1057
+ const a = Et(e, r);
1058
+ if (a)
1059
+ return a;
1060
+ e.maxBodySize !== void 0 && (r = me({ maxBodySize: e.maxBodySize }, r));
1061
+ let i;
1062
+ try {
1063
+ i = await r.json();
1064
+ } catch (s) {
1065
+ return s instanceof pe ? new Response("Security report body too large.", { status: 413 }) : new Response("Invalid security report JSON.", {
1066
+ status: 400
1067
+ });
1068
+ }
1069
+ const o = Rt(i);
1070
+ for (let s = 0; s < o.length; s += 1)
1071
+ await e.onReport?.(o[s], {
1072
+ index: s,
1073
+ request: r
1074
+ });
1075
+ return new Response(null, {
1076
+ status: 204
1077
+ });
1078
+ };
1079
+ }
1080
+ const bt = /* @__PURE__ */ new Set([
1081
+ "application/csp-report",
1082
+ "application/reports+json"
1083
+ ]);
1084
+ function St(e) {
1085
+ const t = e.headers.get("content-type");
1086
+ if (!t)
1087
+ return null;
1088
+ const r = t.split(";", 1)[0]?.trim().toLowerCase();
1089
+ return r && bt.has(r) ? null : new Response("Unsupported security report Content-Type.", {
1090
+ status: 415
1091
+ });
1092
+ }
1093
+ function Et(e, t) {
1094
+ if (e.maxBodySize === void 0)
1095
+ return null;
1096
+ const r = t.headers.get("content-length");
1097
+ if (!r)
1098
+ return null;
1099
+ if (!/^\d+$/.test(r))
1100
+ return new Response("Invalid Content-Length.", {
1101
+ status: 400
1102
+ });
1103
+ const n = Number(r);
1104
+ return Number.isSafeInteger(n) ? n > A(e.maxBodySize) ? new Response("Security report body too large.", {
1105
+ status: 413
1106
+ }) : null : new Response("Invalid Content-Length.", {
1107
+ status: 400
1108
+ });
1109
+ }
1110
+ function Rt(e) {
1111
+ return Array.isArray(e) ? e : $t(e) && "csp-report" in e ? [e["csp-report"]] : [e];
1112
+ }
1113
+ function $t(e) {
1114
+ return typeof e == "object" && e !== null;
1115
+ }
1116
+ function lr(e, t) {
1117
+ const r = {}, n = [];
1118
+ let a = 0;
1119
+ for (const [i, o] of Object.entries(t.files)) {
1120
+ const s = e.getAll(i).filter(Tt);
1121
+ r[i] = s, o.required && s.length === 0 && n.push({
1122
+ code: "file-missing",
1123
+ field: i,
1124
+ message: `Upload field ${i} requires at least one file.`
1125
+ });
1126
+ for (const u of s)
1127
+ a += u.size, xt(i, u, o, n);
1128
+ }
1129
+ return t.maxTotalSize !== void 0 && a > A(t.maxTotalSize) && n.push({
1130
+ code: "total-upload-too-large",
1131
+ field: "*",
1132
+ message: `Uploaded files exceed the maximum total size of ${t.maxTotalSize}.`
1133
+ }), {
1134
+ files: r,
1135
+ issues: n,
1136
+ ok: n.length === 0,
1137
+ totalSize: a
1138
+ };
1139
+ }
1140
+ function xt(e, t, r, n) {
1141
+ r.maxSize !== void 0 && t.size > A(r.maxSize) && n.push({
1142
+ code: "file-too-large",
1143
+ field: e,
1144
+ message: `Upload field ${e} contains ${t.name || "a file"} larger than ${r.maxSize}.`
1145
+ }), r.types?.length && !At(t.type, r.types) && n.push({
1146
+ code: "file-type-not-allowed",
1147
+ field: e,
1148
+ message: `Upload field ${e} contains ${t.name || "a file"} with disallowed type ${t.type || "unknown"}.`
1149
+ });
1150
+ }
1151
+ function At(e, t) {
1152
+ return t.some((r) => r.endsWith("/*") ? e.startsWith(r.slice(0, -1)) : e === r);
1153
+ }
1154
+ function Tt(e) {
1155
+ return e instanceof File;
1156
+ }
1157
+ function It(e, t) {
1158
+ const r = t.headers.get("origin");
1159
+ if (!r)
1160
+ return {
1161
+ allowed: !!e.allowMissingOrigin,
1162
+ expected: e.origins,
1163
+ origin: r,
1164
+ reason: e.allowMissingOrigin ? void 0 : "missing-origin"
1165
+ };
1166
+ const n = q(r);
1167
+ if (!n)
1168
+ return {
1169
+ allowed: !1,
1170
+ expected: e.origins,
1171
+ origin: r,
1172
+ reason: "invalid-origin"
1173
+ };
1174
+ const a = kt(e, n, t);
1175
+ return {
1176
+ allowed: a,
1177
+ expected: e.origins,
1178
+ origin: n,
1179
+ reason: a ? void 0 : "origin-not-allowed"
1180
+ };
1181
+ }
1182
+ function fr(e, t) {
1183
+ return !e || It(e, t).allowed ? null : new Response("WebSocket origin not allowed.", {
1184
+ status: 403
1185
+ });
1186
+ }
1187
+ function kt(e, t, r) {
1188
+ return e.origins === "same-origin" ? t === new URL(r.url).origin : e.origins.some(
1189
+ (n) => Ct(n, t)
1190
+ );
1191
+ }
1192
+ function Ct(e, t) {
1193
+ return e === "null" ? t === "null" : q(e) === t;
1194
+ }
1195
+ function q(e) {
1196
+ if (e === "null")
1197
+ return e;
1198
+ try {
1199
+ if (e !== e.trim())
1200
+ return null;
1201
+ const t = e.indexOf("://");
1202
+ if (t === -1)
1203
+ return null;
1204
+ const r = e.slice(t + 3);
1205
+ if (!r || /[/?#]/.test(r))
1206
+ return null;
1207
+ const n = new URL(e);
1208
+ return n.protocol !== "http:" && n.protocol !== "https:" || n.username || n.password ? null : n.origin;
1209
+ } catch {
1210
+ return null;
1211
+ }
1212
+ }
1213
+ export {
1214
+ dt as EnvValidationError,
1215
+ oe as HTTP_ERROR_STATUSES,
1216
+ gr as HttpError,
1217
+ Yt as Link,
1218
+ Bt as action,
1219
+ Ht as actionInput,
1220
+ nr as analytics,
1221
+ gn as assertAdapterCapabilities,
1222
+ Xe as auditScriptDependencies,
1223
+ wn as checkAdapterCapabilities,
1224
+ It as checkWebSocketOrigin,
1225
+ wr as createCache,
1226
+ yr as createCorsHeaders,
1227
+ vr as createCsrfCookie,
1228
+ br as createCsrfToken,
1229
+ ke as createFileRouter,
1230
+ Sr as createInvalidation,
1231
+ Er as createMemoryCache,
1232
+ Rr as createMemoryCacheStore,
1233
+ Vt as createMemoryIdempotencyStore,
1234
+ $r as createMemoryRateLimitStore,
1235
+ xr as createRequestHandler,
1236
+ ir as createSecurityAudit,
1237
+ de as createSecurityHeaders,
1238
+ ur as createSecurityReportHandler,
1239
+ Ar as cspHash,
1240
+ yn as defineAdapter,
1241
+ sr as defineEnvSchema,
1242
+ er as defineFonts,
1243
+ Zt as defineImages,
1244
+ ar as defineInstrumentation,
1245
+ Tr as defineLinks,
1246
+ Ir as defineMetadata,
1247
+ Ft as defineOgImage,
1248
+ Mt as defineRobots,
1249
+ kr as defineRoutePolicy,
1250
+ Cr as defineScripts,
1251
+ Dr as defineSecurityPolicy,
1252
+ Nt as defineSitemap,
1253
+ zr as defineTags,
1254
+ Pr as enforceAllowedMethods,
1255
+ Lr as enforceCsrfProtection,
1256
+ Or as enforceRateLimit,
1257
+ Nr as enforceRequestSecurity,
1258
+ fr as enforceWebSocketOrigin,
1259
+ cr as env,
1260
+ Jt as font,
1261
+ tr as fontPreloadLinks,
1262
+ Ur as handleRequestWithManifest,
1263
+ ee as href,
1264
+ Mr as html,
1265
+ ce as httpError,
1266
+ Kt as hydrateFileRouter,
1267
+ Qt as isAllowedImageSource,
1268
+ le as isHttpError,
1269
+ Fr as issueCsrfToken,
1270
+ jr as json,
1271
+ qr as jsonl,
1272
+ Br as link,
1273
+ Hr as mergeRoutePolicies,
1274
+ Wr as mergeRouteSecurityPolicies,
1275
+ _r as mergeSecurityPolicies,
1276
+ Vr as meta,
1277
+ Gr as modulePreload,
1278
+ Kr as notFound,
1279
+ Wt as page,
1280
+ A as parseBodySize,
1281
+ D as parseCacheDuration,
1282
+ Yr as parseCookieHeader,
1283
+ Zr as parseRateLimitWindow,
1284
+ Xt as planImageTransform,
1285
+ Qr as preconnect,
1286
+ Xr as preload,
1287
+ Jr as query,
1288
+ en as redirect,
1289
+ rr as renderFontFaceCss,
1290
+ qt as renderOgImageResponse,
1291
+ ge as renderOgImageSvg,
1292
+ mr as renderPageResponse,
1293
+ jt as renderRobots,
1294
+ Ut as renderSitemap,
1295
+ tn as resolveLinks,
1296
+ rn as resolveMetadata,
1297
+ nn as resolveScripts,
1298
+ Q as response,
1299
+ Gt as runIdempotentMutation,
1300
+ fe as script,
1301
+ an as security,
1302
+ J as serializeCacheKey,
1303
+ sn as serializeCacheNamespace,
1304
+ on as serializeCacheTag,
1305
+ cn as serverTiming,
1306
+ un as sse,
1307
+ ln as stream,
1308
+ fn as structuredData,
1309
+ dn as tag,
1310
+ hn as text,
1311
+ X as toResponse,
1312
+ he as validateCorsPolicy,
1313
+ or as validateEnv,
1314
+ mn as validateRateLimitPolicy,
1315
+ lr as validateUploads,
1316
+ _t as webhook
1317
+ };
1318
+ //# sourceMappingURL=index.js.map