@demiurgejs/core 0.1.1 → 0.2.0-beta.1

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