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