@demiurgejs/core 0.2.0-beta.3 → 0.2.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -11
- package/bin/demiurge.mjs +47 -13
- package/dist/adapter/index.d.ts +1 -1
- package/dist/adapter/index.d.ts.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-9GPwtcTt.js +36 -0
- package/dist/chunks/document-shell-9GPwtcTt.js.map +1 -0
- package/dist/chunks/{image-codec-Di53WpcH.js → image-codec-Dh1POFhE.js} +2 -2
- package/dist/chunks/{image-codec-Di53WpcH.js.map → image-codec-Dh1POFhE.js.map} +1 -1
- package/dist/chunks/{images-Edar3eU1.js → images-CG7ZzayG.js} +99 -91
- package/dist/chunks/images-CG7ZzayG.js.map +1 -0
- package/dist/chunks/index-0MNiR_wo.js +833 -0
- package/dist/chunks/index-0MNiR_wo.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-BZauDxRY.js +2310 -0
- package/dist/chunks/plugin-BZauDxRY.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-GYIsVTQH.js +560 -0
- package/dist/chunks/streaming-GYIsVTQH.js.map +1 -0
- package/dist/chunks/testing-CUwGj2ie.js +4751 -0
- package/dist/chunks/testing-CUwGj2ie.js.map +1 -0
- package/dist/chunks/vite-QoqrGl6f.js +259 -0
- package/dist/chunks/vite-QoqrGl6f.js.map +1 -0
- package/dist/cli.d.ts +19 -25
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +289 -128
- 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 +74 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/validate.d.ts +9 -0
- package/dist/config/validate.d.ts.map +1 -0
- package/dist/config/vite.d.ts +12 -0
- package/dist/config/vite.d.ts.map +1 -0
- package/dist/data/cache.d.ts +2 -0
- package/dist/data/cache.d.ts.map +1 -1
- package/dist/data/idempotency.d.ts.map +1 -1
- package/dist/deployment/testing.d.ts +25 -0
- package/dist/deployment/testing.d.ts.map +1 -0
- package/dist/deployment/testing.js +171 -0
- package/dist/deployment/testing.js.map +1 -0
- package/dist/document/hydration.d.ts +9 -0
- package/dist/document/hydration.d.ts.map +1 -1
- package/dist/document/index.d.ts +4 -2
- package/dist/document/index.d.ts.map +1 -1
- package/dist/document/metadata.d.ts +8 -0
- package/dist/document/metadata.d.ts.map +1 -1
- package/dist/document/navigation.d.ts +28 -0
- package/dist/document/navigation.d.ts.map +1 -0
- package/dist/document/render.d.ts +3 -1
- package/dist/document/render.d.ts.map +1 -1
- package/dist/document/seo.d.ts.map +1 -1
- package/dist/edge/assets.d.ts.map +1 -1
- package/dist/edge/index.js +55 -73
- package/dist/edge/index.js.map +1 -1
- package/dist/index.d.ts +12 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1883 -692
- package/dist/index.js.map +1 -1
- package/dist/inspect/command.d.ts +28 -0
- package/dist/inspect/command.d.ts.map +1 -0
- package/dist/inspect/index.d.ts +9 -0
- package/dist/inspect/index.d.ts.map +1 -0
- package/dist/inspect/redact.d.ts +35 -0
- package/dist/inspect/redact.d.ts.map +1 -0
- package/dist/inspect/report.d.ts +24 -0
- package/dist/inspect/report.d.ts.map +1 -0
- package/dist/inspect/types.d.ts +102 -0
- package/dist/inspect/types.d.ts.map +1 -0
- package/dist/internal/testing.js +5 -5
- package/dist/kv/index.d.ts +2 -0
- package/dist/kv/index.d.ts.map +1 -1
- package/dist/kv/index.js +170 -73
- package/dist/kv/index.js.map +1 -1
- package/dist/kv/session-store.d.ts +20 -0
- package/dist/kv/session-store.d.ts.map +1 -0
- package/dist/manifest.d.ts +10 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/node/http.d.ts +5 -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 +4 -1
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +257 -182
- package/dist/node/index.js.map +1 -1
- package/dist/node/serve.d.ts +47 -0
- package/dist/node/serve.d.ts.map +1 -0
- package/dist/node/static.d.ts.map +1 -1
- package/dist/platform/fonts.d.ts.map +1 -1
- package/dist/platform/image-url.d.ts.map +1 -1
- package/dist/platform/url.d.ts +19 -0
- package/dist/platform/url.d.ts.map +1 -0
- package/dist/platform/web-vitals.d.ts.map +1 -1
- package/dist/redis/index.d.ts +2 -0
- package/dist/redis/index.d.ts.map +1 -1
- package/dist/redis/index.js +186 -69
- package/dist/redis/index.js.map +1 -1
- package/dist/redis/session-store.d.ts +9 -0
- package/dist/redis/session-store.d.ts.map +1 -0
- package/dist/route/index.d.ts +3 -2
- package/dist/route/index.d.ts.map +1 -1
- package/dist/route/mutation.d.ts +97 -0
- package/dist/route/mutation.d.ts.map +1 -0
- package/dist/route/serialization.d.ts +24 -0
- package/dist/route/serialization.d.ts.map +1 -0
- package/dist/route/types.d.ts +6 -1
- package/dist/route/types.d.ts.map +1 -1
- package/dist/route/webhook.d.ts +6 -1
- package/dist/route/webhook.d.ts.map +1 -1
- package/dist/router/manifest.d.ts +8 -0
- package/dist/router/manifest.d.ts.map +1 -1
- package/dist/router/navigation-data.d.ts +9 -1
- package/dist/router/navigation-data.d.ts.map +1 -1
- package/dist/routing/generate.d.ts +3 -0
- package/dist/routing/generate.d.ts.map +1 -1
- package/dist/routing/index.d.ts +3 -1
- package/dist/routing/index.d.ts.map +1 -1
- package/dist/routing/locale.d.ts +43 -0
- package/dist/routing/locale.d.ts.map +1 -0
- package/dist/routing/types.d.ts +12 -0
- package/dist/routing/types.d.ts.map +1 -1
- package/dist/security/audit.d.ts +2 -1
- package/dist/security/audit.d.ts.map +1 -1
- package/dist/security/authorization.d.ts +36 -0
- package/dist/security/authorization.d.ts.map +1 -0
- package/dist/security/cookie-session.d.ts +43 -0
- package/dist/security/cookie-session.d.ts.map +1 -0
- package/dist/security/csrf.d.ts +1 -1
- package/dist/security/csrf.d.ts.map +1 -1
- package/dist/security/env-startup.d.ts +13 -0
- package/dist/security/env-startup.d.ts.map +1 -0
- package/dist/security/env.d.ts +49 -11
- package/dist/security/env.d.ts.map +1 -1
- package/dist/security/exceptions.d.ts +29 -0
- package/dist/security/exceptions.d.ts.map +1 -0
- package/dist/security/finding-codes.d.ts +56 -0
- package/dist/security/finding-codes.d.ts.map +1 -0
- package/dist/security/index.d.ts +14 -3
- package/dist/security/index.d.ts.map +1 -1
- package/dist/security/policy.d.ts +2 -5
- package/dist/security/policy.d.ts.map +1 -1
- package/dist/security/report.d.ts +2 -1
- package/dist/security/report.d.ts.map +1 -1
- package/dist/security/request.d.ts +1 -0
- package/dist/security/request.d.ts.map +1 -1
- package/dist/security/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 +139 -5
- package/dist/security/types.d.ts.map +1 -1
- package/dist/security/upload.d.ts +3 -3
- package/dist/security/upload.d.ts.map +1 -1
- package/dist/security/verification.d.ts.map +1 -1
- package/dist/server/document-shell.d.ts.map +1 -1
- package/dist/server/errors.d.ts +1 -0
- package/dist/server/errors.d.ts.map +1 -1
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/not-found.d.ts +1 -0
- package/dist/server/not-found.d.ts.map +1 -1
- package/dist/server/render-tree.d.ts.map +1 -1
- package/dist/server/request-handler.d.ts +7 -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/server-only/browser.d.ts +2 -0
- package/dist/server-only/browser.d.ts.map +1 -0
- package/dist/server-only/browser.js +4 -0
- package/dist/server-only/browser.js.map +1 -0
- package/dist/server-only/index.d.ts +2 -0
- package/dist/server-only/index.d.ts.map +1 -0
- package/dist/server-only/index.js +2 -0
- package/dist/server-only/index.js.map +1 -0
- package/dist/static/index.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 +13 -6
- package/dist/vite/index.d.ts.map +1 -1
- package/dist/vite/index.js +29 -1560
- package/dist/vite/index.js.map +1 -1
- package/dist/vite/plugin.d.ts +24 -3
- package/dist/vite/plugin.d.ts.map +1 -1
- package/dist/vite/policy-verification.d.ts +33 -2
- package/dist/vite/policy-verification.d.ts.map +1 -1
- package/dist/vite/route-audit.d.ts +14 -2
- package/dist/vite/route-audit.d.ts.map +1 -1
- package/dist/vite/server-only-boundary.d.ts +8 -0
- package/dist/vite/server-only-boundary.d.ts.map +1 -0
- package/package.json +24 -6
- package/dist/chunks/document-shell-WoM8yZlR.js +0 -35
- package/dist/chunks/document-shell-WoM8yZlR.js.map +0 -1
- package/dist/chunks/images-Edar3eU1.js.map +0 -1
- package/dist/chunks/request-metadata-DaIYq4Ea.js +0 -677
- package/dist/chunks/request-metadata-DaIYq4Ea.js.map +0 -1
- package/dist/chunks/static-files-DUjHw-4H.js +0 -11
- package/dist/chunks/static-files-DUjHw-4H.js.map +0 -1
- package/dist/chunks/streaming-D0fGAuiO.js +0 -469
- package/dist/chunks/streaming-D0fGAuiO.js.map +0 -1
- package/dist/chunks/testing-CRflAw4X.js +0 -3475
- package/dist/chunks/testing-CRflAw4X.js.map +0 -1
- package/dist/route/action.d.ts +0 -33
- package/dist/route/action.d.ts.map +0 -1
|
@@ -1,3475 +0,0 @@
|
|
|
1
|
-
import { x as It, w as Ut, y as Qe, z as Xe, e as et, F as Ft, A as Ht, B as jt, l as Wt, a as zt } from "./request-metadata-DaIYq4Ea.js";
|
|
2
|
-
import { createElement as de } from "react";
|
|
3
|
-
import { renderToString as tt } from "react-dom/server";
|
|
4
|
-
import { jsxs as H, jsx as j } from "react/jsx-runtime";
|
|
5
|
-
const Ne = ["build", "private", "public"], Bt = {
|
|
6
|
-
app: "demiurge-memory",
|
|
7
|
-
environment: "local",
|
|
8
|
-
schemaVersion: 1
|
|
9
|
-
}, qt = 1e4, Gt = 3e4;
|
|
10
|
-
function Eo(e) {
|
|
11
|
-
return (...t) => ({
|
|
12
|
-
fn: () => e.fn(...t),
|
|
13
|
-
key: e.key(...t),
|
|
14
|
-
notFoundTtl: e.notFoundTtl,
|
|
15
|
-
scope: e.scope,
|
|
16
|
-
staleWhileRevalidate: e.staleWhileRevalidate,
|
|
17
|
-
tags: e.tags?.(...t),
|
|
18
|
-
ttl: e.ttl
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
class A extends Error {
|
|
22
|
-
constructor(t) {
|
|
23
|
-
super(t ?? "Not found"), this.name = "CacheNotFoundError";
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
function vo(e) {
|
|
27
|
-
throw new A(e);
|
|
28
|
-
}
|
|
29
|
-
function Ro(e) {
|
|
30
|
-
return e instanceof A;
|
|
31
|
-
}
|
|
32
|
-
function bo(e) {
|
|
33
|
-
return { id: e };
|
|
34
|
-
}
|
|
35
|
-
function To(e) {
|
|
36
|
-
return e;
|
|
37
|
-
}
|
|
38
|
-
function rt(e) {
|
|
39
|
-
const t = e.now ?? Date.now, r = Kt(e.refreshLeaseTtl), n = nt(e.namespace), s = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map();
|
|
40
|
-
return {
|
|
41
|
-
async get(i) {
|
|
42
|
-
const a = i.scope ?? "request";
|
|
43
|
-
if (a === "none")
|
|
44
|
-
return await i.fn();
|
|
45
|
-
const c = Le(i.key);
|
|
46
|
-
if (a === "request")
|
|
47
|
-
return await Jt(s, c, i, t);
|
|
48
|
-
const u = Me(n, a, c), l = (i.tags ?? []).map(
|
|
49
|
-
(m) => Ie(n, a, he(m))
|
|
50
|
-
), f = await e.store.get(u);
|
|
51
|
-
if (f && (f.expiresAt === null || f.expiresAt > t())) {
|
|
52
|
-
if (f.negative)
|
|
53
|
-
throw new A(
|
|
54
|
-
typeof f.value == "string" ? f.value : void 0
|
|
55
|
-
);
|
|
56
|
-
return f.value;
|
|
57
|
-
}
|
|
58
|
-
if (f && Yt(f, t())) {
|
|
59
|
-
const m = Zt(e.store), k = globalThis.crypto.randomUUID();
|
|
60
|
-
if (await m.acquireRefreshLease(
|
|
61
|
-
u,
|
|
62
|
-
k,
|
|
63
|
-
t() + r
|
|
64
|
-
)) {
|
|
65
|
-
const N = Qt({
|
|
66
|
-
key: u,
|
|
67
|
-
now: t,
|
|
68
|
-
onBackgroundError: e.onBackgroundError,
|
|
69
|
-
refreshStore: m,
|
|
70
|
-
request: i,
|
|
71
|
-
tags: l,
|
|
72
|
-
token: k
|
|
73
|
-
});
|
|
74
|
-
e.waitUntil?.(N);
|
|
75
|
-
}
|
|
76
|
-
return f.value;
|
|
77
|
-
}
|
|
78
|
-
f && await e.store.delete(u);
|
|
79
|
-
const h = o.get(u);
|
|
80
|
-
if (h)
|
|
81
|
-
return await h.promise;
|
|
82
|
-
const d = { invalidated: !1 }, D = Promise.resolve().then(i.fn).then(
|
|
83
|
-
async (m) => (d.invalidated || await e.store.set(u, {
|
|
84
|
-
expiresAt: Se(t(), i.ttl),
|
|
85
|
-
staleUntil: Ee(
|
|
86
|
-
t(),
|
|
87
|
-
i.ttl,
|
|
88
|
-
i.staleWhileRevalidate
|
|
89
|
-
),
|
|
90
|
-
tags: l,
|
|
91
|
-
value: m
|
|
92
|
-
}), m),
|
|
93
|
-
async (m) => {
|
|
94
|
-
throw !d.invalidated && m instanceof A && await e.store.set(u, st(t(), i, l, m)), m;
|
|
95
|
-
}
|
|
96
|
-
), $ = {
|
|
97
|
-
promise: D,
|
|
98
|
-
state: d,
|
|
99
|
-
tags: l
|
|
100
|
-
};
|
|
101
|
-
o.set(u, $);
|
|
102
|
-
try {
|
|
103
|
-
return await D;
|
|
104
|
-
} finally {
|
|
105
|
-
o.get(u) === $ && o.delete(u);
|
|
106
|
-
}
|
|
107
|
-
},
|
|
108
|
-
async invalidateKey(i) {
|
|
109
|
-
const a = Le(i), c = s.delete(a);
|
|
110
|
-
let u = !1;
|
|
111
|
-
const l = await Promise.all(
|
|
112
|
-
Ne.map((f) => {
|
|
113
|
-
const h = Me(n, f, a), d = o.get(h);
|
|
114
|
-
return d && (d.state.invalidated = !0, u = !0), e.store.delete(h);
|
|
115
|
-
})
|
|
116
|
-
);
|
|
117
|
-
return c || u || l.some(Boolean);
|
|
118
|
-
},
|
|
119
|
-
async invalidateTags(i) {
|
|
120
|
-
const a = i.map(he), c = Xt(
|
|
121
|
-
s,
|
|
122
|
-
new Set(a)
|
|
123
|
-
), u = new Set(
|
|
124
|
-
Ne.flatMap(
|
|
125
|
-
(h) => a.map((d) => Ie(n, h, d))
|
|
126
|
-
)
|
|
127
|
-
);
|
|
128
|
-
let l = 0;
|
|
129
|
-
for (const h of o.values())
|
|
130
|
-
!h.state.invalidated && h.tags.some((d) => u.has(d)) && (h.state.invalidated = !0, l += 1);
|
|
131
|
-
const f = await e.store.invalidateTags([...u]);
|
|
132
|
-
return c + l + f;
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
function we(e = {}) {
|
|
137
|
-
const t = e.now ?? Date.now;
|
|
138
|
-
return rt({
|
|
139
|
-
namespace: Bt,
|
|
140
|
-
now: t,
|
|
141
|
-
onBackgroundError: e.onBackgroundError,
|
|
142
|
-
refreshLeaseTtl: e.refreshLeaseTtl,
|
|
143
|
-
store: _t({
|
|
144
|
-
maximumEntries: e.maximumEntries,
|
|
145
|
-
now: t
|
|
146
|
-
}),
|
|
147
|
-
waitUntil: e.waitUntil
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
function _t(e = {}) {
|
|
151
|
-
const t = e.entries ?? /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), n = e.maximumEntries ?? qt, s = e.now ?? Date.now;
|
|
152
|
-
if (!Number.isSafeInteger(n) || n <= 0)
|
|
153
|
-
throw new Error(
|
|
154
|
-
"Demiurge memory cache maximumEntries must be a positive integer."
|
|
155
|
-
);
|
|
156
|
-
se(t, r, s()), Vt(t, n);
|
|
157
|
-
let o = oe(t);
|
|
158
|
-
return {
|
|
159
|
-
acquireRefreshLease(i, a, c) {
|
|
160
|
-
const u = s(), l = r.get(i);
|
|
161
|
-
return l && l.expiresAt > u ? !1 : (r.set(i, { expiresAt: c, token: a }), !0);
|
|
162
|
-
},
|
|
163
|
-
delete(i) {
|
|
164
|
-
return r.delete(i), t.delete(i);
|
|
165
|
-
},
|
|
166
|
-
get(i) {
|
|
167
|
-
return s() >= o && (se(t, r, s()), o = oe(t)), t.get(i);
|
|
168
|
-
},
|
|
169
|
-
invalidateTags(i) {
|
|
170
|
-
const a = new Set(i);
|
|
171
|
-
let c = 0;
|
|
172
|
-
for (const [u, l] of t)
|
|
173
|
-
l.tags.some((f) => a.has(f)) && (t.delete(u), r.delete(u), c += 1);
|
|
174
|
-
return c;
|
|
175
|
-
},
|
|
176
|
-
publishRefresh(i, a, c) {
|
|
177
|
-
const u = r.get(i);
|
|
178
|
-
return !u || u.token !== a || u.expiresAt <= s() ? !1 : (Oe(
|
|
179
|
-
t,
|
|
180
|
-
r,
|
|
181
|
-
n,
|
|
182
|
-
i,
|
|
183
|
-
c
|
|
184
|
-
), r.delete(i), c.staleUntil !== null && (o = Math.min(o, c.staleUntil)), !0);
|
|
185
|
-
},
|
|
186
|
-
releaseRefreshLease(i, a) {
|
|
187
|
-
r.get(i)?.token === a && r.delete(i);
|
|
188
|
-
},
|
|
189
|
-
set(i, a) {
|
|
190
|
-
const c = s();
|
|
191
|
-
c >= o && (se(t, r, c), o = oe(t)), r.delete(i), Oe(
|
|
192
|
-
t,
|
|
193
|
-
r,
|
|
194
|
-
n,
|
|
195
|
-
i,
|
|
196
|
-
a
|
|
197
|
-
), a.staleUntil !== null && (o = Math.min(o, a.staleUntil));
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
function se(e, t, r) {
|
|
202
|
-
for (const [n, s] of e)
|
|
203
|
-
s.staleUntil !== null && s.staleUntil <= r && (e.delete(n), t.delete(n));
|
|
204
|
-
}
|
|
205
|
-
function Oe(e, t, r, n, s) {
|
|
206
|
-
if (!e.has(n) && e.size >= r)
|
|
207
|
-
for (; e.size >= r; ) {
|
|
208
|
-
const o = e.keys().next().value;
|
|
209
|
-
if (o === void 0)
|
|
210
|
-
break;
|
|
211
|
-
e.delete(o), t.delete(o);
|
|
212
|
-
}
|
|
213
|
-
e.set(n, s);
|
|
214
|
-
}
|
|
215
|
-
function Vt(e, t) {
|
|
216
|
-
for (; e.size > t; ) {
|
|
217
|
-
const r = e.keys().next().value;
|
|
218
|
-
if (r === void 0)
|
|
219
|
-
return;
|
|
220
|
-
e.delete(r);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
function oe(e) {
|
|
224
|
-
let t = Number.POSITIVE_INFINITY;
|
|
225
|
-
for (const r of e.values())
|
|
226
|
-
r.staleUntil !== null && (t = Math.min(t, r.staleUntil));
|
|
227
|
-
return t;
|
|
228
|
-
}
|
|
229
|
-
function nt(e) {
|
|
230
|
-
const t = ie("app", e.app), r = ie(
|
|
231
|
-
"environment",
|
|
232
|
-
e.environment
|
|
233
|
-
);
|
|
234
|
-
if (typeof e.schemaVersion == "number" && (!Number.isInteger(e.schemaVersion) || e.schemaVersion < 0))
|
|
235
|
-
throw new Error(
|
|
236
|
-
"Demiurge cache namespace schemaVersion must be a non-negative integer or string."
|
|
237
|
-
);
|
|
238
|
-
const n = ie(
|
|
239
|
-
"schemaVersion",
|
|
240
|
-
String(e.schemaVersion)
|
|
241
|
-
);
|
|
242
|
-
return `${t}:${r}:${n}`;
|
|
243
|
-
}
|
|
244
|
-
function xo(e) {
|
|
245
|
-
return {
|
|
246
|
-
async key(t) {
|
|
247
|
-
return {
|
|
248
|
-
deleted: await e.invalidateKey(t) ? 1 : 0,
|
|
249
|
-
kind: "key"
|
|
250
|
-
};
|
|
251
|
-
},
|
|
252
|
-
async keys(t) {
|
|
253
|
-
let r = 0;
|
|
254
|
-
for (const n of t)
|
|
255
|
-
await e.invalidateKey(n) && (r += 1);
|
|
256
|
-
return {
|
|
257
|
-
deleted: r,
|
|
258
|
-
kind: "key"
|
|
259
|
-
};
|
|
260
|
-
},
|
|
261
|
-
async tag(t) {
|
|
262
|
-
return {
|
|
263
|
-
deleted: await e.invalidateTags([t]),
|
|
264
|
-
kind: "tag"
|
|
265
|
-
};
|
|
266
|
-
},
|
|
267
|
-
async tags(t) {
|
|
268
|
-
return {
|
|
269
|
-
deleted: await e.invalidateTags(t),
|
|
270
|
-
kind: "tag"
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
function P(e) {
|
|
276
|
-
if (e === void 0)
|
|
277
|
-
return Number.POSITIVE_INFINITY;
|
|
278
|
-
if (typeof e == "number") {
|
|
279
|
-
if (!Number.isInteger(e) || e < 0)
|
|
280
|
-
throw new Error("Demiurge cache duration must be a non-negative integer.");
|
|
281
|
-
return e;
|
|
282
|
-
}
|
|
283
|
-
const t = /^(\d+)(ms|s|m|h)$/.exec(e);
|
|
284
|
-
if (!t)
|
|
285
|
-
throw new Error("Demiurge cache duration must use an ms/s/m/h suffix.");
|
|
286
|
-
const r = Number(t[1]), n = t[2];
|
|
287
|
-
return n === "h" ? r * 36e5 : n === "m" ? r * 6e4 : n === "s" ? r * 1e3 : r;
|
|
288
|
-
}
|
|
289
|
-
function Le(e) {
|
|
290
|
-
return me(e, /* @__PURE__ */ new Set());
|
|
291
|
-
}
|
|
292
|
-
function he(e) {
|
|
293
|
-
return e.id;
|
|
294
|
-
}
|
|
295
|
-
async function Jt(e, t, r, n) {
|
|
296
|
-
const s = e.get(t);
|
|
297
|
-
if (s && s.expiresAt > n())
|
|
298
|
-
return await s.value;
|
|
299
|
-
const o = Promise.resolve().then(r.fn), i = {
|
|
300
|
-
expiresAt: n() + P(r.ttl),
|
|
301
|
-
tags: (r.tags ?? []).map(he),
|
|
302
|
-
value: o
|
|
303
|
-
};
|
|
304
|
-
e.set(t, i);
|
|
305
|
-
try {
|
|
306
|
-
return await o;
|
|
307
|
-
} catch (a) {
|
|
308
|
-
throw e.get(t) === i && (a instanceof A ? i.expiresAt = n() + P(r.notFoundTtl ?? r.ttl) : e.delete(t)), a;
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
function Me(e, t, r) {
|
|
312
|
-
return `${e}:${t}:key:${r}`;
|
|
313
|
-
}
|
|
314
|
-
function Ie(e, t, r) {
|
|
315
|
-
return `${e}:${t}:tag:${r}`;
|
|
316
|
-
}
|
|
317
|
-
function Se(e, t) {
|
|
318
|
-
const r = P(t);
|
|
319
|
-
return Number.isFinite(r) ? e + r : null;
|
|
320
|
-
}
|
|
321
|
-
function st(e, t, r, n) {
|
|
322
|
-
const s = t.notFoundTtl ?? t.ttl;
|
|
323
|
-
return {
|
|
324
|
-
expiresAt: Se(e, s),
|
|
325
|
-
negative: !0,
|
|
326
|
-
// Negative entries do not participate in stale-while-revalidate: they
|
|
327
|
-
// expire outright and recompute on the next request.
|
|
328
|
-
staleUntil: Ee(e, s, void 0),
|
|
329
|
-
tags: r,
|
|
330
|
-
value: n.message
|
|
331
|
-
};
|
|
332
|
-
}
|
|
333
|
-
function Ee(e, t, r) {
|
|
334
|
-
const n = P(t);
|
|
335
|
-
if (!Number.isFinite(n)) {
|
|
336
|
-
if (r !== void 0)
|
|
337
|
-
throw new Error(
|
|
338
|
-
"Demiurge staleWhileRevalidate requires a finite cache ttl."
|
|
339
|
-
);
|
|
340
|
-
return null;
|
|
341
|
-
}
|
|
342
|
-
return e + n + P(r ?? 0);
|
|
343
|
-
}
|
|
344
|
-
function Kt(e) {
|
|
345
|
-
const t = P(e ?? Gt);
|
|
346
|
-
if (!Number.isFinite(t) || t <= 0)
|
|
347
|
-
throw new Error(
|
|
348
|
-
"Demiurge cache refreshLeaseTtl must be a positive finite duration."
|
|
349
|
-
);
|
|
350
|
-
return t;
|
|
351
|
-
}
|
|
352
|
-
function Yt(e, t) {
|
|
353
|
-
return e.expiresAt !== null && e.expiresAt <= t && (e.staleUntil === null || e.staleUntil > t);
|
|
354
|
-
}
|
|
355
|
-
function Zt(e) {
|
|
356
|
-
if (!e.acquireRefreshLease || !e.publishRefresh || !e.releaseRefreshLease)
|
|
357
|
-
throw new Error(
|
|
358
|
-
"Demiurge staleWhileRevalidate requires a cache store with acquireRefreshLease, publishRefresh, and releaseRefreshLease coordination methods."
|
|
359
|
-
);
|
|
360
|
-
return e;
|
|
361
|
-
}
|
|
362
|
-
async function Qt(e) {
|
|
363
|
-
try {
|
|
364
|
-
const t = await e.request.fn(), r = e.now();
|
|
365
|
-
await e.refreshStore.publishRefresh(e.key, e.token, {
|
|
366
|
-
expiresAt: Se(r, e.request.ttl),
|
|
367
|
-
staleUntil: Ee(
|
|
368
|
-
r,
|
|
369
|
-
e.request.ttl,
|
|
370
|
-
e.request.staleWhileRevalidate
|
|
371
|
-
),
|
|
372
|
-
tags: e.tags,
|
|
373
|
-
value: t
|
|
374
|
-
});
|
|
375
|
-
} catch (t) {
|
|
376
|
-
if (t instanceof A) {
|
|
377
|
-
await e.refreshStore.publishRefresh(
|
|
378
|
-
e.key,
|
|
379
|
-
e.token,
|
|
380
|
-
st(e.now(), e.request, e.tags, t)
|
|
381
|
-
);
|
|
382
|
-
return;
|
|
383
|
-
}
|
|
384
|
-
e.onBackgroundError ? e.onBackgroundError(t) : console.error("Demiurge stale cache refresh failed.", t);
|
|
385
|
-
} finally {
|
|
386
|
-
await e.refreshStore.releaseRefreshLease(e.key, e.token);
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
function ie(e, t) {
|
|
390
|
-
const r = [...t].some((n) => {
|
|
391
|
-
const s = n.charCodeAt(0);
|
|
392
|
-
return s <= 31 || s === 127;
|
|
393
|
-
});
|
|
394
|
-
if (!t || t.trim() !== t || t.includes(":") || r)
|
|
395
|
-
throw new Error(
|
|
396
|
-
`Demiurge cache namespace ${e} must be non-empty and cannot contain whitespace padding, colons, or control characters.`
|
|
397
|
-
);
|
|
398
|
-
return t;
|
|
399
|
-
}
|
|
400
|
-
function Xt(e, t) {
|
|
401
|
-
let r = 0;
|
|
402
|
-
for (const [n, s] of e)
|
|
403
|
-
s.tags.some((o) => t.has(o)) && (e.delete(n), r += 1);
|
|
404
|
-
return r;
|
|
405
|
-
}
|
|
406
|
-
function me(e, t) {
|
|
407
|
-
if (e === null || typeof e == "boolean" || typeof e == "string")
|
|
408
|
-
return JSON.stringify(e);
|
|
409
|
-
if (typeof e == "number") {
|
|
410
|
-
if (!Number.isFinite(e) || Object.is(e, -0))
|
|
411
|
-
throw new Error(
|
|
412
|
-
"Demiurge cache keys require finite numbers and do not accept negative zero."
|
|
413
|
-
);
|
|
414
|
-
return JSON.stringify(e);
|
|
415
|
-
}
|
|
416
|
-
if (typeof e != "object")
|
|
417
|
-
throw new Error(
|
|
418
|
-
`Demiurge cache keys do not accept values of type ${typeof e}.`
|
|
419
|
-
);
|
|
420
|
-
if (t.has(e))
|
|
421
|
-
throw new Error("Demiurge cache keys cannot contain circular references.");
|
|
422
|
-
if (t.add(e), Array.isArray(e)) {
|
|
423
|
-
const i = Reflect.ownKeys(e), a = [
|
|
424
|
-
...Array.from({ length: e.length }, (u, l) => String(l)),
|
|
425
|
-
"length"
|
|
426
|
-
];
|
|
427
|
-
if (i.length !== a.length || i.some((u, l) => u !== a[l]) || a.slice(0, -1).some((u) => {
|
|
428
|
-
const l = Object.getOwnPropertyDescriptor(e, u);
|
|
429
|
-
return !l?.enumerable || !("value" in l);
|
|
430
|
-
}))
|
|
431
|
-
throw t.delete(e), new Error(
|
|
432
|
-
"Demiurge cache key arrays must be dense and cannot contain accessors or custom properties."
|
|
433
|
-
);
|
|
434
|
-
const c = `[${e.map((u) => me(u, t)).join(",")}]`;
|
|
435
|
-
return t.delete(e), c;
|
|
436
|
-
}
|
|
437
|
-
const r = Object.getPrototypeOf(e);
|
|
438
|
-
if (r !== Object.prototype && r !== null)
|
|
439
|
-
throw new Error(
|
|
440
|
-
"Demiurge cache keys accept only primitives, arrays, and plain objects."
|
|
441
|
-
);
|
|
442
|
-
const n = Reflect.ownKeys(e);
|
|
443
|
-
if (n.some((i) => typeof i == "symbol") || n.some((i) => {
|
|
444
|
-
const a = Object.getOwnPropertyDescriptor(e, i);
|
|
445
|
-
return !a?.enumerable || !("value" in a);
|
|
446
|
-
}))
|
|
447
|
-
throw new Error(
|
|
448
|
-
"Demiurge cache key objects require enumerable string data properties."
|
|
449
|
-
);
|
|
450
|
-
const s = e, o = `{${Object.keys(s).sort().map(
|
|
451
|
-
(i) => `${JSON.stringify(i)}:${me(s[i], t)}`
|
|
452
|
-
).join(",")}}`;
|
|
453
|
-
return t.delete(e), o;
|
|
454
|
-
}
|
|
455
|
-
function Ao(e) {
|
|
456
|
-
return e;
|
|
457
|
-
}
|
|
458
|
-
function Po(e) {
|
|
459
|
-
return {
|
|
460
|
-
...e,
|
|
461
|
-
kind: "meta"
|
|
462
|
-
};
|
|
463
|
-
}
|
|
464
|
-
function Co(e) {
|
|
465
|
-
return {
|
|
466
|
-
...e,
|
|
467
|
-
kind: "link"
|
|
468
|
-
};
|
|
469
|
-
}
|
|
470
|
-
function Do(e) {
|
|
471
|
-
return {
|
|
472
|
-
kind: "structured-data",
|
|
473
|
-
value: e
|
|
474
|
-
};
|
|
475
|
-
}
|
|
476
|
-
function R(...e) {
|
|
477
|
-
const t = {
|
|
478
|
-
custom: [],
|
|
479
|
-
structuredData: []
|
|
480
|
-
};
|
|
481
|
-
for (const o of e)
|
|
482
|
-
o && er(t, o);
|
|
483
|
-
const r = rr(t), n = t.description, s = nr(t.openGraph, r, n);
|
|
484
|
-
return {
|
|
485
|
-
canonical: t.canonical,
|
|
486
|
-
charset: "utf-8",
|
|
487
|
-
custom: t.custom,
|
|
488
|
-
description: n,
|
|
489
|
-
openGraph: s,
|
|
490
|
-
robots: t.robots,
|
|
491
|
-
structuredData: t.structuredData,
|
|
492
|
-
title: r,
|
|
493
|
-
viewport: "width=device-width, initial-scale=1"
|
|
494
|
-
};
|
|
495
|
-
}
|
|
496
|
-
function er(e, t) {
|
|
497
|
-
tr(e, t.title), t.description !== void 0 && (e.description = t.description), t.canonical !== void 0 && (e.canonical = t.canonical), t.robots && (e.robots = {
|
|
498
|
-
...e.robots ?? {},
|
|
499
|
-
...t.robots
|
|
500
|
-
}), t.openGraph && (e.openGraph = {
|
|
501
|
-
...e.openGraph ?? {},
|
|
502
|
-
...t.openGraph
|
|
503
|
-
}), t.custom && e.custom.push(...t.custom), t.structuredData && e.structuredData.push(...t.structuredData);
|
|
504
|
-
}
|
|
505
|
-
function tr(e, t) {
|
|
506
|
-
if (t !== void 0) {
|
|
507
|
-
if (typeof t == "string") {
|
|
508
|
-
e.title = t;
|
|
509
|
-
return;
|
|
510
|
-
}
|
|
511
|
-
t.default !== void 0 && (e.titleDefault = t.default), t.format && (e.titleFormat = t.format);
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
function rr(e) {
|
|
515
|
-
return e.title === void 0 ? e.titleDefault : e.titleFormat ? e.titleFormat(e.title) : e.title;
|
|
516
|
-
}
|
|
517
|
-
function nr(e, t, r) {
|
|
518
|
-
if (!(!e && !t && !r))
|
|
519
|
-
return {
|
|
520
|
-
...t ? { title: t } : {},
|
|
521
|
-
...r ? { description: r } : {},
|
|
522
|
-
...e ?? {}
|
|
523
|
-
};
|
|
524
|
-
}
|
|
525
|
-
function ot(e) {
|
|
526
|
-
const t = {
|
|
527
|
-
fallbacks: {
|
|
528
|
-
error: [],
|
|
529
|
-
loading: [],
|
|
530
|
-
notFound: []
|
|
531
|
-
},
|
|
532
|
-
routes: [],
|
|
533
|
-
layouts: [],
|
|
534
|
-
middlewares: [],
|
|
535
|
-
policies: []
|
|
536
|
-
};
|
|
537
|
-
for (const [r, n] of Object.entries(e)) {
|
|
538
|
-
const s = r.replace(/^\/src\/routes\//, "").replace(/^\.\/routes\//, "").replace(/\.tsx?$/, "").split("/"), o = s.at(-1);
|
|
539
|
-
if (o === "@layout") {
|
|
540
|
-
t.layouts.push({
|
|
541
|
-
file: r,
|
|
542
|
-
fileSegments: s.slice(0, -1),
|
|
543
|
-
segments: v(s.slice(0, -1)),
|
|
544
|
-
load: n
|
|
545
|
-
});
|
|
546
|
-
continue;
|
|
547
|
-
}
|
|
548
|
-
if (o === "@policy") {
|
|
549
|
-
t.policies.push({
|
|
550
|
-
file: r,
|
|
551
|
-
fileSegments: s.slice(0, -1),
|
|
552
|
-
segments: v(s.slice(0, -1)),
|
|
553
|
-
load: n
|
|
554
|
-
});
|
|
555
|
-
continue;
|
|
556
|
-
}
|
|
557
|
-
if (o === "@middleware") {
|
|
558
|
-
t.middlewares.push({
|
|
559
|
-
file: r,
|
|
560
|
-
fileSegments: s.slice(0, -1),
|
|
561
|
-
segments: v(s.slice(0, -1)),
|
|
562
|
-
load: n
|
|
563
|
-
});
|
|
564
|
-
continue;
|
|
565
|
-
}
|
|
566
|
-
if (o === "@loading") {
|
|
567
|
-
t.fallbacks.loading.push({
|
|
568
|
-
file: r,
|
|
569
|
-
fileSegments: s.slice(0, -1),
|
|
570
|
-
segments: v(s.slice(0, -1)),
|
|
571
|
-
load: n
|
|
572
|
-
});
|
|
573
|
-
continue;
|
|
574
|
-
}
|
|
575
|
-
if (o === "@error") {
|
|
576
|
-
t.fallbacks.error.push({
|
|
577
|
-
file: r,
|
|
578
|
-
fileSegments: s.slice(0, -1),
|
|
579
|
-
segments: v(s.slice(0, -1)),
|
|
580
|
-
load: n
|
|
581
|
-
});
|
|
582
|
-
continue;
|
|
583
|
-
}
|
|
584
|
-
if (o === "@not-found") {
|
|
585
|
-
t.fallbacks.notFound.push({
|
|
586
|
-
file: r,
|
|
587
|
-
fileSegments: s.slice(0, -1),
|
|
588
|
-
segments: v(s.slice(0, -1)),
|
|
589
|
-
load: n
|
|
590
|
-
});
|
|
591
|
-
continue;
|
|
592
|
-
}
|
|
593
|
-
t.routes.push({
|
|
594
|
-
file: r,
|
|
595
|
-
fileSegments: s,
|
|
596
|
-
segments: v(s),
|
|
597
|
-
score: Er(s),
|
|
598
|
-
load: n
|
|
599
|
-
});
|
|
600
|
-
}
|
|
601
|
-
return sr(t.routes), t.routes.sort(ar), t.layouts.sort(
|
|
602
|
-
(r, n) => r.fileSegments.length - n.fileSegments.length || r.file.localeCompare(n.file)
|
|
603
|
-
), t.policies.sort(
|
|
604
|
-
(r, n) => r.fileSegments.length - n.fileSegments.length || r.file.localeCompare(n.file)
|
|
605
|
-
), t.middlewares.sort(
|
|
606
|
-
(r, n) => r.fileSegments.length - n.fileSegments.length || r.file.localeCompare(n.file)
|
|
607
|
-
), t.fallbacks.loading.sort(
|
|
608
|
-
(r, n) => r.fileSegments.length - n.fileSegments.length || r.file.localeCompare(n.file)
|
|
609
|
-
), t.fallbacks.error.sort(
|
|
610
|
-
(r, n) => r.fileSegments.length - n.fileSegments.length || r.file.localeCompare(n.file)
|
|
611
|
-
), t.fallbacks.notFound.sort(
|
|
612
|
-
(r, n) => r.fileSegments.length - n.fileSegments.length || r.file.localeCompare(n.file)
|
|
613
|
-
), t;
|
|
614
|
-
}
|
|
615
|
-
function sr(e) {
|
|
616
|
-
const t = /* @__PURE__ */ new Map();
|
|
617
|
-
for (const r of e) {
|
|
618
|
-
const n = r.segments.findIndex(
|
|
619
|
-
(i) => i.startsWith("*")
|
|
620
|
-
);
|
|
621
|
-
if (n !== -1 && n !== r.segments.length - 1)
|
|
622
|
-
throw new Error(
|
|
623
|
-
`Catchall route segment in "${r.file}" must be the final URL segment.`
|
|
624
|
-
);
|
|
625
|
-
const s = r.segments.map(or).join("/"), o = t.get(s);
|
|
626
|
-
if (o)
|
|
627
|
-
throw new Error(
|
|
628
|
-
`Ambiguous routes "${o.file}" and "${r.file}" have the same runtime shape and both match "${ir(r.segments)}".`
|
|
629
|
-
);
|
|
630
|
-
t.set(s, r);
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
function or(e) {
|
|
634
|
-
return e.startsWith("*") ? "*" : e.startsWith(":") ? ":" : `=${e}`;
|
|
635
|
-
}
|
|
636
|
-
function ir(e) {
|
|
637
|
-
return e.length === 0 ? "/" : `/${e.map((t) => t.startsWith(":") || t.startsWith("*") ? "example" : t).join("/")}`;
|
|
638
|
-
}
|
|
639
|
-
function ar(e, t) {
|
|
640
|
-
const r = Math.max(e.segments.length, t.segments.length);
|
|
641
|
-
for (let n = 0; n < r; n += 1) {
|
|
642
|
-
const s = Ue(t.segments[n]) - Ue(e.segments[n]);
|
|
643
|
-
if (s !== 0)
|
|
644
|
-
return s;
|
|
645
|
-
}
|
|
646
|
-
return e.file.localeCompare(t.file);
|
|
647
|
-
}
|
|
648
|
-
function Ue(e) {
|
|
649
|
-
return e === void 0 ? 4 : e.startsWith("*") ? 1 : e.startsWith(":") ? 2 : 3;
|
|
650
|
-
}
|
|
651
|
-
async function it(e, t, r = new Request(`http://demiurge.local${t}`), n, s = we(), o = {}) {
|
|
652
|
-
const i = o.documentContributions ?? !0, a = B(e.routes, t);
|
|
653
|
-
if (!a)
|
|
654
|
-
return {
|
|
655
|
-
...await pe(e, t, {
|
|
656
|
-
documentContributions: i
|
|
657
|
-
}),
|
|
658
|
-
status: "not-found"
|
|
659
|
-
};
|
|
660
|
-
const c = e.layouts.filter(
|
|
661
|
-
(d) => T(d.fileSegments, a.route.fileSegments)
|
|
662
|
-
), u = await a.route.load();
|
|
663
|
-
if (!u.GET || u.GET.kind !== "page")
|
|
664
|
-
return {
|
|
665
|
-
...await pe(e, t, {
|
|
666
|
-
fallback: ve(
|
|
667
|
-
e.fallbacks.notFound,
|
|
668
|
-
a.route
|
|
669
|
-
),
|
|
670
|
-
documentContributions: i,
|
|
671
|
-
layouts: c
|
|
672
|
-
}),
|
|
673
|
-
status: "not-found"
|
|
674
|
-
};
|
|
675
|
-
const l = u.GET.layout === !1 ? [] : await Promise.all(c.map((d) => d.load())), f = new URL(r.url), h = {
|
|
676
|
-
cache: s,
|
|
677
|
-
context: o.requestContext ?? {},
|
|
678
|
-
path: a.path,
|
|
679
|
-
pathname: t,
|
|
680
|
-
request: r,
|
|
681
|
-
search: f.searchParams,
|
|
682
|
-
url: f
|
|
683
|
-
};
|
|
684
|
-
return {
|
|
685
|
-
status: "ready",
|
|
686
|
-
match: {
|
|
687
|
-
data: u.GET.data && !n?.hasData ? await u.GET.data(h) : n?.data,
|
|
688
|
-
error: await at(e, a.route),
|
|
689
|
-
links: i ? await Ut(
|
|
690
|
-
[
|
|
691
|
-
...l.map((d) => d.links),
|
|
692
|
-
u.links
|
|
693
|
-
],
|
|
694
|
-
h
|
|
695
|
-
) : [],
|
|
696
|
-
page: u.GET.view,
|
|
697
|
-
layouts: l.map(
|
|
698
|
-
(d) => d.default
|
|
699
|
-
),
|
|
700
|
-
metadata: i ? R(
|
|
701
|
-
...l.map((d) => d.metadata),
|
|
702
|
-
u.metadata
|
|
703
|
-
) : R(),
|
|
704
|
-
path: a.path,
|
|
705
|
-
pathname: t,
|
|
706
|
-
render: u.GET.render,
|
|
707
|
-
scripts: i ? await It(
|
|
708
|
-
[
|
|
709
|
-
...l.map((d) => d.scripts),
|
|
710
|
-
u.scripts
|
|
711
|
-
],
|
|
712
|
-
h
|
|
713
|
-
) : []
|
|
714
|
-
}
|
|
715
|
-
};
|
|
716
|
-
}
|
|
717
|
-
async function $o(e, t = {}) {
|
|
718
|
-
const r = we(), n = [];
|
|
719
|
-
for (const s of e.routes) {
|
|
720
|
-
const o = await s.load();
|
|
721
|
-
if (!o.GET || o.GET.kind !== "page" && !t.includeResources)
|
|
722
|
-
continue;
|
|
723
|
-
if (o.GET.kind === "page" && o.GET.render.mode !== "static")
|
|
724
|
-
throw new Error(
|
|
725
|
-
`Page route "${s.file}" uses render mode "${o.GET.render.mode}" and cannot be emitted as static output. Set render: { mode: "static" } or deploy a runtime adapter.`
|
|
726
|
-
);
|
|
727
|
-
const i = mr(s.segments);
|
|
728
|
-
if (gr(s.segments).length === 0) {
|
|
729
|
-
n.push({
|
|
730
|
-
file: s.file,
|
|
731
|
-
path: {},
|
|
732
|
-
pattern: i,
|
|
733
|
-
pathname: i
|
|
734
|
-
});
|
|
735
|
-
continue;
|
|
736
|
-
}
|
|
737
|
-
if (!o.paths)
|
|
738
|
-
throw new Error(
|
|
739
|
-
`Dynamic static route "${s.file}" must export paths for "${i}".`
|
|
740
|
-
);
|
|
741
|
-
const c = await o.paths({ cache: r });
|
|
742
|
-
for (const u of c) {
|
|
743
|
-
const l = yr(s, i, u);
|
|
744
|
-
n.push({
|
|
745
|
-
file: s.file,
|
|
746
|
-
path: l,
|
|
747
|
-
pattern: i,
|
|
748
|
-
pathname: Sr(s.segments, l)
|
|
749
|
-
});
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
return n;
|
|
753
|
-
}
|
|
754
|
-
async function ko(e, t) {
|
|
755
|
-
const r = B(e.routes, t);
|
|
756
|
-
if (r)
|
|
757
|
-
return await dr(
|
|
758
|
-
ve(e.fallbacks.loading, r.route)
|
|
759
|
-
);
|
|
760
|
-
}
|
|
761
|
-
async function cr(e, t) {
|
|
762
|
-
let r;
|
|
763
|
-
try {
|
|
764
|
-
r = B(e.routes, t);
|
|
765
|
-
} catch (n) {
|
|
766
|
-
if (!(n instanceof Te)) throw n;
|
|
767
|
-
return await be(
|
|
768
|
-
e.fallbacks.error.find(
|
|
769
|
-
(s) => s.fileSegments.length === 0
|
|
770
|
-
)
|
|
771
|
-
);
|
|
772
|
-
}
|
|
773
|
-
return r ? await at(e, r.route) : await ur(e, t);
|
|
774
|
-
}
|
|
775
|
-
async function at(e, t) {
|
|
776
|
-
return await be(
|
|
777
|
-
ve(e.fallbacks.error, t)
|
|
778
|
-
);
|
|
779
|
-
}
|
|
780
|
-
async function ur(e, t) {
|
|
781
|
-
return await be(
|
|
782
|
-
ct(e.fallbacks.error, t)
|
|
783
|
-
);
|
|
784
|
-
}
|
|
785
|
-
async function pe(e, t, r = {}) {
|
|
786
|
-
const s = await (r.fallback ?? ct(e.fallbacks.notFound, t))?.load(), o = s?.default, i = r.documentContributions ?? !0;
|
|
787
|
-
if (s?.layout === !1)
|
|
788
|
-
return {
|
|
789
|
-
layouts: [],
|
|
790
|
-
metadata: i ? R(s.metadata) : R(),
|
|
791
|
-
notFound: o,
|
|
792
|
-
pathname: t
|
|
793
|
-
};
|
|
794
|
-
const a = r.layouts ?? lr(e, t);
|
|
795
|
-
try {
|
|
796
|
-
const c = await Promise.all(
|
|
797
|
-
a.map((u) => u.load())
|
|
798
|
-
);
|
|
799
|
-
return {
|
|
800
|
-
layouts: c.map(
|
|
801
|
-
(u) => u.default
|
|
802
|
-
),
|
|
803
|
-
metadata: i ? R(
|
|
804
|
-
...c.map((u) => u.metadata),
|
|
805
|
-
s?.metadata
|
|
806
|
-
) : R(),
|
|
807
|
-
notFound: o,
|
|
808
|
-
pathname: t
|
|
809
|
-
};
|
|
810
|
-
} catch (c) {
|
|
811
|
-
return r.onLayoutError?.(c), {
|
|
812
|
-
layouts: [],
|
|
813
|
-
metadata: i ? R(s?.metadata) : R(),
|
|
814
|
-
notFound: o,
|
|
815
|
-
pathname: t
|
|
816
|
-
};
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
function lr(e, t) {
|
|
820
|
-
const r = re(t);
|
|
821
|
-
return e.layouts.filter(
|
|
822
|
-
(n) => !n.fileSegments.some(te) && Re(n.segments, r)
|
|
823
|
-
);
|
|
824
|
-
}
|
|
825
|
-
function fr(e, t) {
|
|
826
|
-
const r = re(t);
|
|
827
|
-
return e.policies.filter(
|
|
828
|
-
(n) => !n.fileSegments.some(te) && Re(n.segments, r)
|
|
829
|
-
);
|
|
830
|
-
}
|
|
831
|
-
function ve(e, t) {
|
|
832
|
-
for (let r = e.length - 1; r >= 0; r -= 1) {
|
|
833
|
-
const n = e[r];
|
|
834
|
-
if (T(n.fileSegments, t.fileSegments))
|
|
835
|
-
return n;
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
function ct(e, t) {
|
|
839
|
-
const r = re(t);
|
|
840
|
-
for (let n = e.length - 1; n >= 0; n -= 1) {
|
|
841
|
-
const s = e[n];
|
|
842
|
-
if (!s.fileSegments.some(te) && Re(s.segments, r))
|
|
843
|
-
return s;
|
|
844
|
-
}
|
|
845
|
-
}
|
|
846
|
-
function Re(e, t) {
|
|
847
|
-
return e.every((r, n) => r.startsWith("*") ? t.length > n : r.startsWith(":") ? !!t[n] : t[n] === r);
|
|
848
|
-
}
|
|
849
|
-
async function dr(e) {
|
|
850
|
-
return e ? (await e.load()).default : void 0;
|
|
851
|
-
}
|
|
852
|
-
async function be(e) {
|
|
853
|
-
return e ? (await e.load()).default : void 0;
|
|
854
|
-
}
|
|
855
|
-
function B(e, t) {
|
|
856
|
-
const r = re(t);
|
|
857
|
-
for (const n of e) {
|
|
858
|
-
const s = hr(n.segments, r);
|
|
859
|
-
if (s)
|
|
860
|
-
return { route: n, path: s };
|
|
861
|
-
}
|
|
862
|
-
return null;
|
|
863
|
-
}
|
|
864
|
-
const No = it, Oo = B;
|
|
865
|
-
function hr(e, t) {
|
|
866
|
-
const r = {};
|
|
867
|
-
for (let n = 0; n < e.length; n += 1) {
|
|
868
|
-
const s = e[n], o = t[n];
|
|
869
|
-
if (s?.startsWith("*"))
|
|
870
|
-
return r[s.slice(1)] = t.slice(n).join("/"), r;
|
|
871
|
-
if (!o)
|
|
872
|
-
return null;
|
|
873
|
-
if (s.startsWith(":")) {
|
|
874
|
-
r[s.slice(1)] = o;
|
|
875
|
-
continue;
|
|
876
|
-
}
|
|
877
|
-
if (s !== o)
|
|
878
|
-
return null;
|
|
879
|
-
}
|
|
880
|
-
return e.length === t.length ? r : null;
|
|
881
|
-
}
|
|
882
|
-
function Lo(e, t) {
|
|
883
|
-
return e.every(
|
|
884
|
-
(r, n) => t[n] === r
|
|
885
|
-
);
|
|
886
|
-
}
|
|
887
|
-
function T(e, t) {
|
|
888
|
-
return e.every(
|
|
889
|
-
(r, n) => t[n] === r
|
|
890
|
-
);
|
|
891
|
-
}
|
|
892
|
-
function v(e) {
|
|
893
|
-
return e.flatMap((t) => te(t) ? [] : t === "index" ? [] : t.startsWith("[...") && t.endsWith("]") ? [`*${t.slice(4, -1)}`] : t.startsWith("[") && t.endsWith("]") ? [`:${t.slice(1, -1)}`] : [t]);
|
|
894
|
-
}
|
|
895
|
-
function te(e) {
|
|
896
|
-
return e.startsWith("(") && e.endsWith(")");
|
|
897
|
-
}
|
|
898
|
-
function mr(e) {
|
|
899
|
-
return e.length === 0 ? "/" : `/${e.map(pr).join("/")}`;
|
|
900
|
-
}
|
|
901
|
-
function pr(e) {
|
|
902
|
-
return e.startsWith("*") ? `[...${e.slice(1)}]` : e.startsWith(":") ? `[${e.slice(1)}]` : e;
|
|
903
|
-
}
|
|
904
|
-
function gr(e) {
|
|
905
|
-
return e.flatMap((t) => t.startsWith(":") || t.startsWith("*") ? [t.slice(1)] : []);
|
|
906
|
-
}
|
|
907
|
-
function yr(e, t, r) {
|
|
908
|
-
const n = {};
|
|
909
|
-
for (const s of e.segments) {
|
|
910
|
-
if (!s.startsWith(":") && !s.startsWith("*"))
|
|
911
|
-
continue;
|
|
912
|
-
const o = s.slice(1), i = r[o];
|
|
913
|
-
if (i === void 0)
|
|
914
|
-
throw new Error(
|
|
915
|
-
`Static paths for "${e.file}" must include "${o}" for "${t}".`
|
|
916
|
-
);
|
|
917
|
-
if (!wr(i))
|
|
918
|
-
throw new Error(
|
|
919
|
-
`Static path "${o}" for "${e.file}" must be a string, number, or boolean.`
|
|
920
|
-
);
|
|
921
|
-
n[o] = String(i);
|
|
922
|
-
}
|
|
923
|
-
return n;
|
|
924
|
-
}
|
|
925
|
-
function wr(e) {
|
|
926
|
-
return typeof e == "string" || typeof e == "number" || typeof e == "boolean";
|
|
927
|
-
}
|
|
928
|
-
function Sr(e, t) {
|
|
929
|
-
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("/")}`;
|
|
930
|
-
}
|
|
931
|
-
function Er(e) {
|
|
932
|
-
return v(e).reduce((t, r) => r.startsWith("*") ? t : r.startsWith(":") ? t + 1 : t + 2, 0);
|
|
933
|
-
}
|
|
934
|
-
function re(e) {
|
|
935
|
-
return e.replace(/^\/|\/$/g, "").split("/").filter(Boolean).map((t) => {
|
|
936
|
-
try {
|
|
937
|
-
return decodeURIComponent(t);
|
|
938
|
-
} catch (r) {
|
|
939
|
-
throw new Te(e, { cause: r });
|
|
940
|
-
}
|
|
941
|
-
});
|
|
942
|
-
}
|
|
943
|
-
class Te extends URIError {
|
|
944
|
-
pathname;
|
|
945
|
-
constructor(t, r) {
|
|
946
|
-
super(
|
|
947
|
-
`Malformed percent encoding in URL pathname ${JSON.stringify(t)}.`,
|
|
948
|
-
r
|
|
949
|
-
), this.name = "MalformedPathnameError", this.pathname = t;
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
const C = "x-demiurge-navigation", vr = "data", Rr = "data", ae = "error", Fe = "not-found";
|
|
953
|
-
function ut(e) {
|
|
954
|
-
return e.headers.get(C) === vr;
|
|
955
|
-
}
|
|
956
|
-
function br(e) {
|
|
957
|
-
return Response.json(
|
|
958
|
-
{ data: e, hasData: !0 },
|
|
959
|
-
{
|
|
960
|
-
headers: {
|
|
961
|
-
"cache-control": "no-store",
|
|
962
|
-
[C]: Rr,
|
|
963
|
-
vary: C
|
|
964
|
-
}
|
|
965
|
-
}
|
|
966
|
-
);
|
|
967
|
-
}
|
|
968
|
-
function _(e, t) {
|
|
969
|
-
return e.headers.set("cache-control", "no-store"), e.headers.set(C, t), e.headers.append("vary", C), e;
|
|
970
|
-
}
|
|
971
|
-
function Tr(e) {
|
|
972
|
-
if (typeof e == "string")
|
|
973
|
-
return e;
|
|
974
|
-
const t = xr(Cr(
|
|
975
|
-
e.to,
|
|
976
|
-
"path" in e ? e.path : void 0
|
|
977
|
-
)), r = e.search === void 0 ? t.search : Ar(e.search), n = e.hash === void 0 ? t.hash : e.hash ? e.hash.startsWith("#") ? e.hash : `#${e.hash}` : "";
|
|
978
|
-
return `${t.pathname}${r}${n}`;
|
|
979
|
-
}
|
|
980
|
-
function xr(e) {
|
|
981
|
-
const t = e.indexOf("#"), r = t === -1 ? e : e.slice(0, t), n = r.indexOf("?");
|
|
982
|
-
return {
|
|
983
|
-
hash: t === -1 ? "" : e.slice(t),
|
|
984
|
-
pathname: n === -1 ? r : r.slice(0, n),
|
|
985
|
-
search: n === -1 ? "" : r.slice(n)
|
|
986
|
-
};
|
|
987
|
-
}
|
|
988
|
-
function Ar(e) {
|
|
989
|
-
if (!e)
|
|
990
|
-
return "";
|
|
991
|
-
if (typeof e == "string")
|
|
992
|
-
return e.startsWith("?") ? e : `?${e}`;
|
|
993
|
-
const r = (e instanceof URLSearchParams ? e : Pr(e)).toString();
|
|
994
|
-
return r ? `?${r}` : "";
|
|
995
|
-
}
|
|
996
|
-
function Pr(e) {
|
|
997
|
-
const t = new URLSearchParams();
|
|
998
|
-
for (const [r, n] of Object.entries(e)) {
|
|
999
|
-
const s = Array.isArray(n) ? n : [n];
|
|
1000
|
-
for (const o of s)
|
|
1001
|
-
o != null && t.append(r, String(o));
|
|
1002
|
-
}
|
|
1003
|
-
return t;
|
|
1004
|
-
}
|
|
1005
|
-
function Cr(e, t) {
|
|
1006
|
-
return t ? e.replace(
|
|
1007
|
-
/\[(\.\.\.)?([a-zA-Z_$][a-zA-Z0-9_$]*)\]/g,
|
|
1008
|
-
(r, n, s) => {
|
|
1009
|
-
const o = t[s];
|
|
1010
|
-
if (o === void 0)
|
|
1011
|
-
throw new Error(`Missing path value for "${s}" in route "${e}".`);
|
|
1012
|
-
return n ? String(o).split("/").filter(Boolean).map((i) => encodeURIComponent(i)).join("/") : encodeURIComponent(String(o));
|
|
1013
|
-
}
|
|
1014
|
-
) : e;
|
|
1015
|
-
}
|
|
1016
|
-
function Mo(e, t) {
|
|
1017
|
-
return {
|
|
1018
|
-
cors: t?.cors,
|
|
1019
|
-
kind: "json",
|
|
1020
|
-
security: t?.security,
|
|
1021
|
-
timing: E(t?.timing),
|
|
1022
|
-
value: e,
|
|
1023
|
-
init: b(t)
|
|
1024
|
-
};
|
|
1025
|
-
}
|
|
1026
|
-
function Io(e, t) {
|
|
1027
|
-
return {
|
|
1028
|
-
cors: t?.cors,
|
|
1029
|
-
init: b(t),
|
|
1030
|
-
kind: "jsonl",
|
|
1031
|
-
lines: e,
|
|
1032
|
-
security: t?.security,
|
|
1033
|
-
timing: E(t?.timing)
|
|
1034
|
-
};
|
|
1035
|
-
}
|
|
1036
|
-
function Uo(e, t) {
|
|
1037
|
-
return {
|
|
1038
|
-
cors: t?.cors,
|
|
1039
|
-
kind: "text",
|
|
1040
|
-
security: t?.security,
|
|
1041
|
-
timing: E(t?.timing),
|
|
1042
|
-
value: e,
|
|
1043
|
-
init: b(t)
|
|
1044
|
-
};
|
|
1045
|
-
}
|
|
1046
|
-
function Fo(e, t) {
|
|
1047
|
-
return {
|
|
1048
|
-
cors: t?.cors,
|
|
1049
|
-
kind: "html",
|
|
1050
|
-
security: t?.security,
|
|
1051
|
-
timing: E(t?.timing),
|
|
1052
|
-
value: e,
|
|
1053
|
-
init: b(t)
|
|
1054
|
-
};
|
|
1055
|
-
}
|
|
1056
|
-
function Ho(e, t) {
|
|
1057
|
-
const r = typeof t == "number" ? void 0 : t;
|
|
1058
|
-
return {
|
|
1059
|
-
cors: r?.cors,
|
|
1060
|
-
kind: "redirect",
|
|
1061
|
-
security: r?.security,
|
|
1062
|
-
timing: E(r?.timing),
|
|
1063
|
-
to: Fr(e) ? Tr(e) : e,
|
|
1064
|
-
init: typeof t == "number" ? { status: t } : b(t)
|
|
1065
|
-
};
|
|
1066
|
-
}
|
|
1067
|
-
function jo(e, t) {
|
|
1068
|
-
return {
|
|
1069
|
-
cors: t?.cors,
|
|
1070
|
-
kind: "not-found",
|
|
1071
|
-
security: t?.security,
|
|
1072
|
-
timing: E(t?.timing),
|
|
1073
|
-
body: e,
|
|
1074
|
-
init: b(t)
|
|
1075
|
-
};
|
|
1076
|
-
}
|
|
1077
|
-
function Wo(e, t) {
|
|
1078
|
-
return {
|
|
1079
|
-
cors: t?.cors,
|
|
1080
|
-
kind: "response",
|
|
1081
|
-
response: e,
|
|
1082
|
-
security: t?.security,
|
|
1083
|
-
timing: E(t?.timing)
|
|
1084
|
-
};
|
|
1085
|
-
}
|
|
1086
|
-
function zo(e, t) {
|
|
1087
|
-
return {
|
|
1088
|
-
body: e,
|
|
1089
|
-
cors: t?.cors,
|
|
1090
|
-
init: b(t),
|
|
1091
|
-
kind: "stream",
|
|
1092
|
-
security: t?.security,
|
|
1093
|
-
timing: E(t?.timing)
|
|
1094
|
-
};
|
|
1095
|
-
}
|
|
1096
|
-
function Bo(e, t) {
|
|
1097
|
-
return {
|
|
1098
|
-
cors: t?.cors,
|
|
1099
|
-
events: e,
|
|
1100
|
-
init: b(t),
|
|
1101
|
-
kind: "sse",
|
|
1102
|
-
security: t?.security,
|
|
1103
|
-
timing: E(t?.timing)
|
|
1104
|
-
};
|
|
1105
|
-
}
|
|
1106
|
-
function qo(...e) {
|
|
1107
|
-
return e;
|
|
1108
|
-
}
|
|
1109
|
-
async function Dr(e, t) {
|
|
1110
|
-
switch (e.kind) {
|
|
1111
|
-
case "json":
|
|
1112
|
-
return new Response(JSON.stringify(await w(e.value, t)), {
|
|
1113
|
-
...e.init,
|
|
1114
|
-
headers: ce(
|
|
1115
|
-
e.init?.headers,
|
|
1116
|
-
"content-type",
|
|
1117
|
-
"application/json; charset=utf-8"
|
|
1118
|
-
)
|
|
1119
|
-
});
|
|
1120
|
-
case "jsonl":
|
|
1121
|
-
return new Response(
|
|
1122
|
-
kr(await w(e.lines, t)),
|
|
1123
|
-
{
|
|
1124
|
-
...e.init,
|
|
1125
|
-
headers: K(e.init?.headers, {
|
|
1126
|
-
"cache-control": "no-cache",
|
|
1127
|
-
"content-type": "application/x-ndjson; charset=utf-8",
|
|
1128
|
-
"x-accel-buffering": "no"
|
|
1129
|
-
})
|
|
1130
|
-
}
|
|
1131
|
-
);
|
|
1132
|
-
case "text":
|
|
1133
|
-
return new Response(await w(e.value, t), {
|
|
1134
|
-
...e.init,
|
|
1135
|
-
headers: ce(
|
|
1136
|
-
e.init?.headers,
|
|
1137
|
-
"content-type",
|
|
1138
|
-
"text/plain; charset=utf-8"
|
|
1139
|
-
)
|
|
1140
|
-
});
|
|
1141
|
-
case "html":
|
|
1142
|
-
return new Response(await w(e.value, t), {
|
|
1143
|
-
...e.init,
|
|
1144
|
-
headers: ce(
|
|
1145
|
-
e.init?.headers,
|
|
1146
|
-
"content-type",
|
|
1147
|
-
"text/html; charset=utf-8"
|
|
1148
|
-
)
|
|
1149
|
-
});
|
|
1150
|
-
case "redirect": {
|
|
1151
|
-
const r = new Headers(e.init?.headers);
|
|
1152
|
-
return r.set("location", String(await w(e.to, t))), new Response(null, {
|
|
1153
|
-
...e.init,
|
|
1154
|
-
headers: r,
|
|
1155
|
-
status: e.init?.status ?? 302
|
|
1156
|
-
});
|
|
1157
|
-
}
|
|
1158
|
-
case "not-found":
|
|
1159
|
-
return new Response(
|
|
1160
|
-
e.body ? await w(e.body, t) : null,
|
|
1161
|
-
{
|
|
1162
|
-
...e.init,
|
|
1163
|
-
status: e.init?.status ?? 404
|
|
1164
|
-
}
|
|
1165
|
-
);
|
|
1166
|
-
case "response":
|
|
1167
|
-
return await w(e.response, t);
|
|
1168
|
-
case "stream":
|
|
1169
|
-
return new Response(
|
|
1170
|
-
Nr(await w(e.body, t)),
|
|
1171
|
-
{
|
|
1172
|
-
...e.init,
|
|
1173
|
-
headers: K(e.init?.headers, {
|
|
1174
|
-
"content-type": "application/octet-stream",
|
|
1175
|
-
"x-accel-buffering": "no"
|
|
1176
|
-
})
|
|
1177
|
-
}
|
|
1178
|
-
);
|
|
1179
|
-
case "sse":
|
|
1180
|
-
return new Response(
|
|
1181
|
-
$r(await w(e.events, t)),
|
|
1182
|
-
{
|
|
1183
|
-
...e.init,
|
|
1184
|
-
headers: K(e.init?.headers, {
|
|
1185
|
-
"cache-control": "no-cache",
|
|
1186
|
-
"content-type": "text/event-stream; charset=utf-8",
|
|
1187
|
-
"x-accel-buffering": "no"
|
|
1188
|
-
})
|
|
1189
|
-
}
|
|
1190
|
-
);
|
|
1191
|
-
}
|
|
1192
|
-
}
|
|
1193
|
-
async function w(e, t) {
|
|
1194
|
-
return typeof e != "function" ? e : await e(
|
|
1195
|
-
t
|
|
1196
|
-
);
|
|
1197
|
-
}
|
|
1198
|
-
function ce(e, t, r) {
|
|
1199
|
-
return K(e, { [t]: r });
|
|
1200
|
-
}
|
|
1201
|
-
function K(e, t) {
|
|
1202
|
-
const r = new Headers(e);
|
|
1203
|
-
for (const [n, s] of Object.entries(t))
|
|
1204
|
-
r.has(n) || r.set(n, s);
|
|
1205
|
-
return r;
|
|
1206
|
-
}
|
|
1207
|
-
function $r(e) {
|
|
1208
|
-
const t = new TextEncoder(), r = xe(e);
|
|
1209
|
-
return new ReadableStream({
|
|
1210
|
-
async pull(n) {
|
|
1211
|
-
const s = await r.next();
|
|
1212
|
-
if (s.done) {
|
|
1213
|
-
n.close();
|
|
1214
|
-
return;
|
|
1215
|
-
}
|
|
1216
|
-
n.enqueue(t.encode(Mr(s.value)));
|
|
1217
|
-
},
|
|
1218
|
-
async cancel() {
|
|
1219
|
-
await r.return?.();
|
|
1220
|
-
}
|
|
1221
|
-
});
|
|
1222
|
-
}
|
|
1223
|
-
function kr(e) {
|
|
1224
|
-
const t = new TextEncoder(), r = xe(e);
|
|
1225
|
-
return new ReadableStream({
|
|
1226
|
-
async pull(n) {
|
|
1227
|
-
const s = await r.next();
|
|
1228
|
-
if (s.done) {
|
|
1229
|
-
n.close();
|
|
1230
|
-
return;
|
|
1231
|
-
}
|
|
1232
|
-
n.enqueue(t.encode(`${JSON.stringify(s.value)}
|
|
1233
|
-
`));
|
|
1234
|
-
},
|
|
1235
|
-
async cancel() {
|
|
1236
|
-
await r.return?.();
|
|
1237
|
-
}
|
|
1238
|
-
});
|
|
1239
|
-
}
|
|
1240
|
-
function Nr(e) {
|
|
1241
|
-
const t = new TextEncoder(), r = xe(e);
|
|
1242
|
-
return new ReadableStream({
|
|
1243
|
-
async pull(n) {
|
|
1244
|
-
const s = await r.next();
|
|
1245
|
-
if (s.done) {
|
|
1246
|
-
n.close();
|
|
1247
|
-
return;
|
|
1248
|
-
}
|
|
1249
|
-
n.enqueue(Or(s.value, t));
|
|
1250
|
-
},
|
|
1251
|
-
async cancel() {
|
|
1252
|
-
await r.return?.();
|
|
1253
|
-
}
|
|
1254
|
-
});
|
|
1255
|
-
}
|
|
1256
|
-
function Or(e, t) {
|
|
1257
|
-
return typeof e == "string" ? t.encode(e) : e;
|
|
1258
|
-
}
|
|
1259
|
-
function xe(e) {
|
|
1260
|
-
if (e instanceof ReadableStream) {
|
|
1261
|
-
const t = e.getReader();
|
|
1262
|
-
return {
|
|
1263
|
-
async next() {
|
|
1264
|
-
return await t.read();
|
|
1265
|
-
},
|
|
1266
|
-
async return() {
|
|
1267
|
-
return t.releaseLock(), { done: !0, value: void 0 };
|
|
1268
|
-
}
|
|
1269
|
-
};
|
|
1270
|
-
}
|
|
1271
|
-
return Symbol.asyncIterator in e ? e[Symbol.asyncIterator]() : Lr(e[Symbol.iterator]());
|
|
1272
|
-
}
|
|
1273
|
-
function Lr(e) {
|
|
1274
|
-
return {
|
|
1275
|
-
async next() {
|
|
1276
|
-
return e.next();
|
|
1277
|
-
},
|
|
1278
|
-
async return() {
|
|
1279
|
-
return e.return?.(), { done: !0, value: void 0 };
|
|
1280
|
-
}
|
|
1281
|
-
};
|
|
1282
|
-
}
|
|
1283
|
-
function Mr(e) {
|
|
1284
|
-
if (typeof e == "string")
|
|
1285
|
-
return Ir(e);
|
|
1286
|
-
const t = [];
|
|
1287
|
-
if (e.comment !== void 0 && t.push(...M("", e.comment)), e.id !== void 0 && t.push(...M("id", e.id)), e.event !== void 0 && t.push(...M("event", e.event)), e.retry !== void 0) {
|
|
1288
|
-
if (!Number.isInteger(e.retry) || e.retry < 0)
|
|
1289
|
-
throw new Error("SSE retry must be a non-negative integer.");
|
|
1290
|
-
t.push(`retry: ${e.retry}`);
|
|
1291
|
-
}
|
|
1292
|
-
return e.data !== void 0 && t.push(...M("data", Ur(e.data))), `${t.join(`
|
|
1293
|
-
`)}
|
|
1294
|
-
|
|
1295
|
-
`;
|
|
1296
|
-
}
|
|
1297
|
-
function Ir(e) {
|
|
1298
|
-
return `${M("data", e).join(`
|
|
1299
|
-
`)}
|
|
1300
|
-
|
|
1301
|
-
`;
|
|
1302
|
-
}
|
|
1303
|
-
function M(e, t) {
|
|
1304
|
-
return t.split(/\r\n|\r|\n/).map(
|
|
1305
|
-
(r) => e ? `${e}: ${r}` : `: ${r}`
|
|
1306
|
-
);
|
|
1307
|
-
}
|
|
1308
|
-
function Ur(e) {
|
|
1309
|
-
return typeof e == "string" ? e : JSON.stringify(e);
|
|
1310
|
-
}
|
|
1311
|
-
function Fr(e) {
|
|
1312
|
-
return typeof e == "object" && e !== null && !(e instanceof URL) && "to" in e;
|
|
1313
|
-
}
|
|
1314
|
-
function b(e) {
|
|
1315
|
-
if (!e)
|
|
1316
|
-
return;
|
|
1317
|
-
const {
|
|
1318
|
-
cors: t,
|
|
1319
|
-
security: r,
|
|
1320
|
-
timing: n,
|
|
1321
|
-
...s
|
|
1322
|
-
} = e;
|
|
1323
|
-
return s;
|
|
1324
|
-
}
|
|
1325
|
-
function Hr(e, t) {
|
|
1326
|
-
if (!t?.length)
|
|
1327
|
-
return e;
|
|
1328
|
-
const r = new Headers(e.headers), n = jr(t), s = r.get("server-timing");
|
|
1329
|
-
return r.set(
|
|
1330
|
-
"server-timing",
|
|
1331
|
-
s ? `${s}, ${n}` : n
|
|
1332
|
-
), new Response(e.body, {
|
|
1333
|
-
headers: r,
|
|
1334
|
-
status: e.status,
|
|
1335
|
-
statusText: e.statusText
|
|
1336
|
-
});
|
|
1337
|
-
}
|
|
1338
|
-
function jr(e) {
|
|
1339
|
-
return e.map(Wr).join(", ");
|
|
1340
|
-
}
|
|
1341
|
-
function E(e) {
|
|
1342
|
-
if (e)
|
|
1343
|
-
return Array.isArray(e) ? e : [e];
|
|
1344
|
-
}
|
|
1345
|
-
function Wr(e) {
|
|
1346
|
-
if (!zr(e.name))
|
|
1347
|
-
throw new Error(
|
|
1348
|
-
`Server-Timing metric name "${e.name}" is not a valid token.`
|
|
1349
|
-
);
|
|
1350
|
-
const t = [e.name];
|
|
1351
|
-
if (e.duration !== void 0) {
|
|
1352
|
-
if (!Number.isFinite(e.duration) || e.duration < 0)
|
|
1353
|
-
throw new Error("Server-Timing metric duration must be a non-negative finite number.");
|
|
1354
|
-
t.push(`dur=${Br(e.duration)}`);
|
|
1355
|
-
}
|
|
1356
|
-
return e.description !== void 0 && t.push(`desc="${qr(e.description)}"`), t.join(";");
|
|
1357
|
-
}
|
|
1358
|
-
function zr(e) {
|
|
1359
|
-
return /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/.test(e);
|
|
1360
|
-
}
|
|
1361
|
-
function Br(e) {
|
|
1362
|
-
return Number.isInteger(e), String(e);
|
|
1363
|
-
}
|
|
1364
|
-
function qr(e) {
|
|
1365
|
-
return e.replaceAll("\\", "\\\\").replaceAll('"', '\\"');
|
|
1366
|
-
}
|
|
1367
|
-
const Gr = [
|
|
1368
|
-
400,
|
|
1369
|
-
401,
|
|
1370
|
-
402,
|
|
1371
|
-
403,
|
|
1372
|
-
404,
|
|
1373
|
-
405,
|
|
1374
|
-
406,
|
|
1375
|
-
407,
|
|
1376
|
-
408,
|
|
1377
|
-
409,
|
|
1378
|
-
410,
|
|
1379
|
-
411,
|
|
1380
|
-
412,
|
|
1381
|
-
413,
|
|
1382
|
-
414,
|
|
1383
|
-
415,
|
|
1384
|
-
416,
|
|
1385
|
-
417,
|
|
1386
|
-
418,
|
|
1387
|
-
421,
|
|
1388
|
-
422,
|
|
1389
|
-
423,
|
|
1390
|
-
424,
|
|
1391
|
-
425,
|
|
1392
|
-
426,
|
|
1393
|
-
428,
|
|
1394
|
-
429,
|
|
1395
|
-
431,
|
|
1396
|
-
451,
|
|
1397
|
-
500,
|
|
1398
|
-
501,
|
|
1399
|
-
502,
|
|
1400
|
-
503,
|
|
1401
|
-
504,
|
|
1402
|
-
505,
|
|
1403
|
-
506,
|
|
1404
|
-
507,
|
|
1405
|
-
508,
|
|
1406
|
-
510,
|
|
1407
|
-
511
|
|
1408
|
-
], _r = {
|
|
1409
|
-
400: "Bad Request",
|
|
1410
|
-
401: "Unauthorized",
|
|
1411
|
-
402: "Payment Required",
|
|
1412
|
-
403: "Forbidden",
|
|
1413
|
-
404: "Not Found",
|
|
1414
|
-
405: "Method Not Allowed",
|
|
1415
|
-
406: "Not Acceptable",
|
|
1416
|
-
407: "Proxy Authentication Required",
|
|
1417
|
-
408: "Request Timeout",
|
|
1418
|
-
409: "Conflict",
|
|
1419
|
-
410: "Gone",
|
|
1420
|
-
411: "Length Required",
|
|
1421
|
-
412: "Precondition Failed",
|
|
1422
|
-
413: "Content Too Large",
|
|
1423
|
-
414: "URI Too Long",
|
|
1424
|
-
415: "Unsupported Media Type",
|
|
1425
|
-
416: "Range Not Satisfiable",
|
|
1426
|
-
417: "Expectation Failed",
|
|
1427
|
-
418: "I'm a Teapot",
|
|
1428
|
-
421: "Misdirected Request",
|
|
1429
|
-
422: "Unprocessable Content",
|
|
1430
|
-
423: "Locked",
|
|
1431
|
-
424: "Failed Dependency",
|
|
1432
|
-
425: "Too Early",
|
|
1433
|
-
426: "Upgrade Required",
|
|
1434
|
-
428: "Precondition Required",
|
|
1435
|
-
429: "Too Many Requests",
|
|
1436
|
-
431: "Request Header Fields Too Large",
|
|
1437
|
-
451: "Unavailable For Legal Reasons",
|
|
1438
|
-
500: "Internal Server Error",
|
|
1439
|
-
501: "Not Implemented",
|
|
1440
|
-
502: "Bad Gateway",
|
|
1441
|
-
503: "Service Unavailable",
|
|
1442
|
-
504: "Gateway Timeout",
|
|
1443
|
-
505: "HTTP Version Not Supported",
|
|
1444
|
-
506: "Variant Also Negotiates",
|
|
1445
|
-
507: "Insufficient Storage",
|
|
1446
|
-
508: "Loop Detected",
|
|
1447
|
-
510: "Not Extended",
|
|
1448
|
-
511: "Network Authentication Required"
|
|
1449
|
-
}, Vr = new Set(Gr);
|
|
1450
|
-
class lt extends Error {
|
|
1451
|
-
detail;
|
|
1452
|
-
extensions;
|
|
1453
|
-
headers;
|
|
1454
|
-
status;
|
|
1455
|
-
title;
|
|
1456
|
-
type;
|
|
1457
|
-
constructor(t, r = {}, n = {}) {
|
|
1458
|
-
Jr(t);
|
|
1459
|
-
const s = typeof r == "string" ? { detail: r } : r, {
|
|
1460
|
-
detail: o,
|
|
1461
|
-
title: i = _r[t],
|
|
1462
|
-
type: a = "about:blank",
|
|
1463
|
-
...c
|
|
1464
|
-
} = s;
|
|
1465
|
-
super(o ?? i, { cause: n.cause }), this.name = "HttpError", this.detail = o, this.extensions = Object.freeze({ ...c }), this.headers = new Headers(n.headers), this.status = t, this.title = i, this.type = a;
|
|
1466
|
-
}
|
|
1467
|
-
}
|
|
1468
|
-
function Go(e, t, r) {
|
|
1469
|
-
return new lt(e, t, r);
|
|
1470
|
-
}
|
|
1471
|
-
function Ae(e) {
|
|
1472
|
-
return e instanceof lt;
|
|
1473
|
-
}
|
|
1474
|
-
function Jr(e) {
|
|
1475
|
-
if (!Vr.has(e))
|
|
1476
|
-
throw new RangeError(
|
|
1477
|
-
`HTTP error status must be a standard 4xx or 5xx status; received ${JSON.stringify(e)}.`
|
|
1478
|
-
);
|
|
1479
|
-
}
|
|
1480
|
-
function He({ pathname: e }) {
|
|
1481
|
-
return /* @__PURE__ */ H("main", { children: [
|
|
1482
|
-
/* @__PURE__ */ j("h1", { children: "404" }),
|
|
1483
|
-
/* @__PURE__ */ H("p", { children: [
|
|
1484
|
-
"No route matched ",
|
|
1485
|
-
e,
|
|
1486
|
-
"."
|
|
1487
|
-
] })
|
|
1488
|
-
] });
|
|
1489
|
-
}
|
|
1490
|
-
function je({ status: e }) {
|
|
1491
|
-
return /* @__PURE__ */ H("main", { children: [
|
|
1492
|
-
/* @__PURE__ */ j("h1", { children: e }),
|
|
1493
|
-
/* @__PURE__ */ j("p", { children: "Something went wrong." })
|
|
1494
|
-
] });
|
|
1495
|
-
}
|
|
1496
|
-
function Kr({ error: e, pathname: t, status: r }) {
|
|
1497
|
-
const { message: n, name: s, stack: o } = ft(e);
|
|
1498
|
-
return /* @__PURE__ */ H("main", { children: [
|
|
1499
|
-
/* @__PURE__ */ H("h1", { children: [
|
|
1500
|
-
r,
|
|
1501
|
-
" ",
|
|
1502
|
-
s,
|
|
1503
|
-
" at ",
|
|
1504
|
-
t
|
|
1505
|
-
] }),
|
|
1506
|
-
/* @__PURE__ */ j("p", { children: n }),
|
|
1507
|
-
o ? /* @__PURE__ */ j("pre", { children: o }) : null
|
|
1508
|
-
] });
|
|
1509
|
-
}
|
|
1510
|
-
function ft(e) {
|
|
1511
|
-
return e instanceof Error ? {
|
|
1512
|
-
message: e.message,
|
|
1513
|
-
name: e.name,
|
|
1514
|
-
stack: e.stack
|
|
1515
|
-
} : {
|
|
1516
|
-
message: typeof e == "string" ? e : String(e),
|
|
1517
|
-
name: "Error",
|
|
1518
|
-
stack: void 0
|
|
1519
|
-
};
|
|
1520
|
-
}
|
|
1521
|
-
const Yr = ["text/html", "application/xhtml+xml"];
|
|
1522
|
-
function dt(e) {
|
|
1523
|
-
return Zr(e.headers.get("accept"));
|
|
1524
|
-
}
|
|
1525
|
-
function Zr(e) {
|
|
1526
|
-
return e ? Qr(e).some(
|
|
1527
|
-
(t) => t.quality > 0 && Yr.includes(t.type)
|
|
1528
|
-
) : !1;
|
|
1529
|
-
}
|
|
1530
|
-
function Qr(e) {
|
|
1531
|
-
return e.split(",").flatMap((t) => {
|
|
1532
|
-
const [r, ...n] = t.split(";"), s = r.trim().toLowerCase();
|
|
1533
|
-
return s ? [
|
|
1534
|
-
{
|
|
1535
|
-
quality: Xr(n),
|
|
1536
|
-
type: s
|
|
1537
|
-
}
|
|
1538
|
-
] : [];
|
|
1539
|
-
});
|
|
1540
|
-
}
|
|
1541
|
-
function Xr(e) {
|
|
1542
|
-
for (const t of e) {
|
|
1543
|
-
const [r, n] = t.split("=");
|
|
1544
|
-
if (r?.trim().toLowerCase() !== "q")
|
|
1545
|
-
continue;
|
|
1546
|
-
const s = Number.parseFloat(n ?? "");
|
|
1547
|
-
return Number.isNaN(s) ? 1 : s;
|
|
1548
|
-
}
|
|
1549
|
-
return 1;
|
|
1550
|
-
}
|
|
1551
|
-
const en = "application/problem+json";
|
|
1552
|
-
function tn({
|
|
1553
|
-
detail: e,
|
|
1554
|
-
instance: t,
|
|
1555
|
-
status: r,
|
|
1556
|
-
title: n,
|
|
1557
|
-
type: s = "about:blank",
|
|
1558
|
-
...o
|
|
1559
|
-
}) {
|
|
1560
|
-
return {
|
|
1561
|
-
type: s,
|
|
1562
|
-
title: n,
|
|
1563
|
-
status: r,
|
|
1564
|
-
...e === void 0 ? {} : { detail: e },
|
|
1565
|
-
...t === void 0 ? {} : { instance: t },
|
|
1566
|
-
...o
|
|
1567
|
-
};
|
|
1568
|
-
}
|
|
1569
|
-
function Z(e, t) {
|
|
1570
|
-
const r = new Headers(t?.headers);
|
|
1571
|
-
return r.set("content-type", `${en}; charset=utf-8`), new Response(JSON.stringify(tn(e)), {
|
|
1572
|
-
...t,
|
|
1573
|
-
headers: r,
|
|
1574
|
-
status: e.status
|
|
1575
|
-
});
|
|
1576
|
-
}
|
|
1577
|
-
const rn = "Internal Server Error";
|
|
1578
|
-
function ht(e) {
|
|
1579
|
-
return e === !0 && process.env.NODE_ENV !== "production";
|
|
1580
|
-
}
|
|
1581
|
-
async function Y(e, t, r, n, s = {}) {
|
|
1582
|
-
s.onError?.(r, n);
|
|
1583
|
-
const o = new URL(t.url);
|
|
1584
|
-
return n === "page" || n === "middleware" && dt(t) ? await sn(e, o, r, s) : nn(o, r, s);
|
|
1585
|
-
}
|
|
1586
|
-
function nn(e, t, r = {}) {
|
|
1587
|
-
if (Ae(t))
|
|
1588
|
-
return Z(
|
|
1589
|
-
{
|
|
1590
|
-
...t.extensions,
|
|
1591
|
-
detail: t.detail,
|
|
1592
|
-
instance: `${e.pathname}${e.search}`,
|
|
1593
|
-
status: t.status,
|
|
1594
|
-
title: t.title,
|
|
1595
|
-
type: t.type
|
|
1596
|
-
},
|
|
1597
|
-
{ headers: t.headers }
|
|
1598
|
-
);
|
|
1599
|
-
const { message: n } = ft(t);
|
|
1600
|
-
return Z({
|
|
1601
|
-
// `detail` carries the thrown message, so it is dev only for the same
|
|
1602
|
-
// reason the stack is.
|
|
1603
|
-
...ht(r.dev) ? { detail: n } : {},
|
|
1604
|
-
instance: `${e.pathname}${e.search}`,
|
|
1605
|
-
status: 500,
|
|
1606
|
-
title: "Internal Server Error"
|
|
1607
|
-
});
|
|
1608
|
-
}
|
|
1609
|
-
async function sn(e, t, r, n) {
|
|
1610
|
-
const s = mt(r);
|
|
1611
|
-
try {
|
|
1612
|
-
const o = await an(
|
|
1613
|
-
e,
|
|
1614
|
-
t.pathname,
|
|
1615
|
-
r,
|
|
1616
|
-
n
|
|
1617
|
-
), i = Ae(r) ? new Headers(r.headers) : new Headers();
|
|
1618
|
-
return i.set("content-type", "text/html; charset=utf-8"), new Response(await n.transformDocument?.(o) ?? o, {
|
|
1619
|
-
headers: i,
|
|
1620
|
-
status: s
|
|
1621
|
-
});
|
|
1622
|
-
} catch (o) {
|
|
1623
|
-
return n.onError?.(o, "page"), on();
|
|
1624
|
-
}
|
|
1625
|
-
}
|
|
1626
|
-
function on() {
|
|
1627
|
-
return new Response(rn, {
|
|
1628
|
-
headers: { "content-type": "text/plain; charset=utf-8" },
|
|
1629
|
-
status: 500
|
|
1630
|
-
});
|
|
1631
|
-
}
|
|
1632
|
-
async function an(e, t, r, n) {
|
|
1633
|
-
const s = await cn(e, t, n), o = Qe({
|
|
1634
|
-
dev: n.dev,
|
|
1635
|
-
nonce: n.nonce
|
|
1636
|
-
}), i = tt(
|
|
1637
|
-
Xe(
|
|
1638
|
-
o,
|
|
1639
|
-
de(s, { error: r, pathname: t, status: mt(r) })
|
|
1640
|
-
)
|
|
1641
|
-
);
|
|
1642
|
-
return et({
|
|
1643
|
-
body: { data: void 0, html: i, navigation: n.navigation },
|
|
1644
|
-
entrySrc: n.clientEntry,
|
|
1645
|
-
lang: n.lang,
|
|
1646
|
-
nonce: n.nonce,
|
|
1647
|
-
scripts: o.scripts(),
|
|
1648
|
-
styles: n.styles,
|
|
1649
|
-
title: n.title
|
|
1650
|
-
});
|
|
1651
|
-
}
|
|
1652
|
-
function mt(e) {
|
|
1653
|
-
return Ae(e) ? e.status : 500;
|
|
1654
|
-
}
|
|
1655
|
-
async function cn(e, t, r) {
|
|
1656
|
-
if (ht(r.dev))
|
|
1657
|
-
return Kr;
|
|
1658
|
-
try {
|
|
1659
|
-
return await cr(e, t) ?? je;
|
|
1660
|
-
} catch {
|
|
1661
|
-
return je;
|
|
1662
|
-
}
|
|
1663
|
-
}
|
|
1664
|
-
const Q = "{nonce}", We = `'nonce-${Q}'`, pt = {
|
|
1665
|
-
baseUri: ["'self'"],
|
|
1666
|
-
connectSrc: ["'self'"],
|
|
1667
|
-
defaultSrc: ["'self'"],
|
|
1668
|
-
fontSrc: ["'self'"],
|
|
1669
|
-
formAction: ["'self'"],
|
|
1670
|
-
frameAncestors: ["'none'"],
|
|
1671
|
-
imgSrc: ["'self'", "data:", "blob:"],
|
|
1672
|
-
objectSrc: ["'none'"],
|
|
1673
|
-
scriptSrc: [We, "'strict-dynamic'"],
|
|
1674
|
-
styleSrc: ["'self'", We],
|
|
1675
|
-
upgradeInsecureRequests: !0
|
|
1676
|
-
}, un = {
|
|
1677
|
-
...pt,
|
|
1678
|
-
scriptSrc: ["'self'"],
|
|
1679
|
-
styleSrc: ["'self'"]
|
|
1680
|
-
}, ze = {
|
|
1681
|
-
contentTypeOptions: "nosniff",
|
|
1682
|
-
crossOriginOpenerPolicy: "same-origin",
|
|
1683
|
-
crossOriginResourcePolicy: "same-origin",
|
|
1684
|
-
permissionsPolicy: "camera=(), microphone=(), geolocation=(), payment=()",
|
|
1685
|
-
referrerPolicy: "strict-origin-when-cross-origin",
|
|
1686
|
-
strictTransportSecurity: {
|
|
1687
|
-
includeSubDomains: !1,
|
|
1688
|
-
maxAge: 31536e3,
|
|
1689
|
-
preload: !1
|
|
1690
|
-
}
|
|
1691
|
-
}, ln = {
|
|
1692
|
-
contentTypeOptions: "nosniff",
|
|
1693
|
-
crossOriginResourcePolicy: "same-origin",
|
|
1694
|
-
referrerPolicy: "strict-origin-when-cross-origin"
|
|
1695
|
-
}, L = {
|
|
1696
|
-
api(e = {}) {
|
|
1697
|
-
return I(
|
|
1698
|
-
{
|
|
1699
|
-
headers: ln
|
|
1700
|
-
},
|
|
1701
|
-
e
|
|
1702
|
-
);
|
|
1703
|
-
},
|
|
1704
|
-
preset(e, t = {}) {
|
|
1705
|
-
return e === "api" ? L.api(t) : e === "cross-origin-isolated" ? L.crossOriginIsolated(t) : e === "static" ? L.static(t) : L.strict(t);
|
|
1706
|
-
},
|
|
1707
|
-
static(e = {}) {
|
|
1708
|
-
return I(
|
|
1709
|
-
{
|
|
1710
|
-
csp: un,
|
|
1711
|
-
headers: ze
|
|
1712
|
-
},
|
|
1713
|
-
e
|
|
1714
|
-
);
|
|
1715
|
-
},
|
|
1716
|
-
strict(e = {}) {
|
|
1717
|
-
return I(
|
|
1718
|
-
{
|
|
1719
|
-
csp: pt,
|
|
1720
|
-
headers: ze
|
|
1721
|
-
},
|
|
1722
|
-
e
|
|
1723
|
-
);
|
|
1724
|
-
},
|
|
1725
|
-
crossOriginIsolated(e = {}) {
|
|
1726
|
-
return I(
|
|
1727
|
-
L.strict({
|
|
1728
|
-
headers: {
|
|
1729
|
-
crossOriginEmbedderPolicy: "require-corp",
|
|
1730
|
-
crossOriginOpenerPolicy: "same-origin"
|
|
1731
|
-
}
|
|
1732
|
-
}),
|
|
1733
|
-
e
|
|
1734
|
-
);
|
|
1735
|
-
}
|
|
1736
|
-
};
|
|
1737
|
-
function _o(e) {
|
|
1738
|
-
return e;
|
|
1739
|
-
}
|
|
1740
|
-
function Vo(e) {
|
|
1741
|
-
return e;
|
|
1742
|
-
}
|
|
1743
|
-
function fn(...e) {
|
|
1744
|
-
return e.reduce((t, r) => r ? I(t, r) : t, {});
|
|
1745
|
-
}
|
|
1746
|
-
function X(...e) {
|
|
1747
|
-
const t = e.reduce((r, n) => n ? {
|
|
1748
|
-
document: fn(r.document, n.document),
|
|
1749
|
-
security: dn(r.security, n.security)
|
|
1750
|
-
} : r, {});
|
|
1751
|
-
return {
|
|
1752
|
-
...t,
|
|
1753
|
-
document: mn(t.document, t.security?.needs)
|
|
1754
|
-
};
|
|
1755
|
-
}
|
|
1756
|
-
function dn(...e) {
|
|
1757
|
-
return e.reduce((t, r) => r ? {
|
|
1758
|
-
csrf: r.csrf ?? t.csrf,
|
|
1759
|
-
fetchMetadata: r.fetchMetadata ?? t.fetchMetadata,
|
|
1760
|
-
needs: hn(t.needs, r.needs),
|
|
1761
|
-
rateLimit: r.rateLimit ?? t.rateLimit,
|
|
1762
|
-
request: wt(t.request, r.request)
|
|
1763
|
-
} : t, {});
|
|
1764
|
-
}
|
|
1765
|
-
const gt = [
|
|
1766
|
-
{ directive: "connectSrc", need: "connect" },
|
|
1767
|
-
{ directive: "imgSrc", need: "img" },
|
|
1768
|
-
{ directive: "scriptSrc", need: "script" }
|
|
1769
|
-
];
|
|
1770
|
-
function hn(e, t) {
|
|
1771
|
-
const r = {};
|
|
1772
|
-
for (const { need: n } of gt) {
|
|
1773
|
-
const s = [.../* @__PURE__ */ new Set([
|
|
1774
|
-
...e?.[n] ?? [],
|
|
1775
|
-
...t?.[n] ?? []
|
|
1776
|
-
])];
|
|
1777
|
-
s.length > 0 && (r[n] = s);
|
|
1778
|
-
}
|
|
1779
|
-
return Object.keys(r).length > 0 ? r : void 0;
|
|
1780
|
-
}
|
|
1781
|
-
function mn(e, t) {
|
|
1782
|
-
if (!e?.csp || !t)
|
|
1783
|
-
return e;
|
|
1784
|
-
let r = e.csp;
|
|
1785
|
-
for (const { directive: n, need: s } of gt)
|
|
1786
|
-
r = pn(r, n, s, t[s]);
|
|
1787
|
-
return r === e.csp ? e : { ...e, csp: r };
|
|
1788
|
-
}
|
|
1789
|
-
function pn(e, t, r, n) {
|
|
1790
|
-
if (!n || n.length === 0)
|
|
1791
|
-
return e;
|
|
1792
|
-
if (e[t] === !1)
|
|
1793
|
-
throw new Error(
|
|
1794
|
-
`A route policy declares security.needs.${r} and sets csp.${t} to false. Set an explicit csp.${t} that includes ${n.join(", ")}.`
|
|
1795
|
-
);
|
|
1796
|
-
if (e[t] === void 0 && e.defaultSrc === void 0)
|
|
1797
|
-
return e;
|
|
1798
|
-
const s = x(
|
|
1799
|
-
e[t] ?? e.defaultSrc
|
|
1800
|
-
) ?? [];
|
|
1801
|
-
return Array.isArray(s) ? {
|
|
1802
|
-
...e,
|
|
1803
|
-
[t]: [.../* @__PURE__ */ new Set([...s, ...n])]
|
|
1804
|
-
} : e;
|
|
1805
|
-
}
|
|
1806
|
-
async function Jo(e, t = "sha256") {
|
|
1807
|
-
const r = await globalThis.crypto.subtle.digest(
|
|
1808
|
-
$n(t),
|
|
1809
|
-
new TextEncoder().encode(e)
|
|
1810
|
-
);
|
|
1811
|
-
return `'${t}-${kn(new Uint8Array(r))}'`;
|
|
1812
|
-
}
|
|
1813
|
-
function q(e, t = {}) {
|
|
1814
|
-
e.csp && Pn(e.csp), An(e);
|
|
1815
|
-
const r = new Headers(), n = e.csp !== !1 && e.csp ? bn(e.csp, t) : void 0, s = En(e.trustedTypes), o = e.trustedTypes ? e.trustedTypes.mode === "report-only" : !1;
|
|
1816
|
-
return S(
|
|
1817
|
-
r,
|
|
1818
|
-
"content-security-policy",
|
|
1819
|
-
ee(n, o ? void 0 : s)
|
|
1820
|
-
), S(
|
|
1821
|
-
r,
|
|
1822
|
-
"content-security-policy-report-only",
|
|
1823
|
-
o ? ee(s, Et(e.csp)) : void 0
|
|
1824
|
-
), Sn(r, e.headers, t), r;
|
|
1825
|
-
}
|
|
1826
|
-
function ne(e) {
|
|
1827
|
-
return !e || !e.csp ? !1 : G(e.csp).some(([, t]) => {
|
|
1828
|
-
const r = x(t);
|
|
1829
|
-
return Array.isArray(r) && r.some((n) => n.includes(Q));
|
|
1830
|
-
});
|
|
1831
|
-
}
|
|
1832
|
-
function yt() {
|
|
1833
|
-
const e = new Uint8Array(16);
|
|
1834
|
-
return globalThis.crypto.getRandomValues(e), btoa(String.fromCharCode(...e));
|
|
1835
|
-
}
|
|
1836
|
-
function I(e, t) {
|
|
1837
|
-
return {
|
|
1838
|
-
csp: yn(e.csp, t.csp),
|
|
1839
|
-
headers: gn(e.headers, t.headers),
|
|
1840
|
-
trustedTypes: t.trustedTypes ?? e.trustedTypes
|
|
1841
|
-
};
|
|
1842
|
-
}
|
|
1843
|
-
function gn(e, t) {
|
|
1844
|
-
const r = wt(e, t);
|
|
1845
|
-
return !r || t?.reportingEndpoints === !1 || e?.reportingEndpoints && t?.reportingEndpoints && (r.reportingEndpoints = {
|
|
1846
|
-
...e.reportingEndpoints,
|
|
1847
|
-
...t.reportingEndpoints
|
|
1848
|
-
}), r;
|
|
1849
|
-
}
|
|
1850
|
-
function wt(e, t) {
|
|
1851
|
-
return t ? {
|
|
1852
|
-
...e ?? {},
|
|
1853
|
-
...t
|
|
1854
|
-
} : e;
|
|
1855
|
-
}
|
|
1856
|
-
function yn(e, t) {
|
|
1857
|
-
if (t === !1)
|
|
1858
|
-
return !1;
|
|
1859
|
-
if (!t)
|
|
1860
|
-
return e;
|
|
1861
|
-
if (!e)
|
|
1862
|
-
return ue(t);
|
|
1863
|
-
const r = ue(e), n = ue(t), s = {
|
|
1864
|
-
...r,
|
|
1865
|
-
...n
|
|
1866
|
-
};
|
|
1867
|
-
for (const [o, i] of G(t)) {
|
|
1868
|
-
const a = x(
|
|
1869
|
-
r[o]
|
|
1870
|
-
);
|
|
1871
|
-
!Pe(i) && Array.isArray(a) && Array.isArray(i) && St(
|
|
1872
|
-
s,
|
|
1873
|
-
o,
|
|
1874
|
-
wn([...a, ...i])
|
|
1875
|
-
);
|
|
1876
|
-
}
|
|
1877
|
-
return s;
|
|
1878
|
-
}
|
|
1879
|
-
function ue(e) {
|
|
1880
|
-
const t = { ...e };
|
|
1881
|
-
for (const [r, n] of G(e))
|
|
1882
|
-
Pe(n) && St(t, r, n.replace);
|
|
1883
|
-
return t;
|
|
1884
|
-
}
|
|
1885
|
-
function wn(e) {
|
|
1886
|
-
return [...new Set(e)];
|
|
1887
|
-
}
|
|
1888
|
-
function St(e, t, r) {
|
|
1889
|
-
if (!(t === "reportTo" || t === "upgradeInsecureRequests")) {
|
|
1890
|
-
if (t === "reportUri") {
|
|
1891
|
-
e.reportUri = r;
|
|
1892
|
-
return;
|
|
1893
|
-
}
|
|
1894
|
-
e[t] = r;
|
|
1895
|
-
}
|
|
1896
|
-
}
|
|
1897
|
-
function Sn(e, t, r) {
|
|
1898
|
-
t && (S(e, "referrer-policy", t.referrerPolicy), S(e, "x-content-type-options", t.contentTypeOptions), S(e, "cross-origin-opener-policy", t.crossOriginOpenerPolicy), S(e, "cross-origin-embedder-policy", t.crossOriginEmbedderPolicy), S(e, "cross-origin-resource-policy", t.crossOriginResourcePolicy), S(e, "permissions-policy", t.permissionsPolicy), S(
|
|
1899
|
-
e,
|
|
1900
|
-
"reporting-endpoints",
|
|
1901
|
-
Tn(t.reportingEndpoints)
|
|
1902
|
-
), t.strictTransportSecurity && (!r.request || new URL(r.request.url).protocol === "https:") && e.set(
|
|
1903
|
-
"strict-transport-security",
|
|
1904
|
-
Rn(t.strictTransportSecurity)
|
|
1905
|
-
));
|
|
1906
|
-
}
|
|
1907
|
-
function En(e) {
|
|
1908
|
-
if (!e)
|
|
1909
|
-
return;
|
|
1910
|
-
const t = [];
|
|
1911
|
-
return e.requireFor?.includes("script") && t.push("require-trusted-types-for 'script'"), t.push(vn(e)), ee(...t);
|
|
1912
|
-
}
|
|
1913
|
-
function vn(e) {
|
|
1914
|
-
if (e.policies !== void 0 && e.policies.length === 0)
|
|
1915
|
-
return "trusted-types 'none'";
|
|
1916
|
-
const t = [Ft];
|
|
1917
|
-
e.allowDefaultPolicy && t.push("default");
|
|
1918
|
-
for (const r of e.policies ?? [])
|
|
1919
|
-
t.push(r);
|
|
1920
|
-
return `trusted-types ${[...new Set(t)].join(" ")}`;
|
|
1921
|
-
}
|
|
1922
|
-
function ee(...e) {
|
|
1923
|
-
const t = e.filter((r) => r);
|
|
1924
|
-
return t.length > 0 ? t.join("; ") : void 0;
|
|
1925
|
-
}
|
|
1926
|
-
function S(e, t, r) {
|
|
1927
|
-
r && e.set(t, r);
|
|
1928
|
-
}
|
|
1929
|
-
function Rn(e) {
|
|
1930
|
-
const t = [`max-age=${e.maxAge}`];
|
|
1931
|
-
return e.includeSubDomains && t.push("includeSubDomains"), e.preload && t.push("preload"), t.join("; ");
|
|
1932
|
-
}
|
|
1933
|
-
function bn(e, t) {
|
|
1934
|
-
const r = [];
|
|
1935
|
-
for (const [s, o] of G(e)) {
|
|
1936
|
-
if (s === "reportTo" || s === "reportUri")
|
|
1937
|
-
continue;
|
|
1938
|
-
const i = x(o);
|
|
1939
|
-
if (i === !1 || i === void 0)
|
|
1940
|
-
continue;
|
|
1941
|
-
const a = vt(s);
|
|
1942
|
-
if (i === !0 || s === "sandbox" && Array.isArray(i) && i.length === 0) {
|
|
1943
|
-
r.push(a);
|
|
1944
|
-
continue;
|
|
1945
|
-
}
|
|
1946
|
-
r.push(
|
|
1947
|
-
`${a} ${Dn(i, t).join(" ")}`
|
|
1948
|
-
);
|
|
1949
|
-
}
|
|
1950
|
-
const n = Et(e);
|
|
1951
|
-
return n && r.push(n), r.join("; ");
|
|
1952
|
-
}
|
|
1953
|
-
function Et(e) {
|
|
1954
|
-
if (!e)
|
|
1955
|
-
return;
|
|
1956
|
-
const t = [], r = x(e.reportUri);
|
|
1957
|
-
return Array.isArray(r) && r.length && t.push(`report-uri ${r.join(" ")}`), e.reportTo && t.push(`report-to ${e.reportTo}`), ee(...t);
|
|
1958
|
-
}
|
|
1959
|
-
function Tn(e) {
|
|
1960
|
-
if (e)
|
|
1961
|
-
return Object.entries(e).sort(([t], [r]) => t.localeCompare(r)).map(([t, r]) => `${t}="${xn(r)}"`).join(", ");
|
|
1962
|
-
}
|
|
1963
|
-
function xn(e) {
|
|
1964
|
-
return e.replaceAll("\\", "\\\\").replaceAll('"', '\\"');
|
|
1965
|
-
}
|
|
1966
|
-
function An(e) {
|
|
1967
|
-
const t = e.headers?.reportingEndpoints;
|
|
1968
|
-
if (t) {
|
|
1969
|
-
const s = Object.entries(t);
|
|
1970
|
-
if (s.length === 0)
|
|
1971
|
-
throw new Error("Demiurge Reporting-Endpoints requires at least one endpoint.");
|
|
1972
|
-
for (const [o, i] of s)
|
|
1973
|
-
Be(o), qe(i, `Reporting-Endpoints member ${JSON.stringify(o)}`);
|
|
1974
|
-
}
|
|
1975
|
-
const r = e.csp || void 0;
|
|
1976
|
-
if (r?.reportTo && (Be(r.reportTo), !t || !(r.reportTo in t)))
|
|
1977
|
-
throw new Error(
|
|
1978
|
-
`Demiurge CSP report-to group ${JSON.stringify(r.reportTo)} is not defined in headers.reportingEndpoints.`
|
|
1979
|
-
);
|
|
1980
|
-
const n = x(r?.reportUri);
|
|
1981
|
-
for (const s of Array.isArray(n) ? n : [])
|
|
1982
|
-
qe(s, "CSP report-uri target");
|
|
1983
|
-
}
|
|
1984
|
-
function Pn(e) {
|
|
1985
|
-
for (const [t, r] of G(e)) {
|
|
1986
|
-
const n = vt(t);
|
|
1987
|
-
if (r === void 0)
|
|
1988
|
-
continue;
|
|
1989
|
-
if (t === "reportTo") {
|
|
1990
|
-
if (typeof r != "string")
|
|
1991
|
-
throw new Error(
|
|
1992
|
-
`Demiurge CSP directive ${JSON.stringify(n)} must be a string.`
|
|
1993
|
-
);
|
|
1994
|
-
continue;
|
|
1995
|
-
}
|
|
1996
|
-
if (t === "upgradeInsecureRequests") {
|
|
1997
|
-
if (typeof r != "boolean")
|
|
1998
|
-
throw new Error(
|
|
1999
|
-
`Demiurge CSP directive ${JSON.stringify(n)} must be a boolean.`
|
|
2000
|
-
);
|
|
2001
|
-
continue;
|
|
2002
|
-
}
|
|
2003
|
-
if (t === "sandbox") {
|
|
2004
|
-
if (typeof r != "boolean" && (!Array.isArray(r) || !r.every((o) => typeof o == "string")))
|
|
2005
|
-
throw new Error(
|
|
2006
|
-
`Demiurge CSP directive ${JSON.stringify(n)} must be a boolean or a list of sandbox tokens.`
|
|
2007
|
-
);
|
|
2008
|
-
continue;
|
|
2009
|
-
}
|
|
2010
|
-
const s = x(r);
|
|
2011
|
-
if (s !== !1 && (!Array.isArray(s) || !s.every((o) => typeof o == "string")))
|
|
2012
|
-
throw new Error(
|
|
2013
|
-
`Demiurge CSP directive ${JSON.stringify(n)} must be a source list, false, or a replacement object with a source list.`
|
|
2014
|
-
);
|
|
2015
|
-
}
|
|
2016
|
-
}
|
|
2017
|
-
function Pe(e) {
|
|
2018
|
-
return !!(e && typeof e == "object" && !Array.isArray(e) && "replace" in e);
|
|
2019
|
-
}
|
|
2020
|
-
function x(e) {
|
|
2021
|
-
return Pe(e) ? e.replace : e;
|
|
2022
|
-
}
|
|
2023
|
-
function Be(e) {
|
|
2024
|
-
if (!/^(?:[a-z]|\*)[a-z0-9_.*-]*$/.test(e))
|
|
2025
|
-
throw new Error(
|
|
2026
|
-
`Invalid reporting endpoint name ${JSON.stringify(e)}. Use a lowercase Structured Field key.`
|
|
2027
|
-
);
|
|
2028
|
-
}
|
|
2029
|
-
function qe(e, t) {
|
|
2030
|
-
if (!Cn(e) || /[\s,;"\\]/.test(e) || !e.startsWith("/") && !e.startsWith("https://"))
|
|
2031
|
-
throw new Error(`${t} must be a same-origin path or an HTTPS URL.`);
|
|
2032
|
-
if (e.startsWith("//"))
|
|
2033
|
-
throw new Error(`${t} must not be a scheme-relative URL.`);
|
|
2034
|
-
let r;
|
|
2035
|
-
try {
|
|
2036
|
-
r = new URL(e, "https://demiurge.invalid");
|
|
2037
|
-
} catch {
|
|
2038
|
-
throw new Error(`${t} must be a valid URI reference.`);
|
|
2039
|
-
}
|
|
2040
|
-
if (r.username || r.password || r.hash)
|
|
2041
|
-
throw new Error(`${t} must not contain credentials or a fragment.`);
|
|
2042
|
-
}
|
|
2043
|
-
function Cn(e) {
|
|
2044
|
-
return /^[\x20-\x7e]+$/.test(e);
|
|
2045
|
-
}
|
|
2046
|
-
function G(e) {
|
|
2047
|
-
return Object.entries(e);
|
|
2048
|
-
}
|
|
2049
|
-
function Dn(e, t) {
|
|
2050
|
-
return e.map((r) => {
|
|
2051
|
-
if (!r.includes(Q))
|
|
2052
|
-
return r;
|
|
2053
|
-
if (!t.nonce)
|
|
2054
|
-
throw new Error("Demiurge security policy requires a CSP nonce.");
|
|
2055
|
-
return r.replaceAll(Q, t.nonce);
|
|
2056
|
-
});
|
|
2057
|
-
}
|
|
2058
|
-
function vt(e) {
|
|
2059
|
-
return e.replace(/[A-Z]/g, (t) => `-${t.toLowerCase()}`);
|
|
2060
|
-
}
|
|
2061
|
-
function $n(e) {
|
|
2062
|
-
return e === "sha384" ? "SHA-384" : e === "sha512" ? "SHA-512" : "SHA-256";
|
|
2063
|
-
}
|
|
2064
|
-
function kn(e) {
|
|
2065
|
-
let t = "";
|
|
2066
|
-
for (const r of e)
|
|
2067
|
-
t += String.fromCharCode(r);
|
|
2068
|
-
return typeof btoa == "function" ? btoa(t) : Buffer.from(t, "binary").toString("base64");
|
|
2069
|
-
}
|
|
2070
|
-
function Rt(e, t, r = {}) {
|
|
2071
|
-
Ce(e);
|
|
2072
|
-
const n = t.request.headers.get("origin"), s = new Headers();
|
|
2073
|
-
if (e.origins !== "*" && bt(s, "Origin"), !n)
|
|
2074
|
-
return s;
|
|
2075
|
-
const o = Ln(e, n);
|
|
2076
|
-
if (!o)
|
|
2077
|
-
return s;
|
|
2078
|
-
if (s.set("access-control-allow-origin", o), e.credentials && s.set("access-control-allow-credentials", "true"), e.exposeHeaders?.length && s.set("access-control-expose-headers", e.exposeHeaders.join(", ")), r.preflight) {
|
|
2079
|
-
s.set("access-control-allow-methods", r.methods.join(", "));
|
|
2080
|
-
const i = t.request.headers.get(
|
|
2081
|
-
"access-control-request-headers"
|
|
2082
|
-
), a = e.headers?.join(", ") ?? i;
|
|
2083
|
-
a && s.set("access-control-allow-headers", a), e.maxAge !== void 0 && s.set("access-control-max-age", String(e.maxAge));
|
|
2084
|
-
}
|
|
2085
|
-
return s;
|
|
2086
|
-
}
|
|
2087
|
-
function U(e, t, r) {
|
|
2088
|
-
if (!t)
|
|
2089
|
-
return e;
|
|
2090
|
-
const n = new Headers(e.headers);
|
|
2091
|
-
return Mn(n, Rt(t, { request: r })), new Response(e.body, {
|
|
2092
|
-
headers: n,
|
|
2093
|
-
status: e.status,
|
|
2094
|
-
statusText: e.statusText
|
|
2095
|
-
});
|
|
2096
|
-
}
|
|
2097
|
-
function Nn(e, t) {
|
|
2098
|
-
const r = t.headers.get("access-control-request-method"), n = In(r);
|
|
2099
|
-
if (!n)
|
|
2100
|
-
return null;
|
|
2101
|
-
const s = Tt(e, n);
|
|
2102
|
-
if (!s?.cors)
|
|
2103
|
-
return null;
|
|
2104
|
-
const o = s.cors.methods ?? Un(e);
|
|
2105
|
-
return o.includes(n) ? new Response(null, {
|
|
2106
|
-
headers: Rt(
|
|
2107
|
-
s.cors,
|
|
2108
|
-
{ request: t },
|
|
2109
|
-
{
|
|
2110
|
-
methods: o,
|
|
2111
|
-
preflight: !0
|
|
2112
|
-
}
|
|
2113
|
-
),
|
|
2114
|
-
status: 204
|
|
2115
|
-
}) : null;
|
|
2116
|
-
}
|
|
2117
|
-
function Ce(e) {
|
|
2118
|
-
if (e.credentials && e.origins === "*")
|
|
2119
|
-
throw new Error(
|
|
2120
|
-
"Demiurge CORS policy cannot use wildcard origins with credentials."
|
|
2121
|
-
);
|
|
2122
|
-
if (e.credentials && (e.headers?.includes("*") || e.exposeHeaders?.includes("*")))
|
|
2123
|
-
throw new Error(
|
|
2124
|
-
"Demiurge credentialed CORS policy must list allowed and exposed headers explicitly."
|
|
2125
|
-
);
|
|
2126
|
-
if (e.origins !== "*")
|
|
2127
|
-
for (const t of e.origins)
|
|
2128
|
-
On(t);
|
|
2129
|
-
if (e.maxAge !== void 0 && (!Number.isSafeInteger(e.maxAge) || e.maxAge < 0))
|
|
2130
|
-
throw new Error(
|
|
2131
|
-
"Demiurge CORS maxAge must be a non-negative integer number of seconds."
|
|
2132
|
-
);
|
|
2133
|
-
}
|
|
2134
|
-
function On(e) {
|
|
2135
|
-
let t;
|
|
2136
|
-
try {
|
|
2137
|
-
t = new URL(e);
|
|
2138
|
-
} catch {
|
|
2139
|
-
throw Ge(e);
|
|
2140
|
-
}
|
|
2141
|
-
if (t.protocol !== "http:" && t.protocol !== "https:" || t.origin !== e)
|
|
2142
|
-
throw Ge(e);
|
|
2143
|
-
}
|
|
2144
|
-
function Ge(e) {
|
|
2145
|
-
return new Error(
|
|
2146
|
-
`Demiurge CORS origin ${JSON.stringify(e)} must be a canonical HTTP(S) origin without credentials, a path, query, or fragment.`
|
|
2147
|
-
);
|
|
2148
|
-
}
|
|
2149
|
-
function Ln(e, t) {
|
|
2150
|
-
return e.origins === "*" ? "*" : e.origins.includes(t) ? t : null;
|
|
2151
|
-
}
|
|
2152
|
-
function Mn(e, t) {
|
|
2153
|
-
t.forEach((r, n) => {
|
|
2154
|
-
if (n === "vary" && e.has("vary")) {
|
|
2155
|
-
for (const s of r.split(","))
|
|
2156
|
-
bt(e, s.trim());
|
|
2157
|
-
return;
|
|
2158
|
-
}
|
|
2159
|
-
e.set(n, r);
|
|
2160
|
-
});
|
|
2161
|
-
}
|
|
2162
|
-
function bt(e, t) {
|
|
2163
|
-
if (!t)
|
|
2164
|
-
return;
|
|
2165
|
-
const r = e.get("vary")?.split(",").map((n) => n.trim()).filter(Boolean) ?? [];
|
|
2166
|
-
r.some((n) => n.toLowerCase() === t.toLowerCase()) || e.set("vary", [...r, t].join(", "));
|
|
2167
|
-
}
|
|
2168
|
-
function In(e) {
|
|
2169
|
-
if (!e)
|
|
2170
|
-
return null;
|
|
2171
|
-
const t = e.toUpperCase();
|
|
2172
|
-
return Fn(t) ? t : null;
|
|
2173
|
-
}
|
|
2174
|
-
function Tt(e, t) {
|
|
2175
|
-
return t === "HEAD" ? e.HEAD ?? _e(e.GET) : _e(e[t]);
|
|
2176
|
-
}
|
|
2177
|
-
function _e(e) {
|
|
2178
|
-
return e?.kind === "page" ? void 0 : e;
|
|
2179
|
-
}
|
|
2180
|
-
function Un(e) {
|
|
2181
|
-
return [
|
|
2182
|
-
"GET",
|
|
2183
|
-
"POST",
|
|
2184
|
-
"PUT",
|
|
2185
|
-
"PATCH",
|
|
2186
|
-
"DELETE",
|
|
2187
|
-
"OPTIONS",
|
|
2188
|
-
"HEAD"
|
|
2189
|
-
].filter((t) => Tt(e, t));
|
|
2190
|
-
}
|
|
2191
|
-
function Fn(e) {
|
|
2192
|
-
return e === "GET" || e === "POST" || e === "PUT" || e === "PATCH" || e === "DELETE" || e === "OPTIONS" || e === "HEAD";
|
|
2193
|
-
}
|
|
2194
|
-
const Hn = /* @__PURE__ */ new Set(["DELETE", "PATCH", "POST", "PUT"]);
|
|
2195
|
-
function jn(e = {}) {
|
|
2196
|
-
const t = [], r = e.document, n = r ? Bn(r.policy, r.headers, t) : {};
|
|
2197
|
-
r && Wn(r.policy, t);
|
|
2198
|
-
const s = e.route ? Qn(e.route, t) : void 0;
|
|
2199
|
-
return r?.scripts && (qn(
|
|
2200
|
-
r.policy.csp,
|
|
2201
|
-
r.scripts,
|
|
2202
|
-
r.headers,
|
|
2203
|
-
t
|
|
2204
|
-
), r.scriptDependencies && t.push(
|
|
2205
|
-
...zn(
|
|
2206
|
-
r.scripts,
|
|
2207
|
-
Gn(r.scriptDependencies)
|
|
2208
|
-
)
|
|
2209
|
-
)), {
|
|
2210
|
-
findings: t,
|
|
2211
|
-
headers: n,
|
|
2212
|
-
route: s
|
|
2213
|
-
};
|
|
2214
|
-
}
|
|
2215
|
-
function Wn(e, t) {
|
|
2216
|
-
if (!e.trustedTypes || e.trustedTypes.mode !== "report-only")
|
|
2217
|
-
return;
|
|
2218
|
-
const r = e.csp || void 0, n = !!ge(r?.reportUri)?.length, s = e.headers?.reportingEndpoints, o = !!(r?.reportTo && s && s[r.reportTo]);
|
|
2219
|
-
!n && !o && t.push({
|
|
2220
|
-
code: "report-only-target-missing",
|
|
2221
|
-
message: "Trusted Types report-only mode has no deliverable target. Configure CSP reportTo with a matching Reporting-Endpoints member, reportUri for compatibility, or both.",
|
|
2222
|
-
severity: "warning"
|
|
2223
|
-
});
|
|
2224
|
-
}
|
|
2225
|
-
function zn(e, t = {}) {
|
|
2226
|
-
const r = t.requirePurpose ?? !0, n = [];
|
|
2227
|
-
for (const s of e) {
|
|
2228
|
-
const o = ts(s);
|
|
2229
|
-
o && (r && !s.purpose && n.push({
|
|
2230
|
-
code: "script-purpose-missing",
|
|
2231
|
-
message: `Third-party script ${s.src} should declare a purpose for audits and consent flows.`,
|
|
2232
|
-
severity: "warning"
|
|
2233
|
-
}), t.requireIntegrity && !s.integrity && n.push({
|
|
2234
|
-
code: "script-integrity-missing",
|
|
2235
|
-
message: `Third-party script ${s.src} should declare an integrity hash or an explicit trust-boundary exception.`,
|
|
2236
|
-
severity: "warning"
|
|
2237
|
-
}), s.strategy === "beforeInteractive" && !t.allowBeforeInteractiveThirdParty && n.push({
|
|
2238
|
-
code: "script-third-party-before-interactive",
|
|
2239
|
-
message: `Third-party script ${s.src} runs before the app is interactive and should be justified by policy.`,
|
|
2240
|
-
severity: "warning"
|
|
2241
|
-
}), rs(o) && n.push({
|
|
2242
|
-
code: "script-gtm-wide-trust-boundary",
|
|
2243
|
-
message: "Google Tag Manager can load additional scripts at runtime and should be treated as a wide trust boundary.",
|
|
2244
|
-
severity: "warning"
|
|
2245
|
-
}));
|
|
2246
|
-
}
|
|
2247
|
-
return n;
|
|
2248
|
-
}
|
|
2249
|
-
function Bn(e, t, r) {
|
|
2250
|
-
try {
|
|
2251
|
-
return Object.fromEntries(q(e, t));
|
|
2252
|
-
} catch (n) {
|
|
2253
|
-
return r.push({
|
|
2254
|
-
code: "security-header-render-failed",
|
|
2255
|
-
message: n instanceof Error ? n.message : "Security headers failed to render.",
|
|
2256
|
-
severity: "error"
|
|
2257
|
-
}), {};
|
|
2258
|
-
}
|
|
2259
|
-
}
|
|
2260
|
-
function qn(e, t, r, n) {
|
|
2261
|
-
if (!e)
|
|
2262
|
-
return;
|
|
2263
|
-
const s = _n(e);
|
|
2264
|
-
for (const o of t) {
|
|
2265
|
-
if (Vn(s) && !o.nonce) {
|
|
2266
|
-
n.push({
|
|
2267
|
-
code: "csp-script-missing-nonce",
|
|
2268
|
-
message: `Document script ${o.src} needs a nonce for the effective script-src policy.`,
|
|
2269
|
-
severity: "error"
|
|
2270
|
-
});
|
|
2271
|
-
continue;
|
|
2272
|
-
}
|
|
2273
|
-
o.nonce && r?.nonce && o.nonce === r.nonce || Jn(s, o.src) || n.push({
|
|
2274
|
-
code: "csp-script-src-blocked",
|
|
2275
|
-
message: `Document script ${o.src} is not allowed by the effective script-src policy.`,
|
|
2276
|
-
severity: "error"
|
|
2277
|
-
});
|
|
2278
|
-
}
|
|
2279
|
-
}
|
|
2280
|
-
function Gn(e) {
|
|
2281
|
-
return typeof e == "boolean" ? {} : e;
|
|
2282
|
-
}
|
|
2283
|
-
function _n(e) {
|
|
2284
|
-
return ge(e.scriptSrc) ?? ge(e.defaultSrc) ?? [];
|
|
2285
|
-
}
|
|
2286
|
-
function ge(e) {
|
|
2287
|
-
if (e)
|
|
2288
|
-
return "replace" in e ? e.replace : e;
|
|
2289
|
-
}
|
|
2290
|
-
function Vn(e) {
|
|
2291
|
-
return e.some((t) => t.includes("'nonce-{nonce}'"));
|
|
2292
|
-
}
|
|
2293
|
-
function Jn(e, t) {
|
|
2294
|
-
return Zn(e) ? !1 : e.includes("*") ? !0 : e.includes("'none'") || e.some((r) => r.startsWith("'nonce-")) ? !1 : e.includes("'self'") && Kn(t) || t.startsWith("https:") && e.includes("https:") || t.startsWith("http:") && e.includes("http:") ? !0 : e.some((r) => Yn(r, t));
|
|
2295
|
-
}
|
|
2296
|
-
function Kn(e) {
|
|
2297
|
-
return e.startsWith("/") && !e.startsWith("//");
|
|
2298
|
-
}
|
|
2299
|
-
function Yn(e, t) {
|
|
2300
|
-
if (e.startsWith("'"))
|
|
2301
|
-
return !1;
|
|
2302
|
-
try {
|
|
2303
|
-
const r = new URL(e), n = new URL(t), s = r.hostname.startsWith("*.") ? n.hostname.endsWith(r.hostname.slice(1)) && n.hostname !== r.hostname.slice(2) : n.hostname === r.hostname, o = r.pathname === "/" || r.pathname.endsWith("/") ? n.pathname.startsWith(r.pathname) : n.pathname === r.pathname;
|
|
2304
|
-
return n.protocol === r.protocol && s && n.port === r.port && o;
|
|
2305
|
-
} catch {
|
|
2306
|
-
return !1;
|
|
2307
|
-
}
|
|
2308
|
-
}
|
|
2309
|
-
function Zn(e) {
|
|
2310
|
-
return e.includes("'strict-dynamic'") && e.some(
|
|
2311
|
-
(t) => t.startsWith("'nonce-") || /^'sha(?:256|384|512)-/.test(t)
|
|
2312
|
-
);
|
|
2313
|
-
}
|
|
2314
|
-
function Qn(e, t) {
|
|
2315
|
-
return Xn(e.cors, t), es(e.method, e.security, t), {
|
|
2316
|
-
cors: e.cors,
|
|
2317
|
-
method: e.method,
|
|
2318
|
-
security: e.security
|
|
2319
|
-
};
|
|
2320
|
-
}
|
|
2321
|
-
function Xn(e, t) {
|
|
2322
|
-
if (e)
|
|
2323
|
-
try {
|
|
2324
|
-
Ce(e);
|
|
2325
|
-
} catch (r) {
|
|
2326
|
-
t.push({
|
|
2327
|
-
code: "cors-invalid",
|
|
2328
|
-
message: r instanceof Error ? r.message : "CORS policy is invalid.",
|
|
2329
|
-
severity: "error"
|
|
2330
|
-
});
|
|
2331
|
-
}
|
|
2332
|
-
}
|
|
2333
|
-
function es(e, t, r) {
|
|
2334
|
-
Hn.has(e) && (t?.csrf === !1 && r.push({
|
|
2335
|
-
code: "csrf-disabled",
|
|
2336
|
-
message: "CSRF protection is explicitly disabled for this unsafe route.",
|
|
2337
|
-
severity: "info"
|
|
2338
|
-
}), t?.rateLimit || r.push({
|
|
2339
|
-
code: "rate-limit-missing",
|
|
2340
|
-
message: "Unsafe routes should declare rate limiting.",
|
|
2341
|
-
severity: "warning"
|
|
2342
|
-
}), t?.request?.maxBodySize || r.push({
|
|
2343
|
-
code: "request-body-limit-missing",
|
|
2344
|
-
message: "Unsafe routes should declare a request body size limit.",
|
|
2345
|
-
severity: "warning"
|
|
2346
|
-
}));
|
|
2347
|
-
}
|
|
2348
|
-
function ts(e) {
|
|
2349
|
-
try {
|
|
2350
|
-
const t = new URL(e.src);
|
|
2351
|
-
if (t.protocol === "http:" || t.protocol === "https:")
|
|
2352
|
-
return t;
|
|
2353
|
-
} catch {
|
|
2354
|
-
return null;
|
|
2355
|
-
}
|
|
2356
|
-
return null;
|
|
2357
|
-
}
|
|
2358
|
-
function rs(e) {
|
|
2359
|
-
return e.hostname === "www.googletagmanager.com" && (e.pathname === "/gtm.js" || e.pathname === "/ns.html");
|
|
2360
|
-
}
|
|
2361
|
-
const ns = /* @__PURE__ */ new Set(["DELETE", "PATCH", "POST", "PUT"]), ss = /^[!#$%&'*+\-.^_`|~A-Za-z0-9]+$/;
|
|
2362
|
-
function os() {
|
|
2363
|
-
const e = new Uint8Array(32);
|
|
2364
|
-
return globalThis.crypto.getRandomValues(e), btoa(String.fromCharCode(...e)).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, "");
|
|
2365
|
-
}
|
|
2366
|
-
function is(e, t = {}) {
|
|
2367
|
-
const r = t.cookie ?? "csrf-token";
|
|
2368
|
-
if (!ss.test(r))
|
|
2369
|
-
throw new Error("Demiurge CSRF cookie name is invalid.");
|
|
2370
|
-
if (!e)
|
|
2371
|
-
throw new Error("Demiurge CSRF token must not be empty.");
|
|
2372
|
-
const n = [
|
|
2373
|
-
`${r}=${encodeURIComponent(e)}`,
|
|
2374
|
-
"Path=/",
|
|
2375
|
-
"SameSite=Lax"
|
|
2376
|
-
];
|
|
2377
|
-
return (t.secure ?? !0) && n.push("Secure"), n.join("; ");
|
|
2378
|
-
}
|
|
2379
|
-
function Ko(e = {}) {
|
|
2380
|
-
const t = os();
|
|
2381
|
-
return {
|
|
2382
|
-
cookie: is(t, e),
|
|
2383
|
-
token: t
|
|
2384
|
-
};
|
|
2385
|
-
}
|
|
2386
|
-
function as(e, t) {
|
|
2387
|
-
if (!ns.has(t.method.toUpperCase()) || e === !1)
|
|
2388
|
-
return null;
|
|
2389
|
-
const r = t.headers.get("cookie");
|
|
2390
|
-
if (e === void 0 && !r?.trim())
|
|
2391
|
-
return null;
|
|
2392
|
-
const n = us(e ?? !0), o = cs(r).get(n.cookie), i = t.headers.get(n.header);
|
|
2393
|
-
return !o || !i || !fs(o, i) ? new Response("Invalid CSRF token.", {
|
|
2394
|
-
status: 403
|
|
2395
|
-
}) : null;
|
|
2396
|
-
}
|
|
2397
|
-
function cs(e) {
|
|
2398
|
-
const t = /* @__PURE__ */ new Map();
|
|
2399
|
-
if (!e)
|
|
2400
|
-
return t;
|
|
2401
|
-
for (const r of e.split(";")) {
|
|
2402
|
-
const n = r.indexOf("=");
|
|
2403
|
-
if (n === -1)
|
|
2404
|
-
continue;
|
|
2405
|
-
const s = r.slice(0, n).trim(), o = r.slice(n + 1).trim();
|
|
2406
|
-
s && t.set(s, ls(o));
|
|
2407
|
-
}
|
|
2408
|
-
return t;
|
|
2409
|
-
}
|
|
2410
|
-
function us(e) {
|
|
2411
|
-
return e === !0 ? {
|
|
2412
|
-
cookie: "csrf-token",
|
|
2413
|
-
header: "x-csrf-token"
|
|
2414
|
-
} : {
|
|
2415
|
-
cookie: e.cookie ?? "csrf-token",
|
|
2416
|
-
header: e.header ?? "x-csrf-token"
|
|
2417
|
-
};
|
|
2418
|
-
}
|
|
2419
|
-
function ls(e) {
|
|
2420
|
-
try {
|
|
2421
|
-
return decodeURIComponent(e);
|
|
2422
|
-
} catch {
|
|
2423
|
-
return e;
|
|
2424
|
-
}
|
|
2425
|
-
}
|
|
2426
|
-
function fs(e, t) {
|
|
2427
|
-
let r = e.length ^ t.length;
|
|
2428
|
-
const n = Math.max(e.length, t.length);
|
|
2429
|
-
for (let s = 0; s < n; s += 1)
|
|
2430
|
-
r |= e.charCodeAt(s) ^ t.charCodeAt(s);
|
|
2431
|
-
return r === 0;
|
|
2432
|
-
}
|
|
2433
|
-
const le = "Sec-Fetch-Dest", ds = "Sec-Fetch-Mode", hs = "Sec-Fetch-Site", ms = /* @__PURE__ */ new Set(["embed", "object"]), ps = /* @__PURE__ */ new Set(["GET", "HEAD"]), Ve = {
|
|
2434
|
-
allowCrossSite: !1,
|
|
2435
|
-
allowNavigation: !0,
|
|
2436
|
-
allowSameSite: !1
|
|
2437
|
-
};
|
|
2438
|
-
function gs(e, t, r = t.method) {
|
|
2439
|
-
const n = e === !0 ? Ve : { ...Ve, ...e }, s = [];
|
|
2440
|
-
if (ws(t, r))
|
|
2441
|
-
return { allowed: !0, reason: "cors-preflight", vary: s };
|
|
2442
|
-
s.push(hs);
|
|
2443
|
-
const o = t.headers.get("sec-fetch-site");
|
|
2444
|
-
if (o === null)
|
|
2445
|
-
return { allowed: !0, reason: "metadata-absent", vary: s };
|
|
2446
|
-
if (o === "same-origin")
|
|
2447
|
-
return { allowed: !0, reason: "same-origin", vary: s };
|
|
2448
|
-
if (o === "none")
|
|
2449
|
-
return { allowed: !0, reason: "user-initiated", vary: s };
|
|
2450
|
-
if (o === "same-site" && n.allowSameSite)
|
|
2451
|
-
return { allowed: !0, reason: "same-site-trusted", vary: s };
|
|
2452
|
-
if (n.allowCrossSite)
|
|
2453
|
-
return { allowed: !0, reason: "cross-site-exempt", vary: s };
|
|
2454
|
-
const i = e === !0 ? void 0 : e.allowedDestinations;
|
|
2455
|
-
if (i?.length && (s.push(le), i.includes(t.headers.get("sec-fetch-dest") ?? "")))
|
|
2456
|
-
return { allowed: !0, reason: "destination-exempt", vary: s };
|
|
2457
|
-
if (n.allowNavigation && ps.has(r.toUpperCase()) && (s.push(ds), t.headers.get("sec-fetch-mode") === "navigate")) {
|
|
2458
|
-
const a = t.headers.get("sec-fetch-dest") ?? "";
|
|
2459
|
-
if (s.includes(le) || s.push(le), !ms.has(a))
|
|
2460
|
-
return { allowed: !0, reason: "top-level-navigation", vary: s };
|
|
2461
|
-
}
|
|
2462
|
-
return {
|
|
2463
|
-
allowed: !1,
|
|
2464
|
-
reason: o === "same-site" ? "same-site-denied" : "cross-site-denied",
|
|
2465
|
-
vary: s
|
|
2466
|
-
};
|
|
2467
|
-
}
|
|
2468
|
-
function ys(e, t, r = t.method) {
|
|
2469
|
-
if (!e)
|
|
2470
|
-
return { response: null, vary: [] };
|
|
2471
|
-
const n = gs(e, t, r);
|
|
2472
|
-
if (n.allowed)
|
|
2473
|
-
return { response: null, vary: n.vary };
|
|
2474
|
-
const s = new Response("Request blocked by the Fetch Metadata policy.", {
|
|
2475
|
-
headers: { "content-type": "text/plain; charset=utf-8" },
|
|
2476
|
-
status: 403
|
|
2477
|
-
});
|
|
2478
|
-
return xt(s, n.vary), { response: s, vary: n.vary };
|
|
2479
|
-
}
|
|
2480
|
-
function xt(e, t) {
|
|
2481
|
-
if (t.length === 0)
|
|
2482
|
-
return e;
|
|
2483
|
-
const r = e.headers.get("vary")?.split(",").map((s) => s.trim()).filter(Boolean) ?? [];
|
|
2484
|
-
if (r.includes("*"))
|
|
2485
|
-
return e;
|
|
2486
|
-
const n = [...r];
|
|
2487
|
-
for (const s of t)
|
|
2488
|
-
n.some((o) => o.toLowerCase() === s.toLowerCase()) || n.push(s);
|
|
2489
|
-
return e.headers.set("vary", n.join(", ")), e;
|
|
2490
|
-
}
|
|
2491
|
-
function ws(e, t) {
|
|
2492
|
-
return t.toUpperCase() === "OPTIONS" && e.headers.has("access-control-request-method");
|
|
2493
|
-
}
|
|
2494
|
-
const Ss = {
|
|
2495
|
-
h: 3600 * 1e3,
|
|
2496
|
-
m: 60 * 1e3,
|
|
2497
|
-
s: 1e3
|
|
2498
|
-
}, Es = 1e4;
|
|
2499
|
-
function At(e = {}) {
|
|
2500
|
-
const t = e.maximumEntries ?? Es;
|
|
2501
|
-
if (!Number.isSafeInteger(t) || t <= 0)
|
|
2502
|
-
throw new Error(
|
|
2503
|
-
"Demiurge rate limit maximumEntries must be a positive integer."
|
|
2504
|
-
);
|
|
2505
|
-
const r = /* @__PURE__ */ new Map();
|
|
2506
|
-
let n = Number.POSITIVE_INFINITY;
|
|
2507
|
-
return {
|
|
2508
|
-
increment(s, o, i) {
|
|
2509
|
-
i >= n && (vs(r, i), n = Rs(r));
|
|
2510
|
-
const a = r.get(s);
|
|
2511
|
-
if (!a || a.resetAt <= i) {
|
|
2512
|
-
const c = {
|
|
2513
|
-
count: 1,
|
|
2514
|
-
resetAt: i + o
|
|
2515
|
-
};
|
|
2516
|
-
return !a && r.size >= t && bs(r), r.set(s, c), n = Math.min(n, c.resetAt), { count: c.count, resetAt: c.resetAt };
|
|
2517
|
-
}
|
|
2518
|
-
return a.count += 1, { count: a.count, resetAt: a.resetAt };
|
|
2519
|
-
}
|
|
2520
|
-
};
|
|
2521
|
-
}
|
|
2522
|
-
function vs(e, t) {
|
|
2523
|
-
for (const [r, n] of e)
|
|
2524
|
-
n.resetAt <= t && e.delete(r);
|
|
2525
|
-
}
|
|
2526
|
-
function Rs(e) {
|
|
2527
|
-
let t = Number.POSITIVE_INFINITY;
|
|
2528
|
-
for (const r of e.values())
|
|
2529
|
-
t = Math.min(t, r.resetAt);
|
|
2530
|
-
return t;
|
|
2531
|
-
}
|
|
2532
|
-
function bs(e) {
|
|
2533
|
-
const t = e.keys().next().value;
|
|
2534
|
-
t !== void 0 && e.delete(t);
|
|
2535
|
-
}
|
|
2536
|
-
async function Ts(e, t, r, n = Date.now()) {
|
|
2537
|
-
if (!e)
|
|
2538
|
-
return null;
|
|
2539
|
-
De(e);
|
|
2540
|
-
const s = Pt(e.window), o = xs(e, t), i = await r.increment(o, s, n), a = Math.max(0, e.limit - i.count), c = new Headers({
|
|
2541
|
-
"retry-after": String(Math.ceil(Math.max(0, i.resetAt - n) / 1e3)),
|
|
2542
|
-
"x-ratelimit-limit": String(e.limit),
|
|
2543
|
-
"x-ratelimit-remaining": String(a),
|
|
2544
|
-
"x-ratelimit-reset": String(Math.ceil(i.resetAt / 1e3))
|
|
2545
|
-
});
|
|
2546
|
-
return i.count > e.limit ? new Response("Rate limit exceeded.", {
|
|
2547
|
-
headers: c,
|
|
2548
|
-
status: 429
|
|
2549
|
-
}) : null;
|
|
2550
|
-
}
|
|
2551
|
-
function Pt(e) {
|
|
2552
|
-
if (typeof e == "number") {
|
|
2553
|
-
if (!Number.isSafeInteger(e) || e <= 0)
|
|
2554
|
-
throw new Error("Demiurge rate limit window must be a positive integer.");
|
|
2555
|
-
return e;
|
|
2556
|
-
}
|
|
2557
|
-
const t = /^(\d+)(s|m|h)$/i.exec(e.trim());
|
|
2558
|
-
if (!t)
|
|
2559
|
-
throw new Error("Demiurge rate limit window must use an s/m/h suffix.");
|
|
2560
|
-
const r = Number(t[1]), n = t[2].toLowerCase(), s = r * Ss[n];
|
|
2561
|
-
if (!Number.isSafeInteger(s))
|
|
2562
|
-
throw new Error("Demiurge rate limit window is too large.");
|
|
2563
|
-
return s;
|
|
2564
|
-
}
|
|
2565
|
-
function De(e) {
|
|
2566
|
-
if (!Number.isSafeInteger(e.limit) || e.limit <= 0)
|
|
2567
|
-
throw new Error("Demiurge rate limit limit must be a positive integer.");
|
|
2568
|
-
Pt(e.window);
|
|
2569
|
-
}
|
|
2570
|
-
function xs(e, t) {
|
|
2571
|
-
return `${As(e.key)}:${Ps(e.key, t)}`;
|
|
2572
|
-
}
|
|
2573
|
-
function As(e) {
|
|
2574
|
-
return typeof e == "string" ? e : `header:${e.header.toLowerCase()}`;
|
|
2575
|
-
}
|
|
2576
|
-
function Ps(e, t) {
|
|
2577
|
-
return e === "ip" ? Cs(t) : t.headers.get(e.header) ?? "missing";
|
|
2578
|
-
}
|
|
2579
|
-
function Cs(e) {
|
|
2580
|
-
return Ht(e)?.clientIp ?? "unknown";
|
|
2581
|
-
}
|
|
2582
|
-
const Ds = {
|
|
2583
|
-
b: 1,
|
|
2584
|
-
gb: 1024 ** 3,
|
|
2585
|
-
kb: 1024,
|
|
2586
|
-
mb: 1024 ** 2
|
|
2587
|
-
};
|
|
2588
|
-
function $s(e, t, r) {
|
|
2589
|
-
const n = Ns(e, r);
|
|
2590
|
-
if (n)
|
|
2591
|
-
return n;
|
|
2592
|
-
if (e?.maxBodySize === void 0)
|
|
2593
|
-
return null;
|
|
2594
|
-
const s = t.headers.get("content-length");
|
|
2595
|
-
if (!s)
|
|
2596
|
-
return null;
|
|
2597
|
-
const o = Os(s);
|
|
2598
|
-
if (o === null)
|
|
2599
|
-
return new Response("Invalid Content-Length.", {
|
|
2600
|
-
status: 400
|
|
2601
|
-
});
|
|
2602
|
-
const i = Ct(e.maxBodySize);
|
|
2603
|
-
return o > i ? new Response("Request body too large.", {
|
|
2604
|
-
status: 413
|
|
2605
|
-
}) : null;
|
|
2606
|
-
}
|
|
2607
|
-
class F extends Error {
|
|
2608
|
-
constructor() {
|
|
2609
|
-
super("Demiurge request body exceeded maxBodySize while being read."), this.name = "RequestBodyTooLargeError";
|
|
2610
|
-
}
|
|
2611
|
-
}
|
|
2612
|
-
function ks(e, t) {
|
|
2613
|
-
if (e?.maxBodySize === void 0 || t.body === null)
|
|
2614
|
-
return t;
|
|
2615
|
-
const r = Ct(e.maxBodySize), n = t.body.getReader();
|
|
2616
|
-
let s = 0;
|
|
2617
|
-
const o = new ReadableStream({
|
|
2618
|
-
async pull(a) {
|
|
2619
|
-
const c = await n.read();
|
|
2620
|
-
if (c.done) {
|
|
2621
|
-
a.close();
|
|
2622
|
-
return;
|
|
2623
|
-
}
|
|
2624
|
-
if (s += c.value.byteLength, s > r) {
|
|
2625
|
-
const u = new F();
|
|
2626
|
-
a.error(u);
|
|
2627
|
-
try {
|
|
2628
|
-
await n.cancel(u);
|
|
2629
|
-
} catch {
|
|
2630
|
-
}
|
|
2631
|
-
return;
|
|
2632
|
-
}
|
|
2633
|
-
a.enqueue(c.value);
|
|
2634
|
-
},
|
|
2635
|
-
async cancel(a) {
|
|
2636
|
-
try {
|
|
2637
|
-
await n.cancel(a);
|
|
2638
|
-
} catch {
|
|
2639
|
-
}
|
|
2640
|
-
}
|
|
2641
|
-
}), i = new Request(t, {
|
|
2642
|
-
body: o,
|
|
2643
|
-
duplex: "half"
|
|
2644
|
-
});
|
|
2645
|
-
return jt(t, i), i;
|
|
2646
|
-
}
|
|
2647
|
-
function V() {
|
|
2648
|
-
return new Response("Request body too large.", { status: 413 });
|
|
2649
|
-
}
|
|
2650
|
-
function Ns(e, t) {
|
|
2651
|
-
return !e?.allowedMethods || Ls(e.allowedMethods, t) ? null : new Response(null, {
|
|
2652
|
-
headers: {
|
|
2653
|
-
allow: Ms(e.allowedMethods)
|
|
2654
|
-
},
|
|
2655
|
-
status: 405
|
|
2656
|
-
});
|
|
2657
|
-
}
|
|
2658
|
-
function Ct(e) {
|
|
2659
|
-
if (typeof e == "number") {
|
|
2660
|
-
if (!Number.isSafeInteger(e) || e < 0)
|
|
2661
|
-
throw new Error("Demiurge request maxBodySize must be a non-negative integer.");
|
|
2662
|
-
return e;
|
|
2663
|
-
}
|
|
2664
|
-
const t = /^(\d+)(b|kb|mb|gb)$/i.exec(e.trim());
|
|
2665
|
-
if (!t)
|
|
2666
|
-
throw new Error(
|
|
2667
|
-
"Demiurge request maxBodySize must use bytes or a b/kb/mb/gb suffix."
|
|
2668
|
-
);
|
|
2669
|
-
const r = Number(t[1]), n = t[2].toLowerCase(), s = r * Ds[n];
|
|
2670
|
-
if (!Number.isSafeInteger(s))
|
|
2671
|
-
throw new Error("Demiurge request maxBodySize is too large.");
|
|
2672
|
-
return s;
|
|
2673
|
-
}
|
|
2674
|
-
function Os(e) {
|
|
2675
|
-
if (!/^\d+$/.test(e))
|
|
2676
|
-
return null;
|
|
2677
|
-
const t = Number(e);
|
|
2678
|
-
return Number.isSafeInteger(t) ? t : null;
|
|
2679
|
-
}
|
|
2680
|
-
function Ls(e, t) {
|
|
2681
|
-
return e.includes(t) || t === "HEAD" && e.includes("GET");
|
|
2682
|
-
}
|
|
2683
|
-
function Ms(e) {
|
|
2684
|
-
const t = [...e];
|
|
2685
|
-
return t.includes("GET") && !t.includes("HEAD") && t.push("HEAD"), t.join(", ");
|
|
2686
|
-
}
|
|
2687
|
-
const Is = [
|
|
2688
|
-
"GET",
|
|
2689
|
-
"POST",
|
|
2690
|
-
"PUT",
|
|
2691
|
-
"PATCH",
|
|
2692
|
-
"DELETE",
|
|
2693
|
-
"OPTIONS",
|
|
2694
|
-
"HEAD"
|
|
2695
|
-
];
|
|
2696
|
-
function Us(e, t = {}) {
|
|
2697
|
-
for (const [n, s] of Object.entries(e)) {
|
|
2698
|
-
Fs(n, s);
|
|
2699
|
-
for (const o of Is) {
|
|
2700
|
-
const i = s[o];
|
|
2701
|
-
!i || i.kind === "page" || Hs(n, o, i, s);
|
|
2702
|
-
}
|
|
2703
|
-
}
|
|
2704
|
-
const r = ot(
|
|
2705
|
-
Object.fromEntries(
|
|
2706
|
-
Object.entries(e).map(([n, s]) => [
|
|
2707
|
-
n,
|
|
2708
|
-
async () => s
|
|
2709
|
-
])
|
|
2710
|
-
)
|
|
2711
|
-
);
|
|
2712
|
-
return Bs(r, e, t.adapter), r;
|
|
2713
|
-
}
|
|
2714
|
-
function Fs(e, t) {
|
|
2715
|
-
const r = t.policy?.security?.rateLimit;
|
|
2716
|
-
r && z(e, "policy", "rate limit", () => {
|
|
2717
|
-
De(r);
|
|
2718
|
-
});
|
|
2719
|
-
}
|
|
2720
|
-
function Hs(e, t, r, n) {
|
|
2721
|
-
r.cors && z(e, t, "CORS", () => {
|
|
2722
|
-
Ce(r.cors), js(e, t, r.cors.methods, n);
|
|
2723
|
-
}), r.security?.rateLimit && z(e, t, "rate limit", () => {
|
|
2724
|
-
De(r.security.rateLimit);
|
|
2725
|
-
});
|
|
2726
|
-
}
|
|
2727
|
-
function js(e, t, r, n) {
|
|
2728
|
-
if (r) {
|
|
2729
|
-
for (const s of r)
|
|
2730
|
-
if (s !== "OPTIONS" && !Ws(n, s))
|
|
2731
|
-
throw new Error(
|
|
2732
|
-
`Route ${JSON.stringify(e)} export ${t} allows CORS method ${s}, but the route does not export that response capability.`
|
|
2733
|
-
);
|
|
2734
|
-
}
|
|
2735
|
-
}
|
|
2736
|
-
function Ws(e, t) {
|
|
2737
|
-
const r = t === "HEAD" ? e.HEAD ?? e.GET : e[t];
|
|
2738
|
-
return zs(r) ? r : void 0;
|
|
2739
|
-
}
|
|
2740
|
-
function zs(e) {
|
|
2741
|
-
return !!(e && e.kind !== "page");
|
|
2742
|
-
}
|
|
2743
|
-
function Bs(e, t, r) {
|
|
2744
|
-
for (const s of e.routes) {
|
|
2745
|
-
const o = t[s.file], i = o?.GET;
|
|
2746
|
-
if (!i || i.kind !== "page")
|
|
2747
|
-
continue;
|
|
2748
|
-
const a = X(
|
|
2749
|
-
...e.policies.filter(
|
|
2750
|
-
(c) => T(c.fileSegments, s.fileSegments)
|
|
2751
|
-
).map((c) => t[c.file]?.policy),
|
|
2752
|
-
o.policy
|
|
2753
|
-
);
|
|
2754
|
-
Je(s.file, "GET", a, r), Ks(
|
|
2755
|
-
s.file,
|
|
2756
|
-
i.render.mode,
|
|
2757
|
-
a.document
|
|
2758
|
-
), qs(
|
|
2759
|
-
s.file,
|
|
2760
|
-
"GET",
|
|
2761
|
-
a,
|
|
2762
|
-
[
|
|
2763
|
-
...e.layouts.filter(
|
|
2764
|
-
(c) => T(c.fileSegments, s.fileSegments)
|
|
2765
|
-
).map((c) => t[c.file]?.scripts),
|
|
2766
|
-
o.scripts
|
|
2767
|
-
]
|
|
2768
|
-
);
|
|
2769
|
-
}
|
|
2770
|
-
const n = [
|
|
2771
|
-
...e.fallbacks.error,
|
|
2772
|
-
...e.fallbacks.loading,
|
|
2773
|
-
...e.fallbacks.notFound
|
|
2774
|
-
];
|
|
2775
|
-
for (const s of n) {
|
|
2776
|
-
const o = X(
|
|
2777
|
-
...e.policies.filter(
|
|
2778
|
-
(i) => T(i.fileSegments, s.fileSegments)
|
|
2779
|
-
).map((i) => t[i.file]?.policy),
|
|
2780
|
-
t[s.file]?.policy
|
|
2781
|
-
);
|
|
2782
|
-
Je(
|
|
2783
|
-
s.file,
|
|
2784
|
-
"policy",
|
|
2785
|
-
o,
|
|
2786
|
-
r
|
|
2787
|
-
);
|
|
2788
|
-
}
|
|
2789
|
-
}
|
|
2790
|
-
function qs(e, t, r, n) {
|
|
2791
|
-
const s = n.flatMap(
|
|
2792
|
-
(f) => Array.isArray(f) ? f : []
|
|
2793
|
-
);
|
|
2794
|
-
if (s.length === 0 || !r.document)
|
|
2795
|
-
return;
|
|
2796
|
-
const o = "startup-verification-nonce", a = jn({
|
|
2797
|
-
document: {
|
|
2798
|
-
headers: { nonce: o },
|
|
2799
|
-
policy: r.document,
|
|
2800
|
-
scripts: s.map((f) => ({
|
|
2801
|
-
...f,
|
|
2802
|
-
nonce: ne(r.document) ? o : f.nonce
|
|
2803
|
-
}))
|
|
2804
|
-
}
|
|
2805
|
-
}).findings.find(
|
|
2806
|
-
(f) => f.code === "csp-script-src-blocked"
|
|
2807
|
-
);
|
|
2808
|
-
if (!a) {
|
|
2809
|
-
_s(
|
|
2810
|
-
e,
|
|
2811
|
-
t,
|
|
2812
|
-
r.document.csp,
|
|
2813
|
-
s
|
|
2814
|
-
);
|
|
2815
|
-
return;
|
|
2816
|
-
}
|
|
2817
|
-
const c = s.find(
|
|
2818
|
-
(f) => a.message.includes(f.src)
|
|
2819
|
-
), l = (q(r.document, { nonce: o }).get("content-security-policy") ?? "").split("; ").find(
|
|
2820
|
-
(f) => f.startsWith("script-src ")
|
|
2821
|
-
) ?? "default-src (script-src fallback)";
|
|
2822
|
-
throw new Error(
|
|
2823
|
-
`Route ${JSON.stringify(e)} export ${t} declares script ${JSON.stringify(c?.src)} that violates the effective ${l} policy.`
|
|
2824
|
-
);
|
|
2825
|
-
}
|
|
2826
|
-
const Gs = [
|
|
2827
|
-
{ directive: "connectSrc", name: "connect-src", need: "connect" },
|
|
2828
|
-
{ directive: "imgSrc", name: "img-src", need: "img" }
|
|
2829
|
-
];
|
|
2830
|
-
function _s(e, t, r, n) {
|
|
2831
|
-
if (r)
|
|
2832
|
-
for (const s of n)
|
|
2833
|
-
for (const { directive: o, name: i, need: a } of Gs) {
|
|
2834
|
-
const c = s.needs?.[a] ?? [];
|
|
2835
|
-
if (c.length === 0)
|
|
2836
|
-
continue;
|
|
2837
|
-
const u = W(r[o]) ?? W(r.defaultSrc);
|
|
2838
|
-
if (u !== void 0) {
|
|
2839
|
-
for (const l of c)
|
|
2840
|
-
if (!(Array.isArray(u) && Vs(u, l)))
|
|
2841
|
-
throw new Error(
|
|
2842
|
-
`Route ${JSON.stringify(e)} export ${t} declares script ${JSON.stringify(s.src)} that needs ${i} ${l}, which the effective policy does not allow. Add ${l} to security.needs.${a} or to csp.${o} for this route.`
|
|
2843
|
-
);
|
|
2844
|
-
}
|
|
2845
|
-
}
|
|
2846
|
-
}
|
|
2847
|
-
function Vs(e, t) {
|
|
2848
|
-
return e.includes("'none'") ? !1 : e.includes("*") || e.includes(t) ? !0 : t.startsWith("'") ? !1 : e.some((r) => Js(r, t));
|
|
2849
|
-
}
|
|
2850
|
-
function Js(e, t) {
|
|
2851
|
-
if (e.startsWith("'"))
|
|
2852
|
-
return !1;
|
|
2853
|
-
let r;
|
|
2854
|
-
try {
|
|
2855
|
-
r = new URL(t);
|
|
2856
|
-
} catch {
|
|
2857
|
-
return !1;
|
|
2858
|
-
}
|
|
2859
|
-
if (e === `${r.protocol}`)
|
|
2860
|
-
return !0;
|
|
2861
|
-
let n;
|
|
2862
|
-
try {
|
|
2863
|
-
n = new URL(e);
|
|
2864
|
-
} catch {
|
|
2865
|
-
return !1;
|
|
2866
|
-
}
|
|
2867
|
-
if (n.protocol !== r.protocol || n.port !== r.port)
|
|
2868
|
-
return !1;
|
|
2869
|
-
if (n.hostname.startsWith("*.")) {
|
|
2870
|
-
const s = n.hostname.slice(1);
|
|
2871
|
-
return r.hostname.endsWith(s) && r.hostname !== n.hostname.slice(2);
|
|
2872
|
-
}
|
|
2873
|
-
return n.hostname === r.hostname;
|
|
2874
|
-
}
|
|
2875
|
-
function Je(e, t, r, n) {
|
|
2876
|
-
z(e, t, "effective document", () => {
|
|
2877
|
-
q(r.document ?? {}, {
|
|
2878
|
-
nonce: "startup-verification-nonce"
|
|
2879
|
-
});
|
|
2880
|
-
}), !(!n || !ne(r.document)) && z(e, t, "effective CSP", () => {
|
|
2881
|
-
Wt(n, ["nonceInjection"]);
|
|
2882
|
-
});
|
|
2883
|
-
}
|
|
2884
|
-
function Ks(e, t, r) {
|
|
2885
|
-
if (t === "static") {
|
|
2886
|
-
const s = Ys(r?.csp);
|
|
2887
|
-
if (s)
|
|
2888
|
-
throw new Error(
|
|
2889
|
-
`Route ${JSON.stringify(e)} uses render mode "static" with an effective ${s} directive that depends on a CSP nonce. Use security.static() for static output or remove the nonce source from the document policy.`
|
|
2890
|
-
);
|
|
2891
|
-
return;
|
|
2892
|
-
}
|
|
2893
|
-
if (t !== "streaming")
|
|
2894
|
-
return;
|
|
2895
|
-
const n = Zs(r?.csp);
|
|
2896
|
-
if (!(!n || Qs(n.sources)))
|
|
2897
|
-
throw new Error(
|
|
2898
|
-
`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.`
|
|
2899
|
-
);
|
|
2900
|
-
}
|
|
2901
|
-
function Ys(e) {
|
|
2902
|
-
if (e)
|
|
2903
|
-
for (const [t, r] of Object.entries(e)) {
|
|
2904
|
-
const n = W(r);
|
|
2905
|
-
if (Array.isArray(n) && n.some((s) => Xs(s)))
|
|
2906
|
-
return to(t);
|
|
2907
|
-
}
|
|
2908
|
-
}
|
|
2909
|
-
function Zs(e) {
|
|
2910
|
-
if (!e)
|
|
2911
|
-
return;
|
|
2912
|
-
const t = W(e.scriptSrc);
|
|
2913
|
-
if (Array.isArray(t))
|
|
2914
|
-
return { name: "script-src", sources: t };
|
|
2915
|
-
const r = W(e.defaultSrc);
|
|
2916
|
-
if (Array.isArray(r))
|
|
2917
|
-
return { name: "default-src", sources: r };
|
|
2918
|
-
}
|
|
2919
|
-
function Qs(e) {
|
|
2920
|
-
return e.some((t) => Dt(t)) ? !0 : e.includes("'unsafe-inline'") && !e.some((t) => eo(t));
|
|
2921
|
-
}
|
|
2922
|
-
function Xs(e) {
|
|
2923
|
-
return Dt(e) || /^'nonce-[^']*'$/i.test(e);
|
|
2924
|
-
}
|
|
2925
|
-
function Dt(e) {
|
|
2926
|
-
return e.includes("{nonce}");
|
|
2927
|
-
}
|
|
2928
|
-
function eo(e) {
|
|
2929
|
-
return /^'(?:nonce-|sha256-|sha384-|sha512-)/i.test(e);
|
|
2930
|
-
}
|
|
2931
|
-
function W(e) {
|
|
2932
|
-
return e && typeof e == "object" && !Array.isArray(e) && "replace" in e ? e.replace : e;
|
|
2933
|
-
}
|
|
2934
|
-
function to(e) {
|
|
2935
|
-
return e.replace(/[A-Z]/g, (t) => `-${t.toLowerCase()}`);
|
|
2936
|
-
}
|
|
2937
|
-
function z(e, t, r, n) {
|
|
2938
|
-
try {
|
|
2939
|
-
n();
|
|
2940
|
-
} catch (s) {
|
|
2941
|
-
if (s instanceof Error && s.message.startsWith(`Route ${JSON.stringify(e)} export `))
|
|
2942
|
-
throw s;
|
|
2943
|
-
const o = s instanceof Error ? s.message : `${r} validation failed.`;
|
|
2944
|
-
throw new Error(
|
|
2945
|
-
`Route ${JSON.stringify(e)} export ${t} has an invalid ${r} policy. ${o}`,
|
|
2946
|
-
{ cause: s }
|
|
2947
|
-
);
|
|
2948
|
-
}
|
|
2949
|
-
}
|
|
2950
|
-
function ro(e) {
|
|
2951
|
-
return Z({
|
|
2952
|
-
instance: `${e.pathname}${e.search}`,
|
|
2953
|
-
status: 404,
|
|
2954
|
-
title: "Not Found"
|
|
2955
|
-
});
|
|
2956
|
-
}
|
|
2957
|
-
async function ye(e, t, r = {}) {
|
|
2958
|
-
const n = new URL(t.url);
|
|
2959
|
-
if (!dt(t))
|
|
2960
|
-
return ro(n);
|
|
2961
|
-
const s = await pe(e, n.pathname, {
|
|
2962
|
-
onLayoutError: (u) => r.onError?.(u, "page")
|
|
2963
|
-
}), o = await no(e, n.pathname), i = r.nonce ?? (ne(o) ? yt() : void 0), a = so(s, { ...r, nonce: i }), c = q(o ?? {}, {
|
|
2964
|
-
nonce: i,
|
|
2965
|
-
request: t
|
|
2966
|
-
});
|
|
2967
|
-
return c.set("content-type", "text/html; charset=utf-8"), new Response(
|
|
2968
|
-
await r.transformDocument?.(a) ?? a,
|
|
2969
|
-
{
|
|
2970
|
-
headers: c,
|
|
2971
|
-
status: 404
|
|
2972
|
-
}
|
|
2973
|
-
);
|
|
2974
|
-
}
|
|
2975
|
-
async function no(e, t) {
|
|
2976
|
-
const r = await Promise.all(
|
|
2977
|
-
fr(e, t).map((n) => n.load())
|
|
2978
|
-
);
|
|
2979
|
-
return X(...r.map((n) => n.policy)).document;
|
|
2980
|
-
}
|
|
2981
|
-
function so(e, t = {}) {
|
|
2982
|
-
const r = e.notFound ?? He;
|
|
2983
|
-
try {
|
|
2984
|
-
return fe(e, r, e.layouts, t);
|
|
2985
|
-
} catch (n) {
|
|
2986
|
-
t.onError?.(n, "page");
|
|
2987
|
-
}
|
|
2988
|
-
try {
|
|
2989
|
-
return fe(e, r, [], t);
|
|
2990
|
-
} catch (n) {
|
|
2991
|
-
t.onError?.(n, "page");
|
|
2992
|
-
}
|
|
2993
|
-
return fe(e, He, [], t);
|
|
2994
|
-
}
|
|
2995
|
-
function fe(e, t, r, n) {
|
|
2996
|
-
const s = r.reduceRight(
|
|
2997
|
-
(i, a) => de(a, {
|
|
2998
|
-
children: i,
|
|
2999
|
-
path: {},
|
|
3000
|
-
pathname: e.pathname
|
|
3001
|
-
}),
|
|
3002
|
-
de(t, { pathname: e.pathname })
|
|
3003
|
-
), o = Qe({
|
|
3004
|
-
dev: n.dev,
|
|
3005
|
-
nonce: n.nonce
|
|
3006
|
-
});
|
|
3007
|
-
return et({
|
|
3008
|
-
body: {
|
|
3009
|
-
data: void 0,
|
|
3010
|
-
fallback: "not-found",
|
|
3011
|
-
html: tt(Xe(o, s)),
|
|
3012
|
-
navigation: n.navigation
|
|
3013
|
-
},
|
|
3014
|
-
entrySrc: n.clientEntry,
|
|
3015
|
-
lang: n.lang,
|
|
3016
|
-
metadata: e.metadata,
|
|
3017
|
-
nonce: n.nonce,
|
|
3018
|
-
scripts: o.scripts(),
|
|
3019
|
-
styles: n.styles,
|
|
3020
|
-
title: n.title
|
|
3021
|
-
});
|
|
3022
|
-
}
|
|
3023
|
-
const $t = [
|
|
3024
|
-
"GET",
|
|
3025
|
-
"POST",
|
|
3026
|
-
"PUT",
|
|
3027
|
-
"PATCH",
|
|
3028
|
-
"DELETE",
|
|
3029
|
-
"OPTIONS",
|
|
3030
|
-
"HEAD"
|
|
3031
|
-
], kt = At();
|
|
3032
|
-
function Yo(e) {
|
|
3033
|
-
e.routeModules && Us(e.routeModules, { adapter: e.adapter });
|
|
3034
|
-
const t = ot(e.routes), r = e.rateLimitStore ?? At();
|
|
3035
|
-
return e.cacheStore && nt(e.cacheStore.namespace), async function(s) {
|
|
3036
|
-
return await oo(t, s, {
|
|
3037
|
-
cacheStore: e.cacheStore,
|
|
3038
|
-
onError: e.onError,
|
|
3039
|
-
rateLimitStore: r,
|
|
3040
|
-
renderPage: e.renderPage,
|
|
3041
|
-
ssr: e.ssr
|
|
3042
|
-
});
|
|
3043
|
-
};
|
|
3044
|
-
}
|
|
3045
|
-
async function oo(e, t, r = {
|
|
3046
|
-
rateLimitStore: kt
|
|
3047
|
-
}) {
|
|
3048
|
-
const n = new URL(t.url), s = co(n, r), o = ut(t);
|
|
3049
|
-
let i;
|
|
3050
|
-
try {
|
|
3051
|
-
i = B(e.routes, n.pathname);
|
|
3052
|
-
} catch (a) {
|
|
3053
|
-
if (!(a instanceof Te))
|
|
3054
|
-
throw a;
|
|
3055
|
-
const c = Z({
|
|
3056
|
-
instance: `${n.pathname}${n.search}`,
|
|
3057
|
-
status: 400,
|
|
3058
|
-
title: "Bad Request"
|
|
3059
|
-
});
|
|
3060
|
-
return o ? _(c, ae) : c;
|
|
3061
|
-
}
|
|
3062
|
-
if (!i)
|
|
3063
|
-
try {
|
|
3064
|
-
const a = await ye(
|
|
3065
|
-
e,
|
|
3066
|
-
t,
|
|
3067
|
-
s
|
|
3068
|
-
);
|
|
3069
|
-
return o ? _(a, Fe) : a;
|
|
3070
|
-
} catch (a) {
|
|
3071
|
-
return s.onError(a, "page"), new Response("Not Found", {
|
|
3072
|
-
headers: { "content-type": "text/plain; charset=utf-8" },
|
|
3073
|
-
status: 404
|
|
3074
|
-
});
|
|
3075
|
-
}
|
|
3076
|
-
try {
|
|
3077
|
-
const a = await io(
|
|
3078
|
-
e,
|
|
3079
|
-
t,
|
|
3080
|
-
n,
|
|
3081
|
-
i,
|
|
3082
|
-
r,
|
|
3083
|
-
s
|
|
3084
|
-
);
|
|
3085
|
-
return o && !a.headers.has(C) ? _(
|
|
3086
|
-
a,
|
|
3087
|
-
a.status === 404 ? Fe : ae
|
|
3088
|
-
) : a;
|
|
3089
|
-
} catch (a) {
|
|
3090
|
-
const c = await Y(
|
|
3091
|
-
e,
|
|
3092
|
-
t,
|
|
3093
|
-
a,
|
|
3094
|
-
"middleware",
|
|
3095
|
-
s
|
|
3096
|
-
);
|
|
3097
|
-
return o ? _(c, ae) : c;
|
|
3098
|
-
}
|
|
3099
|
-
}
|
|
3100
|
-
async function io(e, t, r, n, s, o) {
|
|
3101
|
-
const i = await n.route.load();
|
|
3102
|
-
if (t.method.toUpperCase() === "OPTIONS") {
|
|
3103
|
-
const p = Nn(i, t);
|
|
3104
|
-
if (p)
|
|
3105
|
-
return p;
|
|
3106
|
-
}
|
|
3107
|
-
const a = ho(t.method);
|
|
3108
|
-
if (!a)
|
|
3109
|
-
return Ze(i);
|
|
3110
|
-
const c = mo(i, a);
|
|
3111
|
-
if (!c)
|
|
3112
|
-
return Ze(i);
|
|
3113
|
-
const u = await lo(
|
|
3114
|
-
e,
|
|
3115
|
-
n.route,
|
|
3116
|
-
i,
|
|
3117
|
-
c
|
|
3118
|
-
), l = u.security, f = ys(
|
|
3119
|
-
l?.fetchMetadata,
|
|
3120
|
-
t,
|
|
3121
|
-
a
|
|
3122
|
-
), h = (p) => xt(p, f.vary);
|
|
3123
|
-
if (f.response)
|
|
3124
|
-
return h(
|
|
3125
|
-
U(
|
|
3126
|
-
f.response,
|
|
3127
|
-
J(c),
|
|
3128
|
-
t
|
|
3129
|
-
)
|
|
3130
|
-
);
|
|
3131
|
-
const d = as(l?.csrf, t);
|
|
3132
|
-
if (d)
|
|
3133
|
-
return h(
|
|
3134
|
-
U(d, J(c), t)
|
|
3135
|
-
);
|
|
3136
|
-
const D = await Ts(
|
|
3137
|
-
l?.rateLimit,
|
|
3138
|
-
t,
|
|
3139
|
-
s.rateLimitStore ?? kt
|
|
3140
|
-
);
|
|
3141
|
-
if (D)
|
|
3142
|
-
return h(
|
|
3143
|
-
U(
|
|
3144
|
-
D,
|
|
3145
|
-
J(c),
|
|
3146
|
-
t
|
|
3147
|
-
)
|
|
3148
|
-
);
|
|
3149
|
-
const $ = $s(
|
|
3150
|
-
l?.request,
|
|
3151
|
-
t,
|
|
3152
|
-
a
|
|
3153
|
-
);
|
|
3154
|
-
if ($)
|
|
3155
|
-
return h(
|
|
3156
|
-
U(
|
|
3157
|
-
$,
|
|
3158
|
-
J(c),
|
|
3159
|
-
t
|
|
3160
|
-
)
|
|
3161
|
-
);
|
|
3162
|
-
t = ks(l?.request, t);
|
|
3163
|
-
const m = {};
|
|
3164
|
-
if (c.kind === "page") {
|
|
3165
|
-
const p = {
|
|
3166
|
-
path: n.path,
|
|
3167
|
-
pathname: r.pathname,
|
|
3168
|
-
request: t,
|
|
3169
|
-
context: m,
|
|
3170
|
-
search: r.searchParams,
|
|
3171
|
-
url: r
|
|
3172
|
-
}, Nt = await Ke(
|
|
3173
|
-
e,
|
|
3174
|
-
n.route
|
|
3175
|
-
), O = ne(u.document) ? yt() : void 0, Ot = ao(s.cacheStore);
|
|
3176
|
-
let y;
|
|
3177
|
-
try {
|
|
3178
|
-
y = await Ye(Nt, p, async () => {
|
|
3179
|
-
try {
|
|
3180
|
-
const g = await it(
|
|
3181
|
-
e,
|
|
3182
|
-
r.pathname,
|
|
3183
|
-
t,
|
|
3184
|
-
void 0,
|
|
3185
|
-
Ot,
|
|
3186
|
-
{ requestContext: m }
|
|
3187
|
-
);
|
|
3188
|
-
if (g.status !== "ready")
|
|
3189
|
-
return await ye(e, t, {
|
|
3190
|
-
...o,
|
|
3191
|
-
nonce: O
|
|
3192
|
-
});
|
|
3193
|
-
if (ut(t))
|
|
3194
|
-
return br(g.match.data);
|
|
3195
|
-
if (g.match.render.mode === "streaming" && !s.renderPage)
|
|
3196
|
-
throw new Error(
|
|
3197
|
-
"Streaming page routes require an adapter renderer. Pass renderNodePageResponse from @demiurgejs/core/node as createRequestHandler({ renderPage })."
|
|
3198
|
-
);
|
|
3199
|
-
return await (s.renderPage ?? zt)(g.match, {
|
|
3200
|
-
...s.ssr,
|
|
3201
|
-
dev: s.dev,
|
|
3202
|
-
nonce: O,
|
|
3203
|
-
onStreamError: (Mt) => {
|
|
3204
|
-
s.onError?.(Mt, {
|
|
3205
|
-
pathname: r.pathname,
|
|
3206
|
-
site: "page"
|
|
3207
|
-
});
|
|
3208
|
-
},
|
|
3209
|
-
signal: t.signal
|
|
3210
|
-
});
|
|
3211
|
-
} catch (g) {
|
|
3212
|
-
return g instanceof F ? V() : await Y(e, t, g, "page", {
|
|
3213
|
-
...o,
|
|
3214
|
-
nonce: O
|
|
3215
|
-
});
|
|
3216
|
-
}
|
|
3217
|
-
});
|
|
3218
|
-
} catch (g) {
|
|
3219
|
-
if (!(g instanceof F))
|
|
3220
|
-
throw g;
|
|
3221
|
-
y = V();
|
|
3222
|
-
}
|
|
3223
|
-
const Lt = q(u.document ?? {}, {
|
|
3224
|
-
nonce: O,
|
|
3225
|
-
request: t
|
|
3226
|
-
});
|
|
3227
|
-
for (const [g, ke] of Lt)
|
|
3228
|
-
y.headers.set(g, ke);
|
|
3229
|
-
return O && y.headers.set("cache-control", "private, no-store"), h(y), a === "HEAD" ? (await y.body?.cancel(), new Response(null, {
|
|
3230
|
-
headers: y.headers,
|
|
3231
|
-
status: y.status
|
|
3232
|
-
})) : y;
|
|
3233
|
-
}
|
|
3234
|
-
const k = {
|
|
3235
|
-
path: n.path,
|
|
3236
|
-
pathname: r.pathname,
|
|
3237
|
-
request: t,
|
|
3238
|
-
context: m,
|
|
3239
|
-
search: r.searchParams,
|
|
3240
|
-
url: r
|
|
3241
|
-
}, $e = await Ke(
|
|
3242
|
-
e,
|
|
3243
|
-
n.route
|
|
3244
|
-
);
|
|
3245
|
-
let N;
|
|
3246
|
-
try {
|
|
3247
|
-
N = await Ye($e, k, async () => {
|
|
3248
|
-
try {
|
|
3249
|
-
return c.kind === "not-found" && c.body === void 0 ? uo(
|
|
3250
|
-
await ye(e, t, o),
|
|
3251
|
-
c.init
|
|
3252
|
-
) : await Dr(c, k);
|
|
3253
|
-
} catch (p) {
|
|
3254
|
-
return p instanceof F ? V() : await Y(
|
|
3255
|
-
e,
|
|
3256
|
-
t,
|
|
3257
|
-
p,
|
|
3258
|
-
"route",
|
|
3259
|
-
o
|
|
3260
|
-
);
|
|
3261
|
-
}
|
|
3262
|
-
});
|
|
3263
|
-
} catch (p) {
|
|
3264
|
-
if (!(p instanceof F))
|
|
3265
|
-
throw p;
|
|
3266
|
-
N = V();
|
|
3267
|
-
}
|
|
3268
|
-
try {
|
|
3269
|
-
return h(
|
|
3270
|
-
fo(N, c, t, a)
|
|
3271
|
-
);
|
|
3272
|
-
} catch (p) {
|
|
3273
|
-
return h(
|
|
3274
|
-
await Y(
|
|
3275
|
-
e,
|
|
3276
|
-
t,
|
|
3277
|
-
p,
|
|
3278
|
-
"route",
|
|
3279
|
-
o
|
|
3280
|
-
)
|
|
3281
|
-
);
|
|
3282
|
-
}
|
|
3283
|
-
}
|
|
3284
|
-
function ao(e) {
|
|
3285
|
-
return e ? rt(e) : we();
|
|
3286
|
-
}
|
|
3287
|
-
function co(e, t) {
|
|
3288
|
-
return {
|
|
3289
|
-
...t.ssr,
|
|
3290
|
-
dev: t.dev,
|
|
3291
|
-
onError: (r, n) => {
|
|
3292
|
-
t.onError?.(r, { pathname: e.pathname, site: n });
|
|
3293
|
-
},
|
|
3294
|
-
transformDocument: t.transformDocument
|
|
3295
|
-
};
|
|
3296
|
-
}
|
|
3297
|
-
function uo(e, t) {
|
|
3298
|
-
if (!t)
|
|
3299
|
-
return e;
|
|
3300
|
-
const r = new Headers(e.headers), n = new Headers(t.headers);
|
|
3301
|
-
for (const [s, o] of n)
|
|
3302
|
-
s !== "set-cookie" && r.set(s, o);
|
|
3303
|
-
for (const s of n.getSetCookie())
|
|
3304
|
-
r.append("set-cookie", s);
|
|
3305
|
-
return new Response(e.body, {
|
|
3306
|
-
headers: r,
|
|
3307
|
-
status: t.status ?? e.status,
|
|
3308
|
-
statusText: t.statusText ?? e.statusText
|
|
3309
|
-
});
|
|
3310
|
-
}
|
|
3311
|
-
async function lo(e, t, r, n) {
|
|
3312
|
-
const s = await Promise.all(
|
|
3313
|
-
e.policies.filter(
|
|
3314
|
-
(o) => T(o.fileSegments, t.fileSegments)
|
|
3315
|
-
).map((o) => o.load())
|
|
3316
|
-
);
|
|
3317
|
-
return X(
|
|
3318
|
-
...s.map((o) => o.policy),
|
|
3319
|
-
r.policy,
|
|
3320
|
-
{
|
|
3321
|
-
security: !n || n.kind === "page" ? void 0 : n.security
|
|
3322
|
-
}
|
|
3323
|
-
);
|
|
3324
|
-
}
|
|
3325
|
-
async function Ke(e, t) {
|
|
3326
|
-
return (await Promise.all(
|
|
3327
|
-
e.middlewares.filter(
|
|
3328
|
-
(n) => T(n.fileSegments, t.fileSegments)
|
|
3329
|
-
).map((n) => n.load())
|
|
3330
|
-
)).flatMap(
|
|
3331
|
-
(n) => n.middleware ? [n.middleware] : []
|
|
3332
|
-
);
|
|
3333
|
-
}
|
|
3334
|
-
async function Ye(e, t, r) {
|
|
3335
|
-
let n = -1;
|
|
3336
|
-
async function s(o) {
|
|
3337
|
-
if (o <= n)
|
|
3338
|
-
throw new Error("Demiurge route middleware next() called multiple times.");
|
|
3339
|
-
n = o;
|
|
3340
|
-
const i = e[o];
|
|
3341
|
-
return i ? await i(t, () => s(o + 1)) : await r();
|
|
3342
|
-
}
|
|
3343
|
-
return await s(0);
|
|
3344
|
-
}
|
|
3345
|
-
function fo(e, t, r, n) {
|
|
3346
|
-
const s = Hr(
|
|
3347
|
-
U(e, t.cors, r),
|
|
3348
|
-
t.timing
|
|
3349
|
-
);
|
|
3350
|
-
return n === "HEAD" ? new Response(null, {
|
|
3351
|
-
headers: s.headers,
|
|
3352
|
-
status: s.status,
|
|
3353
|
-
statusText: s.statusText
|
|
3354
|
-
}) : s;
|
|
3355
|
-
}
|
|
3356
|
-
function J(e) {
|
|
3357
|
-
return e.kind === "page" ? void 0 : e.cors;
|
|
3358
|
-
}
|
|
3359
|
-
function ho(e) {
|
|
3360
|
-
const t = e.toUpperCase();
|
|
3361
|
-
return $t.includes(t) ? t : null;
|
|
3362
|
-
}
|
|
3363
|
-
function mo(e, t) {
|
|
3364
|
-
return t === "HEAD" ? e.HEAD ?? e.GET : e[t];
|
|
3365
|
-
}
|
|
3366
|
-
function Ze(e) {
|
|
3367
|
-
return new Response(null, {
|
|
3368
|
-
headers: {
|
|
3369
|
-
allow: po(e).join(", ")
|
|
3370
|
-
},
|
|
3371
|
-
status: 405
|
|
3372
|
-
});
|
|
3373
|
-
}
|
|
3374
|
-
function po(e) {
|
|
3375
|
-
const t = $t.filter((r) => e[r]);
|
|
3376
|
-
return e.GET && !t.includes("HEAD") && t.push("HEAD"), t;
|
|
3377
|
-
}
|
|
3378
|
-
export {
|
|
3379
|
-
is as $,
|
|
3380
|
-
Wo as A,
|
|
3381
|
-
Dr as B,
|
|
3382
|
-
cs as C,
|
|
3383
|
-
ks as D,
|
|
3384
|
-
Ct as E,
|
|
3385
|
-
Tr as F,
|
|
3386
|
-
ko as G,
|
|
3387
|
-
cr as H,
|
|
3388
|
-
vr as I,
|
|
3389
|
-
Rr as J,
|
|
3390
|
-
Fe as K,
|
|
3391
|
-
ae as L,
|
|
3392
|
-
Te as M,
|
|
3393
|
-
C as N,
|
|
3394
|
-
Gr as O,
|
|
3395
|
-
Go as P,
|
|
3396
|
-
He as Q,
|
|
3397
|
-
F as R,
|
|
3398
|
-
Ae as S,
|
|
3399
|
-
A as T,
|
|
3400
|
-
lt as U,
|
|
3401
|
-
xt as V,
|
|
3402
|
-
zn as W,
|
|
3403
|
-
vo as X,
|
|
3404
|
-
gs as Y,
|
|
3405
|
-
rt as Z,
|
|
3406
|
-
Rt as _,
|
|
3407
|
-
Us as a,
|
|
3408
|
-
os as a0,
|
|
3409
|
-
xo as a1,
|
|
3410
|
-
_t as a2,
|
|
3411
|
-
We as a3,
|
|
3412
|
-
Ao as a4,
|
|
3413
|
-
Vo as a5,
|
|
3414
|
-
_o as a6,
|
|
3415
|
-
To as a7,
|
|
3416
|
-
Ns as a8,
|
|
3417
|
-
as as a9,
|
|
3418
|
-
No as aA,
|
|
3419
|
-
hr as aB,
|
|
3420
|
-
Er as aC,
|
|
3421
|
-
re as aD,
|
|
3422
|
-
v as aE,
|
|
3423
|
-
ys as aa,
|
|
3424
|
-
Ts as ab,
|
|
3425
|
-
$s as ac,
|
|
3426
|
-
Fo as ad,
|
|
3427
|
-
Ro as ae,
|
|
3428
|
-
Ko as af,
|
|
3429
|
-
Mo as ag,
|
|
3430
|
-
Io as ah,
|
|
3431
|
-
Co as ai,
|
|
3432
|
-
X as aj,
|
|
3433
|
-
dn as ak,
|
|
3434
|
-
Po as al,
|
|
3435
|
-
jo as am,
|
|
3436
|
-
Pt as an,
|
|
3437
|
-
Eo as ao,
|
|
3438
|
-
Ho as ap,
|
|
3439
|
-
R as aq,
|
|
3440
|
-
nt as ar,
|
|
3441
|
-
qo as as,
|
|
3442
|
-
Bo as at,
|
|
3443
|
-
zo as au,
|
|
3444
|
-
Do as av,
|
|
3445
|
-
bo as aw,
|
|
3446
|
-
Uo as ax,
|
|
3447
|
-
Oo as ay,
|
|
3448
|
-
Lo as az,
|
|
3449
|
-
$o as b,
|
|
3450
|
-
Yo as c,
|
|
3451
|
-
At as d,
|
|
3452
|
-
Jo as e,
|
|
3453
|
-
q as f,
|
|
3454
|
-
De as g,
|
|
3455
|
-
oo as h,
|
|
3456
|
-
it as i,
|
|
3457
|
-
T as j,
|
|
3458
|
-
te as k,
|
|
3459
|
-
lo as l,
|
|
3460
|
-
fn as m,
|
|
3461
|
-
B as n,
|
|
3462
|
-
ne as o,
|
|
3463
|
-
yt as p,
|
|
3464
|
-
jn as q,
|
|
3465
|
-
ye as r,
|
|
3466
|
-
L as s,
|
|
3467
|
-
mr as t,
|
|
3468
|
-
we as u,
|
|
3469
|
-
Ce as v,
|
|
3470
|
-
he as w,
|
|
3471
|
-
Le as x,
|
|
3472
|
-
ot as y,
|
|
3473
|
-
P as z
|
|
3474
|
-
};
|
|
3475
|
-
//# sourceMappingURL=testing-CRflAw4X.js.map
|