@demiurgejs/core 0.2.0-beta.4 → 0.2.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -0
- package/bin/demiurge.mjs +17 -1
- package/dist/adapter/index.d.ts +1 -1
- package/dist/adapter/index.d.ts.map +1 -1
- package/dist/browser/file-router.d.ts +1 -1
- package/dist/chunks/{document-shell-CpJnFtSC.js → document-shell-9GPwtcTt.js} +2 -2
- package/dist/chunks/{document-shell-CpJnFtSC.js.map → document-shell-9GPwtcTt.js.map} +1 -1
- package/dist/chunks/{image-codec-BmzWnH6W.js → image-codec-Dh1POFhE.js} +2 -2
- package/dist/chunks/{image-codec-BmzWnH6W.js.map → image-codec-Dh1POFhE.js.map} +1 -1
- package/dist/chunks/{images-BQ80950B.js → images-CG7ZzayG.js} +2 -2
- package/dist/chunks/{images-BQ80950B.js.map → images-CG7ZzayG.js.map} +1 -1
- package/dist/chunks/{index-BVk9zWbe.js → index-0MNiR_wo.js} +4 -3
- package/dist/chunks/{index-BVk9zWbe.js.map → index-0MNiR_wo.js.map} +1 -1
- package/dist/chunks/plugin-BZauDxRY.js +2310 -0
- package/dist/chunks/plugin-BZauDxRY.js.map +1 -0
- package/dist/chunks/streaming-GYIsVTQH.js +560 -0
- package/dist/chunks/streaming-GYIsVTQH.js.map +1 -0
- package/dist/chunks/testing-CUwGj2ie.js +4751 -0
- package/dist/chunks/testing-CUwGj2ie.js.map +1 -0
- package/dist/chunks/{vite-DO70kZA6.js → vite-QoqrGl6f.js} +43 -43
- package/dist/chunks/vite-QoqrGl6f.js.map +1 -0
- package/dist/cli.d.ts +4 -2
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +224 -98
- package/dist/cli.js.map +1 -1
- package/dist/config/index.js +2 -2
- package/dist/config/types.d.ts +11 -1
- package/dist/config/types.d.ts.map +1 -1
- package/dist/edge/index.js +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +161 -139
- package/dist/index.js.map +1 -1
- package/dist/inspect/command.d.ts +28 -0
- package/dist/inspect/command.d.ts.map +1 -0
- package/dist/inspect/index.d.ts +9 -0
- package/dist/inspect/index.d.ts.map +1 -0
- package/dist/inspect/redact.d.ts +35 -0
- package/dist/inspect/redact.d.ts.map +1 -0
- package/dist/inspect/report.d.ts +24 -0
- package/dist/inspect/report.d.ts.map +1 -0
- package/dist/inspect/types.d.ts +102 -0
- package/dist/inspect/types.d.ts.map +1 -0
- package/dist/internal/testing.js +12 -12
- package/dist/node/http.d.ts +5 -0
- package/dist/node/http.d.ts.map +1 -1
- package/dist/node/index.d.ts +1 -1
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +26 -24
- package/dist/node/index.js.map +1 -1
- package/dist/route/index.d.ts +1 -0
- package/dist/route/index.d.ts.map +1 -1
- package/dist/route/mutation.d.ts.map +1 -1
- package/dist/route/serialization.d.ts +24 -0
- package/dist/route/serialization.d.ts.map +1 -0
- package/dist/route/webhook.d.ts +6 -1
- package/dist/route/webhook.d.ts.map +1 -1
- package/dist/router/manifest.d.ts.map +1 -1
- package/dist/security/audit.d.ts +2 -1
- package/dist/security/audit.d.ts.map +1 -1
- package/dist/security/authorization.d.ts +36 -0
- package/dist/security/authorization.d.ts.map +1 -0
- package/dist/security/csrf.d.ts.map +1 -1
- package/dist/security/env-startup.d.ts +0 -2
- package/dist/security/env-startup.d.ts.map +1 -1
- package/dist/security/env.d.ts +27 -8
- package/dist/security/env.d.ts.map +1 -1
- package/dist/security/exceptions.d.ts +29 -0
- package/dist/security/exceptions.d.ts.map +1 -0
- package/dist/security/finding-codes.d.ts +56 -0
- package/dist/security/finding-codes.d.ts.map +1 -0
- package/dist/security/index.d.ts +5 -2
- package/dist/security/index.d.ts.map +1 -1
- package/dist/security/policy.d.ts +2 -5
- package/dist/security/policy.d.ts.map +1 -1
- package/dist/security/report.d.ts +2 -1
- package/dist/security/report.d.ts.map +1 -1
- package/dist/security/request.d.ts +1 -0
- package/dist/security/request.d.ts.map +1 -1
- package/dist/security/types.d.ts +138 -5
- package/dist/security/types.d.ts.map +1 -1
- package/dist/security/upload.d.ts +3 -3
- package/dist/security/upload.d.ts.map +1 -1
- package/dist/security/verification.d.ts.map +1 -1
- package/dist/server/request-handler.d.ts +3 -2
- package/dist/server/request-handler.d.ts.map +1 -1
- package/dist/server-only/browser.d.ts +2 -0
- package/dist/server-only/browser.d.ts.map +1 -0
- package/dist/server-only/browser.js +4 -0
- package/dist/server-only/browser.js.map +1 -0
- package/dist/server-only/index.d.ts +2 -0
- package/dist/server-only/index.d.ts.map +1 -0
- package/dist/server-only/index.js +2 -0
- package/dist/server-only/index.js.map +1 -0
- package/dist/static/index.js +4 -4
- package/dist/vite/index.d.ts +9 -4
- package/dist/vite/index.d.ts.map +1 -1
- package/dist/vite/index.js +28 -21
- package/dist/vite/plugin.d.ts +18 -2
- package/dist/vite/plugin.d.ts.map +1 -1
- package/dist/vite/policy-verification.d.ts +33 -2
- package/dist/vite/policy-verification.d.ts.map +1 -1
- package/dist/vite/route-audit.d.ts +14 -2
- package/dist/vite/route-audit.d.ts.map +1 -1
- package/dist/vite/server-only-boundary.d.ts +8 -0
- package/dist/vite/server-only-boundary.d.ts.map +1 -0
- package/package.json +6 -1
- package/dist/chunks/env-startup-DOBYWlZD.js +0 -257
- package/dist/chunks/env-startup-DOBYWlZD.js.map +0 -1
- package/dist/chunks/plugin-BQgMiHxa.js +0 -1827
- package/dist/chunks/plugin-BQgMiHxa.js.map +0 -1
- package/dist/chunks/streaming-BEbPN7Uk.js +0 -469
- package/dist/chunks/streaming-BEbPN7Uk.js.map +0 -1
- package/dist/chunks/testing-DueXbMo4.js +0 -4167
- package/dist/chunks/testing-DueXbMo4.js.map +0 -1
- package/dist/chunks/vite-DO70kZA6.js.map +0 -1
|
@@ -0,0 +1,4751 @@
|
|
|
1
|
+
import { B as Nr, A as Mr, C as Je, D as Ft, E as Wt, e as Bt, F as jr, G as Ur, I as Ir, q as zr, o as Hr, a as Fr } from "./index-0MNiR_wo.js";
|
|
2
|
+
import { createElement as Ie } from "react";
|
|
3
|
+
import { renderToString as Vt } from "react-dom/server";
|
|
4
|
+
import { jsxs as X, jsx as ee } from "react/jsx-runtime";
|
|
5
|
+
function Wr(e, t) {
|
|
6
|
+
const r = Ae(t.canonical);
|
|
7
|
+
if (e.canonical && Ae(e.canonical, r) !== r)
|
|
8
|
+
throw new Error(
|
|
9
|
+
`Localized metadata canonical URL ${JSON.stringify(e.canonical)} conflicts with ${JSON.stringify(t.canonical)}.`
|
|
10
|
+
);
|
|
11
|
+
const n = e.custom.filter(
|
|
12
|
+
(i) => i.kind === "link" && i.rel.toLowerCase() === "alternate" && !!i.hrefLang
|
|
13
|
+
), o = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map();
|
|
14
|
+
for (const i of [...t.alternates, ...n]) {
|
|
15
|
+
const c = i.hrefLang.toLowerCase(), u = Ae(i.href, r), l = o.get(c), d = s.get(u);
|
|
16
|
+
if (l && l !== u)
|
|
17
|
+
throw new Error(`Localized metadata language ${JSON.stringify(i.hrefLang)} has conflicting URLs.`);
|
|
18
|
+
if (d && d !== c && d !== "x-default" && c !== "x-default")
|
|
19
|
+
throw new Error(`Localized metadata URL ${JSON.stringify(i.href)} has conflicting languages.`);
|
|
20
|
+
o.set(c, u), s.set(u, c);
|
|
21
|
+
}
|
|
22
|
+
const a = e.custom.filter(
|
|
23
|
+
(i) => !(i.kind === "link" && i.rel.toLowerCase() === "alternate" && i.hrefLang)
|
|
24
|
+
);
|
|
25
|
+
return {
|
|
26
|
+
...e,
|
|
27
|
+
canonical: r,
|
|
28
|
+
custom: [
|
|
29
|
+
...a,
|
|
30
|
+
...[...o].map(([i, c]) => Br({ href: c, hrefLang: i, rel: "alternate" }))
|
|
31
|
+
]
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function Ae(e, t) {
|
|
35
|
+
try {
|
|
36
|
+
return new URL(e, t).href;
|
|
37
|
+
} catch {
|
|
38
|
+
throw new Error(`Localized metadata URL must be an absolute or root-relative URL: ${JSON.stringify(e)}.`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function mi(e) {
|
|
42
|
+
return e;
|
|
43
|
+
}
|
|
44
|
+
function pi(e) {
|
|
45
|
+
return {
|
|
46
|
+
...e,
|
|
47
|
+
kind: "meta"
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function Br(e) {
|
|
51
|
+
return {
|
|
52
|
+
...e,
|
|
53
|
+
kind: "link"
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function gi(e) {
|
|
57
|
+
return {
|
|
58
|
+
kind: "structured-data",
|
|
59
|
+
value: e
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function T(...e) {
|
|
63
|
+
const t = {
|
|
64
|
+
custom: [],
|
|
65
|
+
structuredData: []
|
|
66
|
+
};
|
|
67
|
+
for (const s of e)
|
|
68
|
+
s && Vr(t, s);
|
|
69
|
+
const r = _r(t), n = t.description, o = Gr(t.openGraph, r, n);
|
|
70
|
+
return {
|
|
71
|
+
canonical: t.canonical,
|
|
72
|
+
charset: "utf-8",
|
|
73
|
+
custom: t.custom,
|
|
74
|
+
description: n,
|
|
75
|
+
openGraph: o,
|
|
76
|
+
robots: t.robots,
|
|
77
|
+
structuredData: t.structuredData,
|
|
78
|
+
title: r,
|
|
79
|
+
viewport: "width=device-width, initial-scale=1"
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function Vr(e, t) {
|
|
83
|
+
qr(e, t.title), t.description !== void 0 && (e.description = t.description), t.canonical !== void 0 && (e.canonical = t.canonical), t.robots && (e.robots = {
|
|
84
|
+
...e.robots ?? {},
|
|
85
|
+
...t.robots
|
|
86
|
+
}), t.openGraph && (e.openGraph = {
|
|
87
|
+
...e.openGraph ?? {},
|
|
88
|
+
...t.openGraph
|
|
89
|
+
}), t.custom && e.custom.push(...t.custom), t.structuredData && e.structuredData.push(...t.structuredData);
|
|
90
|
+
}
|
|
91
|
+
function qr(e, t) {
|
|
92
|
+
if (t !== void 0) {
|
|
93
|
+
if (typeof t == "string") {
|
|
94
|
+
e.title = t;
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
t.default !== void 0 && (e.titleDefault = t.default), t.format && (e.titleFormat = t.format);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function _r(e) {
|
|
101
|
+
return e.title === void 0 ? e.titleDefault : e.titleFormat ? e.titleFormat(e.title) : e.title;
|
|
102
|
+
}
|
|
103
|
+
function Gr(e, t, r) {
|
|
104
|
+
if (!(!e && !t && !r))
|
|
105
|
+
return {
|
|
106
|
+
...t ? { title: t } : {},
|
|
107
|
+
...r ? { description: r } : {},
|
|
108
|
+
...e ?? {}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
const mt = ["build", "private", "public"], Jr = {
|
|
112
|
+
app: "demiurge-memory",
|
|
113
|
+
environment: "local",
|
|
114
|
+
schemaVersion: 1
|
|
115
|
+
}, Kr = 1e4, Yr = 3e4;
|
|
116
|
+
function wi(e) {
|
|
117
|
+
return (...t) => ({
|
|
118
|
+
fn: () => e.fn(...t),
|
|
119
|
+
key: e.key(...t),
|
|
120
|
+
locale: e.locale,
|
|
121
|
+
notFoundTtl: e.notFoundTtl,
|
|
122
|
+
scope: e.scope,
|
|
123
|
+
staleWhileRevalidate: e.staleWhileRevalidate,
|
|
124
|
+
tags: e.tags?.(...t),
|
|
125
|
+
ttl: e.ttl
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
class I extends Error {
|
|
129
|
+
constructor(t) {
|
|
130
|
+
super(t ?? "Not found"), this.name = "CacheNotFoundError";
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function yi(e) {
|
|
134
|
+
throw new I(e);
|
|
135
|
+
}
|
|
136
|
+
function vi(e) {
|
|
137
|
+
return e instanceof I;
|
|
138
|
+
}
|
|
139
|
+
function Si(e) {
|
|
140
|
+
return { id: e };
|
|
141
|
+
}
|
|
142
|
+
function bi(e) {
|
|
143
|
+
return e;
|
|
144
|
+
}
|
|
145
|
+
function qt(e) {
|
|
146
|
+
const t = e.now ?? Date.now, r = en(e.refreshLeaseTtl), n = _t(e.namespace), o = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map();
|
|
147
|
+
return {
|
|
148
|
+
async get(a) {
|
|
149
|
+
const i = a.scope ?? "request";
|
|
150
|
+
if (i === "none")
|
|
151
|
+
return await a.fn();
|
|
152
|
+
const c = gt(a.key);
|
|
153
|
+
if (i === "request")
|
|
154
|
+
return await Xr(o, c, a, t);
|
|
155
|
+
const u = wt(n, i, c), l = (a.tags ?? []).map(
|
|
156
|
+
(g) => yt(n, i, ze(g))
|
|
157
|
+
), d = await e.store.get(u);
|
|
158
|
+
if (d && (d.expiresAt === null || d.expiresAt > t())) {
|
|
159
|
+
if (d.negative)
|
|
160
|
+
throw new I(
|
|
161
|
+
typeof d.value == "string" ? d.value : void 0
|
|
162
|
+
);
|
|
163
|
+
return d.value;
|
|
164
|
+
}
|
|
165
|
+
if (d && tn(d, t())) {
|
|
166
|
+
const g = rn(e.store), O = globalThis.crypto.randomUUID();
|
|
167
|
+
if (await g.acquireRefreshLease(
|
|
168
|
+
u,
|
|
169
|
+
O,
|
|
170
|
+
t() + r
|
|
171
|
+
)) {
|
|
172
|
+
const _ = nn({
|
|
173
|
+
key: u,
|
|
174
|
+
now: t,
|
|
175
|
+
onBackgroundError: e.onBackgroundError,
|
|
176
|
+
refreshStore: g,
|
|
177
|
+
request: a,
|
|
178
|
+
tags: l,
|
|
179
|
+
token: O
|
|
180
|
+
});
|
|
181
|
+
e.waitUntil?.(_);
|
|
182
|
+
}
|
|
183
|
+
return d.value;
|
|
184
|
+
}
|
|
185
|
+
d && await e.store.delete(u);
|
|
186
|
+
const h = s.get(u);
|
|
187
|
+
if (h)
|
|
188
|
+
return await h.promise;
|
|
189
|
+
const f = { invalidated: !1 }, m = Promise.resolve().then(a.fn).then(
|
|
190
|
+
async (g) => (f.invalidated || await e.store.set(u, {
|
|
191
|
+
expiresAt: Ye(t(), a.ttl),
|
|
192
|
+
staleUntil: Ze(
|
|
193
|
+
t(),
|
|
194
|
+
a.ttl,
|
|
195
|
+
a.staleWhileRevalidate
|
|
196
|
+
),
|
|
197
|
+
tags: l,
|
|
198
|
+
value: g
|
|
199
|
+
}), g),
|
|
200
|
+
async (g) => {
|
|
201
|
+
throw !f.invalidated && g instanceof I && await e.store.set(u, Gt(t(), a, l, g)), g;
|
|
202
|
+
}
|
|
203
|
+
), w = {
|
|
204
|
+
promise: m,
|
|
205
|
+
state: f,
|
|
206
|
+
tags: l
|
|
207
|
+
};
|
|
208
|
+
s.set(u, w);
|
|
209
|
+
try {
|
|
210
|
+
return await m;
|
|
211
|
+
} finally {
|
|
212
|
+
s.get(u) === w && s.delete(u);
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
async invalidateKey(a) {
|
|
216
|
+
const i = gt(a), c = o.delete(i);
|
|
217
|
+
let u = !1;
|
|
218
|
+
const l = await Promise.all(
|
|
219
|
+
mt.map((d) => {
|
|
220
|
+
const h = wt(n, d, i), f = s.get(h);
|
|
221
|
+
return f && (f.state.invalidated = !0, u = !0), e.store.delete(h);
|
|
222
|
+
})
|
|
223
|
+
);
|
|
224
|
+
return c || u || l.some(Boolean);
|
|
225
|
+
},
|
|
226
|
+
async invalidateTags(a) {
|
|
227
|
+
const i = a.map(ze), c = on(
|
|
228
|
+
o,
|
|
229
|
+
new Set(i)
|
|
230
|
+
), u = new Set(
|
|
231
|
+
mt.flatMap(
|
|
232
|
+
(h) => i.map((f) => yt(n, h, f))
|
|
233
|
+
)
|
|
234
|
+
);
|
|
235
|
+
let l = 0;
|
|
236
|
+
for (const h of s.values())
|
|
237
|
+
!h.state.invalidated && h.tags.some((f) => u.has(f)) && (h.state.invalidated = !0, l += 1);
|
|
238
|
+
const d = await e.store.invalidateTags([...u]);
|
|
239
|
+
return c + l + d;
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
function Ke(e = {}) {
|
|
244
|
+
const t = e.now ?? Date.now;
|
|
245
|
+
return qt({
|
|
246
|
+
namespace: Jr,
|
|
247
|
+
now: t,
|
|
248
|
+
onBackgroundError: e.onBackgroundError,
|
|
249
|
+
refreshLeaseTtl: e.refreshLeaseTtl,
|
|
250
|
+
store: Zr({
|
|
251
|
+
maximumEntries: e.maximumEntries,
|
|
252
|
+
now: t
|
|
253
|
+
}),
|
|
254
|
+
waitUntil: e.waitUntil
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
function Zr(e = {}) {
|
|
258
|
+
const t = e.entries ?? /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), n = e.maximumEntries ?? Kr, o = e.now ?? Date.now;
|
|
259
|
+
if (!Number.isSafeInteger(n) || n <= 0)
|
|
260
|
+
throw new Error(
|
|
261
|
+
"Demiurge memory cache maximumEntries must be a positive integer."
|
|
262
|
+
);
|
|
263
|
+
ke(t, r, o()), Qr(t, n);
|
|
264
|
+
let s = Le(t);
|
|
265
|
+
return {
|
|
266
|
+
acquireRefreshLease(a, i, c) {
|
|
267
|
+
const u = o(), l = r.get(a);
|
|
268
|
+
return l && l.expiresAt > u ? !1 : (r.set(a, { expiresAt: c, token: i }), !0);
|
|
269
|
+
},
|
|
270
|
+
delete(a) {
|
|
271
|
+
return r.delete(a), t.delete(a);
|
|
272
|
+
},
|
|
273
|
+
get(a) {
|
|
274
|
+
return o() >= s && (ke(t, r, o()), s = Le(t)), t.get(a);
|
|
275
|
+
},
|
|
276
|
+
invalidateTags(a) {
|
|
277
|
+
const i = new Set(a);
|
|
278
|
+
let c = 0;
|
|
279
|
+
for (const [u, l] of t)
|
|
280
|
+
l.tags.some((d) => i.has(d)) && (t.delete(u), r.delete(u), c += 1);
|
|
281
|
+
return c;
|
|
282
|
+
},
|
|
283
|
+
publishRefresh(a, i, c) {
|
|
284
|
+
const u = r.get(a);
|
|
285
|
+
return !u || u.token !== i || u.expiresAt <= o() ? !1 : (pt(
|
|
286
|
+
t,
|
|
287
|
+
r,
|
|
288
|
+
n,
|
|
289
|
+
a,
|
|
290
|
+
c
|
|
291
|
+
), r.delete(a), c.staleUntil !== null && (s = Math.min(s, c.staleUntil)), !0);
|
|
292
|
+
},
|
|
293
|
+
releaseRefreshLease(a, i) {
|
|
294
|
+
r.get(a)?.token === i && r.delete(a);
|
|
295
|
+
},
|
|
296
|
+
set(a, i) {
|
|
297
|
+
const c = o();
|
|
298
|
+
c >= s && (ke(t, r, c), s = Le(t)), r.delete(a), pt(
|
|
299
|
+
t,
|
|
300
|
+
r,
|
|
301
|
+
n,
|
|
302
|
+
a,
|
|
303
|
+
i
|
|
304
|
+
), i.staleUntil !== null && (s = Math.min(s, i.staleUntil));
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
function ke(e, t, r) {
|
|
309
|
+
for (const [n, o] of e)
|
|
310
|
+
o.staleUntil !== null && o.staleUntil <= r && (e.delete(n), t.delete(n));
|
|
311
|
+
}
|
|
312
|
+
function pt(e, t, r, n, o) {
|
|
313
|
+
if (!e.has(n) && e.size >= r)
|
|
314
|
+
for (; e.size >= r; ) {
|
|
315
|
+
const s = e.keys().next().value;
|
|
316
|
+
if (s === void 0)
|
|
317
|
+
break;
|
|
318
|
+
e.delete(s), t.delete(s);
|
|
319
|
+
}
|
|
320
|
+
e.set(n, o);
|
|
321
|
+
}
|
|
322
|
+
function Qr(e, t) {
|
|
323
|
+
for (; e.size > t; ) {
|
|
324
|
+
const r = e.keys().next().value;
|
|
325
|
+
if (r === void 0)
|
|
326
|
+
return;
|
|
327
|
+
e.delete(r);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
function Le(e) {
|
|
331
|
+
let t = Number.POSITIVE_INFINITY;
|
|
332
|
+
for (const r of e.values())
|
|
333
|
+
r.staleUntil !== null && (t = Math.min(t, r.staleUntil));
|
|
334
|
+
return t;
|
|
335
|
+
}
|
|
336
|
+
function _t(e) {
|
|
337
|
+
const t = Ce("app", e.app), r = Ce(
|
|
338
|
+
"environment",
|
|
339
|
+
e.environment
|
|
340
|
+
);
|
|
341
|
+
if (typeof e.schemaVersion == "number" && (!Number.isInteger(e.schemaVersion) || e.schemaVersion < 0))
|
|
342
|
+
throw new Error(
|
|
343
|
+
"Demiurge cache namespace schemaVersion must be a non-negative integer or string."
|
|
344
|
+
);
|
|
345
|
+
const n = Ce(
|
|
346
|
+
"schemaVersion",
|
|
347
|
+
String(e.schemaVersion)
|
|
348
|
+
);
|
|
349
|
+
return `${t}:${r}:${n}`;
|
|
350
|
+
}
|
|
351
|
+
function Ei(e) {
|
|
352
|
+
return {
|
|
353
|
+
async key(t) {
|
|
354
|
+
return {
|
|
355
|
+
deleted: await e.invalidateKey(t) ? 1 : 0,
|
|
356
|
+
kind: "key"
|
|
357
|
+
};
|
|
358
|
+
},
|
|
359
|
+
async keys(t) {
|
|
360
|
+
let r = 0;
|
|
361
|
+
for (const n of t)
|
|
362
|
+
await e.invalidateKey(n) && (r += 1);
|
|
363
|
+
return {
|
|
364
|
+
deleted: r,
|
|
365
|
+
kind: "key"
|
|
366
|
+
};
|
|
367
|
+
},
|
|
368
|
+
async tag(t) {
|
|
369
|
+
return {
|
|
370
|
+
deleted: await e.invalidateTags([t]),
|
|
371
|
+
kind: "tag"
|
|
372
|
+
};
|
|
373
|
+
},
|
|
374
|
+
async tags(t) {
|
|
375
|
+
return {
|
|
376
|
+
deleted: await e.invalidateTags(t),
|
|
377
|
+
kind: "tag"
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
function z(e) {
|
|
383
|
+
if (e === void 0)
|
|
384
|
+
return Number.POSITIVE_INFINITY;
|
|
385
|
+
if (typeof e == "number") {
|
|
386
|
+
if (!Number.isInteger(e) || e < 0)
|
|
387
|
+
throw new Error("Demiurge cache duration must be a non-negative integer.");
|
|
388
|
+
return e;
|
|
389
|
+
}
|
|
390
|
+
const t = /^(\d+)(ms|s|m|h)$/.exec(e);
|
|
391
|
+
if (!t)
|
|
392
|
+
throw new Error("Demiurge cache duration must use an ms/s/m/h suffix.");
|
|
393
|
+
const r = Number(t[1]), n = t[2];
|
|
394
|
+
return n === "h" ? r * 36e5 : n === "m" ? r * 6e4 : n === "s" ? r * 1e3 : r;
|
|
395
|
+
}
|
|
396
|
+
function gt(e) {
|
|
397
|
+
return He(e, /* @__PURE__ */ new Set());
|
|
398
|
+
}
|
|
399
|
+
function ze(e) {
|
|
400
|
+
return e.id;
|
|
401
|
+
}
|
|
402
|
+
async function Xr(e, t, r, n) {
|
|
403
|
+
const o = e.get(t);
|
|
404
|
+
if (o && o.expiresAt > n())
|
|
405
|
+
return await o.value;
|
|
406
|
+
const s = Promise.resolve().then(r.fn), a = {
|
|
407
|
+
expiresAt: n() + z(r.ttl),
|
|
408
|
+
tags: (r.tags ?? []).map(ze),
|
|
409
|
+
value: s
|
|
410
|
+
};
|
|
411
|
+
e.set(t, a);
|
|
412
|
+
try {
|
|
413
|
+
return await s;
|
|
414
|
+
} catch (i) {
|
|
415
|
+
throw e.get(t) === a && (i instanceof I ? a.expiresAt = n() + z(r.notFoundTtl ?? r.ttl) : e.delete(t)), i;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
function wt(e, t, r) {
|
|
419
|
+
return `${e}:${t}:key:${r}`;
|
|
420
|
+
}
|
|
421
|
+
function yt(e, t, r) {
|
|
422
|
+
return `${e}:${t}:tag:${r}`;
|
|
423
|
+
}
|
|
424
|
+
function Ye(e, t) {
|
|
425
|
+
const r = z(t);
|
|
426
|
+
return Number.isFinite(r) ? e + r : null;
|
|
427
|
+
}
|
|
428
|
+
function Gt(e, t, r, n) {
|
|
429
|
+
const o = t.notFoundTtl ?? t.ttl;
|
|
430
|
+
return {
|
|
431
|
+
expiresAt: Ye(e, o),
|
|
432
|
+
negative: !0,
|
|
433
|
+
// Negative entries do not participate in stale-while-revalidate: they
|
|
434
|
+
// expire outright and recompute on the next request.
|
|
435
|
+
staleUntil: Ze(e, o, void 0),
|
|
436
|
+
tags: r,
|
|
437
|
+
value: n.message
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
function Ze(e, t, r) {
|
|
441
|
+
const n = z(t);
|
|
442
|
+
if (!Number.isFinite(n)) {
|
|
443
|
+
if (r !== void 0)
|
|
444
|
+
throw new Error(
|
|
445
|
+
"Demiurge staleWhileRevalidate requires a finite cache ttl."
|
|
446
|
+
);
|
|
447
|
+
return null;
|
|
448
|
+
}
|
|
449
|
+
return e + n + z(r ?? 0);
|
|
450
|
+
}
|
|
451
|
+
function en(e) {
|
|
452
|
+
const t = z(e ?? Yr);
|
|
453
|
+
if (!Number.isFinite(t) || t <= 0)
|
|
454
|
+
throw new Error(
|
|
455
|
+
"Demiurge cache refreshLeaseTtl must be a positive finite duration."
|
|
456
|
+
);
|
|
457
|
+
return t;
|
|
458
|
+
}
|
|
459
|
+
function tn(e, t) {
|
|
460
|
+
return e.expiresAt !== null && e.expiresAt <= t && (e.staleUntil === null || e.staleUntil > t);
|
|
461
|
+
}
|
|
462
|
+
function rn(e) {
|
|
463
|
+
if (!e.acquireRefreshLease || !e.publishRefresh || !e.releaseRefreshLease)
|
|
464
|
+
throw new Error(
|
|
465
|
+
"Demiurge staleWhileRevalidate requires a cache store with acquireRefreshLease, publishRefresh, and releaseRefreshLease coordination methods."
|
|
466
|
+
);
|
|
467
|
+
return e;
|
|
468
|
+
}
|
|
469
|
+
async function nn(e) {
|
|
470
|
+
try {
|
|
471
|
+
const t = await e.request.fn(), r = e.now();
|
|
472
|
+
await e.refreshStore.publishRefresh(e.key, e.token, {
|
|
473
|
+
expiresAt: Ye(r, e.request.ttl),
|
|
474
|
+
staleUntil: Ze(
|
|
475
|
+
r,
|
|
476
|
+
e.request.ttl,
|
|
477
|
+
e.request.staleWhileRevalidate
|
|
478
|
+
),
|
|
479
|
+
tags: e.tags,
|
|
480
|
+
value: t
|
|
481
|
+
});
|
|
482
|
+
} catch (t) {
|
|
483
|
+
if (t instanceof I) {
|
|
484
|
+
await e.refreshStore.publishRefresh(
|
|
485
|
+
e.key,
|
|
486
|
+
e.token,
|
|
487
|
+
Gt(e.now(), e.request, e.tags, t)
|
|
488
|
+
);
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
e.onBackgroundError ? e.onBackgroundError(t) : console.error("Demiurge stale cache refresh failed.", t);
|
|
492
|
+
} finally {
|
|
493
|
+
await e.refreshStore.releaseRefreshLease(e.key, e.token);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
function Ce(e, t) {
|
|
497
|
+
const r = [...t].some((n) => {
|
|
498
|
+
const o = n.charCodeAt(0);
|
|
499
|
+
return o <= 31 || o === 127;
|
|
500
|
+
});
|
|
501
|
+
if (!t || t.trim() !== t || t.includes(":") || r)
|
|
502
|
+
throw new Error(
|
|
503
|
+
`Demiurge cache namespace ${e} must be non-empty and cannot contain whitespace padding, colons, or control characters.`
|
|
504
|
+
);
|
|
505
|
+
return t;
|
|
506
|
+
}
|
|
507
|
+
function on(e, t) {
|
|
508
|
+
let r = 0;
|
|
509
|
+
for (const [n, o] of e)
|
|
510
|
+
o.tags.some((s) => t.has(s)) && (e.delete(n), r += 1);
|
|
511
|
+
return r;
|
|
512
|
+
}
|
|
513
|
+
function He(e, t) {
|
|
514
|
+
if (e === null || typeof e == "boolean" || typeof e == "string")
|
|
515
|
+
return JSON.stringify(e);
|
|
516
|
+
if (typeof e == "number") {
|
|
517
|
+
if (!Number.isFinite(e) || Object.is(e, -0))
|
|
518
|
+
throw new Error(
|
|
519
|
+
"Demiurge cache keys require finite numbers and do not accept negative zero."
|
|
520
|
+
);
|
|
521
|
+
return JSON.stringify(e);
|
|
522
|
+
}
|
|
523
|
+
if (typeof e != "object")
|
|
524
|
+
throw new Error(
|
|
525
|
+
`Demiurge cache keys do not accept values of type ${typeof e}.`
|
|
526
|
+
);
|
|
527
|
+
if (t.has(e))
|
|
528
|
+
throw new Error("Demiurge cache keys cannot contain circular references.");
|
|
529
|
+
if (t.add(e), Array.isArray(e)) {
|
|
530
|
+
const a = Reflect.ownKeys(e), i = [
|
|
531
|
+
...Array.from({ length: e.length }, (u, l) => String(l)),
|
|
532
|
+
"length"
|
|
533
|
+
];
|
|
534
|
+
if (a.length !== i.length || a.some((u, l) => u !== i[l]) || i.slice(0, -1).some((u) => {
|
|
535
|
+
const l = Object.getOwnPropertyDescriptor(e, u);
|
|
536
|
+
return !l?.enumerable || !("value" in l);
|
|
537
|
+
}))
|
|
538
|
+
throw t.delete(e), new Error(
|
|
539
|
+
"Demiurge cache key arrays must be dense and cannot contain accessors or custom properties."
|
|
540
|
+
);
|
|
541
|
+
const c = `[${e.map((u) => He(u, t)).join(",")}]`;
|
|
542
|
+
return t.delete(e), c;
|
|
543
|
+
}
|
|
544
|
+
const r = Object.getPrototypeOf(e);
|
|
545
|
+
if (r !== Object.prototype && r !== null)
|
|
546
|
+
throw new Error(
|
|
547
|
+
"Demiurge cache keys accept only primitives, arrays, and plain objects."
|
|
548
|
+
);
|
|
549
|
+
const n = Reflect.ownKeys(e);
|
|
550
|
+
if (n.some((a) => typeof a == "symbol") || n.some((a) => {
|
|
551
|
+
const i = Object.getOwnPropertyDescriptor(e, a);
|
|
552
|
+
return !i?.enumerable || !("value" in i);
|
|
553
|
+
}))
|
|
554
|
+
throw new Error(
|
|
555
|
+
"Demiurge cache key objects require enumerable string data properties."
|
|
556
|
+
);
|
|
557
|
+
const o = e, s = `{${Object.keys(o).sort().map(
|
|
558
|
+
(a) => `${JSON.stringify(a)}:${He(o[a], t)}`
|
|
559
|
+
).join(",")}}`;
|
|
560
|
+
return t.delete(e), s;
|
|
561
|
+
}
|
|
562
|
+
class Jt extends Error {
|
|
563
|
+
field;
|
|
564
|
+
route;
|
|
565
|
+
constructor(t, r, n) {
|
|
566
|
+
super(t), this.name = "RouteSerializationError", this.route = r, this.field = n;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
function Fe(e, t, r = [], n = /* @__PURE__ */ new Set()) {
|
|
570
|
+
if (e === null) return;
|
|
571
|
+
const o = typeof e;
|
|
572
|
+
if (o === "bigint")
|
|
573
|
+
throw vt(t, r, "a bigint value");
|
|
574
|
+
if (o !== "object") return;
|
|
575
|
+
const s = e;
|
|
576
|
+
if (n.has(s))
|
|
577
|
+
throw vt(t, r, "a circular reference");
|
|
578
|
+
if (n.add(s), Array.isArray(s)) {
|
|
579
|
+
for (let a = 0; a < s.length; a += 1)
|
|
580
|
+
Fe(
|
|
581
|
+
s[a],
|
|
582
|
+
t,
|
|
583
|
+
[...r, String(a)],
|
|
584
|
+
n
|
|
585
|
+
);
|
|
586
|
+
n.delete(s);
|
|
587
|
+
return;
|
|
588
|
+
}
|
|
589
|
+
for (const a of Object.keys(s))
|
|
590
|
+
Fe(
|
|
591
|
+
s[a],
|
|
592
|
+
t,
|
|
593
|
+
[...r, a],
|
|
594
|
+
n
|
|
595
|
+
);
|
|
596
|
+
n.delete(s);
|
|
597
|
+
}
|
|
598
|
+
function vt(e, t, r) {
|
|
599
|
+
const n = t.length === 0 ? "<root>" : t.join(".");
|
|
600
|
+
return new Jt(
|
|
601
|
+
`Route ${e} could not serialize the field ${n} for the browser. The value contains ${r}.`,
|
|
602
|
+
e,
|
|
603
|
+
n
|
|
604
|
+
);
|
|
605
|
+
}
|
|
606
|
+
function Kt(e) {
|
|
607
|
+
const t = {
|
|
608
|
+
fallbacks: {
|
|
609
|
+
error: [],
|
|
610
|
+
loading: [],
|
|
611
|
+
notFound: []
|
|
612
|
+
},
|
|
613
|
+
routes: [],
|
|
614
|
+
layouts: [],
|
|
615
|
+
middlewares: [],
|
|
616
|
+
policies: []
|
|
617
|
+
};
|
|
618
|
+
for (const [r, n] of Object.entries(e)) {
|
|
619
|
+
const o = r.replace(/^\/src\/routes\//, "").replace(/^\.\/routes\//, "").replace(/\.tsx?$/, "").split("/"), s = o.at(-1);
|
|
620
|
+
if (s === "@layout") {
|
|
621
|
+
t.layouts.push({
|
|
622
|
+
file: r,
|
|
623
|
+
fileSegments: o.slice(0, -1),
|
|
624
|
+
segments: x(o.slice(0, -1)),
|
|
625
|
+
load: n
|
|
626
|
+
});
|
|
627
|
+
continue;
|
|
628
|
+
}
|
|
629
|
+
if (s === "@policy") {
|
|
630
|
+
t.policies.push({
|
|
631
|
+
file: r,
|
|
632
|
+
fileSegments: o.slice(0, -1),
|
|
633
|
+
segments: x(o.slice(0, -1)),
|
|
634
|
+
load: n
|
|
635
|
+
});
|
|
636
|
+
continue;
|
|
637
|
+
}
|
|
638
|
+
if (s === "@middleware") {
|
|
639
|
+
t.middlewares.push({
|
|
640
|
+
file: r,
|
|
641
|
+
fileSegments: o.slice(0, -1),
|
|
642
|
+
segments: x(o.slice(0, -1)),
|
|
643
|
+
load: n
|
|
644
|
+
});
|
|
645
|
+
continue;
|
|
646
|
+
}
|
|
647
|
+
if (s === "@loading") {
|
|
648
|
+
t.fallbacks.loading.push({
|
|
649
|
+
file: r,
|
|
650
|
+
fileSegments: o.slice(0, -1),
|
|
651
|
+
segments: x(o.slice(0, -1)),
|
|
652
|
+
load: n
|
|
653
|
+
});
|
|
654
|
+
continue;
|
|
655
|
+
}
|
|
656
|
+
if (s === "@error") {
|
|
657
|
+
t.fallbacks.error.push({
|
|
658
|
+
file: r,
|
|
659
|
+
fileSegments: o.slice(0, -1),
|
|
660
|
+
segments: x(o.slice(0, -1)),
|
|
661
|
+
load: n
|
|
662
|
+
});
|
|
663
|
+
continue;
|
|
664
|
+
}
|
|
665
|
+
if (s === "@not-found") {
|
|
666
|
+
t.fallbacks.notFound.push({
|
|
667
|
+
file: r,
|
|
668
|
+
fileSegments: o.slice(0, -1),
|
|
669
|
+
segments: x(o.slice(0, -1)),
|
|
670
|
+
load: n
|
|
671
|
+
});
|
|
672
|
+
continue;
|
|
673
|
+
}
|
|
674
|
+
t.routes.push({
|
|
675
|
+
file: r,
|
|
676
|
+
fileSegments: o,
|
|
677
|
+
segments: x(o),
|
|
678
|
+
score: bn(o),
|
|
679
|
+
load: n
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
return sn(t.routes), t.routes.sort(un), t.layouts.sort(
|
|
683
|
+
(r, n) => r.fileSegments.length - n.fileSegments.length || r.file.localeCompare(n.file)
|
|
684
|
+
), t.policies.sort(
|
|
685
|
+
(r, n) => r.fileSegments.length - n.fileSegments.length || r.file.localeCompare(n.file)
|
|
686
|
+
), t.middlewares.sort(
|
|
687
|
+
(r, n) => r.fileSegments.length - n.fileSegments.length || r.file.localeCompare(n.file)
|
|
688
|
+
), t.fallbacks.loading.sort(
|
|
689
|
+
(r, n) => r.fileSegments.length - n.fileSegments.length || r.file.localeCompare(n.file)
|
|
690
|
+
), t.fallbacks.error.sort(
|
|
691
|
+
(r, n) => r.fileSegments.length - n.fileSegments.length || r.file.localeCompare(n.file)
|
|
692
|
+
), t.fallbacks.notFound.sort(
|
|
693
|
+
(r, n) => r.fileSegments.length - n.fileSegments.length || r.file.localeCompare(n.file)
|
|
694
|
+
), t;
|
|
695
|
+
}
|
|
696
|
+
function sn(e) {
|
|
697
|
+
const t = /* @__PURE__ */ new Map();
|
|
698
|
+
for (const r of e) {
|
|
699
|
+
const n = r.segments.findIndex(
|
|
700
|
+
(a) => a.startsWith("*")
|
|
701
|
+
);
|
|
702
|
+
if (n !== -1 && n !== r.segments.length - 1)
|
|
703
|
+
throw new Error(
|
|
704
|
+
`Catchall route segment in "${r.file}" must be the final URL segment.`
|
|
705
|
+
);
|
|
706
|
+
const o = r.segments.map(an).join("/"), s = t.get(o);
|
|
707
|
+
if (s)
|
|
708
|
+
throw new Error(
|
|
709
|
+
`Ambiguous routes "${s.file}" and "${r.file}" have the same runtime shape and both match "${cn(r.segments)}".`
|
|
710
|
+
);
|
|
711
|
+
t.set(o, r);
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
function an(e) {
|
|
715
|
+
return e.startsWith("*") ? "*" : e.startsWith(":") ? ":" : `=${e}`;
|
|
716
|
+
}
|
|
717
|
+
function cn(e) {
|
|
718
|
+
return e.length === 0 ? "/" : `/${e.map((t) => t.startsWith(":") || t.startsWith("*") ? "example" : t).join("/")}`;
|
|
719
|
+
}
|
|
720
|
+
function un(e, t) {
|
|
721
|
+
const r = Math.max(e.segments.length, t.segments.length);
|
|
722
|
+
for (let n = 0; n < r; n += 1) {
|
|
723
|
+
const o = St(t.segments[n]) - St(e.segments[n]);
|
|
724
|
+
if (o !== 0)
|
|
725
|
+
return o;
|
|
726
|
+
}
|
|
727
|
+
return e.file.localeCompare(t.file);
|
|
728
|
+
}
|
|
729
|
+
function St(e) {
|
|
730
|
+
return e === void 0 ? 4 : e.startsWith("*") ? 1 : e.startsWith(":") ? 2 : 3;
|
|
731
|
+
}
|
|
732
|
+
async function Yt(e, t, r = new Request(`http://demiurge.local${t}`), n, o = Ke(), s = {}) {
|
|
733
|
+
const a = s.documentContributions ?? !0, i = V(e.routes, t);
|
|
734
|
+
if (!i)
|
|
735
|
+
return {
|
|
736
|
+
...await We(e, t, {
|
|
737
|
+
documentContributions: a,
|
|
738
|
+
locale: s.locale
|
|
739
|
+
}),
|
|
740
|
+
status: "not-found"
|
|
741
|
+
};
|
|
742
|
+
const c = e.layouts.filter(
|
|
743
|
+
(m) => C(m.fileSegments, i.route.fileSegments)
|
|
744
|
+
), u = await i.route.load();
|
|
745
|
+
if (!u.GET || u.GET.kind !== "page")
|
|
746
|
+
return {
|
|
747
|
+
...await We(e, t, {
|
|
748
|
+
fallback: Qe(
|
|
749
|
+
e.fallbacks.notFound,
|
|
750
|
+
i.route
|
|
751
|
+
),
|
|
752
|
+
documentContributions: a,
|
|
753
|
+
layouts: c,
|
|
754
|
+
locale: s.locale
|
|
755
|
+
}),
|
|
756
|
+
status: "not-found"
|
|
757
|
+
};
|
|
758
|
+
const l = u.GET.layout === !1 ? [] : await Promise.all(c.map((m) => m.load())), d = new URL(r.url), h = {
|
|
759
|
+
cache: o,
|
|
760
|
+
context: s.requestContext ?? {},
|
|
761
|
+
locale: s.locale,
|
|
762
|
+
path: i.path,
|
|
763
|
+
pathname: t,
|
|
764
|
+
request: r,
|
|
765
|
+
search: d.searchParams,
|
|
766
|
+
url: d
|
|
767
|
+
};
|
|
768
|
+
let f;
|
|
769
|
+
return u.GET.data && !n?.hasData ? (f = await u.GET.data(h), Fe(f, Xt(i.route.segments))) : f = n?.data, {
|
|
770
|
+
status: "ready",
|
|
771
|
+
match: {
|
|
772
|
+
data: f,
|
|
773
|
+
error: await Zt(e, i.route),
|
|
774
|
+
links: a ? await Mr(
|
|
775
|
+
[
|
|
776
|
+
...l.map((m) => m.links),
|
|
777
|
+
u.links
|
|
778
|
+
],
|
|
779
|
+
h
|
|
780
|
+
) : [],
|
|
781
|
+
page: u.GET.view,
|
|
782
|
+
layouts: l.map(
|
|
783
|
+
(m) => m.default
|
|
784
|
+
),
|
|
785
|
+
locale: s.locale,
|
|
786
|
+
metadata: a ? T(...await Promise.all([
|
|
787
|
+
...l.map((m) => M(m, h)),
|
|
788
|
+
M(u, h)
|
|
789
|
+
])) : T(),
|
|
790
|
+
path: i.path,
|
|
791
|
+
pathname: t,
|
|
792
|
+
render: u.GET.render,
|
|
793
|
+
scripts: a ? await Nr(
|
|
794
|
+
[
|
|
795
|
+
...l.map((m) => m.scripts),
|
|
796
|
+
u.scripts
|
|
797
|
+
],
|
|
798
|
+
h
|
|
799
|
+
) : []
|
|
800
|
+
}
|
|
801
|
+
};
|
|
802
|
+
}
|
|
803
|
+
async function Ri(e, t = {}) {
|
|
804
|
+
const r = Ke(), n = [];
|
|
805
|
+
for (const o of e.routes) {
|
|
806
|
+
const s = await o.load();
|
|
807
|
+
if (!s.GET || s.GET.kind !== "page" && !t.includeResources || s.GET.kind === "page" && t.includePages === !1)
|
|
808
|
+
continue;
|
|
809
|
+
if (s.GET.kind === "page" && s.GET.render.mode !== "static")
|
|
810
|
+
throw new Error(
|
|
811
|
+
`Page route "${o.file}" uses render mode "${s.GET.render.mode}" and cannot be emitted as static output. Set render: { mode: "static" } or deploy a runtime adapter.`
|
|
812
|
+
);
|
|
813
|
+
const a = Xt(o.segments);
|
|
814
|
+
if (wn(o.segments).length === 0) {
|
|
815
|
+
n.push({
|
|
816
|
+
file: o.file,
|
|
817
|
+
path: {},
|
|
818
|
+
pattern: a,
|
|
819
|
+
pathname: a
|
|
820
|
+
});
|
|
821
|
+
continue;
|
|
822
|
+
}
|
|
823
|
+
if (!s.paths)
|
|
824
|
+
throw new Error(
|
|
825
|
+
`Dynamic static route "${o.file}" must export paths for "${a}".`
|
|
826
|
+
);
|
|
827
|
+
const c = await s.paths({
|
|
828
|
+
cache: r,
|
|
829
|
+
locale: t.locale
|
|
830
|
+
});
|
|
831
|
+
for (const u of c) {
|
|
832
|
+
const l = yn(o, a, u);
|
|
833
|
+
n.push({
|
|
834
|
+
file: o.file,
|
|
835
|
+
path: l,
|
|
836
|
+
pattern: a,
|
|
837
|
+
pathname: Sn(o.segments, l)
|
|
838
|
+
});
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
return n;
|
|
842
|
+
}
|
|
843
|
+
async function Ti(e, t) {
|
|
844
|
+
const r = V(e.routes, t);
|
|
845
|
+
if (r)
|
|
846
|
+
return await mn(
|
|
847
|
+
Qe(e.fallbacks.loading, r.route)
|
|
848
|
+
);
|
|
849
|
+
}
|
|
850
|
+
async function ln(e, t) {
|
|
851
|
+
let r;
|
|
852
|
+
try {
|
|
853
|
+
r = V(e.routes, t);
|
|
854
|
+
} catch (n) {
|
|
855
|
+
if (!(n instanceof tt)) throw n;
|
|
856
|
+
return await et(
|
|
857
|
+
e.fallbacks.error.find(
|
|
858
|
+
(o) => o.fileSegments.length === 0
|
|
859
|
+
)
|
|
860
|
+
);
|
|
861
|
+
}
|
|
862
|
+
return r ? await Zt(e, r.route) : await dn(e, t);
|
|
863
|
+
}
|
|
864
|
+
async function Zt(e, t) {
|
|
865
|
+
return await et(
|
|
866
|
+
Qe(e.fallbacks.error, t)
|
|
867
|
+
);
|
|
868
|
+
}
|
|
869
|
+
async function dn(e, t) {
|
|
870
|
+
return await et(
|
|
871
|
+
Qt(e.fallbacks.error, t)
|
|
872
|
+
);
|
|
873
|
+
}
|
|
874
|
+
async function We(e, t, r = {}) {
|
|
875
|
+
const o = await (r.fallback ?? Qt(e.fallbacks.notFound, t))?.load(), s = o?.default, a = r.documentContributions ?? !0, i = { locale: r.locale, path: {}, pathname: t };
|
|
876
|
+
if (o?.layout === !1)
|
|
877
|
+
return {
|
|
878
|
+
layouts: [],
|
|
879
|
+
locale: r.locale,
|
|
880
|
+
metadata: a ? T(await M(o, i)) : T(),
|
|
881
|
+
notFound: s,
|
|
882
|
+
pathname: t
|
|
883
|
+
};
|
|
884
|
+
const c = r.layouts ?? fn(e, t);
|
|
885
|
+
try {
|
|
886
|
+
const u = await Promise.all(
|
|
887
|
+
c.map((l) => l.load())
|
|
888
|
+
);
|
|
889
|
+
return {
|
|
890
|
+
layouts: u.map(
|
|
891
|
+
(l) => l.default
|
|
892
|
+
),
|
|
893
|
+
locale: r.locale,
|
|
894
|
+
metadata: a ? T(...await Promise.all([
|
|
895
|
+
...u.map((l) => M(l, i)),
|
|
896
|
+
M(o, i)
|
|
897
|
+
])) : T(),
|
|
898
|
+
notFound: s,
|
|
899
|
+
pathname: t
|
|
900
|
+
};
|
|
901
|
+
} catch (u) {
|
|
902
|
+
return r.onLayoutError?.(u), {
|
|
903
|
+
layouts: [],
|
|
904
|
+
locale: r.locale,
|
|
905
|
+
metadata: a ? T(await M(o, i)) : T(),
|
|
906
|
+
notFound: s,
|
|
907
|
+
pathname: t
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
async function M(e, t) {
|
|
912
|
+
return typeof e?.metadata == "function" ? await e.metadata(t) : e?.metadata;
|
|
913
|
+
}
|
|
914
|
+
function fn(e, t) {
|
|
915
|
+
const r = Te(t);
|
|
916
|
+
return e.layouts.filter(
|
|
917
|
+
(n) => !n.fileSegments.some(Re) && Xe(n.segments, r)
|
|
918
|
+
);
|
|
919
|
+
}
|
|
920
|
+
function hn(e, t) {
|
|
921
|
+
const r = Te(t);
|
|
922
|
+
return e.policies.filter(
|
|
923
|
+
(n) => !n.fileSegments.some(Re) && Xe(n.segments, r)
|
|
924
|
+
);
|
|
925
|
+
}
|
|
926
|
+
function Qe(e, t) {
|
|
927
|
+
for (let r = e.length - 1; r >= 0; r -= 1) {
|
|
928
|
+
const n = e[r];
|
|
929
|
+
if (C(n.fileSegments, t.fileSegments))
|
|
930
|
+
return n;
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
function Qt(e, t) {
|
|
934
|
+
const r = Te(t);
|
|
935
|
+
for (let n = e.length - 1; n >= 0; n -= 1) {
|
|
936
|
+
const o = e[n];
|
|
937
|
+
if (!o.fileSegments.some(Re) && Xe(o.segments, r))
|
|
938
|
+
return o;
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
function Xe(e, t) {
|
|
942
|
+
return e.every((r, n) => r.startsWith("*") ? t.length > n : r.startsWith(":") ? !!t[n] : t[n] === r);
|
|
943
|
+
}
|
|
944
|
+
async function mn(e) {
|
|
945
|
+
return e ? (await e.load()).default : void 0;
|
|
946
|
+
}
|
|
947
|
+
async function et(e) {
|
|
948
|
+
return e ? (await e.load()).default : void 0;
|
|
949
|
+
}
|
|
950
|
+
function V(e, t) {
|
|
951
|
+
const r = Te(t);
|
|
952
|
+
for (const n of e) {
|
|
953
|
+
const o = pn(n.segments, r);
|
|
954
|
+
if (o)
|
|
955
|
+
return { route: n, path: o };
|
|
956
|
+
}
|
|
957
|
+
return null;
|
|
958
|
+
}
|
|
959
|
+
const $i = Yt, xi = V;
|
|
960
|
+
function pn(e, t) {
|
|
961
|
+
const r = {};
|
|
962
|
+
for (let n = 0; n < e.length; n += 1) {
|
|
963
|
+
const o = e[n], s = t[n];
|
|
964
|
+
if (o?.startsWith("*"))
|
|
965
|
+
return r[o.slice(1)] = t.slice(n).join("/"), r;
|
|
966
|
+
if (!s)
|
|
967
|
+
return null;
|
|
968
|
+
if (o.startsWith(":")) {
|
|
969
|
+
r[o.slice(1)] = s;
|
|
970
|
+
continue;
|
|
971
|
+
}
|
|
972
|
+
if (o !== s)
|
|
973
|
+
return null;
|
|
974
|
+
}
|
|
975
|
+
return e.length === t.length ? r : null;
|
|
976
|
+
}
|
|
977
|
+
function Ai(e, t) {
|
|
978
|
+
return e.every(
|
|
979
|
+
(r, n) => t[n] === r
|
|
980
|
+
);
|
|
981
|
+
}
|
|
982
|
+
function C(e, t) {
|
|
983
|
+
return e.every(
|
|
984
|
+
(r, n) => t[n] === r
|
|
985
|
+
);
|
|
986
|
+
}
|
|
987
|
+
function x(e) {
|
|
988
|
+
return e.flatMap((t) => Re(t) ? [] : t === "index" ? [] : t.startsWith("[...") && t.endsWith("]") ? [`*${t.slice(4, -1)}`] : t.startsWith("[") && t.endsWith("]") ? [`:${t.slice(1, -1)}`] : [t]);
|
|
989
|
+
}
|
|
990
|
+
function Re(e) {
|
|
991
|
+
return e.startsWith("(") && e.endsWith(")");
|
|
992
|
+
}
|
|
993
|
+
function Xt(e) {
|
|
994
|
+
return e.length === 0 ? "/" : `/${e.map(gn).join("/")}`;
|
|
995
|
+
}
|
|
996
|
+
function gn(e) {
|
|
997
|
+
return e.startsWith("*") ? `[...${e.slice(1)}]` : e.startsWith(":") ? `[${e.slice(1)}]` : e;
|
|
998
|
+
}
|
|
999
|
+
function wn(e) {
|
|
1000
|
+
return e.flatMap((t) => t.startsWith(":") || t.startsWith("*") ? [t.slice(1)] : []);
|
|
1001
|
+
}
|
|
1002
|
+
function yn(e, t, r) {
|
|
1003
|
+
const n = {};
|
|
1004
|
+
for (const o of e.segments) {
|
|
1005
|
+
if (!o.startsWith(":") && !o.startsWith("*"))
|
|
1006
|
+
continue;
|
|
1007
|
+
const s = o.slice(1), a = r[s];
|
|
1008
|
+
if (a === void 0)
|
|
1009
|
+
throw new Error(
|
|
1010
|
+
`Static paths for "${e.file}" must include "${s}" for "${t}".`
|
|
1011
|
+
);
|
|
1012
|
+
if (!vn(a))
|
|
1013
|
+
throw new Error(
|
|
1014
|
+
`Static path "${s}" for "${e.file}" must be a string, number, or boolean.`
|
|
1015
|
+
);
|
|
1016
|
+
n[s] = String(a);
|
|
1017
|
+
}
|
|
1018
|
+
return n;
|
|
1019
|
+
}
|
|
1020
|
+
function vn(e) {
|
|
1021
|
+
return typeof e == "string" || typeof e == "number" || typeof e == "boolean";
|
|
1022
|
+
}
|
|
1023
|
+
function Sn(e, t) {
|
|
1024
|
+
return `/${e.map((n) => n.startsWith("*") ? t[n.slice(1)].split("/").filter(Boolean).map(encodeURIComponent).join("/") : n.startsWith(":") ? encodeURIComponent(t[n.slice(1)]) : encodeURIComponent(n)).filter(Boolean).join("/")}`;
|
|
1025
|
+
}
|
|
1026
|
+
function bn(e) {
|
|
1027
|
+
return x(e).reduce((t, r) => r.startsWith("*") ? t : r.startsWith(":") ? t + 1 : t + 2, 0);
|
|
1028
|
+
}
|
|
1029
|
+
function Te(e) {
|
|
1030
|
+
return e.replace(/^\/|\/$/g, "").split("/").filter(Boolean).map((t) => {
|
|
1031
|
+
try {
|
|
1032
|
+
return decodeURIComponent(t);
|
|
1033
|
+
} catch (r) {
|
|
1034
|
+
throw new tt(e, { cause: r });
|
|
1035
|
+
}
|
|
1036
|
+
});
|
|
1037
|
+
}
|
|
1038
|
+
class tt extends URIError {
|
|
1039
|
+
pathname;
|
|
1040
|
+
constructor(t, r) {
|
|
1041
|
+
super(
|
|
1042
|
+
`Malformed percent encoding in URL pathname ${JSON.stringify(t)}.`,
|
|
1043
|
+
r
|
|
1044
|
+
), this.name = "MalformedPathnameError", this.pathname = t;
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
const H = "x-demiurge-navigation", En = "data", Rn = "data", fe = "error", Be = "not-found";
|
|
1048
|
+
function F(e) {
|
|
1049
|
+
return e.headers.get(H) === En;
|
|
1050
|
+
}
|
|
1051
|
+
function rt(e, t = {}) {
|
|
1052
|
+
const r = new Headers(t.headers);
|
|
1053
|
+
return r.set("cache-control", "no-store"), r.set(
|
|
1054
|
+
H,
|
|
1055
|
+
t.kind ?? Rn
|
|
1056
|
+
), r.append("vary", H), Response.json(
|
|
1057
|
+
{
|
|
1058
|
+
data: e,
|
|
1059
|
+
document: t.document,
|
|
1060
|
+
error: t.error,
|
|
1061
|
+
hasData: !0,
|
|
1062
|
+
locale: t.locale
|
|
1063
|
+
},
|
|
1064
|
+
{
|
|
1065
|
+
headers: r,
|
|
1066
|
+
status: t.status
|
|
1067
|
+
}
|
|
1068
|
+
);
|
|
1069
|
+
}
|
|
1070
|
+
function ce(e, t) {
|
|
1071
|
+
return e.headers.set("cache-control", "no-store"), e.headers.set(H, t), e.headers.append("vary", H), e;
|
|
1072
|
+
}
|
|
1073
|
+
function oe(e) {
|
|
1074
|
+
return typeof e == "object" && e !== null && !Array.isArray(e);
|
|
1075
|
+
}
|
|
1076
|
+
function ki(e) {
|
|
1077
|
+
return typeof e == "object" && e !== null;
|
|
1078
|
+
}
|
|
1079
|
+
function Tn(e) {
|
|
1080
|
+
if (typeof e == "string")
|
|
1081
|
+
return e;
|
|
1082
|
+
const t = $n(kn(
|
|
1083
|
+
e.to,
|
|
1084
|
+
"path" in e ? e.path : void 0
|
|
1085
|
+
)), r = e.search === void 0 ? t.search : xn(e.search), n = e.hash === void 0 ? t.hash : e.hash ? e.hash.startsWith("#") ? e.hash : `#${e.hash}` : "";
|
|
1086
|
+
return `${t.pathname}${r}${n}`;
|
|
1087
|
+
}
|
|
1088
|
+
function $n(e) {
|
|
1089
|
+
const t = e.indexOf("#"), r = t === -1 ? e : e.slice(0, t), n = r.indexOf("?");
|
|
1090
|
+
return {
|
|
1091
|
+
hash: t === -1 ? "" : e.slice(t),
|
|
1092
|
+
pathname: n === -1 ? r : r.slice(0, n),
|
|
1093
|
+
search: n === -1 ? "" : r.slice(n)
|
|
1094
|
+
};
|
|
1095
|
+
}
|
|
1096
|
+
function xn(e) {
|
|
1097
|
+
if (!e)
|
|
1098
|
+
return "";
|
|
1099
|
+
if (typeof e == "string")
|
|
1100
|
+
return e.startsWith("?") ? e : `?${e}`;
|
|
1101
|
+
const r = (e instanceof URLSearchParams ? e : An(e)).toString();
|
|
1102
|
+
return r ? `?${r}` : "";
|
|
1103
|
+
}
|
|
1104
|
+
function An(e) {
|
|
1105
|
+
const t = new URLSearchParams();
|
|
1106
|
+
for (const [r, n] of Object.entries(e)) {
|
|
1107
|
+
const o = Array.isArray(n) ? n : [n];
|
|
1108
|
+
for (const s of o)
|
|
1109
|
+
s != null && t.append(r, String(s));
|
|
1110
|
+
}
|
|
1111
|
+
return t;
|
|
1112
|
+
}
|
|
1113
|
+
function kn(e, t) {
|
|
1114
|
+
return t ? e.replace(
|
|
1115
|
+
/\[(\.\.\.)?([a-zA-Z_$][a-zA-Z0-9_$]*)\]/g,
|
|
1116
|
+
(r, n, o) => {
|
|
1117
|
+
const s = t[o];
|
|
1118
|
+
if (s === void 0)
|
|
1119
|
+
throw new Error(`Missing path value for "${o}" in route "${e}".`);
|
|
1120
|
+
return n ? String(s).split("/").filter(Boolean).map((a) => encodeURIComponent(a)).join("/") : encodeURIComponent(String(s));
|
|
1121
|
+
}
|
|
1122
|
+
) : e;
|
|
1123
|
+
}
|
|
1124
|
+
function Ln(e) {
|
|
1125
|
+
rr(e);
|
|
1126
|
+
const t = new Map(
|
|
1127
|
+
e.supportedLocales.map((i) => [i, A(i)])
|
|
1128
|
+
), r = (i) => {
|
|
1129
|
+
const c = e.supportedLocales.find((u) => u === i);
|
|
1130
|
+
if (!c) throw new Error(`The locale target "${i}" must be supported.`);
|
|
1131
|
+
return t.get(c) ?? c;
|
|
1132
|
+
}, o = e.path && Object.fromEntries(
|
|
1133
|
+
e.supportedLocales.map((i) => [
|
|
1134
|
+
A(i),
|
|
1135
|
+
e.path?.labels[i].toLowerCase()
|
|
1136
|
+
])
|
|
1137
|
+
), a = e.domains && Object.fromEntries(
|
|
1138
|
+
e.supportedLocales.flatMap((i) => {
|
|
1139
|
+
const c = e.domains?.[i];
|
|
1140
|
+
return c ? [[A(i), nr(c)]] : [];
|
|
1141
|
+
})
|
|
1142
|
+
);
|
|
1143
|
+
return {
|
|
1144
|
+
...e,
|
|
1145
|
+
aliases: e.aliases && Object.fromEntries(
|
|
1146
|
+
Object.entries(e.aliases).map(([i, c]) => [i.toLowerCase(), r(String(c))])
|
|
1147
|
+
),
|
|
1148
|
+
defaultLocale: r(e.defaultLocale),
|
|
1149
|
+
// TYPE-EVIDENCE: validation restricts each direction key to a supported TLocale value.
|
|
1150
|
+
directions: e.directions && Object.fromEntries(
|
|
1151
|
+
Object.entries(e.directions).map(([i, c]) => [
|
|
1152
|
+
A(i),
|
|
1153
|
+
c
|
|
1154
|
+
])
|
|
1155
|
+
),
|
|
1156
|
+
domains: a,
|
|
1157
|
+
path: e.path && {
|
|
1158
|
+
...e.path,
|
|
1159
|
+
labels: o,
|
|
1160
|
+
reserved: e.path.reserved?.map((i) => i.toLowerCase())
|
|
1161
|
+
},
|
|
1162
|
+
supportedLocales: e.supportedLocales.map(A),
|
|
1163
|
+
xDefault: e.xDefault && r(e.xDefault)
|
|
1164
|
+
};
|
|
1165
|
+
}
|
|
1166
|
+
function Pe(e, t) {
|
|
1167
|
+
const r = t?.directions?.[e];
|
|
1168
|
+
if (r) return r;
|
|
1169
|
+
const n = new Intl.Locale(e), o = n.textInfo?.direction;
|
|
1170
|
+
return o || (Nn.has(n.maximize().script ?? "") ? "rtl" : "ltr");
|
|
1171
|
+
}
|
|
1172
|
+
function Cn(e, t) {
|
|
1173
|
+
rr(t);
|
|
1174
|
+
const r = new URL(e.url), [n = "", ...o] = r.pathname.slice(1).split("/"), s = nt(n, t), a = t.path?.reserved?.some(
|
|
1175
|
+
(g) => g.toLowerCase() === n.toLowerCase()
|
|
1176
|
+
) ?? !1, i = Pn(r.hostname, t), c = Dn(e, t), u = On(e.headers.get("accept-language"), t), l = s ?? i ?? c ?? u ?? t.defaultLocale, d = s ? "path" : i ? "domain" : c ? "cookie" : u ? "accept-language" : "default", h = s || a ? `/${o.join("/")}`.replace(/\/$/, "") || "/" : r.pathname, f = tr(r, h, l, t), m = {
|
|
1177
|
+
locale: l,
|
|
1178
|
+
pathname: h,
|
|
1179
|
+
redirect: !a && f.href !== r.href ? f : void 0,
|
|
1180
|
+
source: d,
|
|
1181
|
+
unsupported: a
|
|
1182
|
+
}, w = t.resolver?.({
|
|
1183
|
+
configuration: t,
|
|
1184
|
+
defaultResolution: m,
|
|
1185
|
+
request: e
|
|
1186
|
+
}) ?? m;
|
|
1187
|
+
if (!t.supportedLocales.includes(w.locale))
|
|
1188
|
+
throw new Error(
|
|
1189
|
+
`The locale resolver returned unsupported locale ${JSON.stringify(w.locale)}.`
|
|
1190
|
+
);
|
|
1191
|
+
if (w.redirect && w.redirect.origin !== r.origin && !Object.values(t.domains ?? {}).includes(w.redirect.hostname))
|
|
1192
|
+
throw new Error("The locale resolver returned an external redirect.");
|
|
1193
|
+
return w;
|
|
1194
|
+
}
|
|
1195
|
+
function er(e, t, r, n = "http://demiurge.local") {
|
|
1196
|
+
const o = new URL(e, n), a = nt(o.pathname.slice(1).split("/")[0] ?? "", r) ? `/${o.pathname.slice(1).split("/").slice(1).join("/")}`.replace(/\/$/, "") || "/" : o.pathname, i = tr(o, a, t, r), c = new URL(n);
|
|
1197
|
+
return i.origin === c.origin ? `${i.pathname}${i.search}${i.hash}` : i.href;
|
|
1198
|
+
}
|
|
1199
|
+
function Li(e, t) {
|
|
1200
|
+
if (!t) return e;
|
|
1201
|
+
const r = e.slice(1).split("/");
|
|
1202
|
+
return nt(r[0] ?? "", t) ? `/${r.slice(1).join("/")}`.replace(/\/$/, "") || "/" : e;
|
|
1203
|
+
}
|
|
1204
|
+
function tr(e, t, r, n) {
|
|
1205
|
+
const o = new URL(e), s = n.path?.labels[r], a = s && (r !== n.defaultLocale || n.path?.prefixDefault);
|
|
1206
|
+
o.pathname = a ? `/${s}${t === "/" ? "" : t}` : t;
|
|
1207
|
+
const i = n.domains?.[r];
|
|
1208
|
+
return i && (o.hostname = i), o;
|
|
1209
|
+
}
|
|
1210
|
+
function nt(e, t) {
|
|
1211
|
+
const r = Object.entries(t.path?.labels ?? {}).find(([, n]) => String(n).toLowerCase() === e.toLowerCase());
|
|
1212
|
+
return r ? r[0] : Object.entries(t.aliases ?? {}).find(([n]) => n.toLowerCase() === e.toLowerCase())?.[1];
|
|
1213
|
+
}
|
|
1214
|
+
function Pn(e, t) {
|
|
1215
|
+
return Object.entries(t.domains ?? {}).find(([, r]) => String(r).toLowerCase() === e.toLowerCase())?.[0];
|
|
1216
|
+
}
|
|
1217
|
+
function Dn(e, t) {
|
|
1218
|
+
const r = t.cookie?.name;
|
|
1219
|
+
if (!r) return;
|
|
1220
|
+
const n = e.headers.get("cookie")?.split(";").map((o) => o.trim()).find((o) => o.startsWith(`${r}=`))?.slice(r.length + 1);
|
|
1221
|
+
return t.supportedLocales.find((o) => o === n);
|
|
1222
|
+
}
|
|
1223
|
+
function On(e, t) {
|
|
1224
|
+
if (!e) return;
|
|
1225
|
+
const r = e.split(",").map((n, o) => {
|
|
1226
|
+
const [s = "", ...a] = n.trim().split(";"), i = a.find((u) => u.trim().toLowerCase().startsWith("q=")), c = i ? Number(i.trim().slice(2)) : 1;
|
|
1227
|
+
return { order: o, q: c, tag: s.trim() };
|
|
1228
|
+
}).filter(({ q: n, tag: o }) => o !== "" && Number.isFinite(n) && n > 0 && n <= 1).sort((n, o) => o.q - n.q || n.order - o.order);
|
|
1229
|
+
for (const n of r) {
|
|
1230
|
+
if (n.tag === "*") return t.defaultLocale;
|
|
1231
|
+
let o = n.tag.toLowerCase();
|
|
1232
|
+
for (; o; ) {
|
|
1233
|
+
const s = t.supportedLocales.find((i) => i.toLowerCase() === o) ?? t.supportedLocales.find((i) => i.toLowerCase().startsWith(`${o}-`));
|
|
1234
|
+
if (s) return s;
|
|
1235
|
+
const a = o.lastIndexOf("-");
|
|
1236
|
+
if (a < 0) break;
|
|
1237
|
+
o = o.slice(0, a);
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
function rr(e) {
|
|
1242
|
+
if (e.supportedLocales.length === 0) throw new Error("Locale configuration requires at least one supported locale.");
|
|
1243
|
+
const t = e.supportedLocales.map(A);
|
|
1244
|
+
if (new Set(t).size !== t.length) throw new Error("Locale configuration contains duplicate canonical locales.");
|
|
1245
|
+
if (!t.includes(A(e.defaultLocale))) throw new Error("The default locale must be supported.");
|
|
1246
|
+
if (e.supportedLocales.length > 1 && !e.path && !e.domains) throw new Error("Multiple locales require a path or domain binding.");
|
|
1247
|
+
const r = new Set(t), n = (i, c) => {
|
|
1248
|
+
if (!r.has(A(i))) throw new Error(`The ${c} target "${i}" must be supported.`);
|
|
1249
|
+
}, o = /* @__PURE__ */ new Map(), s = (i, c) => {
|
|
1250
|
+
const u = i.toLowerCase(), l = o.get(u);
|
|
1251
|
+
if (l) throw new Error(`Locale ${c} "${i}" conflicts with ${l}.`);
|
|
1252
|
+
o.set(u, `${c} "${i}"`);
|
|
1253
|
+
};
|
|
1254
|
+
for (const [i, c] of Object.entries(e.path?.labels ?? {})) {
|
|
1255
|
+
if (n(i, "path label"), !/^[a-z0-9][a-z0-9-]*$/i.test(String(c))) throw new Error(`Locale path label "${c}" is invalid.`);
|
|
1256
|
+
s(String(c), "path label");
|
|
1257
|
+
}
|
|
1258
|
+
for (const [i, c] of Object.entries(e.aliases ?? {})) {
|
|
1259
|
+
if (n(String(c), "alias"), !/^[a-z0-9][a-z0-9-]*$/i.test(i)) throw new Error(`Locale alias "${i}" is invalid.`);
|
|
1260
|
+
s(i, "alias");
|
|
1261
|
+
}
|
|
1262
|
+
for (const i of e.path?.reserved ?? []) s(i, "reserved label");
|
|
1263
|
+
const a = /* @__PURE__ */ new Set();
|
|
1264
|
+
for (const [i, c] of Object.entries(e.domains ?? {})) {
|
|
1265
|
+
n(i, "domain");
|
|
1266
|
+
const u = nr(String(c));
|
|
1267
|
+
if (a.has(u)) throw new Error(`Locale domain "${c}" is duplicated.`);
|
|
1268
|
+
a.add(u);
|
|
1269
|
+
}
|
|
1270
|
+
for (const [i, c] of Object.entries(e.directions ?? {}))
|
|
1271
|
+
if (n(i, "direction"), c !== "ltr" && c !== "rtl")
|
|
1272
|
+
throw new Error(`Locale direction for "${i}" must be "ltr" or "rtl".`);
|
|
1273
|
+
if (e.cookie && !/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/.test(e.cookie.name))
|
|
1274
|
+
throw new Error("The locale cookie name is invalid.");
|
|
1275
|
+
e.xDefault && n(e.xDefault, "x-default");
|
|
1276
|
+
}
|
|
1277
|
+
function A(e) {
|
|
1278
|
+
const [t] = Intl.getCanonicalLocales(e);
|
|
1279
|
+
if (!t) throw new Error(`Locale "${e}" is invalid.`);
|
|
1280
|
+
return t;
|
|
1281
|
+
}
|
|
1282
|
+
const Nn = /* @__PURE__ */ new Set([
|
|
1283
|
+
"Adlm",
|
|
1284
|
+
"Arab",
|
|
1285
|
+
"Armi",
|
|
1286
|
+
"Avst",
|
|
1287
|
+
"Chrs",
|
|
1288
|
+
"Cprt",
|
|
1289
|
+
"Elym",
|
|
1290
|
+
"Gara",
|
|
1291
|
+
"Hatr",
|
|
1292
|
+
"Hebr",
|
|
1293
|
+
"Hung",
|
|
1294
|
+
"Khar",
|
|
1295
|
+
"Lydi",
|
|
1296
|
+
"Mand",
|
|
1297
|
+
"Mani",
|
|
1298
|
+
"Mend",
|
|
1299
|
+
"Merc",
|
|
1300
|
+
"Mero",
|
|
1301
|
+
"Narb",
|
|
1302
|
+
"Nbat",
|
|
1303
|
+
"Nkoo",
|
|
1304
|
+
"Orkh",
|
|
1305
|
+
"Ougr",
|
|
1306
|
+
"Palm",
|
|
1307
|
+
"Phli",
|
|
1308
|
+
"Phlp",
|
|
1309
|
+
"Phnx",
|
|
1310
|
+
"Prti",
|
|
1311
|
+
"Rohg",
|
|
1312
|
+
"Samr",
|
|
1313
|
+
"Sarb",
|
|
1314
|
+
"Sidt",
|
|
1315
|
+
"Sogd",
|
|
1316
|
+
"Sogo",
|
|
1317
|
+
"Syrc",
|
|
1318
|
+
"Thaa",
|
|
1319
|
+
"Yezi"
|
|
1320
|
+
]);
|
|
1321
|
+
function nr(e) {
|
|
1322
|
+
if (e.includes(":") || e.includes("/") || e.trim() !== e)
|
|
1323
|
+
throw new Error(`Locale domain "${e}" must be a hostname.`);
|
|
1324
|
+
const t = new URL(`https://${e}`).hostname.toLowerCase();
|
|
1325
|
+
if (!t || t !== e.toLowerCase()) throw new Error(`Locale domain "${e}" must be a hostname.`);
|
|
1326
|
+
return t;
|
|
1327
|
+
}
|
|
1328
|
+
function Ci(e, t) {
|
|
1329
|
+
return {
|
|
1330
|
+
cors: t?.cors,
|
|
1331
|
+
kind: "json",
|
|
1332
|
+
security: t?.security,
|
|
1333
|
+
timing: $(t?.timing),
|
|
1334
|
+
value: e,
|
|
1335
|
+
init: k(t)
|
|
1336
|
+
};
|
|
1337
|
+
}
|
|
1338
|
+
function Pi(e, t) {
|
|
1339
|
+
return {
|
|
1340
|
+
cors: t?.cors,
|
|
1341
|
+
init: k(t),
|
|
1342
|
+
kind: "jsonl",
|
|
1343
|
+
lines: e,
|
|
1344
|
+
security: t?.security,
|
|
1345
|
+
timing: $(t?.timing)
|
|
1346
|
+
};
|
|
1347
|
+
}
|
|
1348
|
+
function Di(e, t) {
|
|
1349
|
+
return {
|
|
1350
|
+
cors: t?.cors,
|
|
1351
|
+
kind: "text",
|
|
1352
|
+
security: t?.security,
|
|
1353
|
+
timing: $(t?.timing),
|
|
1354
|
+
value: e,
|
|
1355
|
+
init: k(t)
|
|
1356
|
+
};
|
|
1357
|
+
}
|
|
1358
|
+
function Oi(e, t) {
|
|
1359
|
+
return {
|
|
1360
|
+
cors: t?.cors,
|
|
1361
|
+
kind: "html",
|
|
1362
|
+
security: t?.security,
|
|
1363
|
+
timing: $(t?.timing),
|
|
1364
|
+
value: e,
|
|
1365
|
+
init: k(t)
|
|
1366
|
+
};
|
|
1367
|
+
}
|
|
1368
|
+
function Ni(e, t) {
|
|
1369
|
+
const r = typeof t == "number" ? void 0 : t;
|
|
1370
|
+
return {
|
|
1371
|
+
cors: r?.cors,
|
|
1372
|
+
kind: "redirect",
|
|
1373
|
+
security: r?.security,
|
|
1374
|
+
timing: $(r?.timing),
|
|
1375
|
+
to: Vn(e) ? Tn(e) : e,
|
|
1376
|
+
init: typeof t == "number" ? { status: t } : k(t)
|
|
1377
|
+
};
|
|
1378
|
+
}
|
|
1379
|
+
function Mi(e, t) {
|
|
1380
|
+
return {
|
|
1381
|
+
cors: t?.cors,
|
|
1382
|
+
kind: "not-found",
|
|
1383
|
+
security: t?.security,
|
|
1384
|
+
timing: $(t?.timing),
|
|
1385
|
+
body: e,
|
|
1386
|
+
init: k(t)
|
|
1387
|
+
};
|
|
1388
|
+
}
|
|
1389
|
+
function Mn(e, t) {
|
|
1390
|
+
return {
|
|
1391
|
+
cors: t?.cors,
|
|
1392
|
+
kind: "response",
|
|
1393
|
+
response: e,
|
|
1394
|
+
security: t?.security,
|
|
1395
|
+
timing: $(t?.timing)
|
|
1396
|
+
};
|
|
1397
|
+
}
|
|
1398
|
+
function ji(e, t) {
|
|
1399
|
+
return {
|
|
1400
|
+
body: e,
|
|
1401
|
+
cors: t?.cors,
|
|
1402
|
+
init: k(t),
|
|
1403
|
+
kind: "stream",
|
|
1404
|
+
security: t?.security,
|
|
1405
|
+
timing: $(t?.timing)
|
|
1406
|
+
};
|
|
1407
|
+
}
|
|
1408
|
+
function Ui(e, t) {
|
|
1409
|
+
return {
|
|
1410
|
+
cors: t?.cors,
|
|
1411
|
+
events: e,
|
|
1412
|
+
init: k(t),
|
|
1413
|
+
kind: "sse",
|
|
1414
|
+
security: t?.security,
|
|
1415
|
+
timing: $(t?.timing)
|
|
1416
|
+
};
|
|
1417
|
+
}
|
|
1418
|
+
function Ii(...e) {
|
|
1419
|
+
return e;
|
|
1420
|
+
}
|
|
1421
|
+
async function or(e, t) {
|
|
1422
|
+
switch (e.kind) {
|
|
1423
|
+
case "json":
|
|
1424
|
+
return new Response(JSON.stringify(await E(e.value, t)), {
|
|
1425
|
+
...e.init,
|
|
1426
|
+
headers: De(
|
|
1427
|
+
e.init?.headers,
|
|
1428
|
+
"content-type",
|
|
1429
|
+
"application/json; charset=utf-8"
|
|
1430
|
+
)
|
|
1431
|
+
});
|
|
1432
|
+
case "jsonl":
|
|
1433
|
+
return new Response(
|
|
1434
|
+
Un(await E(e.lines, t)),
|
|
1435
|
+
{
|
|
1436
|
+
...e.init,
|
|
1437
|
+
headers: he(e.init?.headers, {
|
|
1438
|
+
"cache-control": "no-cache",
|
|
1439
|
+
"content-type": "application/x-ndjson; charset=utf-8",
|
|
1440
|
+
"x-accel-buffering": "no"
|
|
1441
|
+
})
|
|
1442
|
+
}
|
|
1443
|
+
);
|
|
1444
|
+
case "text":
|
|
1445
|
+
return new Response(await E(e.value, t), {
|
|
1446
|
+
...e.init,
|
|
1447
|
+
headers: De(
|
|
1448
|
+
e.init?.headers,
|
|
1449
|
+
"content-type",
|
|
1450
|
+
"text/plain; charset=utf-8"
|
|
1451
|
+
)
|
|
1452
|
+
});
|
|
1453
|
+
case "html":
|
|
1454
|
+
return new Response(await E(e.value, t), {
|
|
1455
|
+
...e.init,
|
|
1456
|
+
headers: De(
|
|
1457
|
+
e.init?.headers,
|
|
1458
|
+
"content-type",
|
|
1459
|
+
"text/html; charset=utf-8"
|
|
1460
|
+
)
|
|
1461
|
+
});
|
|
1462
|
+
case "redirect": {
|
|
1463
|
+
const r = new Headers(e.init?.headers);
|
|
1464
|
+
return r.set("location", String(await E(e.to, t))), new Response(null, {
|
|
1465
|
+
...e.init,
|
|
1466
|
+
headers: r,
|
|
1467
|
+
status: e.init?.status ?? 302
|
|
1468
|
+
});
|
|
1469
|
+
}
|
|
1470
|
+
case "not-found":
|
|
1471
|
+
return new Response(
|
|
1472
|
+
e.body ? await E(e.body, t) : null,
|
|
1473
|
+
{
|
|
1474
|
+
...e.init,
|
|
1475
|
+
status: e.init?.status ?? 404
|
|
1476
|
+
}
|
|
1477
|
+
);
|
|
1478
|
+
case "response":
|
|
1479
|
+
return await E(e.response, t);
|
|
1480
|
+
case "stream":
|
|
1481
|
+
return new Response(
|
|
1482
|
+
In(await E(e.body, t)),
|
|
1483
|
+
{
|
|
1484
|
+
...e.init,
|
|
1485
|
+
headers: he(e.init?.headers, {
|
|
1486
|
+
"content-type": "application/octet-stream",
|
|
1487
|
+
"x-accel-buffering": "no"
|
|
1488
|
+
})
|
|
1489
|
+
}
|
|
1490
|
+
);
|
|
1491
|
+
case "sse":
|
|
1492
|
+
return new Response(
|
|
1493
|
+
jn(await E(e.events, t)),
|
|
1494
|
+
{
|
|
1495
|
+
...e.init,
|
|
1496
|
+
headers: he(e.init?.headers, {
|
|
1497
|
+
"cache-control": "no-cache",
|
|
1498
|
+
"content-type": "text/event-stream; charset=utf-8",
|
|
1499
|
+
"x-accel-buffering": "no"
|
|
1500
|
+
})
|
|
1501
|
+
}
|
|
1502
|
+
);
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
async function E(e, t) {
|
|
1506
|
+
return typeof e != "function" ? e : await e(
|
|
1507
|
+
t
|
|
1508
|
+
);
|
|
1509
|
+
}
|
|
1510
|
+
function De(e, t, r) {
|
|
1511
|
+
return he(e, { [t]: r });
|
|
1512
|
+
}
|
|
1513
|
+
function he(e, t) {
|
|
1514
|
+
const r = new Headers(e);
|
|
1515
|
+
for (const [n, o] of Object.entries(t))
|
|
1516
|
+
r.has(n) || r.set(n, o);
|
|
1517
|
+
return r;
|
|
1518
|
+
}
|
|
1519
|
+
function jn(e) {
|
|
1520
|
+
const t = new TextEncoder(), r = ot(e);
|
|
1521
|
+
return new ReadableStream({
|
|
1522
|
+
async pull(n) {
|
|
1523
|
+
const o = await r.next();
|
|
1524
|
+
if (o.done) {
|
|
1525
|
+
n.close();
|
|
1526
|
+
return;
|
|
1527
|
+
}
|
|
1528
|
+
n.enqueue(t.encode(Fn(o.value)));
|
|
1529
|
+
},
|
|
1530
|
+
async cancel() {
|
|
1531
|
+
await r.return?.();
|
|
1532
|
+
}
|
|
1533
|
+
});
|
|
1534
|
+
}
|
|
1535
|
+
function Un(e) {
|
|
1536
|
+
const t = new TextEncoder(), r = ot(e);
|
|
1537
|
+
return new ReadableStream({
|
|
1538
|
+
async pull(n) {
|
|
1539
|
+
const o = await r.next();
|
|
1540
|
+
if (o.done) {
|
|
1541
|
+
n.close();
|
|
1542
|
+
return;
|
|
1543
|
+
}
|
|
1544
|
+
n.enqueue(t.encode(`${JSON.stringify(o.value)}
|
|
1545
|
+
`));
|
|
1546
|
+
},
|
|
1547
|
+
async cancel() {
|
|
1548
|
+
await r.return?.();
|
|
1549
|
+
}
|
|
1550
|
+
});
|
|
1551
|
+
}
|
|
1552
|
+
function In(e) {
|
|
1553
|
+
const t = new TextEncoder(), r = ot(e);
|
|
1554
|
+
return new ReadableStream({
|
|
1555
|
+
async pull(n) {
|
|
1556
|
+
const o = await r.next();
|
|
1557
|
+
if (o.done) {
|
|
1558
|
+
n.close();
|
|
1559
|
+
return;
|
|
1560
|
+
}
|
|
1561
|
+
n.enqueue(zn(o.value, t));
|
|
1562
|
+
},
|
|
1563
|
+
async cancel() {
|
|
1564
|
+
await r.return?.();
|
|
1565
|
+
}
|
|
1566
|
+
});
|
|
1567
|
+
}
|
|
1568
|
+
function zn(e, t) {
|
|
1569
|
+
return typeof e == "string" ? t.encode(e) : e;
|
|
1570
|
+
}
|
|
1571
|
+
function ot(e) {
|
|
1572
|
+
if (e instanceof ReadableStream) {
|
|
1573
|
+
const t = e.getReader();
|
|
1574
|
+
return {
|
|
1575
|
+
async next() {
|
|
1576
|
+
return await t.read();
|
|
1577
|
+
},
|
|
1578
|
+
async return() {
|
|
1579
|
+
return t.releaseLock(), { done: !0, value: void 0 };
|
|
1580
|
+
}
|
|
1581
|
+
};
|
|
1582
|
+
}
|
|
1583
|
+
return Symbol.asyncIterator in e ? e[Symbol.asyncIterator]() : Hn(e[Symbol.iterator]());
|
|
1584
|
+
}
|
|
1585
|
+
function Hn(e) {
|
|
1586
|
+
return {
|
|
1587
|
+
async next() {
|
|
1588
|
+
return e.next();
|
|
1589
|
+
},
|
|
1590
|
+
async return() {
|
|
1591
|
+
return e.return?.(), { done: !0, value: void 0 };
|
|
1592
|
+
}
|
|
1593
|
+
};
|
|
1594
|
+
}
|
|
1595
|
+
function Fn(e) {
|
|
1596
|
+
if (typeof e == "string")
|
|
1597
|
+
return Wn(e);
|
|
1598
|
+
const t = [];
|
|
1599
|
+
if (e.comment !== void 0 && t.push(...K("", e.comment)), e.id !== void 0 && t.push(...K("id", e.id)), e.event !== void 0 && t.push(...K("event", e.event)), e.retry !== void 0) {
|
|
1600
|
+
if (!Number.isInteger(e.retry) || e.retry < 0)
|
|
1601
|
+
throw new Error("SSE retry must be a non-negative integer.");
|
|
1602
|
+
t.push(`retry: ${e.retry}`);
|
|
1603
|
+
}
|
|
1604
|
+
return e.data !== void 0 && t.push(...K("data", Bn(e.data))), `${t.join(`
|
|
1605
|
+
`)}
|
|
1606
|
+
|
|
1607
|
+
`;
|
|
1608
|
+
}
|
|
1609
|
+
function Wn(e) {
|
|
1610
|
+
return `${K("data", e).join(`
|
|
1611
|
+
`)}
|
|
1612
|
+
|
|
1613
|
+
`;
|
|
1614
|
+
}
|
|
1615
|
+
function K(e, t) {
|
|
1616
|
+
return t.split(/\r\n|\r|\n/).map(
|
|
1617
|
+
(r) => e ? `${e}: ${r}` : `: ${r}`
|
|
1618
|
+
);
|
|
1619
|
+
}
|
|
1620
|
+
function Bn(e) {
|
|
1621
|
+
return typeof e == "string" ? e : JSON.stringify(e);
|
|
1622
|
+
}
|
|
1623
|
+
function Vn(e) {
|
|
1624
|
+
return typeof e == "object" && e !== null && !(e instanceof URL) && "to" in e;
|
|
1625
|
+
}
|
|
1626
|
+
function k(e) {
|
|
1627
|
+
if (!e)
|
|
1628
|
+
return;
|
|
1629
|
+
const {
|
|
1630
|
+
cors: t,
|
|
1631
|
+
security: r,
|
|
1632
|
+
timing: n,
|
|
1633
|
+
...o
|
|
1634
|
+
} = e;
|
|
1635
|
+
return o;
|
|
1636
|
+
}
|
|
1637
|
+
function qn(e, t) {
|
|
1638
|
+
if (!t?.length)
|
|
1639
|
+
return e;
|
|
1640
|
+
const r = new Headers(e.headers), n = _n(t), o = r.get("server-timing");
|
|
1641
|
+
return r.set(
|
|
1642
|
+
"server-timing",
|
|
1643
|
+
o ? `${o}, ${n}` : n
|
|
1644
|
+
), new Response(e.body, {
|
|
1645
|
+
headers: r,
|
|
1646
|
+
status: e.status,
|
|
1647
|
+
statusText: e.statusText
|
|
1648
|
+
});
|
|
1649
|
+
}
|
|
1650
|
+
function _n(e) {
|
|
1651
|
+
return e.map(Gn).join(", ");
|
|
1652
|
+
}
|
|
1653
|
+
function $(e) {
|
|
1654
|
+
if (e)
|
|
1655
|
+
return Array.isArray(e) ? e : [e];
|
|
1656
|
+
}
|
|
1657
|
+
function Gn(e) {
|
|
1658
|
+
if (!Jn(e.name))
|
|
1659
|
+
throw new Error(
|
|
1660
|
+
`Server-Timing metric name "${e.name}" is not a valid token.`
|
|
1661
|
+
);
|
|
1662
|
+
const t = [e.name];
|
|
1663
|
+
if (e.duration !== void 0) {
|
|
1664
|
+
if (!Number.isFinite(e.duration) || e.duration < 0)
|
|
1665
|
+
throw new Error("Server-Timing metric duration must be a non-negative finite number.");
|
|
1666
|
+
t.push(`dur=${Kn(e.duration)}`);
|
|
1667
|
+
}
|
|
1668
|
+
return e.description !== void 0 && t.push(`desc="${Yn(e.description)}"`), t.join(";");
|
|
1669
|
+
}
|
|
1670
|
+
function Jn(e) {
|
|
1671
|
+
return /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/.test(e);
|
|
1672
|
+
}
|
|
1673
|
+
function Kn(e) {
|
|
1674
|
+
return Number.isInteger(e), String(e);
|
|
1675
|
+
}
|
|
1676
|
+
function Yn(e) {
|
|
1677
|
+
return e.replaceAll("\\", "\\\\").replaceAll('"', '\\"');
|
|
1678
|
+
}
|
|
1679
|
+
const Zn = "x-demiurge-mutation", Qn = "data;v=1", Ve = "application/vnd.demiurge.mutation+json;v=1";
|
|
1680
|
+
class sr extends Error {
|
|
1681
|
+
validation;
|
|
1682
|
+
constructor(t) {
|
|
1683
|
+
super("Mutation input validation failed."), this.name = "MutationValidationError", this.validation = {
|
|
1684
|
+
issues: t.issues.map((r) => ({
|
|
1685
|
+
...r,
|
|
1686
|
+
path: [...r.path]
|
|
1687
|
+
}))
|
|
1688
|
+
};
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
const W = "x-demiurge-revalidate-tags";
|
|
1692
|
+
function zi(e) {
|
|
1693
|
+
return {
|
|
1694
|
+
...Mn(
|
|
1695
|
+
async (r) => {
|
|
1696
|
+
let n;
|
|
1697
|
+
try {
|
|
1698
|
+
n = e.input ? await e.input(r) : void 0;
|
|
1699
|
+
} catch (u) {
|
|
1700
|
+
if (!(u instanceof sr)) throw u;
|
|
1701
|
+
return Xn(
|
|
1702
|
+
r.request,
|
|
1703
|
+
u.validation,
|
|
1704
|
+
r.pathname
|
|
1705
|
+
);
|
|
1706
|
+
}
|
|
1707
|
+
const o = {
|
|
1708
|
+
...r,
|
|
1709
|
+
input: n
|
|
1710
|
+
}, s = async () => {
|
|
1711
|
+
const u = await e.handler(o), l = u instanceof Response || u.kind === "response" || u.kind === "not-found", d = await oo(
|
|
1712
|
+
await to(u, r),
|
|
1713
|
+
r
|
|
1714
|
+
);
|
|
1715
|
+
return l || !qe(r.request) ? d : await eo(
|
|
1716
|
+
d,
|
|
1717
|
+
e.revalidateRoute === !0,
|
|
1718
|
+
r.pathname
|
|
1719
|
+
);
|
|
1720
|
+
};
|
|
1721
|
+
if (!e.idempotency) {
|
|
1722
|
+
const u = await s();
|
|
1723
|
+
if (!bt(u)) return u;
|
|
1724
|
+
const l = await Et(
|
|
1725
|
+
e.revalidate,
|
|
1726
|
+
o
|
|
1727
|
+
);
|
|
1728
|
+
return await Rt(
|
|
1729
|
+
u,
|
|
1730
|
+
l,
|
|
1731
|
+
r.pathname
|
|
1732
|
+
);
|
|
1733
|
+
}
|
|
1734
|
+
const a = typeof e.idempotency.key == "function" ? e.idempotency.key(o) : e.idempotency.key, i = await e.idempotency.store.run({
|
|
1735
|
+
fn: s,
|
|
1736
|
+
key: a,
|
|
1737
|
+
ttl: e.idempotency.ttl
|
|
1738
|
+
});
|
|
1739
|
+
if (i.replayed) return ro(i.value);
|
|
1740
|
+
if (!bt(i.value)) return i.value;
|
|
1741
|
+
const c = await Et(
|
|
1742
|
+
e.revalidate,
|
|
1743
|
+
o
|
|
1744
|
+
);
|
|
1745
|
+
return await Rt(
|
|
1746
|
+
i.value,
|
|
1747
|
+
c,
|
|
1748
|
+
r.pathname
|
|
1749
|
+
);
|
|
1750
|
+
},
|
|
1751
|
+
{
|
|
1752
|
+
cors: e.cors,
|
|
1753
|
+
security: e.security,
|
|
1754
|
+
timing: e.timing
|
|
1755
|
+
}
|
|
1756
|
+
),
|
|
1757
|
+
mutation: !0
|
|
1758
|
+
};
|
|
1759
|
+
}
|
|
1760
|
+
function qe(e) {
|
|
1761
|
+
return e.headers.get(Zn) === Qn;
|
|
1762
|
+
}
|
|
1763
|
+
function Xn(e, t, r) {
|
|
1764
|
+
const n = qe(e) ? { version: 1, status: "invalid", validation: t } : { type: "validation-error", validation: t }, o = pe(n, r);
|
|
1765
|
+
return qe(e) ? new Response(o, {
|
|
1766
|
+
headers: { "content-type": Ve },
|
|
1767
|
+
status: 400
|
|
1768
|
+
}) : new Response(o, {
|
|
1769
|
+
headers: { "content-type": "application/json; charset=utf-8" },
|
|
1770
|
+
status: 400
|
|
1771
|
+
});
|
|
1772
|
+
}
|
|
1773
|
+
async function eo(e, t, r) {
|
|
1774
|
+
if (e.status >= 300 && e.status < 400) {
|
|
1775
|
+
const o = e.headers.get("location");
|
|
1776
|
+
return o ? new Response(pe({
|
|
1777
|
+
version: 1,
|
|
1778
|
+
status: "redirect",
|
|
1779
|
+
location: o,
|
|
1780
|
+
history: e.status === 301 || e.status === 308 ? "replace" : "push"
|
|
1781
|
+
}, r), {
|
|
1782
|
+
headers: { "content-type": Ve },
|
|
1783
|
+
status: 200
|
|
1784
|
+
}) : e;
|
|
1785
|
+
}
|
|
1786
|
+
const n = e.headers.get("content-type")?.includes("json") ? await e.clone().json().catch(() => {
|
|
1787
|
+
}) : void 0;
|
|
1788
|
+
return new Response(pe({
|
|
1789
|
+
version: 1,
|
|
1790
|
+
status: e.ok ? "success" : "failed",
|
|
1791
|
+
...t && e.ok ? { revalidate: !0 } : {},
|
|
1792
|
+
...e.ok && n !== void 0 ? { data: n } : {}
|
|
1793
|
+
}, r), {
|
|
1794
|
+
headers: { "content-type": Ve },
|
|
1795
|
+
status: e.status
|
|
1796
|
+
});
|
|
1797
|
+
}
|
|
1798
|
+
async function to(e, t) {
|
|
1799
|
+
if (e instanceof Response || e.kind !== "json") return e;
|
|
1800
|
+
const r = typeof e.value == "function" ? await e.value(t) : e.value;
|
|
1801
|
+
return ge(r, t.pathname), { ...e, value: r };
|
|
1802
|
+
}
|
|
1803
|
+
function pe(e, t) {
|
|
1804
|
+
return ge(e, t), JSON.stringify(e);
|
|
1805
|
+
}
|
|
1806
|
+
function ge(e, t, r = [], n = /* @__PURE__ */ new Set()) {
|
|
1807
|
+
if (!(e === null || typeof e == "string" || typeof e == "boolean")) {
|
|
1808
|
+
if (typeof e == "number") {
|
|
1809
|
+
if (Number.isFinite(e)) return;
|
|
1810
|
+
throw L(t, r);
|
|
1811
|
+
}
|
|
1812
|
+
if (typeof e != "object" || n.has(e)) throw L(t, r);
|
|
1813
|
+
if (n.add(e), Array.isArray(e)) {
|
|
1814
|
+
for (const o of Reflect.ownKeys(e))
|
|
1815
|
+
if (o !== "length" && (typeof o != "string" || !/^(0|[1-9][0-9]*)$/.test(o)))
|
|
1816
|
+
throw L(t, [...r, String(o)]);
|
|
1817
|
+
for (let o = 0; o < e.length; o += 1) {
|
|
1818
|
+
if (!(o in e))
|
|
1819
|
+
throw L(t, [...r, String(o)]);
|
|
1820
|
+
ge(e[o], t, [...r, String(o)], n);
|
|
1821
|
+
}
|
|
1822
|
+
} else {
|
|
1823
|
+
const o = Object.getPrototypeOf(e);
|
|
1824
|
+
if (o !== Object.prototype && o !== null)
|
|
1825
|
+
throw L(t, r);
|
|
1826
|
+
for (const s of Reflect.ownKeys(e)) {
|
|
1827
|
+
if (typeof s != "string")
|
|
1828
|
+
throw L(t, [...r, "<symbol>"]);
|
|
1829
|
+
ge(
|
|
1830
|
+
Object.getOwnPropertyDescriptor(e, s)?.value,
|
|
1831
|
+
t,
|
|
1832
|
+
[...r, s],
|
|
1833
|
+
n
|
|
1834
|
+
);
|
|
1835
|
+
}
|
|
1836
|
+
}
|
|
1837
|
+
n.delete(e);
|
|
1838
|
+
}
|
|
1839
|
+
}
|
|
1840
|
+
function L(e, t) {
|
|
1841
|
+
const r = t.length === 0 ? "<root>" : t.join(".");
|
|
1842
|
+
return new Jt(
|
|
1843
|
+
`Route ${e} could not serialize the field ${r} for the browser. A mutation result contains a value that JSON cannot serialize.`,
|
|
1844
|
+
e,
|
|
1845
|
+
r
|
|
1846
|
+
);
|
|
1847
|
+
}
|
|
1848
|
+
function bt(e) {
|
|
1849
|
+
return e.status >= 200 && e.status < 400;
|
|
1850
|
+
}
|
|
1851
|
+
async function Et(e, t) {
|
|
1852
|
+
return e ? typeof e == "function" ? await e(t) : e : {};
|
|
1853
|
+
}
|
|
1854
|
+
async function Rt(e, t, r) {
|
|
1855
|
+
const n = new Headers(e.headers);
|
|
1856
|
+
n.delete(W);
|
|
1857
|
+
const o = t.keys ?? [], s = t.tags ?? [];
|
|
1858
|
+
return (o.length > 0 || s.length > 0) && n.set(
|
|
1859
|
+
W,
|
|
1860
|
+
encodeURIComponent(pe({
|
|
1861
|
+
keys: o,
|
|
1862
|
+
tags: s.map((a) => a.id),
|
|
1863
|
+
version: 1
|
|
1864
|
+
}, r))
|
|
1865
|
+
), new Response(e.body, {
|
|
1866
|
+
headers: n,
|
|
1867
|
+
status: e.status,
|
|
1868
|
+
statusText: e.statusText
|
|
1869
|
+
});
|
|
1870
|
+
}
|
|
1871
|
+
function ro(e) {
|
|
1872
|
+
if (!e.headers.has(W)) return e;
|
|
1873
|
+
const t = new Headers(e.headers);
|
|
1874
|
+
return t.delete(W), new Response(e.body, {
|
|
1875
|
+
headers: t,
|
|
1876
|
+
status: e.status,
|
|
1877
|
+
statusText: e.statusText
|
|
1878
|
+
});
|
|
1879
|
+
}
|
|
1880
|
+
const Hi = {
|
|
1881
|
+
custom(e) {
|
|
1882
|
+
return e;
|
|
1883
|
+
},
|
|
1884
|
+
form(e, t) {
|
|
1885
|
+
return async (n) => {
|
|
1886
|
+
const o = await n.request.formData(), s = await t(o, n), a = await e["~standard"].validate(s);
|
|
1887
|
+
if (a.issues)
|
|
1888
|
+
throw new sr({
|
|
1889
|
+
issues: a.issues.map((i) => ({
|
|
1890
|
+
code: "invalid",
|
|
1891
|
+
message: i.message,
|
|
1892
|
+
path: no(i.path)
|
|
1893
|
+
}))
|
|
1894
|
+
});
|
|
1895
|
+
return a.value;
|
|
1896
|
+
};
|
|
1897
|
+
},
|
|
1898
|
+
async formData({ request: e }) {
|
|
1899
|
+
return await e.formData();
|
|
1900
|
+
},
|
|
1901
|
+
async json({ request: e }) {
|
|
1902
|
+
return await e.json();
|
|
1903
|
+
},
|
|
1904
|
+
async text({ request: e }) {
|
|
1905
|
+
return await e.text();
|
|
1906
|
+
}
|
|
1907
|
+
};
|
|
1908
|
+
function no(e) {
|
|
1909
|
+
if (!e) return [];
|
|
1910
|
+
const t = e.map(
|
|
1911
|
+
(r) => typeof r == "object" ? r.key : r
|
|
1912
|
+
);
|
|
1913
|
+
return typeof t[0] != "string" ? [] : t.some(
|
|
1914
|
+
(r) => typeof r != "string" && typeof r != "number"
|
|
1915
|
+
) ? [] : t;
|
|
1916
|
+
}
|
|
1917
|
+
async function oo(e, t) {
|
|
1918
|
+
return e instanceof Response ? e : await or(e, t);
|
|
1919
|
+
}
|
|
1920
|
+
const so = [
|
|
1921
|
+
400,
|
|
1922
|
+
401,
|
|
1923
|
+
402,
|
|
1924
|
+
403,
|
|
1925
|
+
404,
|
|
1926
|
+
405,
|
|
1927
|
+
406,
|
|
1928
|
+
407,
|
|
1929
|
+
408,
|
|
1930
|
+
409,
|
|
1931
|
+
410,
|
|
1932
|
+
411,
|
|
1933
|
+
412,
|
|
1934
|
+
413,
|
|
1935
|
+
414,
|
|
1936
|
+
415,
|
|
1937
|
+
416,
|
|
1938
|
+
417,
|
|
1939
|
+
418,
|
|
1940
|
+
421,
|
|
1941
|
+
422,
|
|
1942
|
+
423,
|
|
1943
|
+
424,
|
|
1944
|
+
425,
|
|
1945
|
+
426,
|
|
1946
|
+
428,
|
|
1947
|
+
429,
|
|
1948
|
+
431,
|
|
1949
|
+
451,
|
|
1950
|
+
500,
|
|
1951
|
+
501,
|
|
1952
|
+
502,
|
|
1953
|
+
503,
|
|
1954
|
+
504,
|
|
1955
|
+
505,
|
|
1956
|
+
506,
|
|
1957
|
+
507,
|
|
1958
|
+
508,
|
|
1959
|
+
510,
|
|
1960
|
+
511
|
|
1961
|
+
], ao = {
|
|
1962
|
+
400: "Bad Request",
|
|
1963
|
+
401: "Unauthorized",
|
|
1964
|
+
402: "Payment Required",
|
|
1965
|
+
403: "Forbidden",
|
|
1966
|
+
404: "Not Found",
|
|
1967
|
+
405: "Method Not Allowed",
|
|
1968
|
+
406: "Not Acceptable",
|
|
1969
|
+
407: "Proxy Authentication Required",
|
|
1970
|
+
408: "Request Timeout",
|
|
1971
|
+
409: "Conflict",
|
|
1972
|
+
410: "Gone",
|
|
1973
|
+
411: "Length Required",
|
|
1974
|
+
412: "Precondition Failed",
|
|
1975
|
+
413: "Content Too Large",
|
|
1976
|
+
414: "URI Too Long",
|
|
1977
|
+
415: "Unsupported Media Type",
|
|
1978
|
+
416: "Range Not Satisfiable",
|
|
1979
|
+
417: "Expectation Failed",
|
|
1980
|
+
418: "I'm a Teapot",
|
|
1981
|
+
421: "Misdirected Request",
|
|
1982
|
+
422: "Unprocessable Content",
|
|
1983
|
+
423: "Locked",
|
|
1984
|
+
424: "Failed Dependency",
|
|
1985
|
+
425: "Too Early",
|
|
1986
|
+
426: "Upgrade Required",
|
|
1987
|
+
428: "Precondition Required",
|
|
1988
|
+
429: "Too Many Requests",
|
|
1989
|
+
431: "Request Header Fields Too Large",
|
|
1990
|
+
451: "Unavailable For Legal Reasons",
|
|
1991
|
+
500: "Internal Server Error",
|
|
1992
|
+
501: "Not Implemented",
|
|
1993
|
+
502: "Bad Gateway",
|
|
1994
|
+
503: "Service Unavailable",
|
|
1995
|
+
504: "Gateway Timeout",
|
|
1996
|
+
505: "HTTP Version Not Supported",
|
|
1997
|
+
506: "Variant Also Negotiates",
|
|
1998
|
+
507: "Insufficient Storage",
|
|
1999
|
+
508: "Loop Detected",
|
|
2000
|
+
510: "Not Extended",
|
|
2001
|
+
511: "Network Authentication Required"
|
|
2002
|
+
}, io = new Set(so);
|
|
2003
|
+
class ar extends Error {
|
|
2004
|
+
detail;
|
|
2005
|
+
extensions;
|
|
2006
|
+
headers;
|
|
2007
|
+
status;
|
|
2008
|
+
title;
|
|
2009
|
+
type;
|
|
2010
|
+
constructor(t, r = {}, n = {}) {
|
|
2011
|
+
co(t);
|
|
2012
|
+
const o = typeof r == "string" ? { detail: r } : r, {
|
|
2013
|
+
detail: s,
|
|
2014
|
+
title: a = ao[t],
|
|
2015
|
+
type: i = "about:blank",
|
|
2016
|
+
...c
|
|
2017
|
+
} = o;
|
|
2018
|
+
super(s ?? a, { cause: n.cause }), this.name = "HttpError", this.detail = s, this.extensions = Object.freeze({ ...c }), this.headers = new Headers(n.headers), this.status = t, this.title = a, this.type = i;
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
function Fi(e, t, r) {
|
|
2022
|
+
return new ar(e, t, r);
|
|
2023
|
+
}
|
|
2024
|
+
function j(e) {
|
|
2025
|
+
return e instanceof ar;
|
|
2026
|
+
}
|
|
2027
|
+
function co(e) {
|
|
2028
|
+
if (!io.has(e))
|
|
2029
|
+
throw new RangeError(
|
|
2030
|
+
`HTTP error status must be a standard 4xx or 5xx status; received ${JSON.stringify(e)}.`
|
|
2031
|
+
);
|
|
2032
|
+
}
|
|
2033
|
+
function Tt({ pathname: e }) {
|
|
2034
|
+
return /* @__PURE__ */ X("main", { children: [
|
|
2035
|
+
/* @__PURE__ */ ee("h1", { children: "404" }),
|
|
2036
|
+
/* @__PURE__ */ X("p", { children: [
|
|
2037
|
+
"No route matched ",
|
|
2038
|
+
e,
|
|
2039
|
+
"."
|
|
2040
|
+
] })
|
|
2041
|
+
] });
|
|
2042
|
+
}
|
|
2043
|
+
function $t({ status: e }) {
|
|
2044
|
+
return /* @__PURE__ */ X("main", { children: [
|
|
2045
|
+
/* @__PURE__ */ ee("h1", { children: e }),
|
|
2046
|
+
/* @__PURE__ */ ee("p", { children: "Something went wrong." })
|
|
2047
|
+
] });
|
|
2048
|
+
}
|
|
2049
|
+
function uo({ error: e, pathname: t, status: r }) {
|
|
2050
|
+
const { message: n, name: o, stack: s } = st(e);
|
|
2051
|
+
return /* @__PURE__ */ X("main", { children: [
|
|
2052
|
+
/* @__PURE__ */ X("h1", { children: [
|
|
2053
|
+
r,
|
|
2054
|
+
" ",
|
|
2055
|
+
o,
|
|
2056
|
+
" at ",
|
|
2057
|
+
t
|
|
2058
|
+
] }),
|
|
2059
|
+
/* @__PURE__ */ ee("p", { children: n }),
|
|
2060
|
+
s ? /* @__PURE__ */ ee("pre", { children: s }) : null
|
|
2061
|
+
] });
|
|
2062
|
+
}
|
|
2063
|
+
function st(e) {
|
|
2064
|
+
return e instanceof Error ? {
|
|
2065
|
+
message: e.message,
|
|
2066
|
+
name: e.name,
|
|
2067
|
+
stack: e.stack
|
|
2068
|
+
} : {
|
|
2069
|
+
message: typeof e == "string" ? e : String(e),
|
|
2070
|
+
name: "Error",
|
|
2071
|
+
stack: void 0
|
|
2072
|
+
};
|
|
2073
|
+
}
|
|
2074
|
+
const lo = ["text/html", "application/xhtml+xml"];
|
|
2075
|
+
function ir(e) {
|
|
2076
|
+
return fo(e.headers.get("accept"));
|
|
2077
|
+
}
|
|
2078
|
+
function fo(e) {
|
|
2079
|
+
return e ? ho(e).some(
|
|
2080
|
+
(t) => t.quality > 0 && lo.includes(t.type)
|
|
2081
|
+
) : !1;
|
|
2082
|
+
}
|
|
2083
|
+
function ho(e) {
|
|
2084
|
+
return e.split(",").flatMap((t) => {
|
|
2085
|
+
const [r, ...n] = t.split(";"), o = r.trim().toLowerCase();
|
|
2086
|
+
return o ? [
|
|
2087
|
+
{
|
|
2088
|
+
quality: mo(n),
|
|
2089
|
+
type: o
|
|
2090
|
+
}
|
|
2091
|
+
] : [];
|
|
2092
|
+
});
|
|
2093
|
+
}
|
|
2094
|
+
function mo(e) {
|
|
2095
|
+
for (const t of e) {
|
|
2096
|
+
const [r, n] = t.split("=");
|
|
2097
|
+
if (r?.trim().toLowerCase() !== "q")
|
|
2098
|
+
continue;
|
|
2099
|
+
const o = Number.parseFloat(n ?? "");
|
|
2100
|
+
return Number.isNaN(o) ? 1 : o;
|
|
2101
|
+
}
|
|
2102
|
+
return 1;
|
|
2103
|
+
}
|
|
2104
|
+
const po = "application/problem+json";
|
|
2105
|
+
function go({
|
|
2106
|
+
detail: e,
|
|
2107
|
+
instance: t,
|
|
2108
|
+
status: r,
|
|
2109
|
+
title: n,
|
|
2110
|
+
type: o = "about:blank",
|
|
2111
|
+
...s
|
|
2112
|
+
}) {
|
|
2113
|
+
return {
|
|
2114
|
+
type: o,
|
|
2115
|
+
title: n,
|
|
2116
|
+
status: r,
|
|
2117
|
+
...e === void 0 ? {} : { detail: e },
|
|
2118
|
+
...t === void 0 ? {} : { instance: t },
|
|
2119
|
+
...s
|
|
2120
|
+
};
|
|
2121
|
+
}
|
|
2122
|
+
function te(e, t) {
|
|
2123
|
+
const r = new Headers(t?.headers);
|
|
2124
|
+
return r.set("content-type", `${po}; charset=utf-8`), new Response(JSON.stringify(go(e)), {
|
|
2125
|
+
...t,
|
|
2126
|
+
headers: r,
|
|
2127
|
+
status: e.status
|
|
2128
|
+
});
|
|
2129
|
+
}
|
|
2130
|
+
const wo = "Internal Server Error";
|
|
2131
|
+
function at(e) {
|
|
2132
|
+
return e === !0 && process.env.NODE_ENV !== "production";
|
|
2133
|
+
}
|
|
2134
|
+
async function me(e, t, r, n, o = {}) {
|
|
2135
|
+
o.onError?.(r, n);
|
|
2136
|
+
const s = new URL(t.url);
|
|
2137
|
+
if (!(F(t) || n === "page" || n === "middleware" && ir(t)))
|
|
2138
|
+
return yo(s, r, o);
|
|
2139
|
+
if (F(t)) {
|
|
2140
|
+
const i = st(r), c = j(r) ? new Headers(r.headers) : new Headers();
|
|
2141
|
+
return rt(void 0, {
|
|
2142
|
+
document: Je({
|
|
2143
|
+
dir: o.dir,
|
|
2144
|
+
lang: o.lang,
|
|
2145
|
+
metadata: T(),
|
|
2146
|
+
title: o.title
|
|
2147
|
+
}),
|
|
2148
|
+
locale: o.locale,
|
|
2149
|
+
error: {
|
|
2150
|
+
detail: j(r) ? r.detail : at(o.dev) ? i.message : void 0,
|
|
2151
|
+
title: j(r) ? r.title : "Internal Server Error"
|
|
2152
|
+
},
|
|
2153
|
+
headers: c,
|
|
2154
|
+
kind: fe,
|
|
2155
|
+
status: it(r)
|
|
2156
|
+
});
|
|
2157
|
+
}
|
|
2158
|
+
return await vo(e, s, r, o);
|
|
2159
|
+
}
|
|
2160
|
+
function yo(e, t, r = {}) {
|
|
2161
|
+
if (j(t))
|
|
2162
|
+
return te(
|
|
2163
|
+
{
|
|
2164
|
+
...t.extensions,
|
|
2165
|
+
detail: t.detail,
|
|
2166
|
+
instance: `${e.pathname}${e.search}`,
|
|
2167
|
+
status: t.status,
|
|
2168
|
+
title: t.title,
|
|
2169
|
+
type: t.type
|
|
2170
|
+
},
|
|
2171
|
+
{ headers: t.headers }
|
|
2172
|
+
);
|
|
2173
|
+
const { message: n } = st(t);
|
|
2174
|
+
return te({
|
|
2175
|
+
// `detail` carries the thrown message, so it is dev only for the same
|
|
2176
|
+
// reason the stack is.
|
|
2177
|
+
...at(r.dev) ? { detail: n } : {},
|
|
2178
|
+
instance: `${e.pathname}${e.search}`,
|
|
2179
|
+
status: 500,
|
|
2180
|
+
title: "Internal Server Error"
|
|
2181
|
+
});
|
|
2182
|
+
}
|
|
2183
|
+
async function vo(e, t, r, n) {
|
|
2184
|
+
const o = it(r);
|
|
2185
|
+
try {
|
|
2186
|
+
const s = await bo(
|
|
2187
|
+
e,
|
|
2188
|
+
n.pathname ?? t.pathname,
|
|
2189
|
+
r,
|
|
2190
|
+
n
|
|
2191
|
+
), a = j(r) ? new Headers(r.headers) : new Headers();
|
|
2192
|
+
return a.set("content-type", "text/html; charset=utf-8"), new Response(await n.transformDocument?.(s) ?? s, {
|
|
2193
|
+
headers: a,
|
|
2194
|
+
status: o
|
|
2195
|
+
});
|
|
2196
|
+
} catch (s) {
|
|
2197
|
+
return n.onError?.(s, "page"), So();
|
|
2198
|
+
}
|
|
2199
|
+
}
|
|
2200
|
+
function So() {
|
|
2201
|
+
return new Response(wo, {
|
|
2202
|
+
headers: { "content-type": "text/plain; charset=utf-8" },
|
|
2203
|
+
status: 500
|
|
2204
|
+
});
|
|
2205
|
+
}
|
|
2206
|
+
async function bo(e, t, r, n) {
|
|
2207
|
+
const o = await Eo(e, t, n), s = Ft({
|
|
2208
|
+
dev: n.dev,
|
|
2209
|
+
nonce: n.nonce
|
|
2210
|
+
}), a = Vt(
|
|
2211
|
+
Wt(
|
|
2212
|
+
s,
|
|
2213
|
+
Ie(o, { error: r, locale: n.locale, pathname: t, status: it(r) })
|
|
2214
|
+
)
|
|
2215
|
+
);
|
|
2216
|
+
return Bt({
|
|
2217
|
+
body: { data: void 0, html: a, locale: n.locale, navigation: n.navigation },
|
|
2218
|
+
entrySrc: n.clientEntry,
|
|
2219
|
+
lang: n.lang,
|
|
2220
|
+
nonce: n.nonce,
|
|
2221
|
+
scripts: s.scripts(),
|
|
2222
|
+
styles: n.styles,
|
|
2223
|
+
title: n.title
|
|
2224
|
+
});
|
|
2225
|
+
}
|
|
2226
|
+
function it(e) {
|
|
2227
|
+
return j(e) ? e.status : 500;
|
|
2228
|
+
}
|
|
2229
|
+
async function Eo(e, t, r) {
|
|
2230
|
+
if (at(r.dev))
|
|
2231
|
+
return uo;
|
|
2232
|
+
try {
|
|
2233
|
+
return await ln(e, t) ?? $t;
|
|
2234
|
+
} catch {
|
|
2235
|
+
return $t;
|
|
2236
|
+
}
|
|
2237
|
+
}
|
|
2238
|
+
const Ro = 403;
|
|
2239
|
+
function Wi(e) {
|
|
2240
|
+
return e;
|
|
2241
|
+
}
|
|
2242
|
+
function cr(e) {
|
|
2243
|
+
const t = [], r = [];
|
|
2244
|
+
let n = !1, o = Ro;
|
|
2245
|
+
for (const { policy: s, source: a } of e)
|
|
2246
|
+
s && (s.replaces && (n = !0, t.length = 0, r.push({
|
|
2247
|
+
...s.replaces,
|
|
2248
|
+
source: s.replaces.source ?? a
|
|
2249
|
+
})), s.public && (n = !0), s.denyStatus && (o = s.denyStatus), s.authorize && (n = !0, t.push({ authorize: s.authorize, source: a })));
|
|
2250
|
+
return {
|
|
2251
|
+
chain: t,
|
|
2252
|
+
declared: n,
|
|
2253
|
+
denyStatus: o,
|
|
2254
|
+
exceptions: r,
|
|
2255
|
+
public: n && t.length === 0
|
|
2256
|
+
};
|
|
2257
|
+
}
|
|
2258
|
+
function To(e) {
|
|
2259
|
+
return cr(e.map((t) => ({ policy: t })));
|
|
2260
|
+
}
|
|
2261
|
+
async function xt(e, t) {
|
|
2262
|
+
if (!e.declared)
|
|
2263
|
+
return Oe(
|
|
2264
|
+
e.denyStatus,
|
|
2265
|
+
"Forbidden. This route inherits no access declaration."
|
|
2266
|
+
);
|
|
2267
|
+
for (const r of e.chain) {
|
|
2268
|
+
let n;
|
|
2269
|
+
try {
|
|
2270
|
+
n = await r.authorize(t);
|
|
2271
|
+
} catch {
|
|
2272
|
+
return Oe(e.denyStatus);
|
|
2273
|
+
}
|
|
2274
|
+
if (!$o(n))
|
|
2275
|
+
return Oe(xo(n, e.denyStatus));
|
|
2276
|
+
}
|
|
2277
|
+
return null;
|
|
2278
|
+
}
|
|
2279
|
+
function $o(e) {
|
|
2280
|
+
return e === !0 ? !0 : oe(e) && e.allow === !0;
|
|
2281
|
+
}
|
|
2282
|
+
function xo(e, t) {
|
|
2283
|
+
return oe(e) && Ao(e.status) ? e.status : t;
|
|
2284
|
+
}
|
|
2285
|
+
function Ao(e) {
|
|
2286
|
+
return e === 401 || e === 403 || e === 404;
|
|
2287
|
+
}
|
|
2288
|
+
function Oe(e, t = ko(e)) {
|
|
2289
|
+
return new Response(t, {
|
|
2290
|
+
headers: {
|
|
2291
|
+
"cache-control": "private, no-store",
|
|
2292
|
+
"content-type": "text/plain; charset=utf-8"
|
|
2293
|
+
},
|
|
2294
|
+
status: e
|
|
2295
|
+
});
|
|
2296
|
+
}
|
|
2297
|
+
function ko(e) {
|
|
2298
|
+
return e === 401 ? "Unauthorized." : e === 404 ? "Not Found." : "Forbidden.";
|
|
2299
|
+
}
|
|
2300
|
+
function P(e) {
|
|
2301
|
+
return oe(e) && typeof e.reason == "string" && "value" in e;
|
|
2302
|
+
}
|
|
2303
|
+
function S(e) {
|
|
2304
|
+
return P(e) ? !1 : e;
|
|
2305
|
+
}
|
|
2306
|
+
function ur(e) {
|
|
2307
|
+
return P(e) ? e : void 0;
|
|
2308
|
+
}
|
|
2309
|
+
function Lo(e) {
|
|
2310
|
+
return P(e) ? !1 : e;
|
|
2311
|
+
}
|
|
2312
|
+
function lr(e) {
|
|
2313
|
+
return P(e) ? e : void 0;
|
|
2314
|
+
}
|
|
2315
|
+
function ct(e) {
|
|
2316
|
+
return P(e) ? e.value : e;
|
|
2317
|
+
}
|
|
2318
|
+
function dr(e) {
|
|
2319
|
+
return P(e) ? e : void 0;
|
|
2320
|
+
}
|
|
2321
|
+
function Co(e, t) {
|
|
2322
|
+
if (!e || !t)
|
|
2323
|
+
return e;
|
|
2324
|
+
const r = Po(e.document, t), n = Do(e.security, t);
|
|
2325
|
+
return r === e.document && n === e.security ? e : { ...e, document: r, security: n };
|
|
2326
|
+
}
|
|
2327
|
+
function Po(e, t) {
|
|
2328
|
+
const r = ur(e?.csp);
|
|
2329
|
+
return !e || !r || r.source ? e : { ...e, csp: { ...r, source: t } };
|
|
2330
|
+
}
|
|
2331
|
+
function Do(e, t) {
|
|
2332
|
+
if (!e)
|
|
2333
|
+
return e;
|
|
2334
|
+
const r = lr(e.csrf), n = dr(e.request?.maxBodySize);
|
|
2335
|
+
return (!r || r.source) && (!n || n.source) ? e : {
|
|
2336
|
+
...e,
|
|
2337
|
+
csrf: r && !r.source ? { ...r, source: t } : e.csrf,
|
|
2338
|
+
request: n && !n.source ? { ...e.request, maxBodySize: { ...n, source: t } } : e.request
|
|
2339
|
+
};
|
|
2340
|
+
}
|
|
2341
|
+
const we = "{nonce}", At = `'nonce-${we}'`, fr = {
|
|
2342
|
+
baseUri: ["'self'"],
|
|
2343
|
+
connectSrc: ["'self'"],
|
|
2344
|
+
defaultSrc: ["'self'"],
|
|
2345
|
+
fontSrc: ["'self'"],
|
|
2346
|
+
formAction: ["'self'"],
|
|
2347
|
+
frameAncestors: ["'none'"],
|
|
2348
|
+
imgSrc: ["'self'", "data:", "blob:"],
|
|
2349
|
+
objectSrc: ["'none'"],
|
|
2350
|
+
scriptSrc: [At, "'strict-dynamic'"],
|
|
2351
|
+
styleSrc: ["'self'", At],
|
|
2352
|
+
upgradeInsecureRequests: !0
|
|
2353
|
+
}, Oo = {
|
|
2354
|
+
...fr,
|
|
2355
|
+
scriptSrc: ["'self'"],
|
|
2356
|
+
styleSrc: ["'self'"]
|
|
2357
|
+
}, kt = {
|
|
2358
|
+
contentTypeOptions: "nosniff",
|
|
2359
|
+
crossOriginOpenerPolicy: "same-origin",
|
|
2360
|
+
crossOriginResourcePolicy: "same-origin",
|
|
2361
|
+
permissionsPolicy: "camera=(), microphone=(), geolocation=(), payment=()",
|
|
2362
|
+
referrerPolicy: "strict-origin-when-cross-origin",
|
|
2363
|
+
strictTransportSecurity: {
|
|
2364
|
+
includeSubDomains: !1,
|
|
2365
|
+
maxAge: 31536e3,
|
|
2366
|
+
preload: !1
|
|
2367
|
+
}
|
|
2368
|
+
}, No = {
|
|
2369
|
+
contentTypeOptions: "nosniff",
|
|
2370
|
+
crossOriginResourcePolicy: "same-origin",
|
|
2371
|
+
referrerPolicy: "strict-origin-when-cross-origin"
|
|
2372
|
+
}, J = {
|
|
2373
|
+
api(e = {}) {
|
|
2374
|
+
return Y(
|
|
2375
|
+
{
|
|
2376
|
+
headers: No
|
|
2377
|
+
},
|
|
2378
|
+
e
|
|
2379
|
+
);
|
|
2380
|
+
},
|
|
2381
|
+
preset(e, t = {}) {
|
|
2382
|
+
return e === "api" ? J.api(t) : e === "cross-origin-isolated" ? J.crossOriginIsolated(t) : e === "static" ? J.static(t) : J.strict(t);
|
|
2383
|
+
},
|
|
2384
|
+
static(e = {}) {
|
|
2385
|
+
return Y(
|
|
2386
|
+
{
|
|
2387
|
+
csp: Oo,
|
|
2388
|
+
headers: kt
|
|
2389
|
+
},
|
|
2390
|
+
e
|
|
2391
|
+
);
|
|
2392
|
+
},
|
|
2393
|
+
strict(e = {}) {
|
|
2394
|
+
return Y(
|
|
2395
|
+
{
|
|
2396
|
+
csp: fr,
|
|
2397
|
+
headers: kt
|
|
2398
|
+
},
|
|
2399
|
+
e
|
|
2400
|
+
);
|
|
2401
|
+
},
|
|
2402
|
+
crossOriginIsolated(e = {}) {
|
|
2403
|
+
return Y(
|
|
2404
|
+
J.strict({
|
|
2405
|
+
headers: {
|
|
2406
|
+
crossOriginEmbedderPolicy: "require-corp",
|
|
2407
|
+
crossOriginOpenerPolicy: "same-origin"
|
|
2408
|
+
}
|
|
2409
|
+
}),
|
|
2410
|
+
e
|
|
2411
|
+
);
|
|
2412
|
+
}
|
|
2413
|
+
};
|
|
2414
|
+
function Bi(e) {
|
|
2415
|
+
return e;
|
|
2416
|
+
}
|
|
2417
|
+
function Vi(e) {
|
|
2418
|
+
return e;
|
|
2419
|
+
}
|
|
2420
|
+
function Mo(...e) {
|
|
2421
|
+
return e.reduce((t, r) => r ? Y(t, r) : t, {});
|
|
2422
|
+
}
|
|
2423
|
+
function ye(...e) {
|
|
2424
|
+
const t = e.reduce((r, n) => n ? {
|
|
2425
|
+
document: Mo(r.document, n.document),
|
|
2426
|
+
security: jo(r.security, n.security)
|
|
2427
|
+
} : r, {});
|
|
2428
|
+
return {
|
|
2429
|
+
...t,
|
|
2430
|
+
access: To(
|
|
2431
|
+
e.map((r) => r ? r.access : void 0)
|
|
2432
|
+
),
|
|
2433
|
+
document: Io(t.document, t.security?.needs)
|
|
2434
|
+
};
|
|
2435
|
+
}
|
|
2436
|
+
function jo(...e) {
|
|
2437
|
+
return e.reduce((t, r) => r ? {
|
|
2438
|
+
csrf: r.csrf ?? t.csrf,
|
|
2439
|
+
fetchMetadata: r.fetchMetadata ?? t.fetchMetadata,
|
|
2440
|
+
needs: Uo(t.needs, r.needs),
|
|
2441
|
+
rateLimit: r.rateLimit ?? t.rateLimit,
|
|
2442
|
+
request: pr(t.request, r.request)
|
|
2443
|
+
} : t, {});
|
|
2444
|
+
}
|
|
2445
|
+
const hr = [
|
|
2446
|
+
{ directive: "connectSrc", need: "connect" },
|
|
2447
|
+
{ directive: "imgSrc", need: "img" },
|
|
2448
|
+
{ directive: "scriptSrc", need: "script" }
|
|
2449
|
+
];
|
|
2450
|
+
function Uo(e, t) {
|
|
2451
|
+
const r = {};
|
|
2452
|
+
for (const { need: n } of hr) {
|
|
2453
|
+
const o = [.../* @__PURE__ */ new Set([
|
|
2454
|
+
...e?.[n] ?? [],
|
|
2455
|
+
...t?.[n] ?? []
|
|
2456
|
+
])];
|
|
2457
|
+
o.length > 0 && (r[n] = o);
|
|
2458
|
+
}
|
|
2459
|
+
return Object.keys(r).length > 0 ? r : void 0;
|
|
2460
|
+
}
|
|
2461
|
+
function Io(e, t) {
|
|
2462
|
+
const r = S(e?.csp);
|
|
2463
|
+
if (!e || !r || !t)
|
|
2464
|
+
return e;
|
|
2465
|
+
let n = r;
|
|
2466
|
+
for (const { directive: o, need: s } of hr)
|
|
2467
|
+
n = zo(n, o, s, t[s]);
|
|
2468
|
+
return n === r ? e : { ...e, csp: n };
|
|
2469
|
+
}
|
|
2470
|
+
function zo(e, t, r, n) {
|
|
2471
|
+
if (!n || n.length === 0)
|
|
2472
|
+
return e;
|
|
2473
|
+
if (e[t] === !1)
|
|
2474
|
+
throw new Error(
|
|
2475
|
+
`A route policy declares security.needs.${r} and sets csp.${t} to false. Set an explicit csp.${t} that includes ${n.join(", ")}.`
|
|
2476
|
+
);
|
|
2477
|
+
if (e[t] === void 0 && e.defaultSrc === void 0)
|
|
2478
|
+
return e;
|
|
2479
|
+
const o = D(
|
|
2480
|
+
e[t] ?? e.defaultSrc
|
|
2481
|
+
) ?? [];
|
|
2482
|
+
return Array.isArray(o) ? {
|
|
2483
|
+
...e,
|
|
2484
|
+
[t]: [.../* @__PURE__ */ new Set([...o, ...n])]
|
|
2485
|
+
} : e;
|
|
2486
|
+
}
|
|
2487
|
+
async function qi(e, t = "sha256") {
|
|
2488
|
+
const r = await globalThis.crypto.subtle.digest(
|
|
2489
|
+
es(t),
|
|
2490
|
+
new TextEncoder().encode(e)
|
|
2491
|
+
);
|
|
2492
|
+
return `'${t}-${ts(new Uint8Array(r))}'`;
|
|
2493
|
+
}
|
|
2494
|
+
function se(e, t = {}) {
|
|
2495
|
+
const r = S(e.csp);
|
|
2496
|
+
r && Zo(r), Yo(e);
|
|
2497
|
+
const n = new Headers(), o = r ? Go(r, t) : void 0, s = Vo(e.trustedTypes), a = e.trustedTypes ? e.trustedTypes.mode === "report-only" : !1;
|
|
2498
|
+
return R(
|
|
2499
|
+
n,
|
|
2500
|
+
"content-security-policy",
|
|
2501
|
+
ve(o, a ? void 0 : s)
|
|
2502
|
+
), R(
|
|
2503
|
+
n,
|
|
2504
|
+
"content-security-policy-report-only",
|
|
2505
|
+
a ? ve(s, wr(r)) : void 0
|
|
2506
|
+
), Bo(n, e.headers, t), n;
|
|
2507
|
+
}
|
|
2508
|
+
function $e(e) {
|
|
2509
|
+
const t = e ? S(e.csp) : void 0;
|
|
2510
|
+
return t ? ae(t).some(([, r]) => {
|
|
2511
|
+
const n = D(r);
|
|
2512
|
+
return Array.isArray(n) && n.some((o) => o.includes(we));
|
|
2513
|
+
}) : !1;
|
|
2514
|
+
}
|
|
2515
|
+
function mr() {
|
|
2516
|
+
const e = new Uint8Array(16);
|
|
2517
|
+
return globalThis.crypto.getRandomValues(e), btoa(String.fromCharCode(...e));
|
|
2518
|
+
}
|
|
2519
|
+
function Y(e, t) {
|
|
2520
|
+
return {
|
|
2521
|
+
csp: Fo(e.csp, t.csp),
|
|
2522
|
+
headers: Ho(e.headers, t.headers),
|
|
2523
|
+
trustedTypes: t.trustedTypes ?? e.trustedTypes
|
|
2524
|
+
};
|
|
2525
|
+
}
|
|
2526
|
+
function Ho(e, t) {
|
|
2527
|
+
const r = pr(e, t);
|
|
2528
|
+
return !r || t?.reportingEndpoints === !1 || e?.reportingEndpoints && t?.reportingEndpoints && (r.reportingEndpoints = {
|
|
2529
|
+
...e.reportingEndpoints,
|
|
2530
|
+
...t.reportingEndpoints
|
|
2531
|
+
}), r;
|
|
2532
|
+
}
|
|
2533
|
+
function pr(e, t) {
|
|
2534
|
+
return t ? {
|
|
2535
|
+
...e ?? {},
|
|
2536
|
+
...t
|
|
2537
|
+
} : e;
|
|
2538
|
+
}
|
|
2539
|
+
function Fo(e, t) {
|
|
2540
|
+
if (P(t))
|
|
2541
|
+
return t;
|
|
2542
|
+
if (!t)
|
|
2543
|
+
return e;
|
|
2544
|
+
const r = S(e);
|
|
2545
|
+
if (!r)
|
|
2546
|
+
return Ne(t);
|
|
2547
|
+
const n = Ne(r), o = Ne(t), s = {
|
|
2548
|
+
...n,
|
|
2549
|
+
...o
|
|
2550
|
+
};
|
|
2551
|
+
for (const [a, i] of ae(t)) {
|
|
2552
|
+
const c = D(
|
|
2553
|
+
n[a]
|
|
2554
|
+
);
|
|
2555
|
+
!ut(i) && Array.isArray(c) && Array.isArray(i) && gr(
|
|
2556
|
+
s,
|
|
2557
|
+
a,
|
|
2558
|
+
Wo([...c, ...i])
|
|
2559
|
+
);
|
|
2560
|
+
}
|
|
2561
|
+
return s;
|
|
2562
|
+
}
|
|
2563
|
+
function Ne(e) {
|
|
2564
|
+
const t = { ...e };
|
|
2565
|
+
for (const [r, n] of ae(e))
|
|
2566
|
+
ut(n) && gr(t, r, n.replace);
|
|
2567
|
+
return t;
|
|
2568
|
+
}
|
|
2569
|
+
function Wo(e) {
|
|
2570
|
+
return [...new Set(e)];
|
|
2571
|
+
}
|
|
2572
|
+
function gr(e, t, r) {
|
|
2573
|
+
if (!(t === "reportTo" || t === "upgradeInsecureRequests")) {
|
|
2574
|
+
if (t === "reportUri") {
|
|
2575
|
+
e.reportUri = r;
|
|
2576
|
+
return;
|
|
2577
|
+
}
|
|
2578
|
+
e[t] = r;
|
|
2579
|
+
}
|
|
2580
|
+
}
|
|
2581
|
+
function Bo(e, t, r) {
|
|
2582
|
+
t && (R(e, "referrer-policy", t.referrerPolicy), R(e, "x-content-type-options", t.contentTypeOptions), R(e, "cross-origin-opener-policy", t.crossOriginOpenerPolicy), R(e, "cross-origin-embedder-policy", t.crossOriginEmbedderPolicy), R(e, "cross-origin-resource-policy", t.crossOriginResourcePolicy), R(e, "permissions-policy", t.permissionsPolicy), R(
|
|
2583
|
+
e,
|
|
2584
|
+
"reporting-endpoints",
|
|
2585
|
+
Jo(t.reportingEndpoints)
|
|
2586
|
+
), t.strictTransportSecurity && (!r.request || new URL(r.request.url).protocol === "https:") && e.set(
|
|
2587
|
+
"strict-transport-security",
|
|
2588
|
+
_o(t.strictTransportSecurity)
|
|
2589
|
+
));
|
|
2590
|
+
}
|
|
2591
|
+
function Vo(e) {
|
|
2592
|
+
if (!e)
|
|
2593
|
+
return;
|
|
2594
|
+
const t = [];
|
|
2595
|
+
return e.requireFor?.includes("script") && t.push("require-trusted-types-for 'script'"), t.push(qo(e)), ve(...t);
|
|
2596
|
+
}
|
|
2597
|
+
function qo(e) {
|
|
2598
|
+
if (e.policies !== void 0 && e.policies.length === 0)
|
|
2599
|
+
return "trusted-types 'none'";
|
|
2600
|
+
const t = [jr];
|
|
2601
|
+
e.allowDefaultPolicy && t.push("default");
|
|
2602
|
+
for (const r of e.policies ?? [])
|
|
2603
|
+
t.push(r);
|
|
2604
|
+
return `trusted-types ${[...new Set(t)].join(" ")}`;
|
|
2605
|
+
}
|
|
2606
|
+
function ve(...e) {
|
|
2607
|
+
const t = e.filter((r) => r);
|
|
2608
|
+
return t.length > 0 ? t.join("; ") : void 0;
|
|
2609
|
+
}
|
|
2610
|
+
function R(e, t, r) {
|
|
2611
|
+
r && e.set(t, r);
|
|
2612
|
+
}
|
|
2613
|
+
function _o(e) {
|
|
2614
|
+
const t = [`max-age=${e.maxAge}`];
|
|
2615
|
+
return e.includeSubDomains && t.push("includeSubDomains"), e.preload && t.push("preload"), t.join("; ");
|
|
2616
|
+
}
|
|
2617
|
+
function Go(e, t) {
|
|
2618
|
+
const r = [];
|
|
2619
|
+
for (const [o, s] of ae(e)) {
|
|
2620
|
+
if (o === "reportTo" || o === "reportUri")
|
|
2621
|
+
continue;
|
|
2622
|
+
const a = D(s);
|
|
2623
|
+
if (a === !1 || a === void 0)
|
|
2624
|
+
continue;
|
|
2625
|
+
const i = yr(o);
|
|
2626
|
+
if (a === !0 || o === "sandbox" && Array.isArray(a) && a.length === 0) {
|
|
2627
|
+
r.push(i);
|
|
2628
|
+
continue;
|
|
2629
|
+
}
|
|
2630
|
+
r.push(
|
|
2631
|
+
`${i} ${Xo(a, t).join(" ")}`
|
|
2632
|
+
);
|
|
2633
|
+
}
|
|
2634
|
+
const n = wr(e);
|
|
2635
|
+
return n && r.push(n), r.join("; ");
|
|
2636
|
+
}
|
|
2637
|
+
function wr(e) {
|
|
2638
|
+
if (!e)
|
|
2639
|
+
return;
|
|
2640
|
+
const t = [], r = D(e.reportUri);
|
|
2641
|
+
return Array.isArray(r) && r.length && t.push(`report-uri ${r.join(" ")}`), e.reportTo && t.push(`report-to ${e.reportTo}`), ve(...t);
|
|
2642
|
+
}
|
|
2643
|
+
function Jo(e) {
|
|
2644
|
+
if (e)
|
|
2645
|
+
return Object.entries(e).sort(([t], [r]) => t.localeCompare(r)).map(([t, r]) => `${t}="${Ko(r)}"`).join(", ");
|
|
2646
|
+
}
|
|
2647
|
+
function Ko(e) {
|
|
2648
|
+
return e.replaceAll("\\", "\\\\").replaceAll('"', '\\"');
|
|
2649
|
+
}
|
|
2650
|
+
function Yo(e) {
|
|
2651
|
+
const t = e.headers?.reportingEndpoints;
|
|
2652
|
+
if (t) {
|
|
2653
|
+
const o = Object.entries(t);
|
|
2654
|
+
if (o.length === 0)
|
|
2655
|
+
throw new Error("Demiurge Reporting-Endpoints requires at least one endpoint.");
|
|
2656
|
+
for (const [s, a] of o)
|
|
2657
|
+
Lt(s), Ct(a, `Reporting-Endpoints member ${JSON.stringify(s)}`);
|
|
2658
|
+
}
|
|
2659
|
+
const r = S(e.csp) || void 0;
|
|
2660
|
+
if (r?.reportTo && (Lt(r.reportTo), !t || !(r.reportTo in t)))
|
|
2661
|
+
throw new Error(
|
|
2662
|
+
`Demiurge CSP report-to group ${JSON.stringify(r.reportTo)} is not defined in headers.reportingEndpoints.`
|
|
2663
|
+
);
|
|
2664
|
+
const n = D(r?.reportUri);
|
|
2665
|
+
for (const o of Array.isArray(n) ? n : [])
|
|
2666
|
+
Ct(o, "CSP report-uri target");
|
|
2667
|
+
}
|
|
2668
|
+
function Zo(e) {
|
|
2669
|
+
for (const [t, r] of ae(e)) {
|
|
2670
|
+
const n = yr(t);
|
|
2671
|
+
if (r === void 0)
|
|
2672
|
+
continue;
|
|
2673
|
+
if (t === "reportTo") {
|
|
2674
|
+
if (typeof r != "string")
|
|
2675
|
+
throw new Error(
|
|
2676
|
+
`Demiurge CSP directive ${JSON.stringify(n)} must be a string.`
|
|
2677
|
+
);
|
|
2678
|
+
continue;
|
|
2679
|
+
}
|
|
2680
|
+
if (t === "upgradeInsecureRequests") {
|
|
2681
|
+
if (typeof r != "boolean")
|
|
2682
|
+
throw new Error(
|
|
2683
|
+
`Demiurge CSP directive ${JSON.stringify(n)} must be a boolean.`
|
|
2684
|
+
);
|
|
2685
|
+
continue;
|
|
2686
|
+
}
|
|
2687
|
+
if (t === "sandbox") {
|
|
2688
|
+
if (typeof r != "boolean" && (!Array.isArray(r) || !r.every((s) => typeof s == "string")))
|
|
2689
|
+
throw new Error(
|
|
2690
|
+
`Demiurge CSP directive ${JSON.stringify(n)} must be a boolean or a list of sandbox tokens.`
|
|
2691
|
+
);
|
|
2692
|
+
continue;
|
|
2693
|
+
}
|
|
2694
|
+
const o = D(r);
|
|
2695
|
+
if (o !== !1 && (!Array.isArray(o) || !o.every((s) => typeof s == "string")))
|
|
2696
|
+
throw new Error(
|
|
2697
|
+
`Demiurge CSP directive ${JSON.stringify(n)} must be a source list, false, or a replacement object with a source list.`
|
|
2698
|
+
);
|
|
2699
|
+
}
|
|
2700
|
+
}
|
|
2701
|
+
function ut(e) {
|
|
2702
|
+
return !!(e && typeof e == "object" && !Array.isArray(e) && "replace" in e);
|
|
2703
|
+
}
|
|
2704
|
+
function D(e) {
|
|
2705
|
+
return ut(e) ? e.replace : e;
|
|
2706
|
+
}
|
|
2707
|
+
function Lt(e) {
|
|
2708
|
+
if (!/^(?:[a-z]|\*)[a-z0-9_.*-]*$/.test(e))
|
|
2709
|
+
throw new Error(
|
|
2710
|
+
`Invalid reporting endpoint name ${JSON.stringify(e)}. Use a lowercase Structured Field key.`
|
|
2711
|
+
);
|
|
2712
|
+
}
|
|
2713
|
+
function Ct(e, t) {
|
|
2714
|
+
if (!Qo(e) || /[\s,;"\\]/.test(e) || !e.startsWith("/") && !e.startsWith("https://"))
|
|
2715
|
+
throw new Error(`${t} must be a same-origin path or an HTTPS URL.`);
|
|
2716
|
+
if (e.startsWith("//"))
|
|
2717
|
+
throw new Error(`${t} must not be a scheme-relative URL.`);
|
|
2718
|
+
let r;
|
|
2719
|
+
try {
|
|
2720
|
+
r = new URL(e, "https://demiurge.invalid");
|
|
2721
|
+
} catch {
|
|
2722
|
+
throw new Error(`${t} must be a valid URI reference.`);
|
|
2723
|
+
}
|
|
2724
|
+
if (r.username || r.password || r.hash)
|
|
2725
|
+
throw new Error(`${t} must not contain credentials or a fragment.`);
|
|
2726
|
+
}
|
|
2727
|
+
function Qo(e) {
|
|
2728
|
+
return /^[\x20-\x7e]+$/.test(e);
|
|
2729
|
+
}
|
|
2730
|
+
function ae(e) {
|
|
2731
|
+
return Object.entries(e);
|
|
2732
|
+
}
|
|
2733
|
+
function Xo(e, t) {
|
|
2734
|
+
return e.map((r) => {
|
|
2735
|
+
if (!r.includes(we))
|
|
2736
|
+
return r;
|
|
2737
|
+
if (!t.nonce)
|
|
2738
|
+
throw new Error("Demiurge security policy requires a CSP nonce.");
|
|
2739
|
+
return r.replaceAll(we, t.nonce);
|
|
2740
|
+
});
|
|
2741
|
+
}
|
|
2742
|
+
function yr(e) {
|
|
2743
|
+
return e.replace(/[A-Z]/g, (t) => `-${t.toLowerCase()}`);
|
|
2744
|
+
}
|
|
2745
|
+
function es(e) {
|
|
2746
|
+
return e === "sha384" ? "SHA-384" : e === "sha512" ? "SHA-512" : "SHA-256";
|
|
2747
|
+
}
|
|
2748
|
+
function ts(e) {
|
|
2749
|
+
let t = "";
|
|
2750
|
+
for (const r of e)
|
|
2751
|
+
t += String.fromCharCode(r);
|
|
2752
|
+
return typeof btoa == "function" ? btoa(t) : Buffer.from(t, "binary").toString("base64");
|
|
2753
|
+
}
|
|
2754
|
+
function vr(e, t, r = {}) {
|
|
2755
|
+
lt(e);
|
|
2756
|
+
const n = t.request.headers.get("origin"), o = new Headers();
|
|
2757
|
+
if (e.origins !== "*" && Sr(o, "Origin"), !n)
|
|
2758
|
+
return o;
|
|
2759
|
+
const s = os(e, n);
|
|
2760
|
+
if (!s)
|
|
2761
|
+
return o;
|
|
2762
|
+
if (o.set("access-control-allow-origin", s), e.credentials && o.set("access-control-allow-credentials", "true"), e.exposeHeaders?.length && o.set("access-control-expose-headers", e.exposeHeaders.join(", ")), r.preflight) {
|
|
2763
|
+
o.set("access-control-allow-methods", r.methods.join(", "));
|
|
2764
|
+
const a = t.request.headers.get(
|
|
2765
|
+
"access-control-request-headers"
|
|
2766
|
+
), i = e.headers?.join(", ") ?? a;
|
|
2767
|
+
i && o.set("access-control-allow-headers", i), e.maxAge !== void 0 && o.set("access-control-max-age", String(e.maxAge));
|
|
2768
|
+
}
|
|
2769
|
+
return o;
|
|
2770
|
+
}
|
|
2771
|
+
function Z(e, t, r) {
|
|
2772
|
+
if (!t)
|
|
2773
|
+
return e;
|
|
2774
|
+
const n = new Headers(e.headers);
|
|
2775
|
+
return ss(n, vr(t, { request: r })), new Response(e.body, {
|
|
2776
|
+
headers: n,
|
|
2777
|
+
status: e.status,
|
|
2778
|
+
statusText: e.statusText
|
|
2779
|
+
});
|
|
2780
|
+
}
|
|
2781
|
+
function rs(e, t) {
|
|
2782
|
+
const r = t.headers.get("access-control-request-method"), n = as(r);
|
|
2783
|
+
if (!n)
|
|
2784
|
+
return null;
|
|
2785
|
+
const o = br(e, n);
|
|
2786
|
+
if (!o?.cors)
|
|
2787
|
+
return null;
|
|
2788
|
+
const s = o.cors.methods ?? is(e);
|
|
2789
|
+
return s.includes(n) ? new Response(null, {
|
|
2790
|
+
headers: vr(
|
|
2791
|
+
o.cors,
|
|
2792
|
+
{ request: t },
|
|
2793
|
+
{
|
|
2794
|
+
methods: s,
|
|
2795
|
+
preflight: !0
|
|
2796
|
+
}
|
|
2797
|
+
),
|
|
2798
|
+
status: 204
|
|
2799
|
+
}) : null;
|
|
2800
|
+
}
|
|
2801
|
+
function lt(e) {
|
|
2802
|
+
if (e.credentials && e.origins === "*")
|
|
2803
|
+
throw new Error(
|
|
2804
|
+
"Demiurge CORS policy cannot use wildcard origins with credentials."
|
|
2805
|
+
);
|
|
2806
|
+
if (e.credentials && (e.headers?.includes("*") || e.exposeHeaders?.includes("*")))
|
|
2807
|
+
throw new Error(
|
|
2808
|
+
"Demiurge credentialed CORS policy must list allowed and exposed headers explicitly."
|
|
2809
|
+
);
|
|
2810
|
+
if (e.origins !== "*")
|
|
2811
|
+
for (const t of e.origins)
|
|
2812
|
+
ns(t);
|
|
2813
|
+
if (e.maxAge !== void 0 && (!Number.isSafeInteger(e.maxAge) || e.maxAge < 0))
|
|
2814
|
+
throw new Error(
|
|
2815
|
+
"Demiurge CORS maxAge must be a non-negative integer number of seconds."
|
|
2816
|
+
);
|
|
2817
|
+
}
|
|
2818
|
+
function ns(e) {
|
|
2819
|
+
let t;
|
|
2820
|
+
try {
|
|
2821
|
+
t = new URL(e);
|
|
2822
|
+
} catch {
|
|
2823
|
+
throw Pt(e);
|
|
2824
|
+
}
|
|
2825
|
+
if (t.protocol !== "http:" && t.protocol !== "https:" || t.origin !== e)
|
|
2826
|
+
throw Pt(e);
|
|
2827
|
+
}
|
|
2828
|
+
function Pt(e) {
|
|
2829
|
+
return new Error(
|
|
2830
|
+
`Demiurge CORS origin ${JSON.stringify(e)} must be a canonical HTTP(S) origin without credentials, a path, query, or fragment.`
|
|
2831
|
+
);
|
|
2832
|
+
}
|
|
2833
|
+
function os(e, t) {
|
|
2834
|
+
return e.origins === "*" ? "*" : e.origins.includes(t) ? t : null;
|
|
2835
|
+
}
|
|
2836
|
+
function ss(e, t) {
|
|
2837
|
+
t.forEach((r, n) => {
|
|
2838
|
+
if (n === "vary" && e.has("vary")) {
|
|
2839
|
+
for (const o of r.split(","))
|
|
2840
|
+
Sr(e, o.trim());
|
|
2841
|
+
return;
|
|
2842
|
+
}
|
|
2843
|
+
e.set(n, r);
|
|
2844
|
+
});
|
|
2845
|
+
}
|
|
2846
|
+
function Sr(e, t) {
|
|
2847
|
+
if (!t)
|
|
2848
|
+
return;
|
|
2849
|
+
const r = e.get("vary")?.split(",").map((n) => n.trim()).filter(Boolean) ?? [];
|
|
2850
|
+
r.some((n) => n.toLowerCase() === t.toLowerCase()) || e.set("vary", [...r, t].join(", "));
|
|
2851
|
+
}
|
|
2852
|
+
function as(e) {
|
|
2853
|
+
if (!e)
|
|
2854
|
+
return null;
|
|
2855
|
+
const t = e.toUpperCase();
|
|
2856
|
+
return cs(t) ? t : null;
|
|
2857
|
+
}
|
|
2858
|
+
function br(e, t) {
|
|
2859
|
+
return t === "HEAD" ? e.HEAD ?? Dt(e.GET) : Dt(e[t]);
|
|
2860
|
+
}
|
|
2861
|
+
function Dt(e) {
|
|
2862
|
+
return e?.kind === "page" ? void 0 : e;
|
|
2863
|
+
}
|
|
2864
|
+
function is(e) {
|
|
2865
|
+
return [
|
|
2866
|
+
"GET",
|
|
2867
|
+
"POST",
|
|
2868
|
+
"PUT",
|
|
2869
|
+
"PATCH",
|
|
2870
|
+
"DELETE",
|
|
2871
|
+
"OPTIONS",
|
|
2872
|
+
"HEAD"
|
|
2873
|
+
].filter((t) => br(e, t));
|
|
2874
|
+
}
|
|
2875
|
+
function cs(e) {
|
|
2876
|
+
return e === "GET" || e === "POST" || e === "PUT" || e === "PATCH" || e === "DELETE" || e === "OPTIONS" || e === "HEAD";
|
|
2877
|
+
}
|
|
2878
|
+
const us = {
|
|
2879
|
+
b: 1,
|
|
2880
|
+
gb: 1024 ** 3,
|
|
2881
|
+
kb: 1024,
|
|
2882
|
+
mb: 1024 ** 2
|
|
2883
|
+
}, dt = "1mb";
|
|
2884
|
+
function ls(e, t, r) {
|
|
2885
|
+
const n = fs(e, r);
|
|
2886
|
+
if (n)
|
|
2887
|
+
return n;
|
|
2888
|
+
const o = t.headers.get("content-length");
|
|
2889
|
+
if (!o)
|
|
2890
|
+
return null;
|
|
2891
|
+
const s = hs(o);
|
|
2892
|
+
if (s === null)
|
|
2893
|
+
return new Response("Invalid Content-Length.", {
|
|
2894
|
+
status: 400
|
|
2895
|
+
});
|
|
2896
|
+
const a = Se(ct(e?.maxBodySize) ?? dt);
|
|
2897
|
+
return s > a ? new Response("Request body too large.", {
|
|
2898
|
+
status: 413
|
|
2899
|
+
}) : null;
|
|
2900
|
+
}
|
|
2901
|
+
class Q extends Error {
|
|
2902
|
+
constructor() {
|
|
2903
|
+
super("Demiurge request body exceeded maxBodySize while being read."), this.name = "RequestBodyTooLargeError";
|
|
2904
|
+
}
|
|
2905
|
+
}
|
|
2906
|
+
function ds(e, t) {
|
|
2907
|
+
if (t.body === null)
|
|
2908
|
+
return t;
|
|
2909
|
+
const r = Se(ct(e?.maxBodySize) ?? dt), n = t.body.getReader();
|
|
2910
|
+
let o = 0;
|
|
2911
|
+
const s = new ReadableStream({
|
|
2912
|
+
async pull(i) {
|
|
2913
|
+
const c = await n.read();
|
|
2914
|
+
if (c.done) {
|
|
2915
|
+
i.close();
|
|
2916
|
+
return;
|
|
2917
|
+
}
|
|
2918
|
+
if (o += c.value.byteLength, o > r) {
|
|
2919
|
+
const u = new Q();
|
|
2920
|
+
i.error(u);
|
|
2921
|
+
try {
|
|
2922
|
+
await n.cancel(u);
|
|
2923
|
+
} catch {
|
|
2924
|
+
}
|
|
2925
|
+
return;
|
|
2926
|
+
}
|
|
2927
|
+
i.enqueue(c.value);
|
|
2928
|
+
},
|
|
2929
|
+
async cancel(i) {
|
|
2930
|
+
try {
|
|
2931
|
+
await n.cancel(i);
|
|
2932
|
+
} catch {
|
|
2933
|
+
}
|
|
2934
|
+
}
|
|
2935
|
+
}), a = new Request(t, {
|
|
2936
|
+
body: s,
|
|
2937
|
+
duplex: "half"
|
|
2938
|
+
});
|
|
2939
|
+
return Ur(t, a), a;
|
|
2940
|
+
}
|
|
2941
|
+
function ue() {
|
|
2942
|
+
return new Response("Request body too large.", { status: 413 });
|
|
2943
|
+
}
|
|
2944
|
+
function fs(e, t) {
|
|
2945
|
+
return !e?.allowedMethods || ms(e.allowedMethods, t) ? null : new Response(null, {
|
|
2946
|
+
headers: {
|
|
2947
|
+
allow: ps(e.allowedMethods)
|
|
2948
|
+
},
|
|
2949
|
+
status: 405
|
|
2950
|
+
});
|
|
2951
|
+
}
|
|
2952
|
+
function Se(e) {
|
|
2953
|
+
if (typeof e == "number") {
|
|
2954
|
+
if (!Number.isSafeInteger(e) || e < 0)
|
|
2955
|
+
throw new Error("Demiurge request maxBodySize must be a non-negative integer.");
|
|
2956
|
+
return e;
|
|
2957
|
+
}
|
|
2958
|
+
const t = /^(\d+)(b|kb|mb|gb)$/i.exec(e.trim());
|
|
2959
|
+
if (!t)
|
|
2960
|
+
throw new Error(
|
|
2961
|
+
"Demiurge request maxBodySize must use bytes or a b/kb/mb/gb suffix."
|
|
2962
|
+
);
|
|
2963
|
+
const r = Number(t[1]), n = t[2].toLowerCase(), o = r * us[n];
|
|
2964
|
+
if (!Number.isSafeInteger(o))
|
|
2965
|
+
throw new Error("Demiurge request maxBodySize is too large.");
|
|
2966
|
+
return o;
|
|
2967
|
+
}
|
|
2968
|
+
function hs(e) {
|
|
2969
|
+
if (!/^\d+$/.test(e))
|
|
2970
|
+
return null;
|
|
2971
|
+
const t = Number(e);
|
|
2972
|
+
return Number.isSafeInteger(t) ? t : null;
|
|
2973
|
+
}
|
|
2974
|
+
function ms(e, t) {
|
|
2975
|
+
return e.includes(t) || t === "HEAD" && e.includes("GET");
|
|
2976
|
+
}
|
|
2977
|
+
function ps(e) {
|
|
2978
|
+
const t = [...e];
|
|
2979
|
+
return t.includes("GET") && !t.includes("HEAD") && t.push("HEAD"), t.join(", ");
|
|
2980
|
+
}
|
|
2981
|
+
const gs = /* @__PURE__ */ new Set(["DELETE", "PATCH", "POST", "PUT"]);
|
|
2982
|
+
function ws(e = {}) {
|
|
2983
|
+
const t = [], r = e.document, n = r ? bs(r.policy, r.headers, t) : {};
|
|
2984
|
+
r && (ys(r.policy, t), vs(r.policy, t));
|
|
2985
|
+
const o = e.route ? Cs(e.route, t) : void 0;
|
|
2986
|
+
return r?.scripts && (Es(
|
|
2987
|
+
S(r.policy.csp),
|
|
2988
|
+
r.scripts,
|
|
2989
|
+
r.headers,
|
|
2990
|
+
t
|
|
2991
|
+
), r.scriptDependencies && t.push(
|
|
2992
|
+
...Ss(
|
|
2993
|
+
r.scripts,
|
|
2994
|
+
Rs(r.scriptDependencies)
|
|
2995
|
+
)
|
|
2996
|
+
)), {
|
|
2997
|
+
findings: t,
|
|
2998
|
+
headers: n,
|
|
2999
|
+
route: o
|
|
3000
|
+
};
|
|
3001
|
+
}
|
|
3002
|
+
function ys(e, t) {
|
|
3003
|
+
const r = ur(e.csp);
|
|
3004
|
+
if (r) {
|
|
3005
|
+
t.push({
|
|
3006
|
+
code: "csp-disabled",
|
|
3007
|
+
message: `This document accepts no Content-Security-Policy. ${ft(r)} Reason: ${r.reason}`,
|
|
3008
|
+
origin: r.origin ?? "application",
|
|
3009
|
+
severity: "info",
|
|
3010
|
+
source: r.source
|
|
3011
|
+
});
|
|
3012
|
+
return;
|
|
3013
|
+
}
|
|
3014
|
+
e.csp === void 0 && t.push({
|
|
3015
|
+
code: "document-policy-missing",
|
|
3016
|
+
message: "This document declares no Content-Security-Policy. Add document: security.strict() to the @policy.ts file of the route. To accept a document without a Content-Security-Policy, declare csp with a value of false and a reason.",
|
|
3017
|
+
severity: "error"
|
|
3018
|
+
});
|
|
3019
|
+
}
|
|
3020
|
+
function ft(e) {
|
|
3021
|
+
const r = (e.origin ?? "application") === "framework" ? "A framework helper declared this exception" : "The application declared this exception";
|
|
3022
|
+
return e.source ? `${r} in ${e.source}.` : `${r}.`;
|
|
3023
|
+
}
|
|
3024
|
+
function vs(e, t) {
|
|
3025
|
+
if (!e.trustedTypes || e.trustedTypes.mode !== "report-only")
|
|
3026
|
+
return;
|
|
3027
|
+
const r = S(e.csp) || void 0, n = !!_e(r?.reportUri)?.length, o = e.headers?.reportingEndpoints, s = !!(r?.reportTo && o && o[r.reportTo]);
|
|
3028
|
+
!n && !s && t.push({
|
|
3029
|
+
code: "report-only-target-missing",
|
|
3030
|
+
message: "Trusted Types report-only mode has no deliverable target. Configure CSP reportTo with a matching Reporting-Endpoints member, reportUri for compatibility, or both.",
|
|
3031
|
+
severity: "warning"
|
|
3032
|
+
});
|
|
3033
|
+
}
|
|
3034
|
+
function Ss(e, t = {}) {
|
|
3035
|
+
const r = t.requirePurpose ?? !0, n = [];
|
|
3036
|
+
for (const o of e) {
|
|
3037
|
+
const s = js(o);
|
|
3038
|
+
s && (r && !o.purpose && n.push({
|
|
3039
|
+
code: "script-purpose-missing",
|
|
3040
|
+
message: `Third-party script ${o.src} should declare a purpose for audits and consent flows.`,
|
|
3041
|
+
severity: "warning"
|
|
3042
|
+
}), t.requireIntegrity && !o.integrity && n.push({
|
|
3043
|
+
code: "script-integrity-missing",
|
|
3044
|
+
message: `Third-party script ${o.src} should declare an integrity hash or an explicit trust-boundary exception.`,
|
|
3045
|
+
severity: "warning"
|
|
3046
|
+
}), o.strategy === "beforeInteractive" && !t.allowBeforeInteractiveThirdParty && n.push({
|
|
3047
|
+
code: "script-third-party-before-interactive",
|
|
3048
|
+
message: `Third-party script ${o.src} runs before the app is interactive and should be justified by policy.`,
|
|
3049
|
+
severity: "warning"
|
|
3050
|
+
}), Us(s) && n.push({
|
|
3051
|
+
code: "script-gtm-wide-trust-boundary",
|
|
3052
|
+
message: "Google Tag Manager can load additional scripts at runtime and should be treated as a wide trust boundary.",
|
|
3053
|
+
severity: "warning"
|
|
3054
|
+
}));
|
|
3055
|
+
}
|
|
3056
|
+
return n;
|
|
3057
|
+
}
|
|
3058
|
+
function bs(e, t, r) {
|
|
3059
|
+
try {
|
|
3060
|
+
return Object.fromEntries(se(e, t));
|
|
3061
|
+
} catch (n) {
|
|
3062
|
+
return r.push({
|
|
3063
|
+
code: "security-header-render-failed",
|
|
3064
|
+
message: n instanceof Error ? n.message : "Security headers failed to render.",
|
|
3065
|
+
severity: "error"
|
|
3066
|
+
}), {};
|
|
3067
|
+
}
|
|
3068
|
+
}
|
|
3069
|
+
function Es(e, t, r, n) {
|
|
3070
|
+
if (!e)
|
|
3071
|
+
return;
|
|
3072
|
+
const o = Ts(e);
|
|
3073
|
+
for (const s of t) {
|
|
3074
|
+
if ($s(o) && !s.nonce) {
|
|
3075
|
+
n.push({
|
|
3076
|
+
code: "csp-script-missing-nonce",
|
|
3077
|
+
message: `Document script ${s.src} needs a nonce for the effective script-src policy.`,
|
|
3078
|
+
severity: "error"
|
|
3079
|
+
});
|
|
3080
|
+
continue;
|
|
3081
|
+
}
|
|
3082
|
+
s.nonce && r?.nonce && s.nonce === r.nonce || xs(o, s.src) || n.push({
|
|
3083
|
+
code: "csp-script-src-blocked",
|
|
3084
|
+
message: `Document script ${s.src} is not allowed by the effective script-src policy.`,
|
|
3085
|
+
severity: "error"
|
|
3086
|
+
});
|
|
3087
|
+
}
|
|
3088
|
+
}
|
|
3089
|
+
function Rs(e) {
|
|
3090
|
+
return typeof e == "boolean" ? {} : e;
|
|
3091
|
+
}
|
|
3092
|
+
function Ts(e) {
|
|
3093
|
+
return _e(e.scriptSrc) ?? _e(e.defaultSrc) ?? [];
|
|
3094
|
+
}
|
|
3095
|
+
function _e(e) {
|
|
3096
|
+
if (e)
|
|
3097
|
+
return "replace" in e ? e.replace : e;
|
|
3098
|
+
}
|
|
3099
|
+
function $s(e) {
|
|
3100
|
+
return e.some((t) => t.includes("'nonce-{nonce}'"));
|
|
3101
|
+
}
|
|
3102
|
+
function xs(e, t) {
|
|
3103
|
+
return Ls(e) ? !1 : e.includes("*") ? !0 : e.includes("'none'") || e.some((r) => r.startsWith("'nonce-")) ? !1 : e.includes("'self'") && As(t) || t.startsWith("https:") && e.includes("https:") || t.startsWith("http:") && e.includes("http:") ? !0 : e.some((r) => ks(r, t));
|
|
3104
|
+
}
|
|
3105
|
+
function As(e) {
|
|
3106
|
+
return e.startsWith("/") && !e.startsWith("//");
|
|
3107
|
+
}
|
|
3108
|
+
function ks(e, t) {
|
|
3109
|
+
if (e.startsWith("'"))
|
|
3110
|
+
return !1;
|
|
3111
|
+
try {
|
|
3112
|
+
const r = new URL(e), n = new URL(t), o = r.hostname.startsWith("*.") ? n.hostname.endsWith(r.hostname.slice(1)) && n.hostname !== r.hostname.slice(2) : n.hostname === r.hostname, s = r.pathname === "/" || r.pathname.endsWith("/") ? n.pathname.startsWith(r.pathname) : n.pathname === r.pathname;
|
|
3113
|
+
return n.protocol === r.protocol && o && n.port === r.port && s;
|
|
3114
|
+
} catch {
|
|
3115
|
+
return !1;
|
|
3116
|
+
}
|
|
3117
|
+
}
|
|
3118
|
+
function Ls(e) {
|
|
3119
|
+
return e.includes("'strict-dynamic'") && e.some(
|
|
3120
|
+
(t) => t.startsWith("'nonce-") || /^'sha(?:256|384|512)-/.test(t)
|
|
3121
|
+
);
|
|
3122
|
+
}
|
|
3123
|
+
function Cs(e, t) {
|
|
3124
|
+
return Os(e.cors, t), Ps(e.access, t), Ns(e.method, e.security, t), Ms(e.security, t), {
|
|
3125
|
+
access: e.access,
|
|
3126
|
+
cors: e.cors,
|
|
3127
|
+
method: e.method,
|
|
3128
|
+
security: e.security
|
|
3129
|
+
};
|
|
3130
|
+
}
|
|
3131
|
+
function Ps(e, t) {
|
|
3132
|
+
if (e) {
|
|
3133
|
+
e.declared ? e.public ? t.push({
|
|
3134
|
+
code: "access-public",
|
|
3135
|
+
message: "This route declares public access, so it runs no authorization hook.",
|
|
3136
|
+
severity: "info"
|
|
3137
|
+
}) : t.push({
|
|
3138
|
+
code: "access-authorized",
|
|
3139
|
+
message: `This route runs ${e.chain.length} inherited authorization ${e.chain.length === 1 ? "hook" : "hooks"}, from ${Ds(e)}. A denial uses status ${e.denyStatus}.`,
|
|
3140
|
+
severity: "info"
|
|
3141
|
+
}) : t.push({
|
|
3142
|
+
code: "access-declaration-missing",
|
|
3143
|
+
message: "This route inherits no access declaration, so the request pipeline denies each request. Add access to this route or an ancestor @policy.ts file.",
|
|
3144
|
+
severity: "error"
|
|
3145
|
+
});
|
|
3146
|
+
for (const r of e.exceptions)
|
|
3147
|
+
t.push({
|
|
3148
|
+
code: "access-exception",
|
|
3149
|
+
message: `An access exception in ${r.source ?? "an unnamed policy file"} removed each inherited authorization hook for ${r.scope ?? "this subtree"}. Reason: ${r.reason}`,
|
|
3150
|
+
severity: "warning",
|
|
3151
|
+
source: r.source
|
|
3152
|
+
});
|
|
3153
|
+
}
|
|
3154
|
+
}
|
|
3155
|
+
function Ds(e) {
|
|
3156
|
+
return e.chain.map((r) => r.source ?? "an unnamed policy file").join(", ");
|
|
3157
|
+
}
|
|
3158
|
+
function Os(e, t) {
|
|
3159
|
+
if (e)
|
|
3160
|
+
try {
|
|
3161
|
+
lt(e);
|
|
3162
|
+
} catch (r) {
|
|
3163
|
+
t.push({
|
|
3164
|
+
code: "cors-invalid",
|
|
3165
|
+
message: r instanceof Error ? r.message : "CORS policy is invalid.",
|
|
3166
|
+
severity: "error"
|
|
3167
|
+
});
|
|
3168
|
+
}
|
|
3169
|
+
}
|
|
3170
|
+
function Ns(e, t, r) {
|
|
3171
|
+
if (!gs.has(e))
|
|
3172
|
+
return;
|
|
3173
|
+
const n = lr(t?.csrf);
|
|
3174
|
+
n && r.push({
|
|
3175
|
+
code: "csrf-disabled",
|
|
3176
|
+
message: `This unsafe route runs no CSRF check. ${ft(n)} Reason: ${n.reason}`,
|
|
3177
|
+
origin: n.origin ?? "application",
|
|
3178
|
+
severity: "info",
|
|
3179
|
+
source: n.source
|
|
3180
|
+
}), t?.rateLimit || r.push({
|
|
3181
|
+
code: "rate-limit-missing",
|
|
3182
|
+
message: "Unsafe routes should declare rate limiting.",
|
|
3183
|
+
severity: "warning"
|
|
3184
|
+
});
|
|
3185
|
+
}
|
|
3186
|
+
function Ms(e, t) {
|
|
3187
|
+
const r = dr(e?.request?.maxBodySize), n = ct(e?.request?.maxBodySize);
|
|
3188
|
+
if (n === void 0)
|
|
3189
|
+
return;
|
|
3190
|
+
let o, s;
|
|
3191
|
+
try {
|
|
3192
|
+
o = Se(n), s = Se(dt);
|
|
3193
|
+
} catch {
|
|
3194
|
+
return;
|
|
3195
|
+
}
|
|
3196
|
+
if (!(o <= s)) {
|
|
3197
|
+
if (!r) {
|
|
3198
|
+
t.push({
|
|
3199
|
+
code: "security-exception-reason-missing",
|
|
3200
|
+
message: `This route raises the inherited request body limit to ${n} and states no reason. Declare maxBodySize with a limit value and a reason.`,
|
|
3201
|
+
severity: "error"
|
|
3202
|
+
});
|
|
3203
|
+
return;
|
|
3204
|
+
}
|
|
3205
|
+
t.push({
|
|
3206
|
+
code: "request-body-limit-raised",
|
|
3207
|
+
message: `This route raises the inherited request body limit to ${n}. ${ft(r)} Reason: ${r.reason}`,
|
|
3208
|
+
origin: r.origin ?? "application",
|
|
3209
|
+
severity: "info",
|
|
3210
|
+
source: r.source
|
|
3211
|
+
});
|
|
3212
|
+
}
|
|
3213
|
+
}
|
|
3214
|
+
function js(e) {
|
|
3215
|
+
try {
|
|
3216
|
+
const t = new URL(e.src);
|
|
3217
|
+
if (t.protocol === "http:" || t.protocol === "https:")
|
|
3218
|
+
return t;
|
|
3219
|
+
} catch {
|
|
3220
|
+
return null;
|
|
3221
|
+
}
|
|
3222
|
+
return null;
|
|
3223
|
+
}
|
|
3224
|
+
function Us(e) {
|
|
3225
|
+
return e.hostname === "www.googletagmanager.com" && (e.pathname === "/gtm.js" || e.pathname === "/ns.html");
|
|
3226
|
+
}
|
|
3227
|
+
const Is = /* @__PURE__ */ new Set(["DELETE", "PATCH", "POST", "PUT"]), zs = /^[!#$%&'*+\-.^_`|~A-Za-z0-9]+$/;
|
|
3228
|
+
function Hs() {
|
|
3229
|
+
const e = new Uint8Array(32);
|
|
3230
|
+
return globalThis.crypto.getRandomValues(e), btoa(String.fromCharCode(...e)).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, "");
|
|
3231
|
+
}
|
|
3232
|
+
function Fs(e, t = {}) {
|
|
3233
|
+
const r = t.cookie ?? "csrf-token";
|
|
3234
|
+
if (!zs.test(r))
|
|
3235
|
+
throw new Error("Demiurge CSRF cookie name is invalid.");
|
|
3236
|
+
if (!e)
|
|
3237
|
+
throw new Error("Demiurge CSRF token must not be empty.");
|
|
3238
|
+
const n = [
|
|
3239
|
+
`${r}=${encodeURIComponent(e)}`,
|
|
3240
|
+
"Path=/",
|
|
3241
|
+
"SameSite=Lax"
|
|
3242
|
+
];
|
|
3243
|
+
return (t.secure ?? !0) && n.push("Secure"), n.join("; ");
|
|
3244
|
+
}
|
|
3245
|
+
function _i(e = {}) {
|
|
3246
|
+
const t = Hs();
|
|
3247
|
+
return {
|
|
3248
|
+
cookie: Fs(t, e),
|
|
3249
|
+
token: t
|
|
3250
|
+
};
|
|
3251
|
+
}
|
|
3252
|
+
async function Ws(e, t) {
|
|
3253
|
+
const r = Lo(e);
|
|
3254
|
+
if (!Is.has(t.method.toUpperCase()) || r === !1)
|
|
3255
|
+
return null;
|
|
3256
|
+
const n = t.headers.get("cookie");
|
|
3257
|
+
if (r === void 0 && !n?.trim())
|
|
3258
|
+
return null;
|
|
3259
|
+
const o = Vs(r ?? !0), a = Bs(n).get(o.cookie), i = t.headers.get(o.header);
|
|
3260
|
+
if (!!(a && i && Ot(a, i)))
|
|
3261
|
+
return null;
|
|
3262
|
+
const u = o.field ? await qs(t.clone(), o.field) : null;
|
|
3263
|
+
return !(a && u && Ot(a, u)) ? new Response("Invalid CSRF token.", {
|
|
3264
|
+
status: 403
|
|
3265
|
+
}) : null;
|
|
3266
|
+
}
|
|
3267
|
+
function Bs(e) {
|
|
3268
|
+
const t = /* @__PURE__ */ new Map();
|
|
3269
|
+
if (!e)
|
|
3270
|
+
return t;
|
|
3271
|
+
for (const r of e.split(";")) {
|
|
3272
|
+
const n = r.indexOf("=");
|
|
3273
|
+
if (n === -1)
|
|
3274
|
+
continue;
|
|
3275
|
+
const o = r.slice(0, n).trim(), s = r.slice(n + 1).trim();
|
|
3276
|
+
o && t.set(o, _s(s));
|
|
3277
|
+
}
|
|
3278
|
+
return t;
|
|
3279
|
+
}
|
|
3280
|
+
function Vs(e) {
|
|
3281
|
+
return e === !0 ? {
|
|
3282
|
+
cookie: "csrf-token",
|
|
3283
|
+
header: "x-csrf-token"
|
|
3284
|
+
} : {
|
|
3285
|
+
cookie: e.cookie ?? "csrf-token",
|
|
3286
|
+
field: e.field,
|
|
3287
|
+
header: e.header ?? "x-csrf-token"
|
|
3288
|
+
};
|
|
3289
|
+
}
|
|
3290
|
+
async function qs(e, t) {
|
|
3291
|
+
const r = e.headers.get("content-type")?.toLowerCase() ?? "";
|
|
3292
|
+
if (!r.startsWith("application/x-www-form-urlencoded") && !r.startsWith("multipart/form-data"))
|
|
3293
|
+
return null;
|
|
3294
|
+
try {
|
|
3295
|
+
const n = (await e.formData()).get(t);
|
|
3296
|
+
return typeof n == "string" ? n : null;
|
|
3297
|
+
} catch {
|
|
3298
|
+
return null;
|
|
3299
|
+
}
|
|
3300
|
+
}
|
|
3301
|
+
function _s(e) {
|
|
3302
|
+
try {
|
|
3303
|
+
return decodeURIComponent(e);
|
|
3304
|
+
} catch {
|
|
3305
|
+
return e;
|
|
3306
|
+
}
|
|
3307
|
+
}
|
|
3308
|
+
function Ot(e, t) {
|
|
3309
|
+
let r = e.length ^ t.length;
|
|
3310
|
+
const n = Math.max(e.length, t.length);
|
|
3311
|
+
for (let o = 0; o < n; o += 1)
|
|
3312
|
+
r |= e.charCodeAt(o) ^ t.charCodeAt(o);
|
|
3313
|
+
return r === 0;
|
|
3314
|
+
}
|
|
3315
|
+
const Me = "Sec-Fetch-Dest", Gs = "Sec-Fetch-Mode", Js = "Sec-Fetch-Site", Ks = /* @__PURE__ */ new Set(["embed", "object"]), Ys = /* @__PURE__ */ new Set(["GET", "HEAD"]), Nt = {
|
|
3316
|
+
allowCrossSite: !1,
|
|
3317
|
+
allowNavigation: !0,
|
|
3318
|
+
allowSameSite: !1
|
|
3319
|
+
};
|
|
3320
|
+
function Zs(e, t, r = t.method) {
|
|
3321
|
+
const n = e === !0 ? Nt : { ...Nt, ...e }, o = [];
|
|
3322
|
+
if (Xs(t, r))
|
|
3323
|
+
return { allowed: !0, reason: "cors-preflight", vary: o };
|
|
3324
|
+
o.push(Js);
|
|
3325
|
+
const s = t.headers.get("sec-fetch-site");
|
|
3326
|
+
if (s === null)
|
|
3327
|
+
return { allowed: !0, reason: "metadata-absent", vary: o };
|
|
3328
|
+
if (s === "same-origin")
|
|
3329
|
+
return { allowed: !0, reason: "same-origin", vary: o };
|
|
3330
|
+
if (s === "none")
|
|
3331
|
+
return { allowed: !0, reason: "user-initiated", vary: o };
|
|
3332
|
+
if (s === "same-site" && n.allowSameSite)
|
|
3333
|
+
return { allowed: !0, reason: "same-site-trusted", vary: o };
|
|
3334
|
+
if (n.allowCrossSite)
|
|
3335
|
+
return { allowed: !0, reason: "cross-site-exempt", vary: o };
|
|
3336
|
+
const a = e === !0 ? void 0 : e.allowedDestinations;
|
|
3337
|
+
if (a?.length && (o.push(Me), a.includes(t.headers.get("sec-fetch-dest") ?? "")))
|
|
3338
|
+
return { allowed: !0, reason: "destination-exempt", vary: o };
|
|
3339
|
+
if (n.allowNavigation && Ys.has(r.toUpperCase()) && (o.push(Gs), t.headers.get("sec-fetch-mode") === "navigate")) {
|
|
3340
|
+
const i = t.headers.get("sec-fetch-dest") ?? "";
|
|
3341
|
+
if (o.includes(Me) || o.push(Me), !Ks.has(i))
|
|
3342
|
+
return { allowed: !0, reason: "top-level-navigation", vary: o };
|
|
3343
|
+
}
|
|
3344
|
+
return {
|
|
3345
|
+
allowed: !1,
|
|
3346
|
+
reason: s === "same-site" ? "same-site-denied" : "cross-site-denied",
|
|
3347
|
+
vary: o
|
|
3348
|
+
};
|
|
3349
|
+
}
|
|
3350
|
+
function Qs(e, t, r = t.method) {
|
|
3351
|
+
if (!e)
|
|
3352
|
+
return { response: null, vary: [] };
|
|
3353
|
+
const n = Zs(e, t, r);
|
|
3354
|
+
if (n.allowed)
|
|
3355
|
+
return { response: null, vary: n.vary };
|
|
3356
|
+
const o = new Response("Request blocked by the Fetch Metadata policy.", {
|
|
3357
|
+
headers: { "content-type": "text/plain; charset=utf-8" },
|
|
3358
|
+
status: 403
|
|
3359
|
+
});
|
|
3360
|
+
return Er(o, n.vary), { response: o, vary: n.vary };
|
|
3361
|
+
}
|
|
3362
|
+
function Er(e, t) {
|
|
3363
|
+
if (t.length === 0)
|
|
3364
|
+
return e;
|
|
3365
|
+
const r = e.headers.get("vary")?.split(",").map((o) => o.trim()).filter(Boolean) ?? [];
|
|
3366
|
+
if (r.includes("*"))
|
|
3367
|
+
return e;
|
|
3368
|
+
const n = [...r];
|
|
3369
|
+
for (const o of t)
|
|
3370
|
+
n.some((s) => s.toLowerCase() === o.toLowerCase()) || n.push(o);
|
|
3371
|
+
return e.headers.set("vary", n.join(", ")), e;
|
|
3372
|
+
}
|
|
3373
|
+
function Xs(e, t) {
|
|
3374
|
+
return t.toUpperCase() === "OPTIONS" && e.headers.has("access-control-request-method");
|
|
3375
|
+
}
|
|
3376
|
+
class Rr extends Error {
|
|
3377
|
+
issues;
|
|
3378
|
+
constructor(t) {
|
|
3379
|
+
super(aa(t)), this.name = "EnvValidationError", this.issues = t;
|
|
3380
|
+
}
|
|
3381
|
+
}
|
|
3382
|
+
function Gi(e) {
|
|
3383
|
+
return e;
|
|
3384
|
+
}
|
|
3385
|
+
function Ji(e, t) {
|
|
3386
|
+
const r = [], n = {};
|
|
3387
|
+
for (const o of Object.keys(e)) {
|
|
3388
|
+
const s = e[o], a = t[String(o)];
|
|
3389
|
+
if (a === void 0 || a === "") {
|
|
3390
|
+
if (s.optional) {
|
|
3391
|
+
n[o] = void 0;
|
|
3392
|
+
continue;
|
|
3393
|
+
}
|
|
3394
|
+
r.push({
|
|
3395
|
+
code: "missing",
|
|
3396
|
+
key: String(o),
|
|
3397
|
+
message: `Environment variable ${String(o)} is required.`
|
|
3398
|
+
});
|
|
3399
|
+
continue;
|
|
3400
|
+
}
|
|
3401
|
+
try {
|
|
3402
|
+
n[o] = s.parse(String(o), a);
|
|
3403
|
+
} catch (i) {
|
|
3404
|
+
r.push({
|
|
3405
|
+
code: "invalid",
|
|
3406
|
+
key: String(o),
|
|
3407
|
+
message: i instanceof Error ? i.message : `Environment variable ${String(o)} is invalid.`
|
|
3408
|
+
});
|
|
3409
|
+
}
|
|
3410
|
+
}
|
|
3411
|
+
if (r.length)
|
|
3412
|
+
throw new Rr(r);
|
|
3413
|
+
return n;
|
|
3414
|
+
}
|
|
3415
|
+
function ea(e = {}) {
|
|
3416
|
+
return q(e, !1, (t, r) => {
|
|
3417
|
+
if (r === "true" || r === "1")
|
|
3418
|
+
return !0;
|
|
3419
|
+
if (r === "false" || r === "0")
|
|
3420
|
+
return !1;
|
|
3421
|
+
throw new Error(`Environment variable ${t} must be true, false, 1, or 0.`);
|
|
3422
|
+
}, "boolean");
|
|
3423
|
+
}
|
|
3424
|
+
function ta(e, t = {}) {
|
|
3425
|
+
return q(t, !1, (r, n) => {
|
|
3426
|
+
if (e.includes(n))
|
|
3427
|
+
return n;
|
|
3428
|
+
throw new Error(
|
|
3429
|
+
`Environment variable ${r} must be one of: ${e.join(", ")}.`
|
|
3430
|
+
);
|
|
3431
|
+
}, "enum", { values: [...e] });
|
|
3432
|
+
}
|
|
3433
|
+
function ra(e = {}) {
|
|
3434
|
+
return q(e, !1, (t, r) => {
|
|
3435
|
+
if (!/^-?\d+$/.test(r))
|
|
3436
|
+
throw new Error(`Environment variable ${t} must be an integer.`);
|
|
3437
|
+
const n = Number(r);
|
|
3438
|
+
if (!Number.isSafeInteger(n))
|
|
3439
|
+
throw new Error(`Environment variable ${t} must be a safe integer.`);
|
|
3440
|
+
if (e.min !== void 0 && n < e.min)
|
|
3441
|
+
throw new Error(
|
|
3442
|
+
`Environment variable ${t} must be greater than or equal to ${e.min}.`
|
|
3443
|
+
);
|
|
3444
|
+
if (e.max !== void 0 && n > e.max)
|
|
3445
|
+
throw new Error(
|
|
3446
|
+
`Environment variable ${t} must be less than or equal to ${e.max}.`
|
|
3447
|
+
);
|
|
3448
|
+
return n;
|
|
3449
|
+
}, "integer");
|
|
3450
|
+
}
|
|
3451
|
+
function na(e = {}) {
|
|
3452
|
+
return q(
|
|
3453
|
+
e,
|
|
3454
|
+
!0,
|
|
3455
|
+
(t, r) => Tr(t, r, e),
|
|
3456
|
+
"secret"
|
|
3457
|
+
);
|
|
3458
|
+
}
|
|
3459
|
+
function oa(e = {}) {
|
|
3460
|
+
return q(
|
|
3461
|
+
e,
|
|
3462
|
+
!1,
|
|
3463
|
+
(t, r) => Tr(t, r, e),
|
|
3464
|
+
"string"
|
|
3465
|
+
);
|
|
3466
|
+
}
|
|
3467
|
+
function sa(e = {}) {
|
|
3468
|
+
return q(e, !1, (t, r) => {
|
|
3469
|
+
let n;
|
|
3470
|
+
try {
|
|
3471
|
+
n = new URL(r);
|
|
3472
|
+
} catch {
|
|
3473
|
+
throw new Error(`Environment variable ${t} must be a valid URL.`);
|
|
3474
|
+
}
|
|
3475
|
+
if (e.protocols?.length && !e.protocols.includes(n.protocol))
|
|
3476
|
+
throw new Error(
|
|
3477
|
+
`Environment variable ${t} must use one of these protocols: ${e.protocols.join(", ")}.`
|
|
3478
|
+
);
|
|
3479
|
+
return n;
|
|
3480
|
+
}, "url");
|
|
3481
|
+
}
|
|
3482
|
+
const N = {
|
|
3483
|
+
boolean: ea,
|
|
3484
|
+
enum: ta,
|
|
3485
|
+
integer: ra,
|
|
3486
|
+
secret: na,
|
|
3487
|
+
string: oa,
|
|
3488
|
+
url: sa
|
|
3489
|
+
};
|
|
3490
|
+
function q(e, t, r, n = "string", o = {}) {
|
|
3491
|
+
const s = { ...e, ...o }, { client: a = !1, deferred: i = !1, optional: c = !1, ...u } = s;
|
|
3492
|
+
if (a && t)
|
|
3493
|
+
throw new Error(
|
|
3494
|
+
"A secret environment variable cannot reach client code. Declare a separate variable for the browser."
|
|
3495
|
+
);
|
|
3496
|
+
if (c && i)
|
|
3497
|
+
throw new Error(
|
|
3498
|
+
"An environment variable cannot combine optional with deferred. Declare one of the two options."
|
|
3499
|
+
);
|
|
3500
|
+
if (a && i)
|
|
3501
|
+
throw new Error(
|
|
3502
|
+
"A client environment variable cannot be deferred. The build validates the value of a client variable."
|
|
3503
|
+
);
|
|
3504
|
+
return {
|
|
3505
|
+
client: a,
|
|
3506
|
+
deferred: i,
|
|
3507
|
+
kind: n,
|
|
3508
|
+
optional: c,
|
|
3509
|
+
options: u,
|
|
3510
|
+
parse: r,
|
|
3511
|
+
sensitive: t
|
|
3512
|
+
};
|
|
3513
|
+
}
|
|
3514
|
+
function Tr(e, t, r) {
|
|
3515
|
+
if (r.minLength !== void 0 && t.length < r.minLength)
|
|
3516
|
+
throw new Error(
|
|
3517
|
+
`Environment variable ${e} must be at least ${r.minLength} characters.`
|
|
3518
|
+
);
|
|
3519
|
+
return t;
|
|
3520
|
+
}
|
|
3521
|
+
function aa(e) {
|
|
3522
|
+
return e.length === 1 ? e[0].message : `Environment validation failed with ${e.length} issues.`;
|
|
3523
|
+
}
|
|
3524
|
+
const Mt = Symbol.for("demiurge.environmentState"), jt = Symbol.for("demiurge.deferredEnvironmentState"), be = globalThis, B = ia(), U = ca();
|
|
3525
|
+
function ia() {
|
|
3526
|
+
const e = be[Mt];
|
|
3527
|
+
if (e instanceof Map) return e;
|
|
3528
|
+
const t = /* @__PURE__ */ new Map();
|
|
3529
|
+
return be[Mt] = t, t;
|
|
3530
|
+
}
|
|
3531
|
+
function ca() {
|
|
3532
|
+
const e = be[jt];
|
|
3533
|
+
if (e instanceof Map) return e;
|
|
3534
|
+
const t = /* @__PURE__ */ new Map();
|
|
3535
|
+
return be[jt] = t, t;
|
|
3536
|
+
}
|
|
3537
|
+
function Ki(e) {
|
|
3538
|
+
return Object.fromEntries(
|
|
3539
|
+
Object.entries(e).map(([t, r]) => [t, {
|
|
3540
|
+
client: r.client,
|
|
3541
|
+
deferred: r.deferred,
|
|
3542
|
+
kind: r.kind,
|
|
3543
|
+
optional: r.optional,
|
|
3544
|
+
options: r.options,
|
|
3545
|
+
sensitive: r.sensitive
|
|
3546
|
+
}])
|
|
3547
|
+
);
|
|
3548
|
+
}
|
|
3549
|
+
function ua(e) {
|
|
3550
|
+
return Object.fromEntries(
|
|
3551
|
+
Object.entries(e).map(([t, r]) => [
|
|
3552
|
+
t,
|
|
3553
|
+
da(t, r)
|
|
3554
|
+
])
|
|
3555
|
+
);
|
|
3556
|
+
}
|
|
3557
|
+
function Yi(e, t = {}) {
|
|
3558
|
+
const r = fa(e) ? e : ua(e), n = t.source ?? ha(), o = [], s = {};
|
|
3559
|
+
for (const [a, i] of Object.entries(r)) {
|
|
3560
|
+
const c = n[a];
|
|
3561
|
+
if (i.deferred) {
|
|
3562
|
+
U.set(a, { rawValue: c, variable: i });
|
|
3563
|
+
continue;
|
|
3564
|
+
}
|
|
3565
|
+
if (c === void 0 || c === "") {
|
|
3566
|
+
if (s[a] = void 0, i.optional) continue;
|
|
3567
|
+
o.push({
|
|
3568
|
+
code: "missing",
|
|
3569
|
+
key: a,
|
|
3570
|
+
message: `Environment variable ${a} is required.`
|
|
3571
|
+
});
|
|
3572
|
+
continue;
|
|
3573
|
+
}
|
|
3574
|
+
try {
|
|
3575
|
+
s[a] = i.parse(a, c);
|
|
3576
|
+
} catch (u) {
|
|
3577
|
+
s[a] = void 0, o.push({
|
|
3578
|
+
code: "invalid",
|
|
3579
|
+
key: a,
|
|
3580
|
+
message: u instanceof Error ? u.message : `Environment variable ${a} is invalid.`
|
|
3581
|
+
});
|
|
3582
|
+
}
|
|
3583
|
+
}
|
|
3584
|
+
if (o.length) throw new Rr(o);
|
|
3585
|
+
for (const [a, i] of Object.entries(s)) B.set(a, i);
|
|
3586
|
+
return { values: s };
|
|
3587
|
+
}
|
|
3588
|
+
function Zi(e) {
|
|
3589
|
+
const t = {};
|
|
3590
|
+
for (const r of Object.keys(e)) {
|
|
3591
|
+
if (U.has(r)) {
|
|
3592
|
+
t[r] = la(r);
|
|
3593
|
+
continue;
|
|
3594
|
+
}
|
|
3595
|
+
if (!B.has(r))
|
|
3596
|
+
throw new Error(
|
|
3597
|
+
`Demiurge did not validate the environment variable ${r}. The framework validates the schema of demiurge.config.ts when the server starts.`
|
|
3598
|
+
);
|
|
3599
|
+
t[r] = B.get(r);
|
|
3600
|
+
}
|
|
3601
|
+
return t;
|
|
3602
|
+
}
|
|
3603
|
+
function Qi() {
|
|
3604
|
+
B.clear(), U.clear();
|
|
3605
|
+
}
|
|
3606
|
+
function la(e) {
|
|
3607
|
+
const t = U.get(e), { rawValue: r, variable: n } = t;
|
|
3608
|
+
if (r === void 0 || r === "") {
|
|
3609
|
+
if (n.optional) {
|
|
3610
|
+
U.delete(e), B.set(e, void 0);
|
|
3611
|
+
return;
|
|
3612
|
+
}
|
|
3613
|
+
throw new Error(
|
|
3614
|
+
`Environment variable ${e} is required. Give the variable a value before the code reads it.`
|
|
3615
|
+
);
|
|
3616
|
+
}
|
|
3617
|
+
let o;
|
|
3618
|
+
try {
|
|
3619
|
+
o = n.parse(e, r);
|
|
3620
|
+
} catch (s) {
|
|
3621
|
+
throw new Error(
|
|
3622
|
+
s instanceof Error ? s.message : `Environment variable ${e} is invalid.`,
|
|
3623
|
+
{ cause: s }
|
|
3624
|
+
);
|
|
3625
|
+
}
|
|
3626
|
+
return U.delete(e), B.set(e, o), o;
|
|
3627
|
+
}
|
|
3628
|
+
function da(e, t) {
|
|
3629
|
+
const r = {
|
|
3630
|
+
...t.options,
|
|
3631
|
+
client: t.client,
|
|
3632
|
+
deferred: t.deferred,
|
|
3633
|
+
optional: t.optional
|
|
3634
|
+
};
|
|
3635
|
+
if (t.kind === "boolean") return N.boolean(r);
|
|
3636
|
+
if (t.kind === "integer") return N.integer(r);
|
|
3637
|
+
if (t.kind === "secret") return N.secret(r);
|
|
3638
|
+
if (t.kind === "url") return N.url(r);
|
|
3639
|
+
if (t.kind === "enum") {
|
|
3640
|
+
const n = t.options.values;
|
|
3641
|
+
if (!Array.isArray(n) || !n.length)
|
|
3642
|
+
throw new Error(
|
|
3643
|
+
`The environment variable ${e} does not have the values of its enum.`
|
|
3644
|
+
);
|
|
3645
|
+
return N.enum(n, r);
|
|
3646
|
+
}
|
|
3647
|
+
return N.string(r);
|
|
3648
|
+
}
|
|
3649
|
+
function fa(e) {
|
|
3650
|
+
return Object.values(e).every(
|
|
3651
|
+
(t) => "parse" in t && typeof t.parse == "function"
|
|
3652
|
+
);
|
|
3653
|
+
}
|
|
3654
|
+
function ha() {
|
|
3655
|
+
return globalThis.process?.env ?? {};
|
|
3656
|
+
}
|
|
3657
|
+
const ma = {
|
|
3658
|
+
h: 3600 * 1e3,
|
|
3659
|
+
m: 60 * 1e3,
|
|
3660
|
+
s: 1e3
|
|
3661
|
+
}, pa = 1e4;
|
|
3662
|
+
function $r(e = {}) {
|
|
3663
|
+
const t = e.maximumEntries ?? pa;
|
|
3664
|
+
if (!Number.isSafeInteger(t) || t <= 0)
|
|
3665
|
+
throw new Error(
|
|
3666
|
+
"Demiurge rate limit maximumEntries must be a positive integer."
|
|
3667
|
+
);
|
|
3668
|
+
const r = /* @__PURE__ */ new Map();
|
|
3669
|
+
let n = Number.POSITIVE_INFINITY;
|
|
3670
|
+
return {
|
|
3671
|
+
increment(o, s, a) {
|
|
3672
|
+
a >= n && (ga(r, a), n = wa(r));
|
|
3673
|
+
const i = r.get(o);
|
|
3674
|
+
if (!i || i.resetAt <= a) {
|
|
3675
|
+
const c = {
|
|
3676
|
+
count: 1,
|
|
3677
|
+
resetAt: a + s
|
|
3678
|
+
};
|
|
3679
|
+
return !i && r.size >= t && ya(r), r.set(o, c), n = Math.min(n, c.resetAt), { count: c.count, resetAt: c.resetAt };
|
|
3680
|
+
}
|
|
3681
|
+
return i.count += 1, { count: i.count, resetAt: i.resetAt };
|
|
3682
|
+
}
|
|
3683
|
+
};
|
|
3684
|
+
}
|
|
3685
|
+
function ga(e, t) {
|
|
3686
|
+
for (const [r, n] of e)
|
|
3687
|
+
n.resetAt <= t && e.delete(r);
|
|
3688
|
+
}
|
|
3689
|
+
function wa(e) {
|
|
3690
|
+
let t = Number.POSITIVE_INFINITY;
|
|
3691
|
+
for (const r of e.values())
|
|
3692
|
+
t = Math.min(t, r.resetAt);
|
|
3693
|
+
return t;
|
|
3694
|
+
}
|
|
3695
|
+
function ya(e) {
|
|
3696
|
+
const t = e.keys().next().value;
|
|
3697
|
+
t !== void 0 && e.delete(t);
|
|
3698
|
+
}
|
|
3699
|
+
async function va(e, t, r, n = Date.now()) {
|
|
3700
|
+
if (!e)
|
|
3701
|
+
return null;
|
|
3702
|
+
ht(e);
|
|
3703
|
+
const o = xr(e.window), s = Sa(e, t), a = await r.increment(s, o, n), i = Math.max(0, e.limit - a.count), c = new Headers({
|
|
3704
|
+
"retry-after": String(Math.ceil(Math.max(0, a.resetAt - n) / 1e3)),
|
|
3705
|
+
"x-ratelimit-limit": String(e.limit),
|
|
3706
|
+
"x-ratelimit-remaining": String(i),
|
|
3707
|
+
"x-ratelimit-reset": String(Math.ceil(a.resetAt / 1e3))
|
|
3708
|
+
});
|
|
3709
|
+
return a.count > e.limit ? new Response("Rate limit exceeded.", {
|
|
3710
|
+
headers: c,
|
|
3711
|
+
status: 429
|
|
3712
|
+
}) : null;
|
|
3713
|
+
}
|
|
3714
|
+
function xr(e) {
|
|
3715
|
+
if (typeof e == "number") {
|
|
3716
|
+
if (!Number.isSafeInteger(e) || e <= 0)
|
|
3717
|
+
throw new Error("Demiurge rate limit window must be a positive integer.");
|
|
3718
|
+
return e;
|
|
3719
|
+
}
|
|
3720
|
+
const t = /^(\d+)(s|m|h)$/i.exec(e.trim());
|
|
3721
|
+
if (!t)
|
|
3722
|
+
throw new Error("Demiurge rate limit window must use an s/m/h suffix.");
|
|
3723
|
+
const r = Number(t[1]), n = t[2].toLowerCase(), o = r * ma[n];
|
|
3724
|
+
if (!Number.isSafeInteger(o))
|
|
3725
|
+
throw new Error("Demiurge rate limit window is too large.");
|
|
3726
|
+
return o;
|
|
3727
|
+
}
|
|
3728
|
+
function ht(e) {
|
|
3729
|
+
if (!Number.isSafeInteger(e.limit) || e.limit <= 0)
|
|
3730
|
+
throw new Error("Demiurge rate limit limit must be a positive integer.");
|
|
3731
|
+
xr(e.window);
|
|
3732
|
+
}
|
|
3733
|
+
function Sa(e, t) {
|
|
3734
|
+
return `${ba(e.key)}:${Ea(e.key, t)}`;
|
|
3735
|
+
}
|
|
3736
|
+
function ba(e) {
|
|
3737
|
+
return typeof e == "string" ? e : `header:${e.header.toLowerCase()}`;
|
|
3738
|
+
}
|
|
3739
|
+
function Ea(e, t) {
|
|
3740
|
+
return e === "ip" ? Ra(t) : t.headers.get(e.header) ?? "missing";
|
|
3741
|
+
}
|
|
3742
|
+
function Ra(e) {
|
|
3743
|
+
return Ir(e)?.clientIp ?? "unknown";
|
|
3744
|
+
}
|
|
3745
|
+
const Ta = [
|
|
3746
|
+
"GET",
|
|
3747
|
+
"POST",
|
|
3748
|
+
"PUT",
|
|
3749
|
+
"PATCH",
|
|
3750
|
+
"DELETE",
|
|
3751
|
+
"OPTIONS",
|
|
3752
|
+
"HEAD"
|
|
3753
|
+
];
|
|
3754
|
+
function $a(e, t = {}) {
|
|
3755
|
+
t.adapter && xa(t.adapter);
|
|
3756
|
+
for (const [n, o] of Object.entries(e)) {
|
|
3757
|
+
Aa(n, o);
|
|
3758
|
+
for (const s of Ta) {
|
|
3759
|
+
const a = o[s];
|
|
3760
|
+
!a || a.kind === "page" || ka(n, s, a, o);
|
|
3761
|
+
}
|
|
3762
|
+
}
|
|
3763
|
+
const r = Kt(
|
|
3764
|
+
Object.fromEntries(
|
|
3765
|
+
Object.entries(e).map(([n, o]) => [
|
|
3766
|
+
n,
|
|
3767
|
+
async () => o
|
|
3768
|
+
])
|
|
3769
|
+
)
|
|
3770
|
+
);
|
|
3771
|
+
return Da(r, e, t.adapter), r;
|
|
3772
|
+
}
|
|
3773
|
+
function xa(e) {
|
|
3774
|
+
zr(e, ["requestTimeoutEnforcement"]).ok || console.warn(
|
|
3775
|
+
`Demiurge adapter "${e.name}" does not report requestTimeoutEnforcement. Every route inherits a bounded request body limit. This adapter gives the shared pipeline no guarantee against a slow request. A slow request can hold a connection open below that limit. Bound connection duration at the host or platform.`
|
|
3776
|
+
);
|
|
3777
|
+
}
|
|
3778
|
+
function Aa(e, t) {
|
|
3779
|
+
const r = t.policy?.security?.rateLimit;
|
|
3780
|
+
r && ne(e, "policy", "rate limit", () => {
|
|
3781
|
+
ht(r);
|
|
3782
|
+
});
|
|
3783
|
+
}
|
|
3784
|
+
function ka(e, t, r, n) {
|
|
3785
|
+
r.cors && ne(e, t, "CORS", () => {
|
|
3786
|
+
lt(r.cors), La(e, t, r.cors.methods, n);
|
|
3787
|
+
}), r.security?.rateLimit && ne(e, t, "rate limit", () => {
|
|
3788
|
+
ht(r.security.rateLimit);
|
|
3789
|
+
});
|
|
3790
|
+
}
|
|
3791
|
+
function La(e, t, r, n) {
|
|
3792
|
+
if (r) {
|
|
3793
|
+
for (const o of r)
|
|
3794
|
+
if (o !== "OPTIONS" && !Ca(n, o))
|
|
3795
|
+
throw new Error(
|
|
3796
|
+
`Route ${JSON.stringify(e)} export ${t} allows CORS method ${o}, but the route does not export that response capability.`
|
|
3797
|
+
);
|
|
3798
|
+
}
|
|
3799
|
+
}
|
|
3800
|
+
function Ca(e, t) {
|
|
3801
|
+
const r = t === "HEAD" ? e.HEAD ?? e.GET : e[t];
|
|
3802
|
+
return Pa(r) ? r : void 0;
|
|
3803
|
+
}
|
|
3804
|
+
function Pa(e) {
|
|
3805
|
+
return !!(e && e.kind !== "page");
|
|
3806
|
+
}
|
|
3807
|
+
function Da(e, t, r) {
|
|
3808
|
+
for (const o of e.routes) {
|
|
3809
|
+
const s = t[o.file], a = s?.GET;
|
|
3810
|
+
if (!a || a.kind !== "page")
|
|
3811
|
+
continue;
|
|
3812
|
+
const i = ye(
|
|
3813
|
+
...e.policies.filter(
|
|
3814
|
+
(c) => C(c.fileSegments, o.fileSegments)
|
|
3815
|
+
).map((c) => t[c.file]?.policy),
|
|
3816
|
+
s.policy
|
|
3817
|
+
);
|
|
3818
|
+
Ut(o.file, "GET", i, r), Ia(
|
|
3819
|
+
o.file,
|
|
3820
|
+
a.render.mode,
|
|
3821
|
+
i.document
|
|
3822
|
+
), Oa(
|
|
3823
|
+
o.file,
|
|
3824
|
+
"GET",
|
|
3825
|
+
i,
|
|
3826
|
+
[
|
|
3827
|
+
...e.layouts.filter(
|
|
3828
|
+
(c) => C(c.fileSegments, o.fileSegments)
|
|
3829
|
+
).map((c) => t[c.file]?.scripts),
|
|
3830
|
+
s.scripts
|
|
3831
|
+
]
|
|
3832
|
+
);
|
|
3833
|
+
}
|
|
3834
|
+
const n = [
|
|
3835
|
+
...e.fallbacks.error,
|
|
3836
|
+
...e.fallbacks.loading,
|
|
3837
|
+
...e.fallbacks.notFound
|
|
3838
|
+
];
|
|
3839
|
+
for (const o of n) {
|
|
3840
|
+
const s = ye(
|
|
3841
|
+
...e.policies.filter(
|
|
3842
|
+
(a) => C(a.fileSegments, o.fileSegments)
|
|
3843
|
+
).map((a) => t[a.file]?.policy),
|
|
3844
|
+
t[o.file]?.policy
|
|
3845
|
+
);
|
|
3846
|
+
Ut(
|
|
3847
|
+
o.file,
|
|
3848
|
+
"policy",
|
|
3849
|
+
s,
|
|
3850
|
+
r
|
|
3851
|
+
);
|
|
3852
|
+
}
|
|
3853
|
+
}
|
|
3854
|
+
function Oa(e, t, r, n) {
|
|
3855
|
+
const o = n.flatMap(
|
|
3856
|
+
(d) => Array.isArray(d) ? d : []
|
|
3857
|
+
);
|
|
3858
|
+
if (o.length === 0 || !r.document)
|
|
3859
|
+
return;
|
|
3860
|
+
const s = "startup-verification-nonce", i = ws({
|
|
3861
|
+
document: {
|
|
3862
|
+
headers: { nonce: s },
|
|
3863
|
+
policy: r.document,
|
|
3864
|
+
scripts: o.map((d) => ({
|
|
3865
|
+
...d,
|
|
3866
|
+
nonce: $e(r.document) ? s : d.nonce
|
|
3867
|
+
}))
|
|
3868
|
+
}
|
|
3869
|
+
}).findings.find(
|
|
3870
|
+
(d) => d.code === "csp-script-src-blocked"
|
|
3871
|
+
);
|
|
3872
|
+
if (!i) {
|
|
3873
|
+
Ma(
|
|
3874
|
+
e,
|
|
3875
|
+
t,
|
|
3876
|
+
S(r.document.csp),
|
|
3877
|
+
o
|
|
3878
|
+
);
|
|
3879
|
+
return;
|
|
3880
|
+
}
|
|
3881
|
+
const c = o.find(
|
|
3882
|
+
(d) => i.message.includes(d.src)
|
|
3883
|
+
), l = (se(r.document, { nonce: s }).get("content-security-policy") ?? "").split("; ").find(
|
|
3884
|
+
(d) => d.startsWith("script-src ")
|
|
3885
|
+
) ?? "default-src (script-src fallback)";
|
|
3886
|
+
throw new Error(
|
|
3887
|
+
`Route ${JSON.stringify(e)} export ${t} declares script ${JSON.stringify(c?.src)} that violates the effective ${l} policy.`
|
|
3888
|
+
);
|
|
3889
|
+
}
|
|
3890
|
+
const Na = [
|
|
3891
|
+
{ directive: "connectSrc", name: "connect-src", need: "connect" },
|
|
3892
|
+
{ directive: "imgSrc", name: "img-src", need: "img" }
|
|
3893
|
+
];
|
|
3894
|
+
function Ma(e, t, r, n) {
|
|
3895
|
+
if (r)
|
|
3896
|
+
for (const o of n)
|
|
3897
|
+
for (const { directive: s, name: a, need: i } of Na) {
|
|
3898
|
+
const c = o.needs?.[i] ?? [];
|
|
3899
|
+
if (c.length === 0)
|
|
3900
|
+
continue;
|
|
3901
|
+
const u = re(r[s]) ?? re(r.defaultSrc);
|
|
3902
|
+
if (u !== void 0) {
|
|
3903
|
+
for (const l of c)
|
|
3904
|
+
if (!(Array.isArray(u) && ja(u, l)))
|
|
3905
|
+
throw new Error(
|
|
3906
|
+
`Route ${JSON.stringify(e)} export ${t} declares script ${JSON.stringify(o.src)} that needs ${a} ${l}, which the effective policy does not allow. Add ${l} to security.needs.${i} or to csp.${s} for this route.`
|
|
3907
|
+
);
|
|
3908
|
+
}
|
|
3909
|
+
}
|
|
3910
|
+
}
|
|
3911
|
+
function ja(e, t) {
|
|
3912
|
+
return e.includes("'none'") ? !1 : e.includes("*") || e.includes(t) ? !0 : t.startsWith("'") ? !1 : e.some((r) => Ua(r, t));
|
|
3913
|
+
}
|
|
3914
|
+
function Ua(e, t) {
|
|
3915
|
+
if (e.startsWith("'"))
|
|
3916
|
+
return !1;
|
|
3917
|
+
let r;
|
|
3918
|
+
try {
|
|
3919
|
+
r = new URL(t);
|
|
3920
|
+
} catch {
|
|
3921
|
+
return !1;
|
|
3922
|
+
}
|
|
3923
|
+
if (e === `${r.protocol}`)
|
|
3924
|
+
return !0;
|
|
3925
|
+
let n;
|
|
3926
|
+
try {
|
|
3927
|
+
n = new URL(e);
|
|
3928
|
+
} catch {
|
|
3929
|
+
return !1;
|
|
3930
|
+
}
|
|
3931
|
+
if (n.protocol !== r.protocol || n.port !== r.port)
|
|
3932
|
+
return !1;
|
|
3933
|
+
if (n.hostname.startsWith("*.")) {
|
|
3934
|
+
const o = n.hostname.slice(1);
|
|
3935
|
+
return r.hostname.endsWith(o) && r.hostname !== n.hostname.slice(2);
|
|
3936
|
+
}
|
|
3937
|
+
return n.hostname === r.hostname;
|
|
3938
|
+
}
|
|
3939
|
+
function Ut(e, t, r, n) {
|
|
3940
|
+
ne(e, t, "effective document", () => {
|
|
3941
|
+
se(r.document ?? {}, {
|
|
3942
|
+
nonce: "startup-verification-nonce"
|
|
3943
|
+
});
|
|
3944
|
+
}), !(!n || !$e(r.document)) && ne(e, t, "effective CSP", () => {
|
|
3945
|
+
Hr(n, ["nonceInjection"]);
|
|
3946
|
+
});
|
|
3947
|
+
}
|
|
3948
|
+
function Ia(e, t, r) {
|
|
3949
|
+
if (t === "static") {
|
|
3950
|
+
const o = za(S(r?.csp));
|
|
3951
|
+
if (o)
|
|
3952
|
+
throw new Error(
|
|
3953
|
+
`Route ${JSON.stringify(e)} uses render mode "static" with an effective ${o} directive that depends on a CSP nonce. Use security.static() for static output or remove the nonce source from the document policy.`
|
|
3954
|
+
);
|
|
3955
|
+
return;
|
|
3956
|
+
}
|
|
3957
|
+
if (t !== "streaming")
|
|
3958
|
+
return;
|
|
3959
|
+
const n = Ha(S(r?.csp));
|
|
3960
|
+
if (!(!n || Fa(n.sources)))
|
|
3961
|
+
throw new Error(
|
|
3962
|
+
`Route ${JSON.stringify(e)} uses render mode "streaming" with an effective ${n.name} directive that does not allow React runtime inline payload scripts. Add a nonce placeholder or allow 'unsafe-inline' without nonce or hash sources.`
|
|
3963
|
+
);
|
|
3964
|
+
}
|
|
3965
|
+
function za(e) {
|
|
3966
|
+
if (e)
|
|
3967
|
+
for (const [t, r] of Object.entries(e)) {
|
|
3968
|
+
const n = re(r);
|
|
3969
|
+
if (Array.isArray(n) && n.some((o) => Wa(o)))
|
|
3970
|
+
return Va(t);
|
|
3971
|
+
}
|
|
3972
|
+
}
|
|
3973
|
+
function Ha(e) {
|
|
3974
|
+
if (!e)
|
|
3975
|
+
return;
|
|
3976
|
+
const t = re(e.scriptSrc);
|
|
3977
|
+
if (Array.isArray(t))
|
|
3978
|
+
return { name: "script-src", sources: t };
|
|
3979
|
+
const r = re(e.defaultSrc);
|
|
3980
|
+
if (Array.isArray(r))
|
|
3981
|
+
return { name: "default-src", sources: r };
|
|
3982
|
+
}
|
|
3983
|
+
function Fa(e) {
|
|
3984
|
+
return e.some((t) => Ar(t)) ? !0 : e.includes("'unsafe-inline'") && !e.some((t) => Ba(t));
|
|
3985
|
+
}
|
|
3986
|
+
function Wa(e) {
|
|
3987
|
+
return Ar(e) || /^'nonce-[^']*'$/i.test(e);
|
|
3988
|
+
}
|
|
3989
|
+
function Ar(e) {
|
|
3990
|
+
return e.includes("{nonce}");
|
|
3991
|
+
}
|
|
3992
|
+
function Ba(e) {
|
|
3993
|
+
return /^'(?:nonce-|sha256-|sha384-|sha512-)/i.test(e);
|
|
3994
|
+
}
|
|
3995
|
+
function re(e) {
|
|
3996
|
+
return e && typeof e == "object" && !Array.isArray(e) && "replace" in e ? e.replace : e;
|
|
3997
|
+
}
|
|
3998
|
+
function Va(e) {
|
|
3999
|
+
return e.replace(/[A-Z]/g, (t) => `-${t.toLowerCase()}`);
|
|
4000
|
+
}
|
|
4001
|
+
function ne(e, t, r, n) {
|
|
4002
|
+
try {
|
|
4003
|
+
n();
|
|
4004
|
+
} catch (o) {
|
|
4005
|
+
if (o instanceof Error && o.message.startsWith(`Route ${JSON.stringify(e)} export `))
|
|
4006
|
+
throw o;
|
|
4007
|
+
const s = o instanceof Error ? o.message : `${r} validation failed.`;
|
|
4008
|
+
throw new Error(
|
|
4009
|
+
`Route ${JSON.stringify(e)} export ${t} has an invalid ${r} policy. ${s}`,
|
|
4010
|
+
{ cause: o }
|
|
4011
|
+
);
|
|
4012
|
+
}
|
|
4013
|
+
}
|
|
4014
|
+
function qa(e) {
|
|
4015
|
+
return te({
|
|
4016
|
+
instance: `${e.pathname}${e.search}`,
|
|
4017
|
+
status: 404,
|
|
4018
|
+
title: "Not Found"
|
|
4019
|
+
});
|
|
4020
|
+
}
|
|
4021
|
+
async function Ee(e, t, r = {}) {
|
|
4022
|
+
const n = new URL(t.url), o = r.pathname ?? n.pathname;
|
|
4023
|
+
if (!F(t) && !ir(t))
|
|
4024
|
+
return qa(n);
|
|
4025
|
+
const s = await We(e, o, {
|
|
4026
|
+
locale: r.locale,
|
|
4027
|
+
onLayoutError: (l) => r.onError?.(l, "page")
|
|
4028
|
+
}), a = await _a(e, o), i = r.nonce ?? ($e(a) ? mr() : void 0), c = se(a ?? {}, {
|
|
4029
|
+
nonce: i,
|
|
4030
|
+
request: t
|
|
4031
|
+
});
|
|
4032
|
+
if (F(t))
|
|
4033
|
+
return rt(void 0, {
|
|
4034
|
+
document: Je({
|
|
4035
|
+
dir: r.dir,
|
|
4036
|
+
lang: r.lang,
|
|
4037
|
+
metadata: s.metadata,
|
|
4038
|
+
title: r.title
|
|
4039
|
+
}),
|
|
4040
|
+
locale: r.locale,
|
|
4041
|
+
headers: c,
|
|
4042
|
+
kind: Be,
|
|
4043
|
+
status: 404
|
|
4044
|
+
});
|
|
4045
|
+
const u = Ga(s, { ...r, nonce: i });
|
|
4046
|
+
return c.set("content-type", "text/html; charset=utf-8"), new Response(
|
|
4047
|
+
await r.transformDocument?.(u) ?? u,
|
|
4048
|
+
{
|
|
4049
|
+
headers: c,
|
|
4050
|
+
status: 404
|
|
4051
|
+
}
|
|
4052
|
+
);
|
|
4053
|
+
}
|
|
4054
|
+
async function _a(e, t) {
|
|
4055
|
+
const r = await Promise.all(
|
|
4056
|
+
hn(e, t).map((n) => n.load())
|
|
4057
|
+
);
|
|
4058
|
+
return ye(...r.map((n) => n.policy)).document;
|
|
4059
|
+
}
|
|
4060
|
+
function Ga(e, t = {}) {
|
|
4061
|
+
const r = e.notFound ?? Tt;
|
|
4062
|
+
try {
|
|
4063
|
+
return je(e, r, e.layouts, t);
|
|
4064
|
+
} catch (n) {
|
|
4065
|
+
t.onError?.(n, "page");
|
|
4066
|
+
}
|
|
4067
|
+
try {
|
|
4068
|
+
return je(e, r, [], t);
|
|
4069
|
+
} catch (n) {
|
|
4070
|
+
t.onError?.(n, "page");
|
|
4071
|
+
}
|
|
4072
|
+
return je(e, Tt, [], t);
|
|
4073
|
+
}
|
|
4074
|
+
function je(e, t, r, n) {
|
|
4075
|
+
const o = r.reduceRight(
|
|
4076
|
+
(a, i) => Ie(i, {
|
|
4077
|
+
children: a,
|
|
4078
|
+
locale: e.locale,
|
|
4079
|
+
path: {},
|
|
4080
|
+
pathname: e.pathname
|
|
4081
|
+
}),
|
|
4082
|
+
Ie(t, { locale: e.locale, pathname: e.pathname })
|
|
4083
|
+
), s = Ft({
|
|
4084
|
+
dev: n.dev,
|
|
4085
|
+
nonce: n.nonce
|
|
4086
|
+
});
|
|
4087
|
+
return Bt({
|
|
4088
|
+
body: {
|
|
4089
|
+
data: void 0,
|
|
4090
|
+
fallback: "not-found",
|
|
4091
|
+
html: Vt(Wt(s, o)),
|
|
4092
|
+
locale: n.locale,
|
|
4093
|
+
navigation: n.navigation
|
|
4094
|
+
},
|
|
4095
|
+
entrySrc: n.clientEntry,
|
|
4096
|
+
lang: n.lang,
|
|
4097
|
+
metadata: e.metadata,
|
|
4098
|
+
nonce: n.nonce,
|
|
4099
|
+
scripts: s.scripts(),
|
|
4100
|
+
styles: n.styles,
|
|
4101
|
+
title: n.title
|
|
4102
|
+
});
|
|
4103
|
+
}
|
|
4104
|
+
const kr = [
|
|
4105
|
+
"GET",
|
|
4106
|
+
"POST",
|
|
4107
|
+
"PUT",
|
|
4108
|
+
"PATCH",
|
|
4109
|
+
"DELETE",
|
|
4110
|
+
"OPTIONS",
|
|
4111
|
+
"HEAD"
|
|
4112
|
+
], Lr = $r();
|
|
4113
|
+
function Xi(e) {
|
|
4114
|
+
e.routeModules && $a(e.routeModules, { adapter: e.adapter });
|
|
4115
|
+
const t = Kt(e.routes), r = e.locales ? Ln(e.locales) : void 0, n = e.rateLimitStore ?? $r();
|
|
4116
|
+
return e.cacheStore && _t(e.cacheStore.namespace), async function(s) {
|
|
4117
|
+
let a = e.ssr;
|
|
4118
|
+
if (r) {
|
|
4119
|
+
const i = Cn(s, r);
|
|
4120
|
+
if (i.unsupported)
|
|
4121
|
+
return await Ee(t, s, {
|
|
4122
|
+
...e.ssr,
|
|
4123
|
+
dir: Pe(i.locale, r),
|
|
4124
|
+
lang: i.locale,
|
|
4125
|
+
locale: i.locale,
|
|
4126
|
+
pathname: i.pathname
|
|
4127
|
+
});
|
|
4128
|
+
if (i.redirect) {
|
|
4129
|
+
if (s.method !== "GET" && s.method !== "HEAD")
|
|
4130
|
+
return te({ status: 400, title: "The locale URL is not canonical." });
|
|
4131
|
+
const u = i.source === "cookie" || i.source === "accept-language";
|
|
4132
|
+
if (u && !await Ja(t, i.pathname))
|
|
4133
|
+
return await Ue(t, s, {
|
|
4134
|
+
cacheStore: e.cacheStore,
|
|
4135
|
+
onError: e.onError,
|
|
4136
|
+
rateLimitStore: n,
|
|
4137
|
+
renderPage: e.renderPage,
|
|
4138
|
+
routePathname: i.pathname,
|
|
4139
|
+
ssr: {
|
|
4140
|
+
...e.ssr,
|
|
4141
|
+
dir: Pe(r.defaultLocale, r),
|
|
4142
|
+
lang: r.defaultLocale,
|
|
4143
|
+
locale: r.defaultLocale
|
|
4144
|
+
}
|
|
4145
|
+
});
|
|
4146
|
+
const l = new Headers({ location: i.redirect.href });
|
|
4147
|
+
return u && (l.set("cache-control", "private, no-store"), l.set("vary", [r.cookie ? "Cookie" : void 0, "Accept-Language"].filter(Boolean).join(", "))), new Response(null, { headers: l, status: u ? 307 : 308 });
|
|
4148
|
+
}
|
|
4149
|
+
a = {
|
|
4150
|
+
...e.ssr,
|
|
4151
|
+
dir: Pe(i.locale, r),
|
|
4152
|
+
lang: i.locale,
|
|
4153
|
+
locale: i.locale
|
|
4154
|
+
};
|
|
4155
|
+
const c = await Ue(t, s, {
|
|
4156
|
+
cacheStore: e.cacheStore,
|
|
4157
|
+
locales: r,
|
|
4158
|
+
onError: e.onError,
|
|
4159
|
+
rateLimitStore: n,
|
|
4160
|
+
renderPage: e.renderPage,
|
|
4161
|
+
routePathname: i.pathname,
|
|
4162
|
+
ssr: a
|
|
4163
|
+
});
|
|
4164
|
+
return Ka(c, s, i.locale, r), c;
|
|
4165
|
+
}
|
|
4166
|
+
return await Ue(t, s, {
|
|
4167
|
+
cacheStore: e.cacheStore,
|
|
4168
|
+
onError: e.onError,
|
|
4169
|
+
rateLimitStore: n,
|
|
4170
|
+
renderPage: e.renderPage,
|
|
4171
|
+
ssr: a
|
|
4172
|
+
});
|
|
4173
|
+
};
|
|
4174
|
+
}
|
|
4175
|
+
async function Ja(e, t) {
|
|
4176
|
+
const r = V(e.routes, t);
|
|
4177
|
+
return r ? (await r.route.load()).GET?.kind === "page" : !0;
|
|
4178
|
+
}
|
|
4179
|
+
function Ka(e, t, r, n) {
|
|
4180
|
+
const o = e.headers.get("location");
|
|
4181
|
+
if (!o) return;
|
|
4182
|
+
const s = new URL(t.url);
|
|
4183
|
+
new URL(o, s).origin === s.origin && e.headers.set(
|
|
4184
|
+
"location",
|
|
4185
|
+
er(o, r, n, s.href)
|
|
4186
|
+
);
|
|
4187
|
+
}
|
|
4188
|
+
async function Ue(e, t, r = {
|
|
4189
|
+
rateLimitStore: Lr
|
|
4190
|
+
}) {
|
|
4191
|
+
const n = new URL(t.url), o = r.routePathname ?? n.pathname, s = ri(n, r), a = F(t);
|
|
4192
|
+
let i;
|
|
4193
|
+
try {
|
|
4194
|
+
i = V(e.routes, o);
|
|
4195
|
+
} catch (c) {
|
|
4196
|
+
if (!(c instanceof tt))
|
|
4197
|
+
throw c;
|
|
4198
|
+
const u = te({
|
|
4199
|
+
instance: `${n.pathname}${n.search}`,
|
|
4200
|
+
status: 400,
|
|
4201
|
+
title: "Bad Request"
|
|
4202
|
+
});
|
|
4203
|
+
return a ? ce(u, fe) : u;
|
|
4204
|
+
}
|
|
4205
|
+
if (!i)
|
|
4206
|
+
try {
|
|
4207
|
+
const c = await Ee(
|
|
4208
|
+
e,
|
|
4209
|
+
t,
|
|
4210
|
+
s
|
|
4211
|
+
);
|
|
4212
|
+
return a ? ce(c, Be) : c;
|
|
4213
|
+
} catch (c) {
|
|
4214
|
+
return s.onError(c, "page"), new Response("Not Found", {
|
|
4215
|
+
headers: { "content-type": "text/plain; charset=utf-8" },
|
|
4216
|
+
status: 404
|
|
4217
|
+
});
|
|
4218
|
+
}
|
|
4219
|
+
try {
|
|
4220
|
+
const c = await Ya(
|
|
4221
|
+
e,
|
|
4222
|
+
t,
|
|
4223
|
+
n,
|
|
4224
|
+
i,
|
|
4225
|
+
o,
|
|
4226
|
+
r,
|
|
4227
|
+
s
|
|
4228
|
+
);
|
|
4229
|
+
return a && !c.headers.has(H) ? ce(
|
|
4230
|
+
c,
|
|
4231
|
+
c.status === 404 ? Be : fe
|
|
4232
|
+
) : c;
|
|
4233
|
+
} catch (c) {
|
|
4234
|
+
const u = await me(
|
|
4235
|
+
e,
|
|
4236
|
+
t,
|
|
4237
|
+
c,
|
|
4238
|
+
"middleware",
|
|
4239
|
+
s
|
|
4240
|
+
);
|
|
4241
|
+
return a ? ce(u, fe) : u;
|
|
4242
|
+
}
|
|
4243
|
+
}
|
|
4244
|
+
async function Ya(e, t, r, n, o, s, a) {
|
|
4245
|
+
const i = await n.route.load();
|
|
4246
|
+
if (t.method.toUpperCase() === "OPTIONS") {
|
|
4247
|
+
const p = rs(i, t);
|
|
4248
|
+
if (p)
|
|
4249
|
+
return p;
|
|
4250
|
+
}
|
|
4251
|
+
const c = ai(t.method);
|
|
4252
|
+
if (!c)
|
|
4253
|
+
return Ht(i);
|
|
4254
|
+
const u = ii(i, c);
|
|
4255
|
+
if (!u)
|
|
4256
|
+
return Ht(i);
|
|
4257
|
+
const l = await oi(
|
|
4258
|
+
e,
|
|
4259
|
+
n.route,
|
|
4260
|
+
i,
|
|
4261
|
+
u
|
|
4262
|
+
), d = l.security, h = Qs(
|
|
4263
|
+
d?.fetchMetadata,
|
|
4264
|
+
t,
|
|
4265
|
+
c
|
|
4266
|
+
), f = (p) => Er(p, h.vary);
|
|
4267
|
+
if (h.response)
|
|
4268
|
+
return f(
|
|
4269
|
+
Z(
|
|
4270
|
+
h.response,
|
|
4271
|
+
de(u),
|
|
4272
|
+
t
|
|
4273
|
+
)
|
|
4274
|
+
);
|
|
4275
|
+
const m = await Ws(d?.csrf, t);
|
|
4276
|
+
if (m)
|
|
4277
|
+
return f(
|
|
4278
|
+
Z(m, de(u), t)
|
|
4279
|
+
);
|
|
4280
|
+
const w = await va(
|
|
4281
|
+
d?.rateLimit,
|
|
4282
|
+
t,
|
|
4283
|
+
s.rateLimitStore ?? Lr
|
|
4284
|
+
);
|
|
4285
|
+
if (w)
|
|
4286
|
+
return f(
|
|
4287
|
+
Z(
|
|
4288
|
+
w,
|
|
4289
|
+
de(u),
|
|
4290
|
+
t
|
|
4291
|
+
)
|
|
4292
|
+
);
|
|
4293
|
+
const g = ls(
|
|
4294
|
+
d?.request,
|
|
4295
|
+
t,
|
|
4296
|
+
c
|
|
4297
|
+
);
|
|
4298
|
+
if (g)
|
|
4299
|
+
return f(
|
|
4300
|
+
Z(
|
|
4301
|
+
g,
|
|
4302
|
+
de(u),
|
|
4303
|
+
t
|
|
4304
|
+
)
|
|
4305
|
+
);
|
|
4306
|
+
t = ds(d?.request, t);
|
|
4307
|
+
const O = {}, xe = ti(s.cacheStore, s.ssr?.locale);
|
|
4308
|
+
if (u.kind === "page") {
|
|
4309
|
+
const p = {
|
|
4310
|
+
locale: s.ssr?.locale,
|
|
4311
|
+
path: n.path,
|
|
4312
|
+
pathname: o,
|
|
4313
|
+
request: t,
|
|
4314
|
+
context: O,
|
|
4315
|
+
search: r.searchParams,
|
|
4316
|
+
url: r
|
|
4317
|
+
}, Pr = await It(
|
|
4318
|
+
e,
|
|
4319
|
+
n.route
|
|
4320
|
+
), G = $e(l.document) ? mr() : void 0;
|
|
4321
|
+
let b;
|
|
4322
|
+
try {
|
|
4323
|
+
b = await zt(Pr, p, async () => {
|
|
4324
|
+
try {
|
|
4325
|
+
const v = await xt(l.access, p);
|
|
4326
|
+
if (v)
|
|
4327
|
+
return v;
|
|
4328
|
+
const y = await Yt(
|
|
4329
|
+
e,
|
|
4330
|
+
o,
|
|
4331
|
+
t,
|
|
4332
|
+
void 0,
|
|
4333
|
+
xe,
|
|
4334
|
+
{ locale: s.ssr?.locale, requestContext: O }
|
|
4335
|
+
);
|
|
4336
|
+
if (y.status !== "ready")
|
|
4337
|
+
return await Ee(e, t, {
|
|
4338
|
+
...a,
|
|
4339
|
+
nonce: G
|
|
4340
|
+
});
|
|
4341
|
+
if (s.locales && s.ssr?.locale && (y.match.metadata = Za(
|
|
4342
|
+
y.match.metadata,
|
|
4343
|
+
t,
|
|
4344
|
+
o,
|
|
4345
|
+
s.ssr.locale,
|
|
4346
|
+
s.locales
|
|
4347
|
+
)), F(t))
|
|
4348
|
+
return rt(y.match.data, {
|
|
4349
|
+
document: Je({
|
|
4350
|
+
dir: s.ssr?.dir,
|
|
4351
|
+
lang: s.ssr?.lang,
|
|
4352
|
+
links: y.match.links,
|
|
4353
|
+
metadata: y.match.metadata,
|
|
4354
|
+
scripts: y.match.scripts,
|
|
4355
|
+
title: s.ssr?.title
|
|
4356
|
+
}),
|
|
4357
|
+
locale: s.ssr?.locale
|
|
4358
|
+
});
|
|
4359
|
+
if (y.match.render.mode === "streaming" && !s.renderPage)
|
|
4360
|
+
throw new Error(
|
|
4361
|
+
"Streaming page routes require an adapter renderer. Pass renderNodePageResponse from @demiurgejs/core/node as createRequestHandler({ renderPage })."
|
|
4362
|
+
);
|
|
4363
|
+
return await (s.renderPage ?? Fr)(y.match, {
|
|
4364
|
+
...s.ssr,
|
|
4365
|
+
dev: s.dev,
|
|
4366
|
+
nonce: G,
|
|
4367
|
+
onStreamError: (Or) => {
|
|
4368
|
+
s.onError?.(Or, {
|
|
4369
|
+
pathname: r.pathname,
|
|
4370
|
+
site: "page"
|
|
4371
|
+
});
|
|
4372
|
+
},
|
|
4373
|
+
signal: t.signal
|
|
4374
|
+
});
|
|
4375
|
+
} catch (v) {
|
|
4376
|
+
return v instanceof Q ? ue() : await me(e, t, v, "page", {
|
|
4377
|
+
...a,
|
|
4378
|
+
nonce: G
|
|
4379
|
+
});
|
|
4380
|
+
}
|
|
4381
|
+
});
|
|
4382
|
+
} catch (v) {
|
|
4383
|
+
if (!(v instanceof Q))
|
|
4384
|
+
throw v;
|
|
4385
|
+
b = ue();
|
|
4386
|
+
}
|
|
4387
|
+
const Dr = se(l.document ?? {}, {
|
|
4388
|
+
nonce: G,
|
|
4389
|
+
request: t
|
|
4390
|
+
});
|
|
4391
|
+
for (const [v, y] of Dr)
|
|
4392
|
+
b.headers.set(v, y);
|
|
4393
|
+
return G && b.headers.set("cache-control", "private, no-store"), f(b), c === "HEAD" ? (await b.body?.cancel(), new Response(null, {
|
|
4394
|
+
headers: b.headers,
|
|
4395
|
+
status: b.status
|
|
4396
|
+
})) : b;
|
|
4397
|
+
}
|
|
4398
|
+
const _ = {
|
|
4399
|
+
locale: s.ssr?.locale,
|
|
4400
|
+
path: n.path,
|
|
4401
|
+
pathname: o,
|
|
4402
|
+
request: t,
|
|
4403
|
+
context: O,
|
|
4404
|
+
search: r.searchParams,
|
|
4405
|
+
url: r
|
|
4406
|
+
}, Cr = await It(
|
|
4407
|
+
e,
|
|
4408
|
+
n.route
|
|
4409
|
+
);
|
|
4410
|
+
let ie;
|
|
4411
|
+
try {
|
|
4412
|
+
ie = await zt(Cr, _, async () => {
|
|
4413
|
+
try {
|
|
4414
|
+
const p = await xt(l.access, _);
|
|
4415
|
+
return p || (u.kind === "not-found" && u.body === void 0 ? ni(
|
|
4416
|
+
await Ee(e, t, a),
|
|
4417
|
+
u.init
|
|
4418
|
+
) : await or(u, _));
|
|
4419
|
+
} catch (p) {
|
|
4420
|
+
return p instanceof Q ? ue() : await me(
|
|
4421
|
+
e,
|
|
4422
|
+
t,
|
|
4423
|
+
p,
|
|
4424
|
+
"route",
|
|
4425
|
+
a
|
|
4426
|
+
);
|
|
4427
|
+
}
|
|
4428
|
+
});
|
|
4429
|
+
} catch (p) {
|
|
4430
|
+
if (!(p instanceof Q))
|
|
4431
|
+
throw p;
|
|
4432
|
+
ie = ue();
|
|
4433
|
+
}
|
|
4434
|
+
try {
|
|
4435
|
+
return await Qa(ie, xe, "mutation" in u && u.mutation === !0), f(
|
|
4436
|
+
si(ie, u, t, c)
|
|
4437
|
+
);
|
|
4438
|
+
} catch (p) {
|
|
4439
|
+
return f(
|
|
4440
|
+
await me(
|
|
4441
|
+
e,
|
|
4442
|
+
t,
|
|
4443
|
+
p,
|
|
4444
|
+
"route",
|
|
4445
|
+
a
|
|
4446
|
+
)
|
|
4447
|
+
);
|
|
4448
|
+
}
|
|
4449
|
+
}
|
|
4450
|
+
function Za(e, t, r, n, o) {
|
|
4451
|
+
const s = t.url, a = (c) => new URL(er(r, c, o, s), s).href, i = o.supportedLocales.map((c) => ({
|
|
4452
|
+
href: a(c),
|
|
4453
|
+
hrefLang: c
|
|
4454
|
+
}));
|
|
4455
|
+
return o.xDefault && i.push({
|
|
4456
|
+
href: a(o.xDefault),
|
|
4457
|
+
hrefLang: "x-default"
|
|
4458
|
+
}), Wr(e, {
|
|
4459
|
+
alternates: i,
|
|
4460
|
+
canonical: a(n)
|
|
4461
|
+
});
|
|
4462
|
+
}
|
|
4463
|
+
async function Qa(e, t, r) {
|
|
4464
|
+
const n = e.headers.get(W);
|
|
4465
|
+
if (e.headers.delete(W), !n || !r || e.status < 200 || e.status >= 400) return;
|
|
4466
|
+
const o = Xa(n);
|
|
4467
|
+
for (const s of o.keys) await t.invalidateKey(s);
|
|
4468
|
+
o.tags.length > 0 && await t.invalidateTags(
|
|
4469
|
+
o.tags.map((s) => ({ id: s }))
|
|
4470
|
+
);
|
|
4471
|
+
}
|
|
4472
|
+
function Xa(e) {
|
|
4473
|
+
let t;
|
|
4474
|
+
try {
|
|
4475
|
+
t = JSON.parse(decodeURIComponent(e));
|
|
4476
|
+
} catch {
|
|
4477
|
+
throw le();
|
|
4478
|
+
}
|
|
4479
|
+
if (!oe(t) || t.version !== 1 || Object.keys(t).sort().join(",") !== "keys,tags,version" || !Array.isArray(t.keys) || !t.keys.every(ei) || !Array.isArray(t.tags) || !t.tags.every((n) => typeof n == "string"))
|
|
4480
|
+
throw le();
|
|
4481
|
+
return { keys: t.keys, tags: t.tags };
|
|
4482
|
+
}
|
|
4483
|
+
function ei(e) {
|
|
4484
|
+
return Array.isArray(e) && e.every(Ge);
|
|
4485
|
+
}
|
|
4486
|
+
function Ge(e) {
|
|
4487
|
+
return e === null || typeof e == "string" || typeof e == "boolean" ? !0 : typeof e == "number" ? Number.isFinite(e) : Array.isArray(e) ? e.every(Ge) : oe(e) && Object.values(e).every(Ge);
|
|
4488
|
+
}
|
|
4489
|
+
function le() {
|
|
4490
|
+
return new Error("Demiurge received invalid internal mutation invalidation metadata.");
|
|
4491
|
+
}
|
|
4492
|
+
function ti(e, t) {
|
|
4493
|
+
const r = e ? qt(e) : Ke();
|
|
4494
|
+
if (!t) return r;
|
|
4495
|
+
const n = (s) => ({ id: `demiurge:locale:${t}:${s}` }), o = (s) => [
|
|
4496
|
+
{ "demiurge:locale": t },
|
|
4497
|
+
...s
|
|
4498
|
+
];
|
|
4499
|
+
return {
|
|
4500
|
+
get: (s) => r.get(
|
|
4501
|
+
s.locale === "neutral" ? s : {
|
|
4502
|
+
...s,
|
|
4503
|
+
key: o(s.key),
|
|
4504
|
+
tags: s.tags?.map((a) => n(a.id))
|
|
4505
|
+
}
|
|
4506
|
+
),
|
|
4507
|
+
invalidateKey: (s) => r.invalidateKey(o(s)),
|
|
4508
|
+
invalidateTags: (s) => r.invalidateTags(
|
|
4509
|
+
s.map((a) => n(a.id))
|
|
4510
|
+
)
|
|
4511
|
+
};
|
|
4512
|
+
}
|
|
4513
|
+
function ri(e, t) {
|
|
4514
|
+
return {
|
|
4515
|
+
...t.ssr,
|
|
4516
|
+
dev: t.dev,
|
|
4517
|
+
pathname: t.routePathname ?? e.pathname,
|
|
4518
|
+
onError: (r, n) => {
|
|
4519
|
+
t.onError?.(r, { pathname: e.pathname, site: n });
|
|
4520
|
+
},
|
|
4521
|
+
transformDocument: t.transformDocument
|
|
4522
|
+
};
|
|
4523
|
+
}
|
|
4524
|
+
function ni(e, t) {
|
|
4525
|
+
if (!t)
|
|
4526
|
+
return e;
|
|
4527
|
+
const r = new Headers(e.headers), n = new Headers(t.headers);
|
|
4528
|
+
for (const [o, s] of n)
|
|
4529
|
+
o !== "set-cookie" && r.set(o, s);
|
|
4530
|
+
for (const o of n.getSetCookie())
|
|
4531
|
+
r.append("set-cookie", o);
|
|
4532
|
+
return new Response(e.body, {
|
|
4533
|
+
headers: r,
|
|
4534
|
+
status: t.status ?? e.status,
|
|
4535
|
+
statusText: t.statusText ?? e.statusText
|
|
4536
|
+
});
|
|
4537
|
+
}
|
|
4538
|
+
async function oi(e, t, r, n) {
|
|
4539
|
+
const o = e.policies.filter(
|
|
4540
|
+
(i) => C(i.fileSegments, t.fileSegments)
|
|
4541
|
+
), s = await Promise.all(
|
|
4542
|
+
o.map((i) => i.load())
|
|
4543
|
+
);
|
|
4544
|
+
return {
|
|
4545
|
+
...ye(
|
|
4546
|
+
...s.map(
|
|
4547
|
+
(i, c) => Co(i.policy, o[c]?.file)
|
|
4548
|
+
),
|
|
4549
|
+
r.policy,
|
|
4550
|
+
{
|
|
4551
|
+
security: !n || n.kind === "page" ? void 0 : n.security
|
|
4552
|
+
}
|
|
4553
|
+
),
|
|
4554
|
+
access: cr([
|
|
4555
|
+
...s.map((i, c) => ({
|
|
4556
|
+
policy: i.policy?.access,
|
|
4557
|
+
source: o[c]?.file
|
|
4558
|
+
})),
|
|
4559
|
+
{ policy: r.policy?.access }
|
|
4560
|
+
])
|
|
4561
|
+
};
|
|
4562
|
+
}
|
|
4563
|
+
async function It(e, t) {
|
|
4564
|
+
return (await Promise.all(
|
|
4565
|
+
e.middlewares.filter(
|
|
4566
|
+
(n) => C(n.fileSegments, t.fileSegments)
|
|
4567
|
+
).map((n) => n.load())
|
|
4568
|
+
)).flatMap(
|
|
4569
|
+
(n) => n.middleware ? [n.middleware] : []
|
|
4570
|
+
);
|
|
4571
|
+
}
|
|
4572
|
+
async function zt(e, t, r) {
|
|
4573
|
+
let n = -1;
|
|
4574
|
+
async function o(s) {
|
|
4575
|
+
if (s <= n)
|
|
4576
|
+
throw new Error("Demiurge route middleware next() called multiple times.");
|
|
4577
|
+
n = s;
|
|
4578
|
+
const a = e[s];
|
|
4579
|
+
return a ? await a(t, () => o(s + 1)) : await r();
|
|
4580
|
+
}
|
|
4581
|
+
return await o(0);
|
|
4582
|
+
}
|
|
4583
|
+
function si(e, t, r, n) {
|
|
4584
|
+
const o = qn(
|
|
4585
|
+
Z(e, t.cors, r),
|
|
4586
|
+
t.timing
|
|
4587
|
+
);
|
|
4588
|
+
return n === "HEAD" ? new Response(null, {
|
|
4589
|
+
headers: o.headers,
|
|
4590
|
+
status: o.status,
|
|
4591
|
+
statusText: o.statusText
|
|
4592
|
+
}) : o;
|
|
4593
|
+
}
|
|
4594
|
+
function de(e) {
|
|
4595
|
+
return e.kind === "page" ? void 0 : e.cors;
|
|
4596
|
+
}
|
|
4597
|
+
function ai(e) {
|
|
4598
|
+
const t = e.toUpperCase();
|
|
4599
|
+
return kr.includes(t) ? t : null;
|
|
4600
|
+
}
|
|
4601
|
+
function ii(e, t) {
|
|
4602
|
+
return t === "HEAD" ? e.HEAD ?? e.GET : e[t];
|
|
4603
|
+
}
|
|
4604
|
+
function Ht(e) {
|
|
4605
|
+
return new Response(null, {
|
|
4606
|
+
headers: {
|
|
4607
|
+
allow: ci(e).join(", ")
|
|
4608
|
+
},
|
|
4609
|
+
status: 405
|
|
4610
|
+
});
|
|
4611
|
+
}
|
|
4612
|
+
function ci(e) {
|
|
4613
|
+
const t = kr.filter((r) => e[r]);
|
|
4614
|
+
return e.GET && !t.includes("HEAD") && t.push("HEAD"), t;
|
|
4615
|
+
}
|
|
4616
|
+
export {
|
|
4617
|
+
En as $,
|
|
4618
|
+
C as A,
|
|
4619
|
+
Re as B,
|
|
4620
|
+
V as C,
|
|
4621
|
+
dt as D,
|
|
4622
|
+
$e as E,
|
|
4623
|
+
mr as F,
|
|
4624
|
+
ws as G,
|
|
4625
|
+
Ke as H,
|
|
4626
|
+
ze as I,
|
|
4627
|
+
gt as J,
|
|
4628
|
+
Ki as K,
|
|
4629
|
+
Kt as L,
|
|
4630
|
+
tt as M,
|
|
4631
|
+
Yi as N,
|
|
4632
|
+
z as O,
|
|
4633
|
+
Bs as P,
|
|
4634
|
+
ds as Q,
|
|
4635
|
+
Q as R,
|
|
4636
|
+
ki as S,
|
|
4637
|
+
Tn as T,
|
|
4638
|
+
Qn as U,
|
|
4639
|
+
Ve as V,
|
|
4640
|
+
Zn as W,
|
|
4641
|
+
Li as X,
|
|
4642
|
+
Ti as Y,
|
|
4643
|
+
ln as Z,
|
|
4644
|
+
H as _,
|
|
4645
|
+
x as a,
|
|
4646
|
+
_t as a$,
|
|
4647
|
+
Rn as a0,
|
|
4648
|
+
Be as a1,
|
|
4649
|
+
fe as a2,
|
|
4650
|
+
so as a3,
|
|
4651
|
+
Fi as a4,
|
|
4652
|
+
Tt as a5,
|
|
4653
|
+
j as a6,
|
|
4654
|
+
I as a7,
|
|
4655
|
+
Rr as a8,
|
|
4656
|
+
ar as a9,
|
|
4657
|
+
va as aA,
|
|
4658
|
+
ls as aB,
|
|
4659
|
+
N as aC,
|
|
4660
|
+
ur as aD,
|
|
4661
|
+
lr as aE,
|
|
4662
|
+
Oi as aF,
|
|
4663
|
+
vi as aG,
|
|
4664
|
+
_i as aH,
|
|
4665
|
+
Ci as aI,
|
|
4666
|
+
Pi as aJ,
|
|
4667
|
+
Br as aK,
|
|
4668
|
+
To as aL,
|
|
4669
|
+
ye as aM,
|
|
4670
|
+
jo as aN,
|
|
4671
|
+
pi as aO,
|
|
4672
|
+
zi as aP,
|
|
4673
|
+
Hi as aQ,
|
|
4674
|
+
Mi as aR,
|
|
4675
|
+
xr as aS,
|
|
4676
|
+
$o as aT,
|
|
4677
|
+
wi as aU,
|
|
4678
|
+
Zi as aV,
|
|
4679
|
+
Ni as aW,
|
|
4680
|
+
Lo as aX,
|
|
4681
|
+
T as aY,
|
|
4682
|
+
cr as aZ,
|
|
4683
|
+
Mn as a_,
|
|
4684
|
+
sr as aa,
|
|
4685
|
+
Jt as ab,
|
|
4686
|
+
Er as ac,
|
|
4687
|
+
Wr as ad,
|
|
4688
|
+
Co as ae,
|
|
4689
|
+
Ss as af,
|
|
4690
|
+
xt as ag,
|
|
4691
|
+
yi as ah,
|
|
4692
|
+
Zs as ai,
|
|
4693
|
+
qt as aj,
|
|
4694
|
+
vr as ak,
|
|
4695
|
+
Fs as al,
|
|
4696
|
+
Hs as am,
|
|
4697
|
+
Ei as an,
|
|
4698
|
+
Zr as ao,
|
|
4699
|
+
At as ap,
|
|
4700
|
+
Wi as aq,
|
|
4701
|
+
Gi as ar,
|
|
4702
|
+
mi as as,
|
|
4703
|
+
Vi as at,
|
|
4704
|
+
Bi as au,
|
|
4705
|
+
bi as av,
|
|
4706
|
+
ua as aw,
|
|
4707
|
+
fs as ax,
|
|
4708
|
+
Ws as ay,
|
|
4709
|
+
Qs as az,
|
|
4710
|
+
$a as b,
|
|
4711
|
+
Ii as b0,
|
|
4712
|
+
Ui as b1,
|
|
4713
|
+
ji as b2,
|
|
4714
|
+
gi as b3,
|
|
4715
|
+
Si as b4,
|
|
4716
|
+
Di as b5,
|
|
4717
|
+
or as b6,
|
|
4718
|
+
Qi as b7,
|
|
4719
|
+
Ji as b8,
|
|
4720
|
+
xi as b9,
|
|
4721
|
+
Ai as ba,
|
|
4722
|
+
$i as bb,
|
|
4723
|
+
pn as bc,
|
|
4724
|
+
bn as bd,
|
|
4725
|
+
Te as be,
|
|
4726
|
+
Xi as c,
|
|
4727
|
+
Ri as d,
|
|
4728
|
+
$r as e,
|
|
4729
|
+
Ln as f,
|
|
4730
|
+
Ee as g,
|
|
4731
|
+
Ue as h,
|
|
4732
|
+
oe as i,
|
|
4733
|
+
Pe as j,
|
|
4734
|
+
qi as k,
|
|
4735
|
+
er as l,
|
|
4736
|
+
Mo as m,
|
|
4737
|
+
se as n,
|
|
4738
|
+
ht as o,
|
|
4739
|
+
S as p,
|
|
4740
|
+
dr as q,
|
|
4741
|
+
Cn as r,
|
|
4742
|
+
Se as s,
|
|
4743
|
+
Xt as t,
|
|
4744
|
+
ct as u,
|
|
4745
|
+
lt as v,
|
|
4746
|
+
J as w,
|
|
4747
|
+
P as x,
|
|
4748
|
+
oi as y,
|
|
4749
|
+
Yt as z
|
|
4750
|
+
};
|
|
4751
|
+
//# sourceMappingURL=testing-CUwGj2ie.js.map
|