token-usage-dashboard 1.0.13 → 1.0.14
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/build/adapter-node.js +11 -0
- package/build/client/_app/immutable/chunks/B0VWrXPj.js +1 -0
- package/build/client/_app/immutable/chunks/B0VWrXPj.js.br +0 -0
- package/build/client/_app/immutable/chunks/B0VWrXPj.js.gz +0 -0
- package/build/client/_app/immutable/chunks/BaNbYf_w.js +1 -0
- package/build/client/_app/immutable/chunks/BaNbYf_w.js.br +0 -0
- package/build/client/_app/immutable/chunks/BaNbYf_w.js.gz +0 -0
- package/build/client/_app/immutable/chunks/CbiRHTcG.js +1 -0
- package/build/client/_app/immutable/chunks/CbiRHTcG.js.br +0 -0
- package/build/client/_app/immutable/chunks/CbiRHTcG.js.gz +0 -0
- package/build/client/_app/immutable/chunks/DTingiCe.js +3 -0
- package/build/client/_app/immutable/chunks/DTingiCe.js.br +0 -0
- package/build/client/_app/immutable/chunks/DTingiCe.js.gz +0 -0
- package/build/client/_app/immutable/chunks/ssd4Rw-g.js +3 -0
- package/build/client/_app/immutable/chunks/ssd4Rw-g.js.br +0 -0
- package/build/client/_app/immutable/chunks/ssd4Rw-g.js.gz +0 -0
- package/build/client/_app/immutable/entry/app.CRLWmGVY.js +2 -0
- package/build/client/_app/immutable/entry/app.CRLWmGVY.js.br +0 -0
- package/build/client/_app/immutable/entry/app.CRLWmGVY.js.gz +0 -0
- package/build/client/_app/immutable/entry/payload.DSmR2FwN.js +1 -0
- package/build/client/_app/immutable/entry/payload.DSmR2FwN.js.br +0 -0
- package/build/client/_app/immutable/entry/payload.DSmR2FwN.js.gz +0 -0
- package/build/client/_app/immutable/entry/start.CzGx2BYz.js +2 -0
- package/build/client/_app/immutable/entry/start.CzGx2BYz.js.br +0 -0
- package/build/client/_app/immutable/entry/start.CzGx2BYz.js.gz +0 -0
- package/build/client/_app/immutable/nodes/0.BBGTwdwd.js +1 -0
- package/build/client/_app/immutable/nodes/0.BBGTwdwd.js.br +0 -0
- package/build/client/_app/immutable/nodes/0.BBGTwdwd.js.gz +0 -0
- package/build/client/_app/immutable/nodes/1.Cy2JV0fN.js +1 -0
- package/build/client/_app/immutable/nodes/1.Cy2JV0fN.js.br +2 -0
- package/build/client/_app/immutable/nodes/1.Cy2JV0fN.js.gz +0 -0
- package/build/client/_app/immutable/nodes/2.CRMPKkcX.js +2 -0
- package/build/client/_app/immutable/nodes/2.CRMPKkcX.js.br +0 -0
- package/build/client/_app/immutable/nodes/2.CRMPKkcX.js.gz +0 -0
- package/build/client/_app/version.json +1 -1
- package/build/client/_app/version.json.br +0 -0
- package/build/client/_app/version.json.gz +0 -0
- package/build/handler.js +1 -22
- package/build/index.js +1 -145
- package/build/server/.vite/manifest.json +271 -0
- package/build/server/_app/immutable/assets/_layout.CZ6VMqH1.css +1 -0
- package/build/server/_app/immutable/assets/_page.CZocdpCk.css +1 -0
- package/build/server/adapter-env.js +2 -0
- package/build/server/adapter-index.js +74 -0
- package/build/server/adapter-node-env.js +63 -0
- package/build/server/adapter-node-handler.js +584 -0
- package/build/server/chunks/config.js +10 -0
- package/build/server/chunks/functions.js +30 -0
- package/build/server/chunks/index-server.js +2 -0
- package/build/server/chunks/instance.js +3546 -0
- package/build/server/chunks/internal.js +3323 -0
- package/build/server/chunks/navigation.js +16 -0
- package/build/server/chunks/{chunks/queries.js-BEdRnpMa.js → queries.js} +9 -9
- package/build/server/chunks/{chunks/range.js-CiCoLGqh.js → range.js} +3 -2
- package/build/server/chunks/{chunks/refresh.js-0W7-GwaH.js → refresh.js} +7 -7
- package/build/server/chunks/{chunks/request.js-BF7n7fZo.js → request.js} +5 -5
- package/build/server/chunks/server-errors.js +489 -0
- package/build/server/chunks/server.js +9 -0
- package/build/server/chunks/server2.js +1504 -0
- package/build/server/chunks/shared.js +84 -0
- package/build/server/chunks/uneval.js +537 -0
- package/build/server/entries/endpoints/api/refresh/_server.ts.js +12 -0
- package/build/server/entries/endpoints/api/settings/_server.ts.js +15 -0
- package/build/server/entries/endpoints/api/usage/_server.ts.js +8 -0
- package/build/server/entries/fallbacks/error.svelte.js +47 -0
- package/build/server/entries/hooks.server.js +10 -0
- package/build/server/{chunks/entries/pages/_layout.svelte.js-C9kkUOBf.js → entries/pages/_layout.svelte.js} +4 -2
- package/build/server/entries/pages/_page.server.ts.js +12 -0
- package/build/server/{chunks/entries/pages/_page.svelte.js-HFiLlojS.js → entries/pages/_page.svelte.js} +64 -27
- package/build/server/env.js +2 -0
- package/build/server/handler.js +2 -0
- package/build/server/index.js +67 -0
- package/build/server/manifest-full.js +58 -0
- package/build/server/manifest.js +58 -0
- package/build/server/nodes/0.js +8 -0
- package/build/server/nodes/1.js +8 -0
- package/build/server/nodes/2.js +10 -0
- package/build/server/remote-entry.js +1564 -0
- package/build/server/server.js +60 -0
- package/package.json +8 -8
- package/build/client/_app/immutable/chunks/CukLSH0w.js +0 -2
- package/build/client/_app/immutable/chunks/CukLSH0w.js.br +0 -0
- package/build/client/_app/immutable/chunks/CukLSH0w.js.gz +0 -0
- package/build/client/_app/immutable/chunks/Dsm7b1TR.js +0 -3
- package/build/client/_app/immutable/chunks/Dsm7b1TR.js.br +0 -0
- package/build/client/_app/immutable/chunks/Dsm7b1TR.js.gz +0 -0
- package/build/client/_app/immutable/chunks/xihTtKlq.js +0 -1
- package/build/client/_app/immutable/chunks/xihTtKlq.js.br +0 -1
- package/build/client/_app/immutable/chunks/xihTtKlq.js.gz +0 -0
- package/build/client/_app/immutable/entry/app.Hr-44d0W.js +0 -2
- package/build/client/_app/immutable/entry/app.Hr-44d0W.js.br +0 -0
- package/build/client/_app/immutable/entry/app.Hr-44d0W.js.gz +0 -0
- package/build/client/_app/immutable/entry/start.DGEKXdCU.js +0 -1
- package/build/client/_app/immutable/entry/start.DGEKXdCU.js.br +0 -0
- package/build/client/_app/immutable/entry/start.DGEKXdCU.js.gz +0 -0
- package/build/client/_app/immutable/nodes/0.PGglbI9f.js +0 -1
- package/build/client/_app/immutable/nodes/0.PGglbI9f.js.br +0 -0
- package/build/client/_app/immutable/nodes/0.PGglbI9f.js.gz +0 -0
- package/build/client/_app/immutable/nodes/1.MxgNrYxb.js +0 -1
- package/build/client/_app/immutable/nodes/1.MxgNrYxb.js.br +0 -0
- package/build/client/_app/immutable/nodes/1.MxgNrYxb.js.gz +0 -0
- package/build/client/_app/immutable/nodes/2.DOLqBxXu.js +0 -2
- package/build/client/_app/immutable/nodes/2.DOLqBxXu.js.br +0 -0
- package/build/client/_app/immutable/nodes/2.DOLqBxXu.js.gz +0 -0
- package/build/env.js +0 -70
- package/build/server/chunks/chunks/client.js-9ZtqvVP6.js +0 -28
- package/build/server/chunks/chunks/env.js-l0sNRNKZ.js +0 -2
- package/build/server/chunks/chunks/exports.js-Bbyr-JtB.js +0 -349
- package/build/server/chunks/chunks/internal.js-WGl35QnN.js +0 -1202
- package/build/server/chunks/chunks/internal2.js-BlXt2rfE.js +0 -22
- package/build/server/chunks/chunks/server.js-UOanU7fq.js +0 -5527
- package/build/server/chunks/chunks/shared.js-Dg3Ewm8t.js +0 -255
- package/build/server/chunks/chunks/utils.js-DUDFXVFd.js +0 -1049
- package/build/server/chunks/entries/endpoints/api/refresh/_server.ts.js-CcG44vTx.js +0 -21
- package/build/server/chunks/entries/endpoints/api/settings/_server.ts.js-B0LWCQis.js +0 -24
- package/build/server/chunks/entries/endpoints/api/usage/_server.ts.js-CJGTdjik.js +0 -17
- package/build/server/chunks/entries/fallbacks/error.svelte.js-D7UgI0q0.js +0 -68
- package/build/server/chunks/entries/hooks.server.js-_Fcw_IVA.js +0 -16
- package/build/server/chunks/entries/pages/_page.server.ts.js-BBibcAZP.js +0 -17
- package/build/server/chunks/handler-TvIKu86j.js +0 -1475
- package/build/server/chunks/index.js-C3LwYUKO.js +0 -3972
- package/build/server/chunks/manifest.js-CZoz0xLc.js +0 -63
- package/build/server/chunks/nodes/0.js-7EReDAeT.js +0 -9
- package/build/server/chunks/nodes/1.js-BcW8BjKg.js +0 -9
- package/build/server/chunks/nodes/2.js-fS9KDy-5.js +0 -20
- package/build/shims.js +0 -33
|
@@ -0,0 +1,3546 @@
|
|
|
1
|
+
import { B as get_status, Bt as add_resolution_suffix, C as has_prerendered_path, Ct as resolve, D as throw_devalue_error, Dt as otel, E as serialize_uses, Et as merge_tracing, G as fetch_cache_url, Gt as base64_encode, H as INVALIDATED_PARAM, Ht as has_resolution_suffix, It as PAGE_METHODS, Jt as app_dir, Kt as stream_text, Lt as REROUTED_URL_HEADER, Mt as BODY_DEPENDENT_METHODS, Nt as ENDPOINT_METHODS, O as with_version_header, Ot as record_span, Pt as IN_WEBCONTAINER, Q as init_transport, S as get_node_type, St as relative_pathname, T as redirect_response, Tt as invalid_export_location, U as TRAILING_SLASH_PARAM, Ut as strip_data_suffix, V as normalize_error, Vt as has_data_suffix, Wt as strip_resolution_suffix, X as encoders, Yt as assets, Z as has_custom_transporters, _ as handle_action_request, a as set_hooks, b as uneval_action_response, bt as make_trackable, d as get_remote_action, dt as get_hooks, f as get_remote_id, ft as options, g as handle_action_json_request, gt as text, h as action_json_redirect, ht as isRedirect, i as read_implementation, jt as with_request_store, k as handle_error_and_jsonify, m as handle_remote_form_post, n as hooks, nt as is_form_content_type, p as handle_remote_call, pt as find_route, qt as text_encoder, r as manifest, rt as negotiate, tt as uneval, u as collect_remote_data, ut as stringify, v as is_action_json_request, vt as decode_pathname, w as method_not_allowed, wt as invalid_export, xt as normalize_path, y as is_action_request, yt as disable_search, zt as add_data_suffix } from "./internal.js";
|
|
2
|
+
import { a as SvelteKitError, i as Redirect } from "./shared.js";
|
|
3
|
+
import { C as prerender_endpoint_methods, E as prerender_template_nonce, K as set_headers_after_response, S as prerender_actions, T as prerender_nonce, Z as capture_error, _ as load_fetch_cors, b as load_promise_not_serializable, c as client_address_unsupported, d as cookies_set_after_response, f as csp_report_only_missing_report, g as header_already_set, p as endpoint_invalid_response, q as set_headers_cookie, u as cookies_serialize_before_route, w as prerender_endpoint_not_prerenderable, x as load_response_header_not_serialized } from "./server-errors.js";
|
|
4
|
+
import { t as uneval$1 } from "./uneval.js";
|
|
5
|
+
import { n as noop, r as once } from "./functions.js";
|
|
6
|
+
import { i as set_env, n as explicit_public_env, r as rendered_env } from "./config.js";
|
|
7
|
+
import { c as render, i as derived, p as escape_html$1 } from "./server2.js";
|
|
8
|
+
import { t as afterNavigate } from "./navigation.js";
|
|
9
|
+
//#region node_modules/@sveltejs/kit/src/runtime/server/endpoint.js
|
|
10
|
+
/**
|
|
11
|
+
* @param {import('@sveltejs/kit').RequestEvent} event
|
|
12
|
+
* @param {import('types').RequestState} state
|
|
13
|
+
* @param {import('types').SSREndpoint} mod
|
|
14
|
+
* @returns {Promise<Response>}
|
|
15
|
+
*/
|
|
16
|
+
async function render_endpoint(event, state, mod) {
|
|
17
|
+
const method = event.request.method;
|
|
18
|
+
let handler = mod[method] || mod.fallback;
|
|
19
|
+
if (method === "HEAD" && !mod.HEAD && mod.GET) handler = mod.GET;
|
|
20
|
+
if (!handler) return method_not_allowed(mod, method);
|
|
21
|
+
const prerender = mod.prerender ?? state.prerender_default;
|
|
22
|
+
if (prerender && (mod.fallback || BODY_DEPENDENT_METHODS.some((method) => mod[method]))) prerender_endpoint_methods({
|
|
23
|
+
methods: BODY_DEPENDENT_METHODS.join(", "),
|
|
24
|
+
id: event.route.id
|
|
25
|
+
});
|
|
26
|
+
if (state.prerendering && !state.prerendering.inside_reroute && !prerender) {
|
|
27
|
+
if (state.depth > 0) prerender_endpoint_not_prerenderable({ id: event.route.id });
|
|
28
|
+
else return new Response(void 0, { status: 204 });
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
const response = await with_request_store({
|
|
32
|
+
event,
|
|
33
|
+
state
|
|
34
|
+
}, () => handler(event));
|
|
35
|
+
if (!(response instanceof Response)) endpoint_invalid_response({ path: event.url.pathname });
|
|
36
|
+
if (state.prerendering && (!state.prerendering.inside_reroute || prerender)) {
|
|
37
|
+
const cloned = new Response(response.clone().body, {
|
|
38
|
+
status: response.status,
|
|
39
|
+
statusText: response.statusText,
|
|
40
|
+
headers: new Headers(response.headers)
|
|
41
|
+
});
|
|
42
|
+
cloned.headers.set("x-sveltekit-prerender", String(prerender));
|
|
43
|
+
if (state.prerendering.inside_reroute && prerender) {
|
|
44
|
+
cloned.headers.set("x-sveltekit-routeid", encodeURI(event.route.id));
|
|
45
|
+
state.prerendering.dependencies.set(event.url.pathname, {
|
|
46
|
+
response: cloned,
|
|
47
|
+
body: null
|
|
48
|
+
});
|
|
49
|
+
} else return cloned;
|
|
50
|
+
}
|
|
51
|
+
return response;
|
|
52
|
+
} catch (e) {
|
|
53
|
+
if (e instanceof Redirect) return new Response(void 0, {
|
|
54
|
+
status: e.status,
|
|
55
|
+
headers: { location: e.location }
|
|
56
|
+
});
|
|
57
|
+
throw e;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* @param {import('@sveltejs/kit').RequestEvent} event
|
|
62
|
+
*/
|
|
63
|
+
function is_endpoint_request(event) {
|
|
64
|
+
const { method, headers } = event.request;
|
|
65
|
+
if (ENDPOINT_METHODS.includes(method) && !PAGE_METHODS.includes(method)) return true;
|
|
66
|
+
if (method === "POST" && headers.get("x-sveltekit-action") === "true") return false;
|
|
67
|
+
const accept = event.request.headers.get("accept") ?? "*/*";
|
|
68
|
+
return negotiate(accept, ["*", "text/html"]) !== "text/html";
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region node_modules/@sveltejs/kit/src/utils/array.js
|
|
72
|
+
/**
|
|
73
|
+
* Removes nullish values from an array.
|
|
74
|
+
*
|
|
75
|
+
* @template T
|
|
76
|
+
* @param {Array<T>} arr
|
|
77
|
+
*/
|
|
78
|
+
function compact(arr) {
|
|
79
|
+
return arr.filter(
|
|
80
|
+
/** @returns {val is NonNullable<T>} */
|
|
81
|
+
(val) => val != null
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region node_modules/@sveltejs/kit/src/runtime/pathname.js
|
|
86
|
+
var ROUTES_PREFIX = "/routes";
|
|
87
|
+
/**
|
|
88
|
+
* The pathname of the route-ID-keyed resolution module for a given route ID,
|
|
89
|
+
* e.g. `/_app/routes/blog/[slug]/__route.js` (before prefixing with `base`).
|
|
90
|
+
* @param {string} route_id
|
|
91
|
+
* @returns {string}
|
|
92
|
+
*/
|
|
93
|
+
function route_id_resolution_pathname(route_id) {
|
|
94
|
+
return add_resolution_suffix(`/${app_dir}${ROUTES_PREFIX}${route_id === "/" ? "" : route_id}`);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Whether a pathname (with the `/__route.js` suffix already stripped, and `base` NOT yet stripped)
|
|
98
|
+
* is a route-ID resolution request rather than a pathname resolution request.
|
|
99
|
+
* @param {string} pathname
|
|
100
|
+
* @returns {boolean}
|
|
101
|
+
*/
|
|
102
|
+
function is_route_id_resolution_path(pathname) {
|
|
103
|
+
const prefix = `/${app_dir}${ROUTES_PREFIX}`;
|
|
104
|
+
return pathname === prefix || pathname.startsWith(prefix + "/");
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Extract the route ID from a decoded, base-stripped, suffix-stripped pathname,
|
|
108
|
+
* e.g. `/_app/routes/blog/[slug]` -> `/blog/[slug]`, `/_app/routes` -> `/`.
|
|
109
|
+
* @param {string} pathname
|
|
110
|
+
* @returns {string}
|
|
111
|
+
*/
|
|
112
|
+
function extract_route_id(pathname) {
|
|
113
|
+
return pathname.slice(`/_app${ROUTES_PREFIX}`.length) || "/";
|
|
114
|
+
}
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region node_modules/@sveltejs/kit/src/runtime/error-chain.js
|
|
117
|
+
/** @import { Component } from 'svelte'; */
|
|
118
|
+
/**
|
|
119
|
+
* Resolves the `+error.svelte` component that guards each node of `branch`, aligned to the
|
|
120
|
+
* branch with its empty slots removed. A node is guarded by the closest error page declared
|
|
121
|
+
* at or above it, except the root layout, which wraps the root error component rather than
|
|
122
|
+
* being wrapped by it.
|
|
123
|
+
* @template T
|
|
124
|
+
* @param {Array<unknown>} branch
|
|
125
|
+
* @param {Array<T | undefined | null>} errors the error page declared at each depth, if any
|
|
126
|
+
* @param {(error: T) => Promise<Component | undefined> | undefined} load
|
|
127
|
+
* @returns {Promise<Array<Component | undefined>>}
|
|
128
|
+
*/
|
|
129
|
+
function build_error_chain(branch, errors, load) {
|
|
130
|
+
/** @type {Array<Promise<Component | undefined> | undefined>} */
|
|
131
|
+
const chain = [void 0];
|
|
132
|
+
let last_idx = -1;
|
|
133
|
+
for (let i = 1; i < branch.length; i += 1) {
|
|
134
|
+
if (!branch[i]) continue;
|
|
135
|
+
let j = i - 1;
|
|
136
|
+
while (j > last_idx + 1 && errors[j] == null) j -= 1;
|
|
137
|
+
last_idx = j;
|
|
138
|
+
const error = errors[j];
|
|
139
|
+
chain.push(error == null ? void 0 : load(error)?.catch(() => void 0));
|
|
140
|
+
}
|
|
141
|
+
return Promise.all(chain);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Walks up from the node at index `i` through the `+error.svelte` pages declared strictly
|
|
145
|
+
* above it, nearest first. Yields each candidate with the branch depth it attaches at,
|
|
146
|
+
* rewound past empty branch slots, so callers can skip candidates that fail to load.
|
|
147
|
+
* @template T
|
|
148
|
+
* @param {number} i
|
|
149
|
+
* @param {Array<unknown>} branch
|
|
150
|
+
* @param {Array<T | undefined | null>} errors the error page declared at each depth, if any
|
|
151
|
+
* @returns {Generator<{ error: T; idx: number }>}
|
|
152
|
+
*/
|
|
153
|
+
function* nearest_error_pages(i, branch, errors) {
|
|
154
|
+
while (i--) {
|
|
155
|
+
const error = errors[i];
|
|
156
|
+
if (error != null) {
|
|
157
|
+
let j = i;
|
|
158
|
+
while (!branch[j]) j -= 1;
|
|
159
|
+
yield {
|
|
160
|
+
error,
|
|
161
|
+
idx: j + 1
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
//#endregion
|
|
167
|
+
//#region node_modules/@sveltejs/kit/src/utils/streaming.js
|
|
168
|
+
/**
|
|
169
|
+
* Create an async iterator and a function to push values into it
|
|
170
|
+
* @template T
|
|
171
|
+
* @returns {{
|
|
172
|
+
* iterate: (transform?: (input: T) => T) => AsyncIterable<T>;
|
|
173
|
+
* add: (promise: Promise<T>) => void;
|
|
174
|
+
* }}
|
|
175
|
+
*/
|
|
176
|
+
function create_async_iterator() {
|
|
177
|
+
let resolved = -1;
|
|
178
|
+
/** @type {PromiseWithResolvers<T>[]} */
|
|
179
|
+
const deferred = [];
|
|
180
|
+
return {
|
|
181
|
+
async *iterate(transform = (x) => x) {
|
|
182
|
+
for (let i = 0; i < deferred.length; i += 1) yield transform(await deferred[i].promise);
|
|
183
|
+
},
|
|
184
|
+
add: (promise) => {
|
|
185
|
+
const next = Promise.withResolvers();
|
|
186
|
+
next.promise.catch(noop);
|
|
187
|
+
deferred.push(next);
|
|
188
|
+
promise.then((value) => {
|
|
189
|
+
deferred[++resolved].resolve(value);
|
|
190
|
+
}, (error) => {
|
|
191
|
+
deferred[++resolved].reject(error);
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
//#endregion
|
|
197
|
+
//#region node_modules/@sveltejs/kit/src/runtime/server/page/data_serializer.js
|
|
198
|
+
/**
|
|
199
|
+
* If the serialized data contains promises, `chunks` will be an
|
|
200
|
+
* async iterable containing their resolutions
|
|
201
|
+
* @param {import('@sveltejs/kit').RequestEvent} event
|
|
202
|
+
* @param {import('types').RequestState} state
|
|
203
|
+
* @returns {import('./types.js').ServerDataSerializer}
|
|
204
|
+
*/
|
|
205
|
+
function server_data_serializer(event, state) {
|
|
206
|
+
let promise_id = 1;
|
|
207
|
+
let max_nodes = -1;
|
|
208
|
+
const iterator = create_async_iterator();
|
|
209
|
+
const global = "__sveltekit_g80ct5";
|
|
210
|
+
/** @param {number} index */
|
|
211
|
+
function get_replacer(index) {
|
|
212
|
+
/** @param {any} thing */
|
|
213
|
+
return function replacer(thing) {
|
|
214
|
+
if (typeof thing?.then === "function") {
|
|
215
|
+
const id = promise_id++;
|
|
216
|
+
const promise = thing.then(
|
|
217
|
+
/** @param {any} data */
|
|
218
|
+
(data) => ({ data })
|
|
219
|
+
).catch(
|
|
220
|
+
/** @param {any} error */
|
|
221
|
+
async (error) => ({ error: await handle_error_and_jsonify(event, state, error) })
|
|
222
|
+
).then(
|
|
223
|
+
/**
|
|
224
|
+
* @param {{data: any; error: any}} result
|
|
225
|
+
*/
|
|
226
|
+
async ({ data, error }) => {
|
|
227
|
+
let str;
|
|
228
|
+
try {
|
|
229
|
+
str = uneval$1(error ? [, error] : [data], replacer);
|
|
230
|
+
} catch (serialization_error) {
|
|
231
|
+
error = await handle_error_and_jsonify(event, state, capture_error(() => load_promise_not_serializable({ id: event.route.id }, { cause: serialization_error })));
|
|
232
|
+
str = uneval$1([, error], replacer);
|
|
233
|
+
}
|
|
234
|
+
return {
|
|
235
|
+
index,
|
|
236
|
+
str: `${global}.resolve(${id}, ${str.includes("app.decode") ? `(app) => ${str}` : `() => ${str}`})`
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
);
|
|
240
|
+
iterator.add(promise);
|
|
241
|
+
return `${global}.defer(${id})`;
|
|
242
|
+
} else for (const key in encoders) {
|
|
243
|
+
const encoded = encoders[key](thing);
|
|
244
|
+
if (encoded) return `app.decode('${key}', ${uneval$1(encoded, replacer)})`;
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
const strings = [];
|
|
249
|
+
return {
|
|
250
|
+
set_max_nodes(i) {
|
|
251
|
+
max_nodes = i;
|
|
252
|
+
},
|
|
253
|
+
add_node(i, node) {
|
|
254
|
+
try {
|
|
255
|
+
if (!node) {
|
|
256
|
+
strings[i] = "null";
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
/** @type {any} */
|
|
260
|
+
const payload = {
|
|
261
|
+
type: "data",
|
|
262
|
+
data: node.data,
|
|
263
|
+
uses: serialize_uses(node)
|
|
264
|
+
};
|
|
265
|
+
if (node.slash) payload.slash = node.slash;
|
|
266
|
+
strings[i] = uneval$1(payload, get_replacer(i));
|
|
267
|
+
} catch (error) {
|
|
268
|
+
error.path = error.path.slice(1);
|
|
269
|
+
throw_devalue_error(event, error);
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
get_data(csp) {
|
|
273
|
+
const open = `<script${csp.script_needs_nonce ? ` nonce="${csp.nonce}"` : ""}>`;
|
|
274
|
+
const close = `<\/script>\n`;
|
|
275
|
+
return {
|
|
276
|
+
data: `[${compact(max_nodes > -1 ? strings.slice(0, max_nodes) : strings).join(",")}]`,
|
|
277
|
+
chunks: promise_id > 1 ? iterator.iterate(({ index, str }) => {
|
|
278
|
+
if (max_nodes > -1 && index >= max_nodes) return "";
|
|
279
|
+
return open + str + close;
|
|
280
|
+
}) : null
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* If the serialized data contains promises, `chunks` will be an
|
|
287
|
+
* async iterable containing their resolutions
|
|
288
|
+
* @param {import('@sveltejs/kit').RequestEvent} event
|
|
289
|
+
* @param {import('types').RequestState} state
|
|
290
|
+
* @returns {import('./types.js').ServerDataSerializerJson}
|
|
291
|
+
*/
|
|
292
|
+
function server_data_serializer_json(event, state) {
|
|
293
|
+
let promise_id = 1;
|
|
294
|
+
const iterator = create_async_iterator();
|
|
295
|
+
const reducers = {
|
|
296
|
+
...encoders,
|
|
297
|
+
/** @param {any} thing */
|
|
298
|
+
Promise: (thing) => {
|
|
299
|
+
if (typeof thing?.then !== "function") return;
|
|
300
|
+
const id = promise_id++;
|
|
301
|
+
/** @type {'data' | 'error'} */
|
|
302
|
+
let key = "data";
|
|
303
|
+
const promise = thing.catch(
|
|
304
|
+
/** @param {any} error */
|
|
305
|
+
async (error) => {
|
|
306
|
+
key = "error";
|
|
307
|
+
return handle_error_and_jsonify(event, state, error);
|
|
308
|
+
}
|
|
309
|
+
).then(
|
|
310
|
+
/** @param {any} value */
|
|
311
|
+
async (value) => {
|
|
312
|
+
let str;
|
|
313
|
+
try {
|
|
314
|
+
str = stringify(value, reducers);
|
|
315
|
+
} catch (serialization_error) {
|
|
316
|
+
const error = await handle_error_and_jsonify(event, state, capture_error(() => load_promise_not_serializable({ id: event.route.id }, { cause: serialization_error })));
|
|
317
|
+
key = "error";
|
|
318
|
+
str = stringify(error, reducers);
|
|
319
|
+
}
|
|
320
|
+
return `{"type":"chunk","id":${id},"${key}":${str}}\n`;
|
|
321
|
+
}
|
|
322
|
+
);
|
|
323
|
+
iterator.add(promise);
|
|
324
|
+
return id;
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
const strings = [];
|
|
328
|
+
return {
|
|
329
|
+
add_node(i, node) {
|
|
330
|
+
try {
|
|
331
|
+
if (!node) {
|
|
332
|
+
strings[i] = "null";
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
if (node.type === "error" || node.type === "skip") {
|
|
336
|
+
strings[i] = JSON.stringify(node);
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
strings[i] = `{"type":"data","data":${stringify(node.data, reducers)},"uses":${JSON.stringify(serialize_uses(node))}${node.slash ? `,"slash":${JSON.stringify(node.slash)}` : ""}}`;
|
|
340
|
+
} catch (error) {
|
|
341
|
+
error.path = "data" + error.path;
|
|
342
|
+
throw_devalue_error(event, error);
|
|
343
|
+
}
|
|
344
|
+
},
|
|
345
|
+
get_data() {
|
|
346
|
+
return {
|
|
347
|
+
data: `{"type":"data","nodes":[${strings.join(",")}]}\n`,
|
|
348
|
+
chunks: promise_id > 1 ? iterator.iterate() : null
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
//#endregion
|
|
354
|
+
//#region node_modules/@sveltejs/kit/src/runtime/server/constants.js
|
|
355
|
+
var NULL_BODY_STATUS = [
|
|
356
|
+
101,
|
|
357
|
+
103,
|
|
358
|
+
204,
|
|
359
|
+
205,
|
|
360
|
+
304
|
|
361
|
+
];
|
|
362
|
+
//#endregion
|
|
363
|
+
//#region node_modules/@sveltejs/kit/src/runtime/server/page/load_data.js
|
|
364
|
+
/**
|
|
365
|
+
* Calls the user's server `load` function.
|
|
366
|
+
* @param {{
|
|
367
|
+
* event: import('@sveltejs/kit').RequestEvent;
|
|
368
|
+
* state: import('types').RequestState;
|
|
369
|
+
* node: import('types').SSRNode | undefined;
|
|
370
|
+
* parent: () => Promise<Record<string, any>>;
|
|
371
|
+
* }} opts
|
|
372
|
+
* @returns {Promise<import('types').ServerDataNode | null>}
|
|
373
|
+
*/
|
|
374
|
+
async function load_server_data({ event, state, node, parent }) {
|
|
375
|
+
if (!node?.server) return null;
|
|
376
|
+
let is_tracking = true;
|
|
377
|
+
const uses = {
|
|
378
|
+
dependencies: /* @__PURE__ */ new Set(),
|
|
379
|
+
params: /* @__PURE__ */ new Set(),
|
|
380
|
+
parent: false,
|
|
381
|
+
route: false,
|
|
382
|
+
url: false,
|
|
383
|
+
search_params: /* @__PURE__ */ new Set()
|
|
384
|
+
};
|
|
385
|
+
const load = node.server.load;
|
|
386
|
+
const slash = node.server.trailingSlash;
|
|
387
|
+
if (!load) return {
|
|
388
|
+
type: "data",
|
|
389
|
+
data: null,
|
|
390
|
+
uses,
|
|
391
|
+
slash
|
|
392
|
+
};
|
|
393
|
+
const url = make_trackable(event.url, () => {
|
|
394
|
+
if (is_tracking) uses.url = true;
|
|
395
|
+
}, (param) => {
|
|
396
|
+
if (is_tracking) uses.search_params.add(param);
|
|
397
|
+
});
|
|
398
|
+
if (state.prerendering || state.prerender_default === true) disable_search(url);
|
|
399
|
+
return {
|
|
400
|
+
type: "data",
|
|
401
|
+
data: await record_span({
|
|
402
|
+
name: "sveltekit.load",
|
|
403
|
+
attributes: {
|
|
404
|
+
"sveltekit.load.node_id": node.server_id || "unknown",
|
|
405
|
+
"sveltekit.load.node_type": get_node_type(node.server_id),
|
|
406
|
+
"sveltekit.load.environment": "server",
|
|
407
|
+
"http.route": event.route.id || "unknown"
|
|
408
|
+
},
|
|
409
|
+
fn: async (current) => {
|
|
410
|
+
const traced_event = merge_tracing(event, current);
|
|
411
|
+
return await with_request_store({
|
|
412
|
+
event: traced_event,
|
|
413
|
+
state
|
|
414
|
+
}, () => load.call(null, {
|
|
415
|
+
...traced_event,
|
|
416
|
+
fetch: (info, init) => {
|
|
417
|
+
new URL(info instanceof Request ? info.url : info, event.url);
|
|
418
|
+
return event.fetch(info, init);
|
|
419
|
+
},
|
|
420
|
+
/** @param {string[]} deps */
|
|
421
|
+
depends: (...deps) => {
|
|
422
|
+
for (const dep of deps) {
|
|
423
|
+
const { href } = new URL(dep, event.url);
|
|
424
|
+
uses.dependencies.add(href);
|
|
425
|
+
}
|
|
426
|
+
},
|
|
427
|
+
params: new Proxy(event.params, { get: (target, key) => {
|
|
428
|
+
if (is_tracking) uses.params.add(key);
|
|
429
|
+
return target[key];
|
|
430
|
+
} }),
|
|
431
|
+
parent: async () => {
|
|
432
|
+
if (is_tracking) uses.parent = true;
|
|
433
|
+
return parent();
|
|
434
|
+
},
|
|
435
|
+
route: new Proxy(event.route, { get: (target, key) => {
|
|
436
|
+
if (is_tracking) uses.route = true;
|
|
437
|
+
return target[key];
|
|
438
|
+
} }),
|
|
439
|
+
url,
|
|
440
|
+
untrack(fn) {
|
|
441
|
+
is_tracking = false;
|
|
442
|
+
try {
|
|
443
|
+
return fn();
|
|
444
|
+
} finally {
|
|
445
|
+
is_tracking = true;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}));
|
|
449
|
+
}
|
|
450
|
+
}) ?? null,
|
|
451
|
+
uses,
|
|
452
|
+
slash
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Calls the user's `load` function.
|
|
457
|
+
* @param {{
|
|
458
|
+
* event: import('@sveltejs/kit').RequestEvent;
|
|
459
|
+
* state: import('types').RequestState;
|
|
460
|
+
* fetched: import('./types.js').Fetched[];
|
|
461
|
+
* node: import('types').SSRNode | undefined;
|
|
462
|
+
* parent: () => Promise<Record<string, any>>;
|
|
463
|
+
* resolve_opts: import('types').RequiredResolveOptions;
|
|
464
|
+
* server_data_promise: Promise<import('types').ServerDataNode | null>;
|
|
465
|
+
* csr: boolean;
|
|
466
|
+
* }} opts
|
|
467
|
+
* @returns {Promise<Record<string, any | Promise<any>> | null>}
|
|
468
|
+
*/
|
|
469
|
+
async function load_data({ event, state, fetched, node, parent, server_data_promise, resolve_opts, csr }) {
|
|
470
|
+
const server_data_node = await server_data_promise;
|
|
471
|
+
const load = node?.universal?.load;
|
|
472
|
+
if (!load) return server_data_node?.data ?? null;
|
|
473
|
+
return await record_span({
|
|
474
|
+
name: "sveltekit.load",
|
|
475
|
+
attributes: {
|
|
476
|
+
"sveltekit.load.node_id": node.universal_id || "unknown",
|
|
477
|
+
"sveltekit.load.node_type": get_node_type(node.universal_id),
|
|
478
|
+
"sveltekit.load.environment": "server",
|
|
479
|
+
"http.route": event.route.id || "unknown"
|
|
480
|
+
},
|
|
481
|
+
fn: async (current) => {
|
|
482
|
+
const traced_event = merge_tracing(event, current);
|
|
483
|
+
return await with_request_store({
|
|
484
|
+
event: traced_event,
|
|
485
|
+
state
|
|
486
|
+
}, () => load.call(null, {
|
|
487
|
+
url: event.url,
|
|
488
|
+
params: event.params,
|
|
489
|
+
data: server_data_node?.data ?? null,
|
|
490
|
+
route: event.route,
|
|
491
|
+
fetch: create_universal_fetch(event, state.prerendering, fetched, csr, resolve_opts),
|
|
492
|
+
setHeaders: event.setHeaders,
|
|
493
|
+
depends: noop,
|
|
494
|
+
parent,
|
|
495
|
+
untrack: (fn) => fn(),
|
|
496
|
+
tracing: traced_event.tracing
|
|
497
|
+
}));
|
|
498
|
+
}
|
|
499
|
+
}) ?? null;
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* @param {Pick<import('@sveltejs/kit').RequestEvent, 'fetch' | 'url' | 'request' | 'route'>} event
|
|
503
|
+
* @param {import('types').PrerenderOptions | undefined} prerendering
|
|
504
|
+
* @param {import('./types.js').Fetched[]} fetched
|
|
505
|
+
* @param {boolean} csr
|
|
506
|
+
* @param {Pick<Required<import('@sveltejs/kit/hooks').ResolveOptions>, 'filterSerializedResponseHeaders'>} resolve_opts
|
|
507
|
+
* @returns {typeof fetch}
|
|
508
|
+
*/
|
|
509
|
+
function create_universal_fetch(event, prerendering, fetched, csr, resolve_opts) {
|
|
510
|
+
/**
|
|
511
|
+
* @param {URL | RequestInfo} input
|
|
512
|
+
* @param {RequestInit} [init]
|
|
513
|
+
*/
|
|
514
|
+
const universal_fetch = async (input, init) => {
|
|
515
|
+
const cloned_body = input instanceof Request && input.body ? input.clone().body : null;
|
|
516
|
+
const cloned_headers = input instanceof Request && [...input.headers].length ? new Headers(input.headers) : init?.headers;
|
|
517
|
+
let response = await event.fetch(input, init);
|
|
518
|
+
const url = new URL(input instanceof Request ? input.url : input, event.url);
|
|
519
|
+
const same_origin = url.origin === event.url.origin;
|
|
520
|
+
/** @type {import('types').PrerenderDependency} */
|
|
521
|
+
let dependency;
|
|
522
|
+
if (same_origin) {
|
|
523
|
+
if (prerendering) {
|
|
524
|
+
dependency = {
|
|
525
|
+
response,
|
|
526
|
+
body: null
|
|
527
|
+
};
|
|
528
|
+
prerendering.dependencies.set(url.pathname, dependency);
|
|
529
|
+
}
|
|
530
|
+
} else if (url.protocol === "https:" || url.protocol === "http:") {
|
|
531
|
+
if ((input instanceof Request ? input.mode : init?.mode ?? "cors") === "no-cors") response = new Response("", {
|
|
532
|
+
status: response.status,
|
|
533
|
+
statusText: response.statusText,
|
|
534
|
+
headers: response.headers
|
|
535
|
+
});
|
|
536
|
+
else {
|
|
537
|
+
const acao = response.headers.get("access-control-allow-origin");
|
|
538
|
+
if (!acao || acao !== event.url.origin && acao !== "*") load_fetch_cors({ reason: acao ? "Incorrect" : "No" });
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
/** @type {ReadableStream<Uint8Array>} */
|
|
542
|
+
let teed_body;
|
|
543
|
+
const proxy = new Proxy(response, { get(response, key, receiver) {
|
|
544
|
+
/**
|
|
545
|
+
* @param {string | undefined} body
|
|
546
|
+
* @param {boolean} is_b64
|
|
547
|
+
*/
|
|
548
|
+
async function push_fetched(body, is_b64) {
|
|
549
|
+
const status_number = Number(response.status);
|
|
550
|
+
if (isNaN(status_number)) throw new Error(`response.status is not a number. value: "${response.status}" type: ${typeof response.status}`);
|
|
551
|
+
const request_body = input instanceof Request && cloned_body ? await new Response(cloned_body).text() : init?.body;
|
|
552
|
+
if (request_body && typeof request_body !== "string" && !ArrayBuffer.isView(request_body)) return;
|
|
553
|
+
fetched.push({
|
|
554
|
+
url: fetch_cache_url(url, event.url),
|
|
555
|
+
method: event.request.method,
|
|
556
|
+
request_body,
|
|
557
|
+
request_headers: cloned_headers,
|
|
558
|
+
response_body: body,
|
|
559
|
+
response,
|
|
560
|
+
is_b64
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
if (key === "body") {
|
|
564
|
+
if (response.body === null) return null;
|
|
565
|
+
if (teed_body) return teed_body;
|
|
566
|
+
const [a, b] = response.body.tee();
|
|
567
|
+
(async () => {
|
|
568
|
+
const result = new Uint8Array(await new Response(a).arrayBuffer());
|
|
569
|
+
if (dependency) dependency.body = new Uint8Array(result);
|
|
570
|
+
push_fetched(base64_encode(result), true);
|
|
571
|
+
})().catch(noop);
|
|
572
|
+
return teed_body = b;
|
|
573
|
+
}
|
|
574
|
+
if (key === "arrayBuffer") return async () => {
|
|
575
|
+
const buffer = await response.arrayBuffer();
|
|
576
|
+
const bytes = new Uint8Array(buffer);
|
|
577
|
+
if (dependency) dependency.body = bytes;
|
|
578
|
+
if (buffer instanceof ArrayBuffer) await push_fetched(base64_encode(bytes), true);
|
|
579
|
+
return buffer;
|
|
580
|
+
};
|
|
581
|
+
async function text() {
|
|
582
|
+
const body = await response.text();
|
|
583
|
+
if (body === "" && NULL_BODY_STATUS.includes(response.status)) {
|
|
584
|
+
await push_fetched(void 0, false);
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
if (!body || typeof body === "string") await push_fetched(body, false);
|
|
588
|
+
if (dependency) dependency.body = body;
|
|
589
|
+
return body;
|
|
590
|
+
}
|
|
591
|
+
if (key === "text") return text;
|
|
592
|
+
if (key === "json") return async () => {
|
|
593
|
+
const body = await text();
|
|
594
|
+
return body ? JSON.parse(body) : void 0;
|
|
595
|
+
};
|
|
596
|
+
const value = Reflect.get(response, key, response);
|
|
597
|
+
if (value instanceof Function) return Object.defineProperties(
|
|
598
|
+
/**
|
|
599
|
+
* @this {any}
|
|
600
|
+
*/
|
|
601
|
+
function() {
|
|
602
|
+
return Reflect.apply(value, this === receiver ? response : this, arguments);
|
|
603
|
+
},
|
|
604
|
+
{
|
|
605
|
+
name: { value: value.name },
|
|
606
|
+
length: { value: value.length }
|
|
607
|
+
}
|
|
608
|
+
);
|
|
609
|
+
return value;
|
|
610
|
+
} });
|
|
611
|
+
if (csr) {
|
|
612
|
+
const get = response.headers.get;
|
|
613
|
+
response.headers.get = (key) => {
|
|
614
|
+
const lower = key.toLowerCase();
|
|
615
|
+
const value = get.call(response.headers, lower);
|
|
616
|
+
if (value && !lower.startsWith("x-sveltekit-")) {
|
|
617
|
+
if (!resolve_opts.filterSerializedResponseHeaders(lower, value)) load_response_header_not_serialized({
|
|
618
|
+
name: lower,
|
|
619
|
+
id: event.route.id
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
return value;
|
|
623
|
+
};
|
|
624
|
+
const get_set_cookie = response.headers.getSetCookie;
|
|
625
|
+
response.headers.getSetCookie = () => {
|
|
626
|
+
const values = get_set_cookie.call(response.headers);
|
|
627
|
+
for (const value of values) if (!resolve_opts.filterSerializedResponseHeaders("set-cookie", value)) load_response_header_not_serialized({
|
|
628
|
+
name: "set-cookie",
|
|
629
|
+
id: event.route.id
|
|
630
|
+
});
|
|
631
|
+
return values;
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
return proxy;
|
|
635
|
+
};
|
|
636
|
+
return (input, init) => {
|
|
637
|
+
const response = universal_fetch(input, init);
|
|
638
|
+
response.catch(noop);
|
|
639
|
+
return response;
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
//#endregion
|
|
643
|
+
//#region node_modules/@sveltejs/kit/src/utils/hash.js
|
|
644
|
+
/**
|
|
645
|
+
* Hash using djb2
|
|
646
|
+
* @param {import('types').StrictBody[]} values
|
|
647
|
+
*/
|
|
648
|
+
function hash(...values) {
|
|
649
|
+
let hash = 5381;
|
|
650
|
+
for (const value of values) if (typeof value === "string") {
|
|
651
|
+
let i = value.length;
|
|
652
|
+
while (i) hash = hash * 33 ^ value.charCodeAt(--i);
|
|
653
|
+
} else if (ArrayBuffer.isView(value)) {
|
|
654
|
+
const buffer = new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
655
|
+
let i = buffer.length;
|
|
656
|
+
while (i) hash = hash * 33 ^ buffer[--i];
|
|
657
|
+
} else throw new TypeError("value must be a string or TypedArray");
|
|
658
|
+
return (hash >>> 0).toString(36);
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* Hash of the headers and body a `fetch` was called with. The server-side serializer and the
|
|
662
|
+
* client-side cache lookup must produce identical values for cached responses to be found.
|
|
663
|
+
* @param {HeadersInit | undefined} headers
|
|
664
|
+
* @param {import('types').StrictBody | null | undefined} body
|
|
665
|
+
*/
|
|
666
|
+
function hash_request(headers, body) {
|
|
667
|
+
/** @type {import('types').StrictBody[]} */
|
|
668
|
+
const values = [];
|
|
669
|
+
if (headers) values.push([...new Headers(headers)].join(","));
|
|
670
|
+
if (body) values.push(body);
|
|
671
|
+
return hash(...values);
|
|
672
|
+
}
|
|
673
|
+
//#endregion
|
|
674
|
+
//#region node_modules/@sveltejs/kit/src/utils/misc.js
|
|
675
|
+
var s = JSON.stringify;
|
|
676
|
+
//#endregion
|
|
677
|
+
//#region node_modules/@sveltejs/kit/src/utils/escape.js
|
|
678
|
+
/**
|
|
679
|
+
* When inside a double-quoted attribute value, only `&` and `"` hold special meaning.
|
|
680
|
+
* @see https://html.spec.whatwg.org/multipage/parsing.html#attribute-value-(double-quoted)-state
|
|
681
|
+
* @type {Record<string, string>}
|
|
682
|
+
*/
|
|
683
|
+
var escape_html_attr_dict = {
|
|
684
|
+
"&": "&",
|
|
685
|
+
"\"": """
|
|
686
|
+
};
|
|
687
|
+
/**
|
|
688
|
+
* @type {Record<string, string>}
|
|
689
|
+
*/
|
|
690
|
+
var escape_html_dict = {
|
|
691
|
+
"&": "&",
|
|
692
|
+
"<": "<"
|
|
693
|
+
};
|
|
694
|
+
/** @param {Record<string, string>} dict */
|
|
695
|
+
var escape_regex = (dict) => new RegExp(`[${Object.keys(dict).join("")}]|\\p{Surrogate}`, "gu");
|
|
696
|
+
var escape_html_attr_regex = escape_regex(escape_html_attr_dict);
|
|
697
|
+
var escape_html_regex = escape_regex(escape_html_dict);
|
|
698
|
+
/**
|
|
699
|
+
* Escapes unpaired surrogates (which are allowed in js strings but invalid in HTML) and
|
|
700
|
+
* escapes characters that are special.
|
|
701
|
+
*
|
|
702
|
+
* @param {string} str
|
|
703
|
+
* @param {boolean} [is_attr]
|
|
704
|
+
* @returns {string} escaped string
|
|
705
|
+
* @example const html = `<tag data-value="${escape_html('value', true)}">...</tag>`;
|
|
706
|
+
*/
|
|
707
|
+
function escape_html(str, is_attr) {
|
|
708
|
+
const dict = is_attr ? escape_html_attr_dict : escape_html_dict;
|
|
709
|
+
return str.replace(is_attr ? escape_html_attr_regex : escape_html_regex, (match) => dict[match] ?? `&#${match.charCodeAt(0)};`);
|
|
710
|
+
}
|
|
711
|
+
//#endregion
|
|
712
|
+
//#region node_modules/@sveltejs/kit/src/runtime/server/page/serialize_data.js
|
|
713
|
+
/**
|
|
714
|
+
* Inside a script element, only `<\/script` and `<!--` hold special meaning to the HTML parser.
|
|
715
|
+
*
|
|
716
|
+
* The first closes the script element, so everything after is treated as raw HTML.
|
|
717
|
+
* The second disables further parsing until `-->`, so the script element might be unexpectedly
|
|
718
|
+
* kept open up until an unrelated HTML comment in the page.
|
|
719
|
+
*
|
|
720
|
+
* U+2028 LINE SEPARATOR and U+2029 PARAGRAPH SEPARATOR are escaped for the sake of pre-2018
|
|
721
|
+
* browsers.
|
|
722
|
+
*
|
|
723
|
+
* @see tests for unsafe parsing examples.
|
|
724
|
+
* @see https://html.spec.whatwg.org/multipage/scripting.html#restrictions-for-contents-of-script-elements
|
|
725
|
+
* @see https://html.spec.whatwg.org/multipage/syntax.html#cdata-rcdata-restrictions
|
|
726
|
+
* @see https://html.spec.whatwg.org/multipage/parsing.html#script-data-state
|
|
727
|
+
* @see https://html.spec.whatwg.org/multipage/parsing.html#script-data-double-escaped-state
|
|
728
|
+
* @see https://github.com/tc39/proposal-json-superset
|
|
729
|
+
* @type {Record<string, string>}
|
|
730
|
+
*/
|
|
731
|
+
var replacements = {
|
|
732
|
+
"<": "\\u003C",
|
|
733
|
+
"\u2028": "\\u2028",
|
|
734
|
+
"\u2029": "\\u2029"
|
|
735
|
+
};
|
|
736
|
+
var pattern = new RegExp(`[${Object.keys(replacements).join("")}]`, "g");
|
|
737
|
+
/**
|
|
738
|
+
* Generates a raw HTML string containing a safe script element carrying data and associated attributes.
|
|
739
|
+
*
|
|
740
|
+
* It escapes all the special characters needed to guarantee the element is unbroken, but care must
|
|
741
|
+
* be taken to ensure it is inserted in the document at an acceptable position for a script element,
|
|
742
|
+
* and that the resulting string isn't further modified.
|
|
743
|
+
*
|
|
744
|
+
* @param {import('./types.js').Fetched} fetched
|
|
745
|
+
* @param {(name: string, value: string) => boolean} filter
|
|
746
|
+
* @param {boolean} [prerendering]
|
|
747
|
+
* @returns {string} The raw HTML of a script element carrying the JSON payload.
|
|
748
|
+
* @example const html = serialize_data('/data.json', null, { foo: 'bar' });
|
|
749
|
+
*/
|
|
750
|
+
function serialize_data(fetched, filter, prerendering = false) {
|
|
751
|
+
/** @type {Record<string, string>} */
|
|
752
|
+
const headers = {};
|
|
753
|
+
let cache_control = null;
|
|
754
|
+
let age = null;
|
|
755
|
+
let varyAny = false;
|
|
756
|
+
for (const [key, value] of fetched.response.headers) {
|
|
757
|
+
if (filter(key, value)) headers[key] = value;
|
|
758
|
+
if (key === "cache-control") cache_control = value;
|
|
759
|
+
else if (key === "age") age = value;
|
|
760
|
+
else if (key === "vary" && value.trim() === "*") varyAny = true;
|
|
761
|
+
}
|
|
762
|
+
const payload = {
|
|
763
|
+
status: fetched.response.status,
|
|
764
|
+
statusText: fetched.response.statusText,
|
|
765
|
+
headers,
|
|
766
|
+
body: fetched.response_body
|
|
767
|
+
};
|
|
768
|
+
const safe_payload = JSON.stringify(payload).replace(pattern, (match) => replacements[match]);
|
|
769
|
+
const attrs = [
|
|
770
|
+
"type=\"application/json\"",
|
|
771
|
+
"data-sveltekit-fetched",
|
|
772
|
+
`data-url="${escape_html(fetched.url, true)}"`
|
|
773
|
+
];
|
|
774
|
+
if (fetched.is_b64) attrs.push("data-b64");
|
|
775
|
+
if (fetched.request_headers || fetched.request_body) attrs.push(`data-hash="${hash_request(fetched.request_headers, fetched.request_body)}"`);
|
|
776
|
+
if (!prerendering && fetched.method === "GET" && cache_control && !varyAny) {
|
|
777
|
+
const match = /s-maxage=(\d+)/g.exec(cache_control) ?? /max-age=(\d+)/g.exec(cache_control);
|
|
778
|
+
if (match) {
|
|
779
|
+
const ttl = +match[1] - +(age ?? "0");
|
|
780
|
+
attrs.push(`data-ttl="${ttl}"`);
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
return `<script ${attrs.join(" ")}>${safe_payload}<\/script>`;
|
|
784
|
+
}
|
|
785
|
+
//#endregion
|
|
786
|
+
//#region node_modules/@sveltejs/kit/src/runtime/server/page/csp.js
|
|
787
|
+
var array = /* @__PURE__ */ new Uint8Array(16);
|
|
788
|
+
function generate_nonce() {
|
|
789
|
+
crypto.getRandomValues(array);
|
|
790
|
+
return base64_encode(array);
|
|
791
|
+
}
|
|
792
|
+
/** @param {string} content */
|
|
793
|
+
async function sha256(content) {
|
|
794
|
+
const digest = await crypto.subtle.digest("SHA-256", text_encoder.encode(content));
|
|
795
|
+
return base64_encode(new Uint8Array(digest));
|
|
796
|
+
}
|
|
797
|
+
/** @typedef {`nonce-${string}` | `sha256-${string}`} CspSource */
|
|
798
|
+
var quoted = /* @__PURE__ */ new Set([
|
|
799
|
+
"self",
|
|
800
|
+
"unsafe-eval",
|
|
801
|
+
"unsafe-hashes",
|
|
802
|
+
"unsafe-inline",
|
|
803
|
+
"none",
|
|
804
|
+
"strict-dynamic",
|
|
805
|
+
"report-sample",
|
|
806
|
+
"wasm-unsafe-eval",
|
|
807
|
+
"script"
|
|
808
|
+
]);
|
|
809
|
+
var crypto_pattern = /^(nonce|sha\d\d\d)-/;
|
|
810
|
+
var BaseProvider = class {
|
|
811
|
+
/** @type {boolean} */
|
|
812
|
+
#use_hashes;
|
|
813
|
+
/** @type {boolean} */
|
|
814
|
+
script_needs_csp;
|
|
815
|
+
/** @type {boolean} */
|
|
816
|
+
#script_src_needs_csp;
|
|
817
|
+
/** @type {boolean} */
|
|
818
|
+
#script_src_elem_needs_csp;
|
|
819
|
+
/** @type {boolean} */
|
|
820
|
+
style_needs_csp;
|
|
821
|
+
/** @type {boolean} */
|
|
822
|
+
#style_src_needs_csp;
|
|
823
|
+
/** @type {boolean} */
|
|
824
|
+
#style_src_attr_needs_csp;
|
|
825
|
+
/** @type {boolean} */
|
|
826
|
+
#style_src_elem_needs_csp;
|
|
827
|
+
/** @type {import('types').CspDirectives} */
|
|
828
|
+
#directives;
|
|
829
|
+
/** @type {Set<import('types').Csp.Source>} */
|
|
830
|
+
#script_src = /* @__PURE__ */ new Set();
|
|
831
|
+
/** @type {Set<import('types').Csp.Source>} */
|
|
832
|
+
#script_src_elem = /* @__PURE__ */ new Set();
|
|
833
|
+
/** @type {Set<import('types').Csp.Source>} */
|
|
834
|
+
#style_src = /* @__PURE__ */ new Set();
|
|
835
|
+
/** @type {Set<import('types').Csp.Source>} */
|
|
836
|
+
#style_src_attr = /* @__PURE__ */ new Set();
|
|
837
|
+
/** @type {Set<import('types').Csp.Source>} */
|
|
838
|
+
#style_src_elem = /* @__PURE__ */ new Set();
|
|
839
|
+
/** @type {boolean} */
|
|
840
|
+
script_needs_nonce;
|
|
841
|
+
/** @type {boolean} */
|
|
842
|
+
style_needs_nonce;
|
|
843
|
+
/** @type {boolean} */
|
|
844
|
+
script_needs_hash;
|
|
845
|
+
/**
|
|
846
|
+
* @param {boolean} use_hashes
|
|
847
|
+
* @param {import('types').CspDirectives} directives
|
|
848
|
+
*/
|
|
849
|
+
constructor(use_hashes, directives) {
|
|
850
|
+
this.#use_hashes = use_hashes;
|
|
851
|
+
this.#directives = directives;
|
|
852
|
+
const d = this.#directives;
|
|
853
|
+
const effective_script_src = d["script-src"] || d["default-src"];
|
|
854
|
+
const script_src_elem = d["script-src-elem"];
|
|
855
|
+
const effective_style_src = d["style-src"] || d["default-src"];
|
|
856
|
+
const style_src_attr = d["style-src-attr"];
|
|
857
|
+
const style_src_elem = d["style-src-elem"];
|
|
858
|
+
/** @param {(import('types').Csp.Source | import('types').Csp.ActionSource)[] | undefined} directive */
|
|
859
|
+
const style_needs_csp = (directive) => !!directive && !directive.some((value) => value === "unsafe-inline");
|
|
860
|
+
/** @param {(import('types').Csp.Source | import('types').Csp.ActionSource)[] | undefined} directive */
|
|
861
|
+
const script_needs_csp = (directive) => !!directive && (!directive.some((value) => value === "unsafe-inline") || directive.some((value) => value === "strict-dynamic"));
|
|
862
|
+
this.#script_src_needs_csp = script_needs_csp(effective_script_src);
|
|
863
|
+
this.#script_src_elem_needs_csp = script_needs_csp(script_src_elem);
|
|
864
|
+
this.#style_src_needs_csp = style_needs_csp(effective_style_src);
|
|
865
|
+
this.#style_src_attr_needs_csp = style_needs_csp(style_src_attr);
|
|
866
|
+
this.#style_src_elem_needs_csp = style_needs_csp(style_src_elem);
|
|
867
|
+
this.script_needs_csp = this.#script_src_needs_csp || this.#script_src_elem_needs_csp;
|
|
868
|
+
this.style_needs_csp = this.#style_src_needs_csp || this.#style_src_attr_needs_csp || this.#style_src_elem_needs_csp;
|
|
869
|
+
this.script_needs_nonce = this.script_needs_csp && !this.#use_hashes;
|
|
870
|
+
this.style_needs_nonce = this.style_needs_csp && !this.#use_hashes;
|
|
871
|
+
this.script_needs_hash = this.script_needs_csp && this.#use_hashes;
|
|
872
|
+
}
|
|
873
|
+
/** @param {CspSource} source */
|
|
874
|
+
add_script(source) {
|
|
875
|
+
if (this.#script_src_needs_csp) this.#script_src.add(source);
|
|
876
|
+
if (this.#script_src_elem_needs_csp) this.#script_src_elem.add(source);
|
|
877
|
+
}
|
|
878
|
+
/** @param {CspSource} source */
|
|
879
|
+
add_style(source) {
|
|
880
|
+
if (!this.style_needs_csp) return;
|
|
881
|
+
if (this.#style_src_needs_csp) this.#style_src.add(source);
|
|
882
|
+
if (this.#style_src_attr_needs_csp) this.#style_src_attr.add(source);
|
|
883
|
+
if (this.#style_src_elem_needs_csp) {
|
|
884
|
+
const sha256_empty_comment_hash = "sha256-9OlNO0DNEeaVzHL4RZwCLsBHA8WBQ8toBp/4F5XV2nc=";
|
|
885
|
+
const d = this.#directives;
|
|
886
|
+
if (d["style-src-elem"] && !d["style-src-elem"].includes(sha256_empty_comment_hash) && !this.#style_src_elem.has(sha256_empty_comment_hash)) this.#style_src_elem.add(sha256_empty_comment_hash);
|
|
887
|
+
if (source !== sha256_empty_comment_hash) this.#style_src_elem.add(source);
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
/**
|
|
891
|
+
* @param {boolean} [is_meta]
|
|
892
|
+
*/
|
|
893
|
+
get_header(is_meta = false) {
|
|
894
|
+
const header = [];
|
|
895
|
+
const directives = { ...this.#directives };
|
|
896
|
+
/**
|
|
897
|
+
* @template {'style-src' | 'style-src-attr' | 'style-src-elem' | 'script-src' | 'script-src-elem'} K
|
|
898
|
+
* @param {K} key
|
|
899
|
+
* @param {Set<import('types').Csp.Source>} sources
|
|
900
|
+
* @param {import('types').CspDirectives[K]} [base]
|
|
901
|
+
*/
|
|
902
|
+
const merge_sources = (key, sources, base) => {
|
|
903
|
+
if (sources.size > 0) directives[key] = [...base || [], ...sources];
|
|
904
|
+
};
|
|
905
|
+
merge_sources("style-src", this.#style_src, directives["style-src"] || directives["default-src"]);
|
|
906
|
+
merge_sources("style-src-attr", this.#style_src_attr, directives["style-src-attr"]);
|
|
907
|
+
merge_sources("style-src-elem", this.#style_src_elem, directives["style-src-elem"]);
|
|
908
|
+
merge_sources("script-src", this.#script_src, directives["script-src"] || directives["default-src"]);
|
|
909
|
+
merge_sources("script-src-elem", this.#script_src_elem, directives["script-src-elem"]);
|
|
910
|
+
for (const key in directives) {
|
|
911
|
+
if (is_meta && (key === "frame-ancestors" || key === "report-uri" || key === "sandbox")) continue;
|
|
912
|
+
const value = directives[key];
|
|
913
|
+
if (!value) continue;
|
|
914
|
+
const directive = [key];
|
|
915
|
+
if (Array.isArray(value)) for (const source of value) directive.push(quoted.has(source) || crypto_pattern.test(source) ? `'${source}'` : source);
|
|
916
|
+
header.push(directive.join(" "));
|
|
917
|
+
}
|
|
918
|
+
return header.join("; ");
|
|
919
|
+
}
|
|
920
|
+
};
|
|
921
|
+
var CspProvider = class extends BaseProvider {
|
|
922
|
+
get_meta() {
|
|
923
|
+
const content = this.get_header(true);
|
|
924
|
+
if (!content) return;
|
|
925
|
+
return `<meta http-equiv="content-security-policy" content="${escape_html(content, true)}">`;
|
|
926
|
+
}
|
|
927
|
+
};
|
|
928
|
+
var CspReportOnlyProvider = class extends BaseProvider {
|
|
929
|
+
/**
|
|
930
|
+
* @param {boolean} use_hashes
|
|
931
|
+
* @param {import('types').CspDirectives} directives
|
|
932
|
+
*/
|
|
933
|
+
constructor(use_hashes, directives) {
|
|
934
|
+
super(use_hashes, directives);
|
|
935
|
+
if (Object.values(directives).some((v) => !!v) && !directives["report-to"]?.length && !directives["report-uri"]?.length) csp_report_only_missing_report();
|
|
936
|
+
}
|
|
937
|
+
};
|
|
938
|
+
var Csp = class {
|
|
939
|
+
/** @readonly */
|
|
940
|
+
nonce = generate_nonce();
|
|
941
|
+
/** @type {CspProvider} */
|
|
942
|
+
csp_provider;
|
|
943
|
+
/** @type {CspReportOnlyProvider} */
|
|
944
|
+
report_only_provider;
|
|
945
|
+
/** @type {boolean} */
|
|
946
|
+
#use_hashes;
|
|
947
|
+
/**
|
|
948
|
+
* @param {import('./types.js').CspConfig} config
|
|
949
|
+
* @param {import('./types.js').CspOpts} opts
|
|
950
|
+
*/
|
|
951
|
+
constructor({ mode, directives, reportOnly }, { prerender }) {
|
|
952
|
+
this.#use_hashes = mode === "hash" || mode === "auto" && prerender;
|
|
953
|
+
this.csp_provider = new CspProvider(this.#use_hashes, directives);
|
|
954
|
+
this.report_only_provider = new CspReportOnlyProvider(this.#use_hashes, reportOnly);
|
|
955
|
+
}
|
|
956
|
+
/**
|
|
957
|
+
* @param {string} content
|
|
958
|
+
* @returns {Promise<CspSource>}
|
|
959
|
+
*/
|
|
960
|
+
async #get_source(content) {
|
|
961
|
+
return this.#use_hashes ? `sha256-${await sha256(content)}` : `nonce-${this.nonce}`;
|
|
962
|
+
}
|
|
963
|
+
get script_needs_hash() {
|
|
964
|
+
return this.csp_provider.script_needs_hash || this.report_only_provider.script_needs_hash;
|
|
965
|
+
}
|
|
966
|
+
get script_needs_nonce() {
|
|
967
|
+
return this.csp_provider.script_needs_nonce || this.report_only_provider.script_needs_nonce;
|
|
968
|
+
}
|
|
969
|
+
get style_needs_nonce() {
|
|
970
|
+
return this.csp_provider.style_needs_nonce || this.report_only_provider.style_needs_nonce;
|
|
971
|
+
}
|
|
972
|
+
/** @param {string} content */
|
|
973
|
+
async add_script(content) {
|
|
974
|
+
if (!this.csp_provider.script_needs_csp && !this.report_only_provider.script_needs_csp) return;
|
|
975
|
+
const source = await this.#get_source(content);
|
|
976
|
+
if (this.csp_provider.script_needs_csp) this.csp_provider.add_script(source);
|
|
977
|
+
if (this.report_only_provider.script_needs_csp) this.report_only_provider.add_script(source);
|
|
978
|
+
}
|
|
979
|
+
/** @param {`sha256-${string}`[]} hashes */
|
|
980
|
+
add_script_hashes(hashes) {
|
|
981
|
+
for (const hash of hashes) {
|
|
982
|
+
this.csp_provider.add_script(hash);
|
|
983
|
+
this.report_only_provider.add_script(hash);
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
/** @param {string} content */
|
|
987
|
+
async add_style(content) {
|
|
988
|
+
if (!this.csp_provider.style_needs_csp && !this.report_only_provider.style_needs_csp) return;
|
|
989
|
+
const source = await this.#get_source(content);
|
|
990
|
+
this.csp_provider.add_style(source);
|
|
991
|
+
this.report_only_provider.add_style(source);
|
|
992
|
+
}
|
|
993
|
+
};
|
|
994
|
+
//#endregion
|
|
995
|
+
//#region node_modules/@sveltejs/kit/src/runtime/server/page/server_routing.js
|
|
996
|
+
/** @import { ParamValue } from '@sveltejs/kit/params' */
|
|
997
|
+
/** @import { SSRManifest } from 'types' */
|
|
998
|
+
/**
|
|
999
|
+
* @param {import('types').SSRClientRoute} route
|
|
1000
|
+
* @param {URL} url
|
|
1001
|
+
* @param {NonNullable<SSRManifest['client']>} client
|
|
1002
|
+
* @returns {string}
|
|
1003
|
+
*/
|
|
1004
|
+
function generate_route_object(route, url, client) {
|
|
1005
|
+
const { errors, layouts, leaf } = route;
|
|
1006
|
+
const paths = resolve_paths(url.pathname);
|
|
1007
|
+
const nodes = [
|
|
1008
|
+
...errors,
|
|
1009
|
+
...layouts.map((l) => l?.[1]),
|
|
1010
|
+
leaf[1]
|
|
1011
|
+
].filter((n) => typeof n === "number").map((n) => `'${n}': () => ${create_client_import(client.nodes?.[n], paths)}`).join(",\n ");
|
|
1012
|
+
return [
|
|
1013
|
+
`{\n\tid: ${s(route.id)}`,
|
|
1014
|
+
`errors: ${s(route.errors)}`,
|
|
1015
|
+
`layouts: ${s(route.layouts)}`,
|
|
1016
|
+
`leaf: ${s(route.leaf)}`,
|
|
1017
|
+
`nodes: {\n\t\t${nodes}\n\t}\n}`
|
|
1018
|
+
].join(",\n ");
|
|
1019
|
+
}
|
|
1020
|
+
/**
|
|
1021
|
+
* The `base` and `assets` prefixes for client paths in a document at `pathname`. With
|
|
1022
|
+
* `paths.relative`, they're relative to that document so the app also works when served
|
|
1023
|
+
* from IPFS, the internet archive, or behind a proxy.
|
|
1024
|
+
* @param {string} pathname
|
|
1025
|
+
*/
|
|
1026
|
+
function resolve_paths(pathname) {
|
|
1027
|
+
const relative_base = pathname.slice(0).split("/").slice(2).map(() => "..").join("/") || ".";
|
|
1028
|
+
return {
|
|
1029
|
+
base: relative_base,
|
|
1030
|
+
assets: !assets || assets[0] === "/" && assets !== "/_svelte_kit_assets" ? relative_base : assets
|
|
1031
|
+
};
|
|
1032
|
+
}
|
|
1033
|
+
/**
|
|
1034
|
+
* @param {string} path a root-absolute dev path (e.g. `/@fs/...`) or a prod path relative to `assets`
|
|
1035
|
+
* @param {ReturnType<typeof resolve_paths>} paths
|
|
1036
|
+
*/
|
|
1037
|
+
function client_path(path, { base, assets }) {
|
|
1038
|
+
return path[0] === "/" ? base + path : `${assets}/${path}`;
|
|
1039
|
+
}
|
|
1040
|
+
/**
|
|
1041
|
+
* @param {string | undefined} import_path
|
|
1042
|
+
* @param {ReturnType<typeof resolve_paths>} paths
|
|
1043
|
+
*/
|
|
1044
|
+
function create_client_import(import_path, paths) {
|
|
1045
|
+
return import_path ? `import('${client_path(import_path, paths)}')` : "Promise.resolve({})";
|
|
1046
|
+
}
|
|
1047
|
+
/**
|
|
1048
|
+
* @param {string} resolved_path
|
|
1049
|
+
* @param {URL} url
|
|
1050
|
+
* @returns {Promise<Response>}
|
|
1051
|
+
*/
|
|
1052
|
+
async function resolve_route(resolved_path, url) {
|
|
1053
|
+
if (!manifest.client?.routes) return text("Server-side route resolution disabled", { status: 400 });
|
|
1054
|
+
try {
|
|
1055
|
+
const matchers = await manifest.matchers();
|
|
1056
|
+
const result = find_route(resolved_path, manifest.client.routes, matchers);
|
|
1057
|
+
return create_server_routing_response(result?.route ?? null, result?.params ?? {}, url, manifest.client).response;
|
|
1058
|
+
} catch {
|
|
1059
|
+
return text("Error resolving route", { status: 500 });
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
/**
|
|
1063
|
+
* Resolve a route-ID resolution request (`/_app/routes/<id>/__route.js`) to a
|
|
1064
|
+
* JS module containing the route's node loaders. Params are always `{}` since
|
|
1065
|
+
* this endpoint exists to support `preloadCode(routeId)`, which doesn't need them.
|
|
1066
|
+
*
|
|
1067
|
+
* The module has one of three shapes, which the client uses to tell three cases apart:
|
|
1068
|
+
*
|
|
1069
|
+
* - `export const route = {...}` — a page route, with loaders to import
|
|
1070
|
+
* - `export const endpoint_only = true` — a real route with no `+page`, so there is
|
|
1071
|
+
* nothing to preload, but the client can cache that fact and stop asking
|
|
1072
|
+
* - an empty module — no such route
|
|
1073
|
+
*
|
|
1074
|
+
* @param {string} route_id
|
|
1075
|
+
* @param {URL} url
|
|
1076
|
+
* @returns {Response}
|
|
1077
|
+
*/
|
|
1078
|
+
function resolve_route_by_id(route_id, url) {
|
|
1079
|
+
if (!manifest.client?.routes) return text("Server-side route resolution disabled", { status: 400 });
|
|
1080
|
+
try {
|
|
1081
|
+
const route = manifest.client.routes.find((r) => r.id === route_id);
|
|
1082
|
+
if (route) return create_server_routing_response(route, null, url, manifest.client).response;
|
|
1083
|
+
if (manifest.routes.some((r) => r.id === route_id && !r.page)) return text("export const endpoint_only = true;", { headers: js_headers() });
|
|
1084
|
+
return create_server_routing_response(null, null, url, manifest.client).response;
|
|
1085
|
+
} catch {
|
|
1086
|
+
return text("Error resolving route", { status: 500 });
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
function js_headers() {
|
|
1090
|
+
return new Headers({ "content-type": "application/javascript; charset=utf-8" });
|
|
1091
|
+
}
|
|
1092
|
+
/**
|
|
1093
|
+
* @param {import('types').SSRClientRoute | null} route
|
|
1094
|
+
* @param {Partial<Record<string, ParamValue>> | null} params
|
|
1095
|
+
* @param {URL} url
|
|
1096
|
+
* @param {NonNullable<SSRManifest['client']>} client
|
|
1097
|
+
* @returns {{response: Response, body: string}}
|
|
1098
|
+
*/
|
|
1099
|
+
function create_server_routing_response(route, params, url, client) {
|
|
1100
|
+
const headers = js_headers();
|
|
1101
|
+
let body = "";
|
|
1102
|
+
if (route) {
|
|
1103
|
+
const csr_route = generate_route_object(route, url, client);
|
|
1104
|
+
body = `${create_css_import(route, url, client)}export const route = ${csr_route};`;
|
|
1105
|
+
if (params !== null) body += `\nexport const params = ${uneval$1(params)}`;
|
|
1106
|
+
}
|
|
1107
|
+
return {
|
|
1108
|
+
response: text(body, { headers }),
|
|
1109
|
+
body
|
|
1110
|
+
};
|
|
1111
|
+
}
|
|
1112
|
+
/**
|
|
1113
|
+
* This function generates the client-side import for the CSS files that are
|
|
1114
|
+
* associated with the current route. Vite takes care of that when using
|
|
1115
|
+
* client-side route resolution, but for server-side resolution it does
|
|
1116
|
+
* not know about the CSS files automatically.
|
|
1117
|
+
*
|
|
1118
|
+
* @param {import('types').SSRClientRoute} route
|
|
1119
|
+
* @param {URL} url
|
|
1120
|
+
* @param {NonNullable<SSRManifest['client']>} client
|
|
1121
|
+
* @returns {string}
|
|
1122
|
+
*/
|
|
1123
|
+
function create_css_import(route, url, client) {
|
|
1124
|
+
const { errors, layouts, leaf } = route;
|
|
1125
|
+
const paths = resolve_paths(url.pathname);
|
|
1126
|
+
let css = "";
|
|
1127
|
+
for (const node of [
|
|
1128
|
+
...errors,
|
|
1129
|
+
...layouts.map((l) => l?.[1]),
|
|
1130
|
+
leaf[1]
|
|
1131
|
+
]) {
|
|
1132
|
+
if (typeof node !== "number") continue;
|
|
1133
|
+
const node_css = client.css?.[node];
|
|
1134
|
+
for (const css_path of node_css ?? []) css += `'${client_path(css_path, paths)}',`;
|
|
1135
|
+
}
|
|
1136
|
+
if (!css) return "";
|
|
1137
|
+
return `${create_client_import(client.start, paths)}.then(x => x.load_css([${css}]));\n`;
|
|
1138
|
+
}
|
|
1139
|
+
//#endregion
|
|
1140
|
+
//#region node_modules/@sveltejs/kit/src/runtime/components/root.svelte
|
|
1141
|
+
function Root($$renderer, $$props) {
|
|
1142
|
+
$$renderer.component(($$renderer) => {
|
|
1143
|
+
const { page, components, onerror, tree, form, error } = $$props;
|
|
1144
|
+
let mounted = false;
|
|
1145
|
+
let navigated = false;
|
|
1146
|
+
let title = "";
|
|
1147
|
+
afterNavigate(() => {
|
|
1148
|
+
if (mounted) {
|
|
1149
|
+
navigated = true;
|
|
1150
|
+
title = document.title || "untitled page";
|
|
1151
|
+
} else mounted = true;
|
|
1152
|
+
});
|
|
1153
|
+
function node($$renderer, n, depth) {
|
|
1154
|
+
const Component = derived(() => n.component);
|
|
1155
|
+
const Error = derived(() => n.error);
|
|
1156
|
+
const data = derived(() => n.data);
|
|
1157
|
+
function failed($$renderer, error) {
|
|
1158
|
+
if (Error()) {
|
|
1159
|
+
$$renderer.push("<!--[-->");
|
|
1160
|
+
Error()($$renderer, { error });
|
|
1161
|
+
$$renderer.push("<!--]-->");
|
|
1162
|
+
} else {
|
|
1163
|
+
$$renderer.push("<!--[!-->");
|
|
1164
|
+
$$renderer.push("<!--]-->");
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
$$renderer.boundary({ failed: Error() ? failed : void 0 }, ($$renderer) => {
|
|
1168
|
+
$$renderer.push(`<!--[-->`);
|
|
1169
|
+
if (n.child) {
|
|
1170
|
+
$$renderer.push("<!--[0-->");
|
|
1171
|
+
if (Component()) {
|
|
1172
|
+
$$renderer.push("<!--[-->");
|
|
1173
|
+
Component()($$renderer, {
|
|
1174
|
+
data: data(),
|
|
1175
|
+
form,
|
|
1176
|
+
params: page.params,
|
|
1177
|
+
children: ($$renderer) => {
|
|
1178
|
+
node($$renderer, n.child, depth + 1);
|
|
1179
|
+
},
|
|
1180
|
+
$$slots: { default: true }
|
|
1181
|
+
});
|
|
1182
|
+
$$renderer.push("<!--]-->");
|
|
1183
|
+
} else {
|
|
1184
|
+
$$renderer.push("<!--[!-->");
|
|
1185
|
+
$$renderer.push("<!--]-->");
|
|
1186
|
+
}
|
|
1187
|
+
} else {
|
|
1188
|
+
$$renderer.push("<!--[-1-->");
|
|
1189
|
+
if (Component()) {
|
|
1190
|
+
$$renderer.push("<!--[-->");
|
|
1191
|
+
Component()($$renderer, {
|
|
1192
|
+
data: data(),
|
|
1193
|
+
form,
|
|
1194
|
+
params: page.params,
|
|
1195
|
+
error
|
|
1196
|
+
});
|
|
1197
|
+
$$renderer.push("<!--]-->");
|
|
1198
|
+
} else {
|
|
1199
|
+
$$renderer.push("<!--[!-->");
|
|
1200
|
+
$$renderer.push("<!--]-->");
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
$$renderer.push(`<!--]-->`);
|
|
1204
|
+
$$renderer.push(`<!--]-->`);
|
|
1205
|
+
});
|
|
1206
|
+
}
|
|
1207
|
+
node($$renderer, tree, 0);
|
|
1208
|
+
$$renderer.push(`<!----> `);
|
|
1209
|
+
if (mounted) {
|
|
1210
|
+
$$renderer.push(`<!--[0--><div id="svelte-announcer" aria-live="assertive" aria-atomic="true" style="position: absolute; left: 0; top: 0; clip: rect(0 0 0 0); clip-path: inset(50%); overflow: hidden; white-space: nowrap; width: 1px; height: 1px">`);
|
|
1211
|
+
if (navigated) $$renderer.push(`<!--[0-->${escape_html$1(title)}`);
|
|
1212
|
+
else $$renderer.push("<!--[-1-->");
|
|
1213
|
+
$$renderer.push(`<!--]--></div>`);
|
|
1214
|
+
} else $$renderer.push("<!--[-1-->");
|
|
1215
|
+
$$renderer.push(`<!--]-->`);
|
|
1216
|
+
});
|
|
1217
|
+
}
|
|
1218
|
+
//#endregion
|
|
1219
|
+
//#region node_modules/@sveltejs/kit/src/runtime/props.svelte.js
|
|
1220
|
+
var Props = class {
|
|
1221
|
+
/** @type {Page} */
|
|
1222
|
+
page;
|
|
1223
|
+
/**
|
|
1224
|
+
* An array of the `+layout.svelte` and `+page.svelte` component instances
|
|
1225
|
+
* that currently live on the page — used for capturing and restoring snapshots.
|
|
1226
|
+
* It's updated/manipulated through `bind:this` in `Root.svelte`.
|
|
1227
|
+
* @type {Array<Record<string, any>>}
|
|
1228
|
+
* @deprecated only used for `export const snapshot` — TODO 4.0 get rid
|
|
1229
|
+
*/
|
|
1230
|
+
components = [];
|
|
1231
|
+
/** @type {any} */
|
|
1232
|
+
form;
|
|
1233
|
+
/** @type {App.Error | undefined} */
|
|
1234
|
+
error;
|
|
1235
|
+
/** @type {RenderNode} */
|
|
1236
|
+
tree;
|
|
1237
|
+
/** @type {(error: unknown, reset: () => void) => void} */
|
|
1238
|
+
onerror;
|
|
1239
|
+
/**
|
|
1240
|
+
* @param {{
|
|
1241
|
+
* page: Page;
|
|
1242
|
+
* tree: RenderNode;
|
|
1243
|
+
* form: any;
|
|
1244
|
+
* error: App.Error | undefined;
|
|
1245
|
+
* onerror?: (error: unknown, reset: () => void) => void;
|
|
1246
|
+
* }} props
|
|
1247
|
+
*/
|
|
1248
|
+
constructor({ page, tree, form, error, onerror = noop }) {
|
|
1249
|
+
this.page = page;
|
|
1250
|
+
this.tree = tree;
|
|
1251
|
+
this.onerror = onerror;
|
|
1252
|
+
this.form = form;
|
|
1253
|
+
this.error = error;
|
|
1254
|
+
}
|
|
1255
|
+
};
|
|
1256
|
+
var RenderNode = class {
|
|
1257
|
+
/** @type {Component} */
|
|
1258
|
+
component;
|
|
1259
|
+
/** @type {Component | undefined} */
|
|
1260
|
+
error;
|
|
1261
|
+
/** @type {Record<string, any>} */
|
|
1262
|
+
data = {};
|
|
1263
|
+
/** @type {RenderNode | undefined} */
|
|
1264
|
+
child;
|
|
1265
|
+
/**
|
|
1266
|
+
*
|
|
1267
|
+
* @param {Component} component
|
|
1268
|
+
* @param {Component | undefined} error
|
|
1269
|
+
*/
|
|
1270
|
+
constructor(component, error) {
|
|
1271
|
+
this.component = component;
|
|
1272
|
+
this.error = error;
|
|
1273
|
+
}
|
|
1274
|
+
};
|
|
1275
|
+
//#endregion
|
|
1276
|
+
//#region node_modules/@sveltejs/kit/src/runtime/server/page/render.js
|
|
1277
|
+
/** @import { Component } from 'svelte'; */
|
|
1278
|
+
/** @import { SyncRenderOutput } from 'svelte/server' */
|
|
1279
|
+
/**
|
|
1280
|
+
* Creates the HTML response.
|
|
1281
|
+
* @param {{
|
|
1282
|
+
* branch: Array<import('./types.js').Loaded>;
|
|
1283
|
+
* fetched: Array<import('./types.js').Fetched>;
|
|
1284
|
+
* page_config: { ssr: boolean; csr: boolean };
|
|
1285
|
+
* status: number;
|
|
1286
|
+
* error: App.Error | null;
|
|
1287
|
+
* event: import('@sveltejs/kit').RequestEvent;
|
|
1288
|
+
* state: import('types').RequestState;
|
|
1289
|
+
* resolve_opts: import('types').RequiredResolveOptions;
|
|
1290
|
+
* action_result?: import('types').ServerActionResult;
|
|
1291
|
+
* data_serializer: import('./types.js').ServerDataSerializer;
|
|
1292
|
+
* error_components?: Array<import('svelte').Component | undefined>
|
|
1293
|
+
* }} opts
|
|
1294
|
+
*/
|
|
1295
|
+
async function render_response({ branch, fetched, page_config, status, error = null, event, state, resolve_opts, action_result, data_serializer, error_components }) {
|
|
1296
|
+
if (state.prerendering || state.prerender_default === true) {
|
|
1297
|
+
if (options.csp.mode === "nonce") prerender_nonce();
|
|
1298
|
+
if (options.app_template_contains_nonce) prerender_template_nonce({ tag: "%sveltekit.nonce%" });
|
|
1299
|
+
}
|
|
1300
|
+
const client = manifest.client;
|
|
1301
|
+
const modulepreloads = new Set(client?.imports);
|
|
1302
|
+
const stylesheets = new Set(client?.stylesheets);
|
|
1303
|
+
/** @type {Map<string, import('types').FontDependency>} */
|
|
1304
|
+
const fonts = new Map(client?.fonts.map((font) => [font.file, font]));
|
|
1305
|
+
/** @type {Map<string, string>} */
|
|
1306
|
+
const inline_styles = /* @__PURE__ */ new Map();
|
|
1307
|
+
/** @type {Omit<SyncRenderOutput, 'html'>} */
|
|
1308
|
+
let rendered;
|
|
1309
|
+
const form_value = action_result?.type === "success" || action_result?.type === "failure" ? action_result.data ?? null : null;
|
|
1310
|
+
/** @type {string} */
|
|
1311
|
+
let base = "";
|
|
1312
|
+
/** @type {string} */
|
|
1313
|
+
let assets$1 = assets;
|
|
1314
|
+
/**
|
|
1315
|
+
* An expression that will evaluate in the client to determine the resolved base path.
|
|
1316
|
+
* We use a relative path when possible to support IPFS, the internet archive, etc.
|
|
1317
|
+
*/
|
|
1318
|
+
let base_expression = s("");
|
|
1319
|
+
const csp = new Csp(options.csp, { prerender: !!(state.prerendering || state.prerender_default === true) });
|
|
1320
|
+
if (!state.prerendering?.fallback) {
|
|
1321
|
+
const pathname = event.isDataRequest ? add_data_suffix(event.url.pathname) : event.url.pathname;
|
|
1322
|
+
({base, assets: assets$1} = resolve_paths(pathname));
|
|
1323
|
+
base_expression = `new URL(${s(base)}, location).pathname.slice(0, -1)`;
|
|
1324
|
+
}
|
|
1325
|
+
if (page_config.ssr) {
|
|
1326
|
+
const props = new Props({
|
|
1327
|
+
page: {
|
|
1328
|
+
error,
|
|
1329
|
+
params: event.params,
|
|
1330
|
+
route: event.route,
|
|
1331
|
+
status,
|
|
1332
|
+
url: event.url,
|
|
1333
|
+
data: {},
|
|
1334
|
+
form: form_value,
|
|
1335
|
+
shallow: null,
|
|
1336
|
+
state: {}
|
|
1337
|
+
},
|
|
1338
|
+
tree: new RenderNode(await branch[0].node.component?.(), void 0),
|
|
1339
|
+
form: form_value,
|
|
1340
|
+
error: error ?? void 0
|
|
1341
|
+
});
|
|
1342
|
+
let current_node = props.tree;
|
|
1343
|
+
let data = props.page.data;
|
|
1344
|
+
for (let i = 0; i < branch.length; i += 1) {
|
|
1345
|
+
const node = branch[i];
|
|
1346
|
+
data = {
|
|
1347
|
+
...data,
|
|
1348
|
+
...node.data
|
|
1349
|
+
};
|
|
1350
|
+
current_node.data = data;
|
|
1351
|
+
if (i < branch.length - 1) current_node = current_node.child = new RenderNode(await branch[i + 1].node.component?.(), error_components?.[i + 1]);
|
|
1352
|
+
}
|
|
1353
|
+
props.page.data = data;
|
|
1354
|
+
const render_state = {
|
|
1355
|
+
...state,
|
|
1356
|
+
is_in_render: true
|
|
1357
|
+
};
|
|
1358
|
+
const render_opts = {
|
|
1359
|
+
context: /* @__PURE__ */ new Map([["__request__", { page: props.page }]]),
|
|
1360
|
+
csp: csp.script_needs_nonce ? { nonce: csp.nonce } : { hash: csp.script_needs_hash },
|
|
1361
|
+
transformError: error_components ? (e) => {
|
|
1362
|
+
if (isRedirect(e)) throw e;
|
|
1363
|
+
const handled = handle_error_and_jsonify(event, render_state, e);
|
|
1364
|
+
if (handled instanceof Promise) return handled.then((e) => {
|
|
1365
|
+
error = e;
|
|
1366
|
+
props.page.error = error;
|
|
1367
|
+
props.page.status = status = error.status;
|
|
1368
|
+
return error;
|
|
1369
|
+
});
|
|
1370
|
+
error = handled;
|
|
1371
|
+
props.page.error = error;
|
|
1372
|
+
props.page.status = status = error.status;
|
|
1373
|
+
return error;
|
|
1374
|
+
} : void 0
|
|
1375
|
+
};
|
|
1376
|
+
globalThis.fetch;
|
|
1377
|
+
try {
|
|
1378
|
+
rendered = await with_request_store({
|
|
1379
|
+
event,
|
|
1380
|
+
state: render_state
|
|
1381
|
+
}, async () => {
|
|
1382
|
+
return render(Root, {
|
|
1383
|
+
...render_opts,
|
|
1384
|
+
props
|
|
1385
|
+
});
|
|
1386
|
+
});
|
|
1387
|
+
if (rendered.hashes) csp.add_script_hashes(rendered.hashes.script);
|
|
1388
|
+
} finally {}
|
|
1389
|
+
} else rendered = {
|
|
1390
|
+
head: "",
|
|
1391
|
+
body: "",
|
|
1392
|
+
hashes: { script: [] }
|
|
1393
|
+
};
|
|
1394
|
+
for (const { node } of branch) {
|
|
1395
|
+
for (const url of node.imports) modulepreloads.add(url);
|
|
1396
|
+
for (const url of node.stylesheets) stylesheets.add(url);
|
|
1397
|
+
for (const font of node.fonts) fonts.set(font.file, font);
|
|
1398
|
+
if (node.inline_styles && !client?.inline) Object.entries(await node.inline_styles()).forEach(([filename, css]) => {
|
|
1399
|
+
if (typeof css === "string") {
|
|
1400
|
+
inline_styles.set(filename, css);
|
|
1401
|
+
return;
|
|
1402
|
+
}
|
|
1403
|
+
inline_styles.set(filename, css(`${assets$1}/${app_dir}/immutable/assets`, assets$1));
|
|
1404
|
+
});
|
|
1405
|
+
}
|
|
1406
|
+
const head = new Head(rendered.head);
|
|
1407
|
+
let body = rendered.body;
|
|
1408
|
+
/** @param {string} path */
|
|
1409
|
+
const prefixed = (path) => client_path(path, {
|
|
1410
|
+
base,
|
|
1411
|
+
assets: assets$1
|
|
1412
|
+
});
|
|
1413
|
+
const style = client?.inline ? client.inline?.style : Array.from(inline_styles.values()).join("\n");
|
|
1414
|
+
if (style) {
|
|
1415
|
+
const attributes = [];
|
|
1416
|
+
if (csp.style_needs_nonce) attributes.push(`nonce="${csp.nonce}"`);
|
|
1417
|
+
await csp.add_style(style);
|
|
1418
|
+
head.add_style(style, attributes);
|
|
1419
|
+
}
|
|
1420
|
+
/**
|
|
1421
|
+
* see the `output.linkHeaderPreload` option for details on why we have multiple options here
|
|
1422
|
+
* @param {string} path
|
|
1423
|
+
* @param {string[]} attributes
|
|
1424
|
+
*/
|
|
1425
|
+
const add_preload = (path, attributes) => {
|
|
1426
|
+
head.add_link_tag(path, attributes);
|
|
1427
|
+
};
|
|
1428
|
+
for (const dep of stylesheets) {
|
|
1429
|
+
const path = prefixed(dep);
|
|
1430
|
+
const attributes = ["rel=\"stylesheet\""];
|
|
1431
|
+
if (inline_styles.has(dep)) attributes.push("disabled", "media=\"(max-width: 0)\"");
|
|
1432
|
+
head.add_stylesheet(path, attributes);
|
|
1433
|
+
}
|
|
1434
|
+
for (const { file, filename } of fonts.values()) {
|
|
1435
|
+
const path = prefixed(file);
|
|
1436
|
+
if (resolve_opts.preload({
|
|
1437
|
+
type: "font",
|
|
1438
|
+
path,
|
|
1439
|
+
filename
|
|
1440
|
+
})) add_preload(path, [
|
|
1441
|
+
"rel=\"preload\"",
|
|
1442
|
+
"as=\"font\"",
|
|
1443
|
+
`type="font/${file.slice(file.lastIndexOf(".") + 1)}"`,
|
|
1444
|
+
"crossorigin"
|
|
1445
|
+
]);
|
|
1446
|
+
}
|
|
1447
|
+
const global = "__sveltekit_g80ct5";
|
|
1448
|
+
const { data, chunks } = data_serializer.get_data(csp);
|
|
1449
|
+
if (page_config.ssr && page_config.csr) body += `\n\t\t\t${fetched.map((item) => serialize_data(item, resolve_opts.filterSerializedResponseHeaders, !!(state.prerendering || state.prerender_default === true))).join("\n ")}`;
|
|
1450
|
+
if (page_config.csr && client) {
|
|
1451
|
+
const route = client.routes?.find((r) => r.id === event.route.id) ?? null;
|
|
1452
|
+
const load_env_eagerly = client.uses_env_dynamic_public && (state.prerendering || state.prerender_default === true);
|
|
1453
|
+
if (load_env_eagerly) modulepreloads.add(`${app_dir}/env.js`);
|
|
1454
|
+
if (!client.inline) for (const dep of modulepreloads) {
|
|
1455
|
+
const path = prefixed(dep);
|
|
1456
|
+
if (resolve_opts.preload({
|
|
1457
|
+
type: "js",
|
|
1458
|
+
path
|
|
1459
|
+
})) add_preload(path, ["rel=\"modulepreload\""]);
|
|
1460
|
+
}
|
|
1461
|
+
if (client.routes && state.prerendering && !state.prerendering.fallback) {
|
|
1462
|
+
const pathname = add_resolution_suffix(event.url.pathname);
|
|
1463
|
+
state.prerendering.dependencies.set(pathname, create_server_routing_response(route, event.params, new URL(pathname, event.url), client));
|
|
1464
|
+
if (route && !state.prerendering.resolved_route_ids.has(route.id)) {
|
|
1465
|
+
state.prerendering.resolved_route_ids.add(route.id);
|
|
1466
|
+
const id_pathname = "" + route_id_resolution_pathname(route.id);
|
|
1467
|
+
state.prerendering.dependencies.set(id_pathname, create_server_routing_response(route, null, new URL(id_pathname, event.url), client));
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
const blocks = [];
|
|
1471
|
+
const properties = [`base: ${base_expression}`, `version: ${s("1791433154666")}`];
|
|
1472
|
+
if (assets) properties.push(`assets: ${s(assets)}`);
|
|
1473
|
+
if (client.uses_env_dynamic_public) properties.push(`env: ${load_env_eagerly ? "null" : uneval$1(rendered_env)}`);
|
|
1474
|
+
if (chunks) {
|
|
1475
|
+
blocks.push("const deferred = new Map();");
|
|
1476
|
+
properties.push(`defer: (id) => new Promise((fulfil, reject) => {
|
|
1477
|
+
deferred.set(id, { fulfil, reject });
|
|
1478
|
+
})`);
|
|
1479
|
+
let app_declaration = "";
|
|
1480
|
+
if (has_custom_transporters) {
|
|
1481
|
+
if (client.inline) app_declaration = `const app = ${global}.app.app;`;
|
|
1482
|
+
else if (client.app) app_declaration = `const kit = await import(${s(prefixed(client.start))});
|
|
1483
|
+
kit.init(${global});
|
|
1484
|
+
const app = await import(${s(prefixed(client.app))});`;
|
|
1485
|
+
else app_declaration = `const { app } = await import(${s(prefixed(client.start))});`;
|
|
1486
|
+
}
|
|
1487
|
+
const prelude = app_declaration ? `${app_declaration}
|
|
1488
|
+
const [data, error] = fn(app);` : `const [data, error] = fn();`;
|
|
1489
|
+
properties.push(`resolve: async (id, fn) => {
|
|
1490
|
+
${prelude}
|
|
1491
|
+
|
|
1492
|
+
const try_to_resolve = () => {
|
|
1493
|
+
if (!deferred.has(id)) {
|
|
1494
|
+
setTimeout(try_to_resolve, 0);
|
|
1495
|
+
return;
|
|
1496
|
+
}
|
|
1497
|
+
const { fulfil, reject } = deferred.get(id);
|
|
1498
|
+
deferred.delete(id);
|
|
1499
|
+
if (error) reject(error);
|
|
1500
|
+
else fulfil(data);
|
|
1501
|
+
}
|
|
1502
|
+
try_to_resolve();
|
|
1503
|
+
}`);
|
|
1504
|
+
}
|
|
1505
|
+
blocks.push(`${global} = {
|
|
1506
|
+
${properties.join(",\n ")}
|
|
1507
|
+
};`);
|
|
1508
|
+
const args = ["element"];
|
|
1509
|
+
blocks.push("const element = document.currentScript.parentElement;");
|
|
1510
|
+
if (page_config.ssr) {
|
|
1511
|
+
const serialized = {
|
|
1512
|
+
form: "null",
|
|
1513
|
+
error: "null"
|
|
1514
|
+
};
|
|
1515
|
+
if (form_value) serialized.form = uneval_action_response(form_value, event.route.id);
|
|
1516
|
+
if (error) serialized.error = uneval$1(error);
|
|
1517
|
+
const hydrate = [
|
|
1518
|
+
`node_ids: [${branch.map(({ node }) => node.index).join(", ")}]`,
|
|
1519
|
+
`data: ${data}`,
|
|
1520
|
+
`form: ${serialized.form}`,
|
|
1521
|
+
`error: ${serialized.error}`
|
|
1522
|
+
];
|
|
1523
|
+
if (status !== 200 && !error) hydrate.push(`status: ${status}`);
|
|
1524
|
+
if (client.routes) {
|
|
1525
|
+
if (route) {
|
|
1526
|
+
const stringified = generate_route_object(route, event.url, client).replaceAll("\n", "\n ");
|
|
1527
|
+
hydrate.push(`params: ${uneval$1(event.params)}`, `server_route: ${stringified}`);
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
const indent = " ".repeat(load_env_eagerly ? 7 : 6);
|
|
1531
|
+
args.push(`{\n${indent}\t${hydrate.join(`,\n${indent}\t`)}\n${indent}}`);
|
|
1532
|
+
}
|
|
1533
|
+
const remote_data = await collect_remote_data({}, event, state);
|
|
1534
|
+
const serialized_data = Object.keys(remote_data).length > 0 ? `${global}.data = ${uneval(remote_data)};\n\n\t\t\t\t\t\t` : "";
|
|
1535
|
+
const boot = client.inline ? `${client.inline.script}
|
|
1536
|
+
|
|
1537
|
+
${serialized_data}${global}.app.start(${args.join(", ")});` : client.app ? `import(${s(prefixed(client.start))}).then(async (kit) => {
|
|
1538
|
+
kit.init(${global});
|
|
1539
|
+
const app = await import(${s(prefixed(client.app))});
|
|
1540
|
+
${serialized_data}kit.start(app, ${args.join(", ")});
|
|
1541
|
+
});` : `import(${s(prefixed(client.start))}).then((app) => {
|
|
1542
|
+
${serialized_data}app.start(${args.join(", ")})
|
|
1543
|
+
});`;
|
|
1544
|
+
if (load_env_eagerly) blocks.push(`import(${s(`${base}/${app_dir}/env.js`)}).then(({ env }) => {
|
|
1545
|
+
${global}.env = env;
|
|
1546
|
+
|
|
1547
|
+
${boot.replace(/\n/g, "\n ")}
|
|
1548
|
+
});`);
|
|
1549
|
+
else blocks.push(boot);
|
|
1550
|
+
const init_app = `
|
|
1551
|
+
{
|
|
1552
|
+
${blocks.join("\n\n ")}
|
|
1553
|
+
}
|
|
1554
|
+
`;
|
|
1555
|
+
await csp.add_script(init_app);
|
|
1556
|
+
body += `\n\t\t\t<script${csp.script_needs_nonce ? ` nonce="${csp.nonce}"` : ""}>${init_app}<\/script>\n\t\t`;
|
|
1557
|
+
}
|
|
1558
|
+
const headers = new Headers({
|
|
1559
|
+
"x-sveltekit-page": "true",
|
|
1560
|
+
"content-type": "text/html"
|
|
1561
|
+
});
|
|
1562
|
+
if (state.prerendering || state.prerender_default === true) {
|
|
1563
|
+
const csp_headers = csp.csp_provider.get_meta();
|
|
1564
|
+
if (csp_headers) head.add_http_equiv(csp_headers);
|
|
1565
|
+
if (state.prerendering?.cache) head.add_http_equiv(`<meta http-equiv="cache-control" content="${escape_html(state.prerendering.cache, true)}">`);
|
|
1566
|
+
} else {
|
|
1567
|
+
const csp_header = csp.csp_provider.get_header();
|
|
1568
|
+
if (csp_header) headers.set("content-security-policy", csp_header);
|
|
1569
|
+
const report_only_header = csp.report_only_provider.get_header();
|
|
1570
|
+
if (report_only_header) headers.set("content-security-policy-report-only", report_only_header);
|
|
1571
|
+
}
|
|
1572
|
+
const html = options.templates.app({
|
|
1573
|
+
head: head.build(),
|
|
1574
|
+
body,
|
|
1575
|
+
assets: assets$1,
|
|
1576
|
+
nonce: csp.nonce,
|
|
1577
|
+
env: explicit_public_env
|
|
1578
|
+
});
|
|
1579
|
+
const transformed = await resolve_opts.transformPageChunk({
|
|
1580
|
+
html,
|
|
1581
|
+
done: true
|
|
1582
|
+
}) || "";
|
|
1583
|
+
if (!chunks) headers.set("etag", `"${hash(transformed)}"`);
|
|
1584
|
+
return chunks ? new Response(stream_text(transformed + "\n", chunks), {
|
|
1585
|
+
status,
|
|
1586
|
+
headers
|
|
1587
|
+
}) : text(transformed, {
|
|
1588
|
+
status,
|
|
1589
|
+
headers
|
|
1590
|
+
});
|
|
1591
|
+
}
|
|
1592
|
+
var Head = class {
|
|
1593
|
+
#rendered;
|
|
1594
|
+
/** @type {string[]} */
|
|
1595
|
+
#http_equiv = [];
|
|
1596
|
+
/** @type {string[]} */
|
|
1597
|
+
#link_tags = [];
|
|
1598
|
+
/** @type {string[]} */
|
|
1599
|
+
#style_tags = [];
|
|
1600
|
+
/** @type {string[]} */
|
|
1601
|
+
#stylesheet_links = [];
|
|
1602
|
+
/**
|
|
1603
|
+
* @param {string} rendered
|
|
1604
|
+
*/
|
|
1605
|
+
constructor(rendered) {
|
|
1606
|
+
this.#rendered = rendered;
|
|
1607
|
+
}
|
|
1608
|
+
build() {
|
|
1609
|
+
return [
|
|
1610
|
+
...this.#http_equiv,
|
|
1611
|
+
...this.#link_tags,
|
|
1612
|
+
this.#rendered,
|
|
1613
|
+
...this.#style_tags,
|
|
1614
|
+
...this.#stylesheet_links
|
|
1615
|
+
].join("\n ");
|
|
1616
|
+
}
|
|
1617
|
+
/**
|
|
1618
|
+
* @param {string} style
|
|
1619
|
+
* @param {string[]} attributes
|
|
1620
|
+
*/
|
|
1621
|
+
add_style(style, attributes) {
|
|
1622
|
+
this.#style_tags.push(`<style${attributes.length ? " " + attributes.join(" ") : ""}>${style}</style>`);
|
|
1623
|
+
}
|
|
1624
|
+
/**
|
|
1625
|
+
* @param {string} href
|
|
1626
|
+
* @param {string[]} attributes
|
|
1627
|
+
*/
|
|
1628
|
+
add_stylesheet(href, attributes) {
|
|
1629
|
+
this.#stylesheet_links.push(`<link href="${href}" ${attributes.join(" ")}>`);
|
|
1630
|
+
}
|
|
1631
|
+
/**
|
|
1632
|
+
* @param {string} href
|
|
1633
|
+
* @param {string[]} attributes
|
|
1634
|
+
*/
|
|
1635
|
+
add_link_tag(href, attributes) {
|
|
1636
|
+
this.#link_tags.push(`<link href="${href}" ${attributes.join(" ")}>`);
|
|
1637
|
+
}
|
|
1638
|
+
/** @param {string} tag */
|
|
1639
|
+
add_http_equiv(tag) {
|
|
1640
|
+
this.#http_equiv.push(tag);
|
|
1641
|
+
}
|
|
1642
|
+
};
|
|
1643
|
+
//#endregion
|
|
1644
|
+
//#region node_modules/@sveltejs/kit/src/utils/format.js
|
|
1645
|
+
/**
|
|
1646
|
+
* Joins a list as `a`, `a or b` or `a, b or c`, for use in diagnostics
|
|
1647
|
+
* @param {string[]} items
|
|
1648
|
+
*/
|
|
1649
|
+
function join_or(items) {
|
|
1650
|
+
return items.length > 1 ? `${items.slice(0, -1).join(", ")} or ${items.at(-1)}` : items[0];
|
|
1651
|
+
}
|
|
1652
|
+
//#endregion
|
|
1653
|
+
//#region node_modules/@sveltejs/kit/src/utils/exports.js
|
|
1654
|
+
/**
|
|
1655
|
+
* @param {Set<string>} expected
|
|
1656
|
+
*/
|
|
1657
|
+
function validator(expected) {
|
|
1658
|
+
/**
|
|
1659
|
+
* @param {any} module
|
|
1660
|
+
* @param {string} [file]
|
|
1661
|
+
*/
|
|
1662
|
+
function validate(module, file) {
|
|
1663
|
+
if (!module) return;
|
|
1664
|
+
for (const key in module) {
|
|
1665
|
+
if (key[0] === "_" || expected.has(key)) continue;
|
|
1666
|
+
const locations = valid_locations(key, file?.slice(file.lastIndexOf(".")));
|
|
1667
|
+
if (locations.length > 0) invalid_export_location({
|
|
1668
|
+
key,
|
|
1669
|
+
locations: join_or(locations),
|
|
1670
|
+
file: file || void 0
|
|
1671
|
+
});
|
|
1672
|
+
invalid_export({
|
|
1673
|
+
key,
|
|
1674
|
+
exports: [...expected.values()].join(", "),
|
|
1675
|
+
file: file || void 0
|
|
1676
|
+
});
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
return validate;
|
|
1680
|
+
}
|
|
1681
|
+
/**
|
|
1682
|
+
* Returns the route files in which `key` is a valid export
|
|
1683
|
+
* @param {string} key
|
|
1684
|
+
* @param {string} ext
|
|
1685
|
+
* @returns {string[]}
|
|
1686
|
+
*/
|
|
1687
|
+
function valid_locations(key, ext = ".js") {
|
|
1688
|
+
const locations = [];
|
|
1689
|
+
if (valid_layout_exports.has(key)) locations.push(`+layout${ext}`);
|
|
1690
|
+
if (valid_page_exports.has(key)) locations.push(`+page${ext}`);
|
|
1691
|
+
if (valid_layout_server_exports.has(key)) locations.push(`+layout.server${ext}`);
|
|
1692
|
+
if (valid_page_server_exports.has(key)) locations.push(`+page.server${ext}`);
|
|
1693
|
+
if (valid_server_exports.has(key)) locations.push(`+server${ext}`);
|
|
1694
|
+
return locations;
|
|
1695
|
+
}
|
|
1696
|
+
var valid_layout_exports = /* @__PURE__ */ new Set([
|
|
1697
|
+
"load",
|
|
1698
|
+
"prerender",
|
|
1699
|
+
"csr",
|
|
1700
|
+
"ssr",
|
|
1701
|
+
"trailingSlash",
|
|
1702
|
+
"config"
|
|
1703
|
+
]);
|
|
1704
|
+
var valid_page_exports = /* @__PURE__ */ new Set([...valid_layout_exports, "entries"]);
|
|
1705
|
+
var valid_layout_server_exports = /* @__PURE__ */ new Set([...valid_layout_exports]);
|
|
1706
|
+
var valid_page_server_exports = /* @__PURE__ */ new Set([
|
|
1707
|
+
...valid_layout_server_exports,
|
|
1708
|
+
"actions",
|
|
1709
|
+
"entries"
|
|
1710
|
+
]);
|
|
1711
|
+
var valid_server_exports = /* @__PURE__ */ new Set([
|
|
1712
|
+
"GET",
|
|
1713
|
+
"POST",
|
|
1714
|
+
"PATCH",
|
|
1715
|
+
"PUT",
|
|
1716
|
+
"DELETE",
|
|
1717
|
+
"OPTIONS",
|
|
1718
|
+
"HEAD",
|
|
1719
|
+
"QUERY",
|
|
1720
|
+
"fallback",
|
|
1721
|
+
"prerender",
|
|
1722
|
+
"trailingSlash",
|
|
1723
|
+
"config",
|
|
1724
|
+
"entries"
|
|
1725
|
+
]);
|
|
1726
|
+
var validate_layout_exports = validator(valid_layout_exports);
|
|
1727
|
+
var validate_page_exports = validator(valid_page_exports);
|
|
1728
|
+
var validate_layout_server_exports = validator(valid_layout_server_exports);
|
|
1729
|
+
var validate_page_server_exports = validator(valid_page_server_exports);
|
|
1730
|
+
//#endregion
|
|
1731
|
+
//#region node_modules/@sveltejs/kit/src/utils/page_nodes.js
|
|
1732
|
+
/** @import { UniversalNode, ServerNode } from 'types' */
|
|
1733
|
+
var PageNodes = class {
|
|
1734
|
+
/** All layout nodes and the page node, if any */
|
|
1735
|
+
data;
|
|
1736
|
+
/**
|
|
1737
|
+
* @param {Array<import('types').SSRNode | undefined>} nodes
|
|
1738
|
+
*/
|
|
1739
|
+
constructor(nodes) {
|
|
1740
|
+
this.data = nodes;
|
|
1741
|
+
}
|
|
1742
|
+
layouts() {
|
|
1743
|
+
return this.data.slice(0, -1);
|
|
1744
|
+
}
|
|
1745
|
+
page() {
|
|
1746
|
+
return this.data.at(-1);
|
|
1747
|
+
}
|
|
1748
|
+
validate() {
|
|
1749
|
+
for (const layout of this.layouts()) if (layout) {
|
|
1750
|
+
validate_layout_server_exports(layout.server, layout.server_id);
|
|
1751
|
+
validate_layout_exports(layout.universal, layout.universal_id);
|
|
1752
|
+
}
|
|
1753
|
+
const page = this.page();
|
|
1754
|
+
if (page) {
|
|
1755
|
+
validate_page_server_exports(page.server, page.server_id);
|
|
1756
|
+
validate_page_exports(page.universal, page.universal_id);
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1759
|
+
/**
|
|
1760
|
+
* @template {'prerender' | 'ssr' | 'csr' | 'trailingSlash'} Option
|
|
1761
|
+
* @param {Option} option
|
|
1762
|
+
* @returns {(UniversalNode | ServerNode)[Option] | undefined}
|
|
1763
|
+
*/
|
|
1764
|
+
#get_option(option) {
|
|
1765
|
+
/** @typedef {(UniversalNode | ServerNode)[Option]} Value */
|
|
1766
|
+
return this.data.reduce((value, node) => {
|
|
1767
|
+
return node?.universal?.[option] ?? node?.server?.[option] ?? value;
|
|
1768
|
+
}, void 0);
|
|
1769
|
+
}
|
|
1770
|
+
csr() {
|
|
1771
|
+
return this.#get_option("csr") ?? true;
|
|
1772
|
+
}
|
|
1773
|
+
ssr() {
|
|
1774
|
+
return this.#get_option("ssr") ?? true;
|
|
1775
|
+
}
|
|
1776
|
+
prerender() {
|
|
1777
|
+
return this.#get_option("prerender") ?? false;
|
|
1778
|
+
}
|
|
1779
|
+
trailing_slash() {
|
|
1780
|
+
return this.#get_option("trailingSlash") ?? "never";
|
|
1781
|
+
}
|
|
1782
|
+
get_config() {
|
|
1783
|
+
/** @type {Record<string, any>} */
|
|
1784
|
+
let current = {};
|
|
1785
|
+
for (const node of this.data) {
|
|
1786
|
+
if (!node?.universal?.config && !node?.server?.config) continue;
|
|
1787
|
+
current = {
|
|
1788
|
+
...current,
|
|
1789
|
+
...node?.server?.config,
|
|
1790
|
+
...node?.universal?.config
|
|
1791
|
+
};
|
|
1792
|
+
}
|
|
1793
|
+
return Object.keys(current).length ? current : void 0;
|
|
1794
|
+
}
|
|
1795
|
+
should_prerender_data() {
|
|
1796
|
+
return this.data.some((node) => node?.server?.load || node?.server?.trailingSlash !== void 0);
|
|
1797
|
+
}
|
|
1798
|
+
};
|
|
1799
|
+
//#endregion
|
|
1800
|
+
//#region node_modules/@sveltejs/kit/src/runtime/server/page/respond_with_error.js
|
|
1801
|
+
/**
|
|
1802
|
+
* @typedef {import('./types.js').Loaded} Loaded
|
|
1803
|
+
*/
|
|
1804
|
+
/**
|
|
1805
|
+
* @param {{
|
|
1806
|
+
* event: import('@sveltejs/kit').RequestEvent;
|
|
1807
|
+
* state: import('types').RequestState;
|
|
1808
|
+
* error: unknown;
|
|
1809
|
+
* resolve_opts: import('types').RequiredResolveOptions;
|
|
1810
|
+
* }} opts
|
|
1811
|
+
*/
|
|
1812
|
+
async function respond_with_error({ event, state, error, resolve_opts }) {
|
|
1813
|
+
if (event.request.headers.get("x-sveltekit-error")) {
|
|
1814
|
+
const transformed = await handle_error_and_jsonify(event, state, error);
|
|
1815
|
+
return static_error_page(transformed.status, transformed.message);
|
|
1816
|
+
}
|
|
1817
|
+
/** @type {import('./types.js').Fetched[]} */
|
|
1818
|
+
const fetched = [];
|
|
1819
|
+
try {
|
|
1820
|
+
const branch = [];
|
|
1821
|
+
const default_layout = await manifest.nodes[0]();
|
|
1822
|
+
const nodes = new PageNodes([default_layout]);
|
|
1823
|
+
const ssr = nodes.ssr();
|
|
1824
|
+
const csr = nodes.csr();
|
|
1825
|
+
const data_serializer = server_data_serializer(event, state);
|
|
1826
|
+
const transformed = await handle_error_and_jsonify(event, state, error);
|
|
1827
|
+
if (ssr) {
|
|
1828
|
+
state.error = true;
|
|
1829
|
+
const server_data_promise = load_server_data({
|
|
1830
|
+
event,
|
|
1831
|
+
state,
|
|
1832
|
+
node: default_layout,
|
|
1833
|
+
parent: async () => ({})
|
|
1834
|
+
});
|
|
1835
|
+
const server_data = await server_data_promise;
|
|
1836
|
+
data_serializer.add_node(0, server_data);
|
|
1837
|
+
const data = await load_data({
|
|
1838
|
+
event,
|
|
1839
|
+
state,
|
|
1840
|
+
fetched,
|
|
1841
|
+
node: default_layout,
|
|
1842
|
+
parent: async () => ({}),
|
|
1843
|
+
resolve_opts,
|
|
1844
|
+
server_data_promise,
|
|
1845
|
+
csr
|
|
1846
|
+
});
|
|
1847
|
+
branch.push({
|
|
1848
|
+
node: default_layout,
|
|
1849
|
+
server_data,
|
|
1850
|
+
data
|
|
1851
|
+
}, {
|
|
1852
|
+
node: await manifest.nodes[1](),
|
|
1853
|
+
data: null,
|
|
1854
|
+
server_data: null
|
|
1855
|
+
});
|
|
1856
|
+
}
|
|
1857
|
+
return await render_response({
|
|
1858
|
+
page_config: {
|
|
1859
|
+
ssr,
|
|
1860
|
+
csr
|
|
1861
|
+
},
|
|
1862
|
+
status: transformed.status,
|
|
1863
|
+
error: transformed,
|
|
1864
|
+
branch,
|
|
1865
|
+
error_components: [],
|
|
1866
|
+
fetched,
|
|
1867
|
+
event,
|
|
1868
|
+
state,
|
|
1869
|
+
resolve_opts,
|
|
1870
|
+
data_serializer
|
|
1871
|
+
});
|
|
1872
|
+
} catch (e) {
|
|
1873
|
+
if (e instanceof Redirect) return redirect_response(e.status, e.location);
|
|
1874
|
+
const transformed = await handle_error_and_jsonify(event, state, e);
|
|
1875
|
+
return static_error_page(transformed.status, transformed.message);
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
/**
|
|
1879
|
+
* Return as a response that renders the error.html
|
|
1880
|
+
*
|
|
1881
|
+
* @param {number} status
|
|
1882
|
+
* @param {string} message
|
|
1883
|
+
*/
|
|
1884
|
+
function static_error_page(status, message) {
|
|
1885
|
+
let page = options.templates.error({
|
|
1886
|
+
status,
|
|
1887
|
+
message: escape_html(message)
|
|
1888
|
+
});
|
|
1889
|
+
return text(page, {
|
|
1890
|
+
headers: { "content-type": "text/html; charset=utf-8" },
|
|
1891
|
+
status
|
|
1892
|
+
});
|
|
1893
|
+
}
|
|
1894
|
+
/**
|
|
1895
|
+
* @param {import('@sveltejs/kit').RequestEvent} event
|
|
1896
|
+
* @param {import('types').RequestState} state
|
|
1897
|
+
* @param {unknown} error
|
|
1898
|
+
*/
|
|
1899
|
+
async function handle_fatal_error(event, state, error) {
|
|
1900
|
+
const body = await handle_error_and_jsonify(event, state, error);
|
|
1901
|
+
const status = body.status;
|
|
1902
|
+
const type = negotiate(event.request.headers.get("accept") || "text/html", ["application/json", "text/html"]);
|
|
1903
|
+
if (event.isDataRequest || type === "application/json") return Response.json(body, { status });
|
|
1904
|
+
return static_error_page(status, body.message);
|
|
1905
|
+
}
|
|
1906
|
+
//#endregion
|
|
1907
|
+
//#region node_modules/@sveltejs/kit/src/runtime/server/page/index.js
|
|
1908
|
+
/** @import { RequestEvent } from '@sveltejs/kit' */
|
|
1909
|
+
/** @import { PageNodeIndexes, RequestState, RequiredResolveOptions, ServerDataNode, SSRNode } from 'types' */
|
|
1910
|
+
/**
|
|
1911
|
+
* The maximum request depth permitted before assuming we're stuck in an infinite loop
|
|
1912
|
+
*/
|
|
1913
|
+
var MAX_DEPTH = 10;
|
|
1914
|
+
/**
|
|
1915
|
+
* @param {RequestEvent} event
|
|
1916
|
+
* @param {RequestState} state
|
|
1917
|
+
* @param {PageNodeIndexes} page
|
|
1918
|
+
* @param {import('../../../utils/page_nodes.js').PageNodes} nodes
|
|
1919
|
+
* @param {RequiredResolveOptions} resolve_opts
|
|
1920
|
+
* @returns {Promise<Response>}
|
|
1921
|
+
*/
|
|
1922
|
+
async function render_page(event, state, page, nodes, resolve_opts) {
|
|
1923
|
+
if (state.depth > MAX_DEPTH) return text(`Not found: ${event.url.pathname}`, { status: 404 });
|
|
1924
|
+
if (is_action_json_request(event)) {
|
|
1925
|
+
const node = await manifest.nodes[page.leaf]();
|
|
1926
|
+
return handle_action_json_request(event, state, node?.server);
|
|
1927
|
+
}
|
|
1928
|
+
try {
|
|
1929
|
+
const leaf_node = nodes.page();
|
|
1930
|
+
let status = 200;
|
|
1931
|
+
/** @type {import('types').ServerActionResult | undefined} */
|
|
1932
|
+
let action_result = void 0;
|
|
1933
|
+
if (is_action_request(event)) {
|
|
1934
|
+
const remote_id = get_remote_action(event.url);
|
|
1935
|
+
if (remote_id) action_result = await handle_remote_form_post(event, state, remote_id);
|
|
1936
|
+
else action_result = await handle_action_request(event, state, leaf_node.server);
|
|
1937
|
+
if (action_result?.type === "redirect") return redirect_response(action_result.status, action_result.location);
|
|
1938
|
+
if (action_result?.type === "error") status = get_status(action_result.error);
|
|
1939
|
+
if (action_result?.type === "failure") status = action_result.status;
|
|
1940
|
+
}
|
|
1941
|
+
const should_prerender = nodes.prerender();
|
|
1942
|
+
if (should_prerender) {
|
|
1943
|
+
if (leaf_node.server?.actions) prerender_actions();
|
|
1944
|
+
} else if (state.prerendering) return new Response(void 0, { status: 204 });
|
|
1945
|
+
state.prerender_default = should_prerender;
|
|
1946
|
+
const should_prerender_data = nodes.should_prerender_data();
|
|
1947
|
+
const data_pathname = add_data_suffix(event.url.pathname);
|
|
1948
|
+
/** @type {import('./types.js').Fetched[]} */
|
|
1949
|
+
const fetched = [];
|
|
1950
|
+
const ssr = nodes.ssr();
|
|
1951
|
+
const csr = nodes.csr();
|
|
1952
|
+
if (ssr === false && !((state.prerendering || state.prerender_default === true) && should_prerender_data)) return await render_response({
|
|
1953
|
+
branch: compact(nodes.data).map((node) => {
|
|
1954
|
+
return {
|
|
1955
|
+
node,
|
|
1956
|
+
data: null,
|
|
1957
|
+
server_data: null
|
|
1958
|
+
};
|
|
1959
|
+
}),
|
|
1960
|
+
fetched,
|
|
1961
|
+
page_config: {
|
|
1962
|
+
ssr: false,
|
|
1963
|
+
csr
|
|
1964
|
+
},
|
|
1965
|
+
status,
|
|
1966
|
+
error: null,
|
|
1967
|
+
event,
|
|
1968
|
+
state,
|
|
1969
|
+
resolve_opts,
|
|
1970
|
+
data_serializer: server_data_serializer(event, state)
|
|
1971
|
+
});
|
|
1972
|
+
/** @type {Array<import('./types.js').Loaded | null>} */
|
|
1973
|
+
const branch = [];
|
|
1974
|
+
/** @type {Error | null} */
|
|
1975
|
+
let load_error = null;
|
|
1976
|
+
const data_serializer = server_data_serializer(event, state);
|
|
1977
|
+
const data_serializer_json = (state.prerendering || state.prerender_default === true) && should_prerender_data ? server_data_serializer_json(event, state) : null;
|
|
1978
|
+
/** @type {Array<Promise<ServerDataNode | null>>} */
|
|
1979
|
+
const server_promises = nodes.data.map((node, i) => {
|
|
1980
|
+
if (load_error) throw load_error;
|
|
1981
|
+
return Promise.resolve().then(async () => {
|
|
1982
|
+
try {
|
|
1983
|
+
if (node === leaf_node && action_result?.type === "error") throw action_result.error;
|
|
1984
|
+
const server_data = await load_server_data({
|
|
1985
|
+
event,
|
|
1986
|
+
state,
|
|
1987
|
+
node,
|
|
1988
|
+
parent: async () => {
|
|
1989
|
+
/** @type {Record<string, any>} */
|
|
1990
|
+
const data = {};
|
|
1991
|
+
for (let j = 0; j < i; j += 1) {
|
|
1992
|
+
const parent = await server_promises[j];
|
|
1993
|
+
if (parent) Object.assign(data, parent.data);
|
|
1994
|
+
}
|
|
1995
|
+
return data;
|
|
1996
|
+
}
|
|
1997
|
+
});
|
|
1998
|
+
if (node) data_serializer.add_node(i, server_data);
|
|
1999
|
+
data_serializer_json?.add_node(i, server_data);
|
|
2000
|
+
return server_data;
|
|
2001
|
+
} catch (e) {
|
|
2002
|
+
load_error = e;
|
|
2003
|
+
throw load_error;
|
|
2004
|
+
}
|
|
2005
|
+
});
|
|
2006
|
+
});
|
|
2007
|
+
/** @type {Array<Promise<Record<string, any> | null>>} */
|
|
2008
|
+
const load_promises = nodes.data.map((node, i) => {
|
|
2009
|
+
if (load_error) throw load_error;
|
|
2010
|
+
return Promise.resolve().then(async () => {
|
|
2011
|
+
try {
|
|
2012
|
+
return await load_data({
|
|
2013
|
+
event,
|
|
2014
|
+
state,
|
|
2015
|
+
fetched,
|
|
2016
|
+
node,
|
|
2017
|
+
parent: async () => {
|
|
2018
|
+
const data = {};
|
|
2019
|
+
for (let j = 0; j < i; j += 1) Object.assign(data, await load_promises[j]);
|
|
2020
|
+
return data;
|
|
2021
|
+
},
|
|
2022
|
+
resolve_opts,
|
|
2023
|
+
server_data_promise: server_promises[i],
|
|
2024
|
+
csr
|
|
2025
|
+
});
|
|
2026
|
+
} catch (e) {
|
|
2027
|
+
load_error = e;
|
|
2028
|
+
throw load_error;
|
|
2029
|
+
}
|
|
2030
|
+
});
|
|
2031
|
+
});
|
|
2032
|
+
for (const p of server_promises) p.catch(noop);
|
|
2033
|
+
for (const p of load_promises) p.catch(noop);
|
|
2034
|
+
for (let i = 0; i < nodes.data.length; i += 1) {
|
|
2035
|
+
const node = nodes.data[i];
|
|
2036
|
+
if (node) try {
|
|
2037
|
+
const server_data = await server_promises[i];
|
|
2038
|
+
const data = await load_promises[i];
|
|
2039
|
+
branch.push({
|
|
2040
|
+
node,
|
|
2041
|
+
server_data,
|
|
2042
|
+
data
|
|
2043
|
+
});
|
|
2044
|
+
} catch (e) {
|
|
2045
|
+
const err = normalize_error(e);
|
|
2046
|
+
if (err instanceof Redirect) {
|
|
2047
|
+
if (state.prerendering && should_prerender_data) {
|
|
2048
|
+
const body = JSON.stringify({
|
|
2049
|
+
type: "redirect",
|
|
2050
|
+
status: err.status,
|
|
2051
|
+
location: err.location
|
|
2052
|
+
});
|
|
2053
|
+
state.prerendering.dependencies.set(data_pathname, {
|
|
2054
|
+
response: text(body),
|
|
2055
|
+
body
|
|
2056
|
+
});
|
|
2057
|
+
}
|
|
2058
|
+
return redirect_response(err.status, err.location);
|
|
2059
|
+
}
|
|
2060
|
+
const error = await handle_error_and_jsonify(event, state, err);
|
|
2061
|
+
const status = error.status;
|
|
2062
|
+
for (const { error: index, idx } of nearest_error_pages(i, branch, page.errors)) {
|
|
2063
|
+
const node = await manifest.nodes[index]();
|
|
2064
|
+
data_serializer.set_max_nodes(idx);
|
|
2065
|
+
const layouts = compact(branch.slice(0, idx));
|
|
2066
|
+
const nodes = new PageNodes(layouts.map((layout) => layout.node));
|
|
2067
|
+
const error_branch = layouts.concat({
|
|
2068
|
+
node,
|
|
2069
|
+
data: null,
|
|
2070
|
+
server_data: null
|
|
2071
|
+
});
|
|
2072
|
+
return await render_response({
|
|
2073
|
+
event,
|
|
2074
|
+
state,
|
|
2075
|
+
resolve_opts,
|
|
2076
|
+
page_config: {
|
|
2077
|
+
ssr: nodes.ssr(),
|
|
2078
|
+
csr: nodes.csr()
|
|
2079
|
+
},
|
|
2080
|
+
status,
|
|
2081
|
+
error,
|
|
2082
|
+
error_components: await load_error_components(ssr, error_branch, page),
|
|
2083
|
+
branch: error_branch,
|
|
2084
|
+
fetched,
|
|
2085
|
+
data_serializer
|
|
2086
|
+
});
|
|
2087
|
+
}
|
|
2088
|
+
return static_error_page(status, error.message);
|
|
2089
|
+
}
|
|
2090
|
+
else branch.push(null);
|
|
2091
|
+
}
|
|
2092
|
+
if (state.prerendering && data_serializer_json) {
|
|
2093
|
+
let { data, chunks } = data_serializer_json.get_data();
|
|
2094
|
+
if (chunks) for await (const chunk of chunks) data += chunk;
|
|
2095
|
+
state.prerendering.dependencies.set(data_pathname, {
|
|
2096
|
+
response: text(data),
|
|
2097
|
+
body: data
|
|
2098
|
+
});
|
|
2099
|
+
}
|
|
2100
|
+
return await render_response({
|
|
2101
|
+
event,
|
|
2102
|
+
state,
|
|
2103
|
+
resolve_opts,
|
|
2104
|
+
page_config: {
|
|
2105
|
+
csr,
|
|
2106
|
+
ssr
|
|
2107
|
+
},
|
|
2108
|
+
status,
|
|
2109
|
+
error: null,
|
|
2110
|
+
branch: compact(branch),
|
|
2111
|
+
action_result,
|
|
2112
|
+
fetched,
|
|
2113
|
+
data_serializer: !ssr ? server_data_serializer(event, state) : data_serializer,
|
|
2114
|
+
error_components: await load_error_components(ssr, branch, page)
|
|
2115
|
+
});
|
|
2116
|
+
} catch (e) {
|
|
2117
|
+
if (e instanceof Redirect) return redirect_response(e.status, e.location);
|
|
2118
|
+
return await respond_with_error({
|
|
2119
|
+
event,
|
|
2120
|
+
state,
|
|
2121
|
+
error: e,
|
|
2122
|
+
resolve_opts
|
|
2123
|
+
});
|
|
2124
|
+
}
|
|
2125
|
+
}
|
|
2126
|
+
/**
|
|
2127
|
+
* @param {boolean} ssr
|
|
2128
|
+
* @param {Array<import('./types.js').Loaded | null>} branch
|
|
2129
|
+
* @param {PageNodeIndexes} page
|
|
2130
|
+
*/
|
|
2131
|
+
function load_error_components(ssr, branch, page) {
|
|
2132
|
+
if (!ssr) return void 0;
|
|
2133
|
+
return build_error_chain(branch, page.errors, (idx) => manifest.nodes[idx]?.().then((e) => e.component?.()));
|
|
2134
|
+
}
|
|
2135
|
+
//#endregion
|
|
2136
|
+
//#region node_modules/@sveltejs/kit/src/runtime/server/csrf.js
|
|
2137
|
+
var mutating_form_methods = /* @__PURE__ */ new Set([
|
|
2138
|
+
"POST",
|
|
2139
|
+
"PUT",
|
|
2140
|
+
"PATCH",
|
|
2141
|
+
"DELETE"
|
|
2142
|
+
]);
|
|
2143
|
+
/**
|
|
2144
|
+
* The origin SvelteKit treats as "self" when validating the `Origin` header on
|
|
2145
|
+
* cross-site requests.
|
|
2146
|
+
*
|
|
2147
|
+
* By default (`paths.origin` is `undefined`), SvelteKit derives the origin
|
|
2148
|
+
* from `request.url` (which is set by the adapter, and ultimately by the
|
|
2149
|
+
* platform). When `paths.origin` is configured — for example so that a preview
|
|
2150
|
+
* deployment whose URL isn't known at build time, or an app behind a reverse
|
|
2151
|
+
* proxy, can declare a canonical origin — that value takes precedence.
|
|
2152
|
+
*
|
|
2153
|
+
* @param {string | undefined} paths_origin the configured `kit.paths.origin`
|
|
2154
|
+
* @param {string} url_origin the origin derived from `request.url`
|
|
2155
|
+
* @returns {string}
|
|
2156
|
+
*/
|
|
2157
|
+
function get_self_origin(paths_origin, url_origin) {
|
|
2158
|
+
return paths_origin || url_origin;
|
|
2159
|
+
}
|
|
2160
|
+
/**
|
|
2161
|
+
* Determines whether a non-remote request should be rejected as a cross-site
|
|
2162
|
+
* request forgery (CSRF). Used by `respond.js` to gate form `POST`/`PUT`/
|
|
2163
|
+
* `PATCH`/`DELETE` requests whose `Origin` header doesn't match the app's
|
|
2164
|
+
* self-origin (and isn't in `trusted_origins`).
|
|
2165
|
+
*
|
|
2166
|
+
* @param {{
|
|
2167
|
+
* request: Request;
|
|
2168
|
+
* request_origin: string | null;
|
|
2169
|
+
* self_origin: string;
|
|
2170
|
+
* trusted_origins: string[];
|
|
2171
|
+
* }} input
|
|
2172
|
+
* @returns {boolean}
|
|
2173
|
+
*/
|
|
2174
|
+
function is_csrf_forbidden({ request, request_origin, self_origin, trusted_origins }) {
|
|
2175
|
+
return (!request.headers.get("content-type") || is_form_content_type(request)) && mutating_form_methods.has(request.method) && request_origin !== self_origin && (!request_origin || !trusted_origins.includes(request_origin));
|
|
2176
|
+
}
|
|
2177
|
+
/**
|
|
2178
|
+
* Determines whether a remote-function request should be rejected as cross-site.
|
|
2179
|
+
*
|
|
2180
|
+
* Unlike form submissions, remote functions accept any content type (e.g.
|
|
2181
|
+
* `application/json`), so the check is solely on the request method and origin:
|
|
2182
|
+
* a non-`GET` request is forbidden when its `Origin` header doesn't match the
|
|
2183
|
+
* app's self-origin. Unlike `is_csrf_forbidden`, entries in `trusted_origins`
|
|
2184
|
+
* are *not* honoured — remote function endpoints are an implementation detail,
|
|
2185
|
+
* not a public API, so cross-origin calls are forbidden regardless.
|
|
2186
|
+
*
|
|
2187
|
+
* @param {{
|
|
2188
|
+
* request: Request;
|
|
2189
|
+
* request_origin: string | null;
|
|
2190
|
+
* self_origin: string;
|
|
2191
|
+
* }} input
|
|
2192
|
+
* @returns {boolean}
|
|
2193
|
+
*/
|
|
2194
|
+
function is_remote_forbidden({ request, request_origin, self_origin }) {
|
|
2195
|
+
return request.method !== "GET" && request_origin !== self_origin;
|
|
2196
|
+
}
|
|
2197
|
+
//#endregion
|
|
2198
|
+
//#region node_modules/@sveltejs/kit/src/runtime/server/data/index.js
|
|
2199
|
+
/**
|
|
2200
|
+
* @param {import('@sveltejs/kit').RequestEvent} event
|
|
2201
|
+
* @param {import('types').RequestState} state
|
|
2202
|
+
* @param {{ page: Pick<import('types').PageNodeIndexes, 'layouts' | 'leaf'> | null }} route
|
|
2203
|
+
* @param {boolean[] | undefined} invalidated_data_nodes
|
|
2204
|
+
* @param {import('types').TrailingSlash} trailing_slash
|
|
2205
|
+
* @returns {Promise<Response>}
|
|
2206
|
+
*/
|
|
2207
|
+
async function render_data(event, state, route, invalidated_data_nodes, trailing_slash) {
|
|
2208
|
+
if (!route.page) return with_version_header(new Response(void 0, { status: 404 }));
|
|
2209
|
+
try {
|
|
2210
|
+
const node_ids = [...route.page.layouts, route.page.leaf];
|
|
2211
|
+
const invalidated = invalidated_data_nodes ?? node_ids.map(() => true);
|
|
2212
|
+
let aborted = false;
|
|
2213
|
+
const url = new URL(event.url);
|
|
2214
|
+
url.pathname = normalize_path(url.pathname, trailing_slash);
|
|
2215
|
+
const new_event = {
|
|
2216
|
+
...event,
|
|
2217
|
+
url
|
|
2218
|
+
};
|
|
2219
|
+
const functions = node_ids.map((n, i) => {
|
|
2220
|
+
return once(async () => {
|
|
2221
|
+
try {
|
|
2222
|
+
if (aborted) return { type: "skip" };
|
|
2223
|
+
const node = n == void 0 ? n : await manifest.nodes[n]();
|
|
2224
|
+
return load_server_data({
|
|
2225
|
+
event: new_event,
|
|
2226
|
+
state,
|
|
2227
|
+
node,
|
|
2228
|
+
parent: async () => {
|
|
2229
|
+
/** @type {Record<string, any>} */
|
|
2230
|
+
const data = {};
|
|
2231
|
+
for (let j = 0; j < i; j += 1) {
|
|
2232
|
+
const parent = await functions[j]();
|
|
2233
|
+
if (parent) Object.assign(data, parent.data);
|
|
2234
|
+
}
|
|
2235
|
+
return data;
|
|
2236
|
+
}
|
|
2237
|
+
});
|
|
2238
|
+
} catch (e) {
|
|
2239
|
+
aborted = true;
|
|
2240
|
+
throw e;
|
|
2241
|
+
}
|
|
2242
|
+
});
|
|
2243
|
+
});
|
|
2244
|
+
const promises = functions.map(async (fn, i) => {
|
|
2245
|
+
if (!invalidated[i]) return { type: "skip" };
|
|
2246
|
+
return fn();
|
|
2247
|
+
});
|
|
2248
|
+
const data_serializer = server_data_serializer_json(event, state);
|
|
2249
|
+
await Promise.all(promises.map(async (p, i) => {
|
|
2250
|
+
const node = await p.catch(async (error) => {
|
|
2251
|
+
if (error instanceof Redirect) throw error;
|
|
2252
|
+
return {
|
|
2253
|
+
type: "error",
|
|
2254
|
+
error: await handle_error_and_jsonify(event, state, error)
|
|
2255
|
+
};
|
|
2256
|
+
});
|
|
2257
|
+
data_serializer.add_node(i, node);
|
|
2258
|
+
}));
|
|
2259
|
+
const { data, chunks } = data_serializer.get_data();
|
|
2260
|
+
if (!chunks) return json_response(data);
|
|
2261
|
+
return with_version_header(new Response(stream_text(data, chunks), { headers: {
|
|
2262
|
+
"content-type": "text/sveltekit-data",
|
|
2263
|
+
"cache-control": "private, no-store"
|
|
2264
|
+
} }));
|
|
2265
|
+
} catch (e) {
|
|
2266
|
+
const error = normalize_error(e);
|
|
2267
|
+
if (error instanceof Redirect) return redirect_json_response(error);
|
|
2268
|
+
else {
|
|
2269
|
+
const transformed = await handle_error_and_jsonify(event, state, error);
|
|
2270
|
+
return json_response(transformed, transformed.status);
|
|
2271
|
+
}
|
|
2272
|
+
}
|
|
2273
|
+
}
|
|
2274
|
+
/**
|
|
2275
|
+
* @param {Record<string, any> | string} json
|
|
2276
|
+
* @param {number} [status]
|
|
2277
|
+
*/
|
|
2278
|
+
function json_response(json, status = 200) {
|
|
2279
|
+
return with_version_header(text(typeof json === "string" ? json : JSON.stringify(json), {
|
|
2280
|
+
status,
|
|
2281
|
+
headers: {
|
|
2282
|
+
"content-type": "application/json",
|
|
2283
|
+
"cache-control": "private, no-store"
|
|
2284
|
+
}
|
|
2285
|
+
}));
|
|
2286
|
+
}
|
|
2287
|
+
/**
|
|
2288
|
+
* @param {Redirect} redirect
|
|
2289
|
+
*/
|
|
2290
|
+
function redirect_json_response(redirect) {
|
|
2291
|
+
return json_response({
|
|
2292
|
+
type: "redirect",
|
|
2293
|
+
status: redirect.status,
|
|
2294
|
+
location: redirect.location
|
|
2295
|
+
});
|
|
2296
|
+
}
|
|
2297
|
+
//#endregion
|
|
2298
|
+
//#region node_modules/cookie/dist/index.js
|
|
2299
|
+
/**
|
|
2300
|
+
* RegExp to match cookie-name in RFC 6265 sec 4.1.1
|
|
2301
|
+
* This refers out to the obsoleted definition of token in RFC 2616 sec 2.2
|
|
2302
|
+
* which has been replaced by the token definition in RFC 7230 appendix B.
|
|
2303
|
+
*
|
|
2304
|
+
* cookie-name = token
|
|
2305
|
+
* token = 1*tchar
|
|
2306
|
+
* tchar = "!" / "#" / "$" / "%" / "&" / "'" /
|
|
2307
|
+
* "*" / "+" / "-" / "." / "^" / "_" /
|
|
2308
|
+
* "`" / "|" / "~" / DIGIT / ALPHA
|
|
2309
|
+
*
|
|
2310
|
+
* Note: Allowing more characters - https://github.com/jshttp/cookie/issues/191
|
|
2311
|
+
* Allow same range as cookie value, except `=`, which delimits end of name.
|
|
2312
|
+
*/
|
|
2313
|
+
var cookieNameRegExp = /^[\u0021-\u003A\u003C\u003E-\u007E]+$/;
|
|
2314
|
+
/**
|
|
2315
|
+
* RegExp to match cookie-value in RFC 6265 sec 4.1.1
|
|
2316
|
+
*
|
|
2317
|
+
* cookie-value = *cookie-octet / ( DQUOTE *cookie-octet DQUOTE )
|
|
2318
|
+
* cookie-octet = %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E
|
|
2319
|
+
* ; US-ASCII characters excluding CTLs,
|
|
2320
|
+
* ; whitespace DQUOTE, comma, semicolon,
|
|
2321
|
+
* ; and backslash
|
|
2322
|
+
*
|
|
2323
|
+
* Allowing more characters: https://github.com/jshttp/cookie/issues/191
|
|
2324
|
+
* Comma, backslash, and DQUOTE are not part of the parsing algorithm.
|
|
2325
|
+
*/
|
|
2326
|
+
var cookieValueRegExp = /^[\u0021-\u003A\u003C-\u007E]*$/;
|
|
2327
|
+
/**
|
|
2328
|
+
* RegExp to match domain-value in RFC 6265 sec 4.1.1
|
|
2329
|
+
*
|
|
2330
|
+
* domain-value = <subdomain>
|
|
2331
|
+
* ; defined in [RFC1034], Section 3.5, as
|
|
2332
|
+
* ; enhanced by [RFC1123], Section 2.1
|
|
2333
|
+
* <subdomain> = <label> | <subdomain> "." <label>
|
|
2334
|
+
* <label> = <let-dig> [ [ <ldh-str> ] <let-dig> ]
|
|
2335
|
+
* Labels must be 63 characters or less.
|
|
2336
|
+
* 'let-dig' not 'letter' in the first char, per RFC1123
|
|
2337
|
+
* <ldh-str> = <let-dig-hyp> | <let-dig-hyp> <ldh-str>
|
|
2338
|
+
* <let-dig-hyp> = <let-dig> | "-"
|
|
2339
|
+
* <let-dig> = <letter> | <digit>
|
|
2340
|
+
* <letter> = any one of the 52 alphabetic characters A through Z in
|
|
2341
|
+
* upper case and a through z in lower case
|
|
2342
|
+
* <digit> = any one of the ten digits 0 through 9
|
|
2343
|
+
*
|
|
2344
|
+
* Keep support for leading dot: https://github.com/jshttp/cookie/issues/173
|
|
2345
|
+
*
|
|
2346
|
+
* > (Note that a leading %x2E ("."), if present, is ignored even though that
|
|
2347
|
+
* character is not permitted, but a trailing %x2E ("."), if present, will
|
|
2348
|
+
* cause the user agent to ignore the attribute.)
|
|
2349
|
+
*/
|
|
2350
|
+
var domainValueRegExp = /^([.]?[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)([.][a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*$/i;
|
|
2351
|
+
/**
|
|
2352
|
+
* RegExp to match path-value in RFC 6265 sec 4.1.1
|
|
2353
|
+
*
|
|
2354
|
+
* path-value = <any CHAR except CTLs or ";">
|
|
2355
|
+
* CHAR = %x01-7F
|
|
2356
|
+
* ; defined in RFC 5234 appendix B.1
|
|
2357
|
+
*/
|
|
2358
|
+
var pathValueRegExp = /^[\u0020-\u003A\u003D-\u007E]*$/;
|
|
2359
|
+
/**
|
|
2360
|
+
* RegExp to match max-age-value in RFC 6265 sec 5.6.2
|
|
2361
|
+
*/
|
|
2362
|
+
var maxAgeRegExp = /^-?\d+$/;
|
|
2363
|
+
/**
|
|
2364
|
+
* RegExp to match RFC 6265 cookie-octet values (without % to preserve roundtrip) that need no URL encoding.
|
|
2365
|
+
*/
|
|
2366
|
+
var cookieOctetRegExp = /^[!#$&'()*+\-.\/0-9:<=>?@A-Z[\]\^_`a-z{|}~]*$/;
|
|
2367
|
+
var NullObject = /* @__PURE__ */ (() => {
|
|
2368
|
+
const C = function() {};
|
|
2369
|
+
C.prototype = Object.create(null);
|
|
2370
|
+
return C;
|
|
2371
|
+
})();
|
|
2372
|
+
/**
|
|
2373
|
+
* Parse a `Cookie` header.
|
|
2374
|
+
*
|
|
2375
|
+
* Parse the given cookie header string into an object
|
|
2376
|
+
* The object has the various cookies as keys(names) => values
|
|
2377
|
+
*/
|
|
2378
|
+
function parseCookie(str, options) {
|
|
2379
|
+
const obj = new NullObject();
|
|
2380
|
+
const len = str.length;
|
|
2381
|
+
if (len < 2) return obj;
|
|
2382
|
+
const dec = options?.decode || decode;
|
|
2383
|
+
let index = 0;
|
|
2384
|
+
do {
|
|
2385
|
+
const eqIdx = eqIndex(str, index, len);
|
|
2386
|
+
if (eqIdx === len) break;
|
|
2387
|
+
const endIdx = endIndex(str, index, len);
|
|
2388
|
+
if (eqIdx > endIdx) {
|
|
2389
|
+
index = str.lastIndexOf(";", eqIdx - 1) + 1;
|
|
2390
|
+
continue;
|
|
2391
|
+
}
|
|
2392
|
+
const key = valueSlice(str, index, eqIdx);
|
|
2393
|
+
if (obj[key] === void 0) obj[key] = dec(valueSlice(str, eqIdx + 1, endIdx));
|
|
2394
|
+
index = endIdx + 1;
|
|
2395
|
+
} while (index < len);
|
|
2396
|
+
return obj;
|
|
2397
|
+
}
|
|
2398
|
+
/**
|
|
2399
|
+
* Serialize data into a cookie header.
|
|
2400
|
+
*
|
|
2401
|
+
* Serialize a name value pair into a cookie string suitable for
|
|
2402
|
+
* http headers. An optional options object specifies cookie parameters.
|
|
2403
|
+
*
|
|
2404
|
+
* stringifySetCookie({ name: 'foo', value: 'bar', httpOnly: true })
|
|
2405
|
+
* => "foo=bar; HttpOnly"
|
|
2406
|
+
*/
|
|
2407
|
+
function stringifySetCookie(cookie, options) {
|
|
2408
|
+
const enc = options?.encode || defaultEncode;
|
|
2409
|
+
if (!cookieNameRegExp.test(cookie.name)) throw new TypeError(`argument name is invalid: ${cookie.name}`);
|
|
2410
|
+
const value = cookie.value == null ? "" : enc(cookie.value);
|
|
2411
|
+
if (!cookieValueRegExp.test(value)) throw new TypeError(`argument val is invalid: ${cookie.value}`);
|
|
2412
|
+
let str = cookie.name + "=" + value;
|
|
2413
|
+
if (cookie.maxAge !== void 0) {
|
|
2414
|
+
if (!Number.isInteger(cookie.maxAge)) throw new TypeError(`option maxAge is invalid: ${cookie.maxAge}`);
|
|
2415
|
+
str += "; Max-Age=" + cookie.maxAge;
|
|
2416
|
+
}
|
|
2417
|
+
if (cookie.domain) {
|
|
2418
|
+
if (!domainValueRegExp.test(cookie.domain)) throw new TypeError(`option domain is invalid: ${cookie.domain}`);
|
|
2419
|
+
str += "; Domain=" + cookie.domain;
|
|
2420
|
+
}
|
|
2421
|
+
if (cookie.path) {
|
|
2422
|
+
if (!pathValueRegExp.test(cookie.path)) throw new TypeError(`option path is invalid: ${cookie.path}`);
|
|
2423
|
+
str += "; Path=" + cookie.path;
|
|
2424
|
+
}
|
|
2425
|
+
if (cookie.expires) {
|
|
2426
|
+
if (!Number.isFinite(cookie.expires.valueOf())) throw new TypeError(`option expires is invalid: ${cookie.expires}`);
|
|
2427
|
+
str += "; Expires=" + cookie.expires.toUTCString();
|
|
2428
|
+
}
|
|
2429
|
+
if (cookie.httpOnly) str += "; HttpOnly";
|
|
2430
|
+
if (cookie.secure) str += "; Secure";
|
|
2431
|
+
if (cookie.partitioned) str += "; Partitioned";
|
|
2432
|
+
if (cookie.priority) switch (typeof cookie.priority === "string" ? cookie.priority.toLowerCase() : void 0) {
|
|
2433
|
+
case "low":
|
|
2434
|
+
str += "; Priority=Low";
|
|
2435
|
+
break;
|
|
2436
|
+
case "medium":
|
|
2437
|
+
str += "; Priority=Medium";
|
|
2438
|
+
break;
|
|
2439
|
+
case "high":
|
|
2440
|
+
str += "; Priority=High";
|
|
2441
|
+
break;
|
|
2442
|
+
default: throw new TypeError(`option priority is invalid: ${cookie.priority}`);
|
|
2443
|
+
}
|
|
2444
|
+
if (cookie.sameSite) switch (typeof cookie.sameSite === "string" ? cookie.sameSite.toLowerCase() : cookie.sameSite) {
|
|
2445
|
+
case true:
|
|
2446
|
+
case "strict":
|
|
2447
|
+
str += "; SameSite=Strict";
|
|
2448
|
+
break;
|
|
2449
|
+
case "lax":
|
|
2450
|
+
str += "; SameSite=Lax";
|
|
2451
|
+
break;
|
|
2452
|
+
case "none":
|
|
2453
|
+
str += "; SameSite=None";
|
|
2454
|
+
break;
|
|
2455
|
+
default: throw new TypeError(`option sameSite is invalid: ${cookie.sameSite}`);
|
|
2456
|
+
}
|
|
2457
|
+
return str;
|
|
2458
|
+
}
|
|
2459
|
+
/**
|
|
2460
|
+
* Deserialize a `Set-Cookie` header into an object.
|
|
2461
|
+
*
|
|
2462
|
+
* parseSetCookie('foo=bar; HttpOnly')
|
|
2463
|
+
* => { name: 'foo', value: 'bar', httpOnly: true }
|
|
2464
|
+
*/
|
|
2465
|
+
function parseSetCookie(str, options) {
|
|
2466
|
+
const dec = options?.decode || decode;
|
|
2467
|
+
const len = str.length;
|
|
2468
|
+
const endIdx = endIndex(str, 0, len);
|
|
2469
|
+
let eqIdx = eqIndex(str, 0, len);
|
|
2470
|
+
const setCookie = eqIdx < endIdx ? {
|
|
2471
|
+
name: valueSlice(str, 0, eqIdx),
|
|
2472
|
+
value: dec(valueSlice(str, eqIdx + 1, endIdx))
|
|
2473
|
+
} : {
|
|
2474
|
+
name: "",
|
|
2475
|
+
value: dec(valueSlice(str, 0, endIdx))
|
|
2476
|
+
};
|
|
2477
|
+
let index = endIdx + 1;
|
|
2478
|
+
while (index < len) {
|
|
2479
|
+
const endIdx = endIndex(str, index, len);
|
|
2480
|
+
if (eqIdx < index) eqIdx = eqIndex(str, index, len);
|
|
2481
|
+
const attr = eqIdx < endIdx ? valueSlice(str, index, eqIdx) : valueSlice(str, index, endIdx);
|
|
2482
|
+
const val = eqIdx < endIdx ? valueSlice(str, eqIdx + 1, endIdx) : void 0;
|
|
2483
|
+
switch (attr.toLowerCase()) {
|
|
2484
|
+
case "httponly":
|
|
2485
|
+
setCookie.httpOnly = true;
|
|
2486
|
+
break;
|
|
2487
|
+
case "secure":
|
|
2488
|
+
setCookie.secure = true;
|
|
2489
|
+
break;
|
|
2490
|
+
case "partitioned":
|
|
2491
|
+
setCookie.partitioned = true;
|
|
2492
|
+
break;
|
|
2493
|
+
case "domain":
|
|
2494
|
+
setCookie.domain = val;
|
|
2495
|
+
break;
|
|
2496
|
+
case "path":
|
|
2497
|
+
setCookie.path = val;
|
|
2498
|
+
break;
|
|
2499
|
+
case "max-age":
|
|
2500
|
+
if (val && maxAgeRegExp.test(val)) setCookie.maxAge = Number(val);
|
|
2501
|
+
break;
|
|
2502
|
+
case "expires":
|
|
2503
|
+
if (!val) break;
|
|
2504
|
+
const date = new Date(val);
|
|
2505
|
+
if (Number.isFinite(date.valueOf())) setCookie.expires = date;
|
|
2506
|
+
break;
|
|
2507
|
+
case "priority":
|
|
2508
|
+
if (!val) break;
|
|
2509
|
+
const priority = val.toLowerCase();
|
|
2510
|
+
if (priority === "low" || priority === "medium" || priority === "high") setCookie.priority = priority;
|
|
2511
|
+
break;
|
|
2512
|
+
case "samesite":
|
|
2513
|
+
if (!val) break;
|
|
2514
|
+
const sameSite = val.toLowerCase();
|
|
2515
|
+
if (sameSite === "lax" || sameSite === "strict" || sameSite === "none") setCookie.sameSite = sameSite;
|
|
2516
|
+
}
|
|
2517
|
+
index = endIdx + 1;
|
|
2518
|
+
}
|
|
2519
|
+
return setCookie;
|
|
2520
|
+
}
|
|
2521
|
+
/**
|
|
2522
|
+
* Find the next `;` character, or return `len`.
|
|
2523
|
+
*/
|
|
2524
|
+
function endIndex(str, min, len) {
|
|
2525
|
+
const index = str.indexOf(";", min);
|
|
2526
|
+
return index === -1 ? len : index;
|
|
2527
|
+
}
|
|
2528
|
+
/**
|
|
2529
|
+
* Find the next `=` character, or return `len`.
|
|
2530
|
+
*/
|
|
2531
|
+
function eqIndex(str, min, len) {
|
|
2532
|
+
const index = str.indexOf("=", min);
|
|
2533
|
+
return index === -1 ? len : index;
|
|
2534
|
+
}
|
|
2535
|
+
/**
|
|
2536
|
+
* Slice out a value between startPod to max.
|
|
2537
|
+
*/
|
|
2538
|
+
function valueSlice(str, min, max) {
|
|
2539
|
+
if (min === max) return "";
|
|
2540
|
+
let start = min;
|
|
2541
|
+
let end = max;
|
|
2542
|
+
do {
|
|
2543
|
+
const code = str.charCodeAt(start);
|
|
2544
|
+
if (code !== 32 && code !== 9) break;
|
|
2545
|
+
} while (++start < end);
|
|
2546
|
+
while (end > start) {
|
|
2547
|
+
const code = str.charCodeAt(end - 1);
|
|
2548
|
+
if (code !== 32 && code !== 9) break;
|
|
2549
|
+
end--;
|
|
2550
|
+
}
|
|
2551
|
+
return str.slice(start, end);
|
|
2552
|
+
}
|
|
2553
|
+
/**
|
|
2554
|
+
* URL-decode string value. Optimized to skip native call when no %.
|
|
2555
|
+
*/
|
|
2556
|
+
function decode(str) {
|
|
2557
|
+
if (str.indexOf("%") === -1) return str;
|
|
2558
|
+
try {
|
|
2559
|
+
return decodeURIComponent(str);
|
|
2560
|
+
} catch (e) {
|
|
2561
|
+
return str;
|
|
2562
|
+
}
|
|
2563
|
+
}
|
|
2564
|
+
/**
|
|
2565
|
+
* URL-encode string value. Optimized to skip native call for roundtrip-safe cookie-octet values.
|
|
2566
|
+
*/
|
|
2567
|
+
function defaultEncode(str) {
|
|
2568
|
+
return cookieOctetRegExp.test(str) ? str : encodeURIComponent(str);
|
|
2569
|
+
}
|
|
2570
|
+
/**
|
|
2571
|
+
* Generates a unique key for a cookie based on its domain, path, and name in
|
|
2572
|
+
* the format: `<domain>/<path>?<name>`.
|
|
2573
|
+
* If domain is undefined, it will be omitted.
|
|
2574
|
+
* For example: `/?name`, `example.com/foo?name`.
|
|
2575
|
+
*
|
|
2576
|
+
* @param {string | undefined} domain
|
|
2577
|
+
* @param {string} path
|
|
2578
|
+
* @param {string} name
|
|
2579
|
+
* @returns {string}
|
|
2580
|
+
*/
|
|
2581
|
+
function generate_cookie_key(domain, path, name) {
|
|
2582
|
+
return `${domain || ""}${path}?${encodeURIComponent(name)}`;
|
|
2583
|
+
}
|
|
2584
|
+
/**
|
|
2585
|
+
* @param {Request} request
|
|
2586
|
+
* @param {URL} url
|
|
2587
|
+
*/
|
|
2588
|
+
function get_cookies(request, url) {
|
|
2589
|
+
const header = request.headers.get("cookie") ?? "";
|
|
2590
|
+
const initial_cookies = parseCookie(header, { decode: (value) => value });
|
|
2591
|
+
/** @type {ReturnType<typeof parseCookie> | undefined} */
|
|
2592
|
+
let default_cookies;
|
|
2593
|
+
/**
|
|
2594
|
+
* The header never changes during the request, so the default-decode parse is cached
|
|
2595
|
+
* @param {import('cookie').ParseOptions} [opts]
|
|
2596
|
+
*/
|
|
2597
|
+
function parse_header(opts) {
|
|
2598
|
+
return opts?.decode ? parseCookie(header, opts) : default_cookies ??= parseCookie(header);
|
|
2599
|
+
}
|
|
2600
|
+
/** @param {import('./page/types.js').Cookie} cookie */
|
|
2601
|
+
function matches_url(cookie) {
|
|
2602
|
+
return domain_matches(url.hostname, cookie.options.domain) && path_matches(url.pathname, cookie.options.path);
|
|
2603
|
+
}
|
|
2604
|
+
/** @type {string | undefined} */
|
|
2605
|
+
let normalized_url;
|
|
2606
|
+
/** @type {Map<string, import('./page/types.js').Cookie>} */
|
|
2607
|
+
const new_cookies = /* @__PURE__ */ new Map();
|
|
2608
|
+
/** @type {Omit<import('cookie').SetCookie, 'name' | 'value'>} */
|
|
2609
|
+
const defaults = {
|
|
2610
|
+
httpOnly: true,
|
|
2611
|
+
path: "/",
|
|
2612
|
+
sameSite: "lax",
|
|
2613
|
+
secure: !(url.hostname === "localhost" && url.protocol === "http:")
|
|
2614
|
+
};
|
|
2615
|
+
/** @type {import('@sveltejs/kit').Cookies} */
|
|
2616
|
+
const cookies = {
|
|
2617
|
+
get(name, opts) {
|
|
2618
|
+
/** @type {import('./page/types.js').Cookie | undefined} */
|
|
2619
|
+
let best_match;
|
|
2620
|
+
for (const c of new_cookies.values()) if (c.name === name && matches_url(c) && (!best_match || c.options.path.length > best_match.options.path.length)) best_match = c;
|
|
2621
|
+
if (best_match) return best_match.options.maxAge === 0 ? void 0 : best_match.value;
|
|
2622
|
+
return parse_header(opts)[name];
|
|
2623
|
+
},
|
|
2624
|
+
getAll(opts) {
|
|
2625
|
+
const cookies = { ...parse_header(opts) };
|
|
2626
|
+
const lookup = /* @__PURE__ */ new Map();
|
|
2627
|
+
for (const c of new_cookies.values()) if (matches_url(c)) {
|
|
2628
|
+
const existing = lookup.get(c.name);
|
|
2629
|
+
if (!existing || c.options.path.length > existing.options.path.length) lookup.set(c.name, c);
|
|
2630
|
+
}
|
|
2631
|
+
for (const c of lookup.values()) if (c.options.maxAge === 0) delete cookies[c.name];
|
|
2632
|
+
else cookies[c.name] = c.value;
|
|
2633
|
+
return Object.entries(cookies).filter(([, value]) => value != null).map(([name, value]) => ({
|
|
2634
|
+
name,
|
|
2635
|
+
value
|
|
2636
|
+
}));
|
|
2637
|
+
},
|
|
2638
|
+
set(name, value, options) {
|
|
2639
|
+
set_internal(name, value, {
|
|
2640
|
+
...defaults,
|
|
2641
|
+
...options
|
|
2642
|
+
});
|
|
2643
|
+
},
|
|
2644
|
+
delete(name, options) {
|
|
2645
|
+
cookies.set(name, "", {
|
|
2646
|
+
...options,
|
|
2647
|
+
maxAge: 0
|
|
2648
|
+
});
|
|
2649
|
+
},
|
|
2650
|
+
parse: parseSetCookie,
|
|
2651
|
+
serialize(name, value, { encode, ...options } = {}) {
|
|
2652
|
+
let path = options.path ?? "/";
|
|
2653
|
+
if (!options.domain || options.domain === url.hostname) {
|
|
2654
|
+
if (!normalized_url) cookies_serialize_before_route();
|
|
2655
|
+
path = resolve(normalized_url, path);
|
|
2656
|
+
}
|
|
2657
|
+
return stringifySetCookie({
|
|
2658
|
+
name,
|
|
2659
|
+
value,
|
|
2660
|
+
...defaults,
|
|
2661
|
+
...options,
|
|
2662
|
+
path
|
|
2663
|
+
}, { encode });
|
|
2664
|
+
}
|
|
2665
|
+
};
|
|
2666
|
+
/**
|
|
2667
|
+
* @param {URL} destination
|
|
2668
|
+
* @param {string | null} header
|
|
2669
|
+
*/
|
|
2670
|
+
function get_cookie_header(destination, header) {
|
|
2671
|
+
/** @type {Record<string, string>} */
|
|
2672
|
+
const combined_cookies = { ...initial_cookies };
|
|
2673
|
+
for (const cookie of new_cookies.values()) {
|
|
2674
|
+
if (!domain_matches(destination.hostname, cookie.options.domain)) continue;
|
|
2675
|
+
if (!path_matches(destination.pathname, cookie.options.path)) continue;
|
|
2676
|
+
const encoder = cookie.options.encode || encodeURIComponent;
|
|
2677
|
+
combined_cookies[cookie.name] = encoder(cookie.value);
|
|
2678
|
+
}
|
|
2679
|
+
if (header) {
|
|
2680
|
+
const parsed = parseCookie(header, { decode: (value) => value });
|
|
2681
|
+
for (const name in parsed) combined_cookies[name] = parsed[name];
|
|
2682
|
+
}
|
|
2683
|
+
return Object.entries(combined_cookies).map(([name, value]) => `${name}=${value}`).join("; ");
|
|
2684
|
+
}
|
|
2685
|
+
/** @type {Array<() => void>} */
|
|
2686
|
+
const internal_queue = [];
|
|
2687
|
+
/**
|
|
2688
|
+
* @param {string} name
|
|
2689
|
+
* @param {string} value
|
|
2690
|
+
* @param {import('cookie').SerializeOptions} options
|
|
2691
|
+
*/
|
|
2692
|
+
function set_internal(name, value, options) {
|
|
2693
|
+
if (!normalized_url) {
|
|
2694
|
+
internal_queue.push(() => set_internal(name, value, options));
|
|
2695
|
+
return;
|
|
2696
|
+
}
|
|
2697
|
+
let path = options.path ?? "/";
|
|
2698
|
+
if (!options.domain || options.domain === url.hostname) path = resolve(normalized_url, path);
|
|
2699
|
+
const cookie_key = generate_cookie_key(options.domain, path, name);
|
|
2700
|
+
const cookie = {
|
|
2701
|
+
name,
|
|
2702
|
+
value,
|
|
2703
|
+
options: {
|
|
2704
|
+
...options,
|
|
2705
|
+
path
|
|
2706
|
+
}
|
|
2707
|
+
};
|
|
2708
|
+
new_cookies.set(cookie_key, cookie);
|
|
2709
|
+
}
|
|
2710
|
+
/**
|
|
2711
|
+
* @param {import('types').TrailingSlash} trailing_slash
|
|
2712
|
+
*/
|
|
2713
|
+
function set_trailing_slash(trailing_slash) {
|
|
2714
|
+
normalized_url = normalize_path(url.pathname, trailing_slash);
|
|
2715
|
+
internal_queue.forEach((fn) => fn());
|
|
2716
|
+
}
|
|
2717
|
+
return {
|
|
2718
|
+
cookies,
|
|
2719
|
+
new_cookies,
|
|
2720
|
+
get_cookie_header,
|
|
2721
|
+
set_internal,
|
|
2722
|
+
set_trailing_slash
|
|
2723
|
+
};
|
|
2724
|
+
}
|
|
2725
|
+
/**
|
|
2726
|
+
* @param {string} hostname
|
|
2727
|
+
* @param {string} [constraint]
|
|
2728
|
+
*/
|
|
2729
|
+
function domain_matches(hostname, constraint) {
|
|
2730
|
+
if (!constraint) return true;
|
|
2731
|
+
const normalized = constraint[0] === "." ? constraint.slice(1) : constraint;
|
|
2732
|
+
if (hostname === normalized) return true;
|
|
2733
|
+
return hostname.endsWith("." + normalized);
|
|
2734
|
+
}
|
|
2735
|
+
/**
|
|
2736
|
+
* @param {string} path
|
|
2737
|
+
* @param {string} [constraint]
|
|
2738
|
+
*/
|
|
2739
|
+
function path_matches(path, constraint) {
|
|
2740
|
+
if (!constraint) return true;
|
|
2741
|
+
const normalized = constraint.endsWith("/") ? constraint.slice(0, -1) : constraint;
|
|
2742
|
+
if (path === normalized) return true;
|
|
2743
|
+
return path.startsWith(normalized + "/");
|
|
2744
|
+
}
|
|
2745
|
+
/**
|
|
2746
|
+
* @param {Headers} headers
|
|
2747
|
+
* @param {MapIterator<import('./page/types.js').Cookie>} cookies
|
|
2748
|
+
*/
|
|
2749
|
+
function add_cookies_to_headers(headers, cookies) {
|
|
2750
|
+
for (const new_cookie of cookies) {
|
|
2751
|
+
const { name, value, options: { encode, ...options } } = new_cookie;
|
|
2752
|
+
headers.append("set-cookie", stringifySetCookie({
|
|
2753
|
+
name,
|
|
2754
|
+
value,
|
|
2755
|
+
...options
|
|
2756
|
+
}, { encode }));
|
|
2757
|
+
if (options.path.endsWith(".html")) {
|
|
2758
|
+
const path = add_data_suffix(options.path);
|
|
2759
|
+
headers.append("set-cookie", stringifySetCookie({
|
|
2760
|
+
name,
|
|
2761
|
+
value,
|
|
2762
|
+
...options,
|
|
2763
|
+
path
|
|
2764
|
+
}, { encode }));
|
|
2765
|
+
}
|
|
2766
|
+
}
|
|
2767
|
+
}
|
|
2768
|
+
//#endregion
|
|
2769
|
+
//#region node_modules/@sveltejs/kit/src/runtime/server/state.js
|
|
2770
|
+
/** @import { InternalRequestOptions, RequestState } from 'types' */
|
|
2771
|
+
/** Per-request caches and context flags — never carried into a fork. */
|
|
2772
|
+
function transient_fields() {
|
|
2773
|
+
return {
|
|
2774
|
+
remote: {
|
|
2775
|
+
data: null,
|
|
2776
|
+
explicit: null,
|
|
2777
|
+
implicit: null,
|
|
2778
|
+
forms: null,
|
|
2779
|
+
requested: null,
|
|
2780
|
+
ignored: null,
|
|
2781
|
+
batches: null,
|
|
2782
|
+
live_iterators: null
|
|
2783
|
+
},
|
|
2784
|
+
is_in_remote_function: false,
|
|
2785
|
+
is_in_remote_form_or_command: false,
|
|
2786
|
+
is_in_remote_query: false,
|
|
2787
|
+
is_in_remote_prerender: false,
|
|
2788
|
+
is_in_render: false
|
|
2789
|
+
};
|
|
2790
|
+
}
|
|
2791
|
+
/**
|
|
2792
|
+
* @param {InternalRequestOptions} options
|
|
2793
|
+
* @returns {RequestState}
|
|
2794
|
+
*/
|
|
2795
|
+
function create_request_state(options) {
|
|
2796
|
+
return {
|
|
2797
|
+
getClientAddress: options.getClientAddress,
|
|
2798
|
+
platform: options.platform,
|
|
2799
|
+
read: options.read,
|
|
2800
|
+
before_handle: options.before_handle,
|
|
2801
|
+
emulator: options.emulator,
|
|
2802
|
+
prerendering: options.prerendering,
|
|
2803
|
+
prerender_default: void 0,
|
|
2804
|
+
error: false,
|
|
2805
|
+
depth: 0,
|
|
2806
|
+
rerouted_url: null,
|
|
2807
|
+
...transient_fields()
|
|
2808
|
+
};
|
|
2809
|
+
}
|
|
2810
|
+
/**
|
|
2811
|
+
* @param {RequestState} state
|
|
2812
|
+
* @returns {RequestState}
|
|
2813
|
+
*/
|
|
2814
|
+
function fork_state_for_subrequest(state) {
|
|
2815
|
+
return {
|
|
2816
|
+
...state,
|
|
2817
|
+
...transient_fields(),
|
|
2818
|
+
depth: state.depth + 1
|
|
2819
|
+
};
|
|
2820
|
+
}
|
|
2821
|
+
//#endregion
|
|
2822
|
+
//#region node_modules/@sveltejs/kit/src/runtime/server/fetch.js
|
|
2823
|
+
/**
|
|
2824
|
+
* @param {{
|
|
2825
|
+
* event: import('@sveltejs/kit').RequestEvent;
|
|
2826
|
+
* state: import('types').RequestState;
|
|
2827
|
+
* get_cookie_header: (url: URL, header: string | null) => string;
|
|
2828
|
+
* set_internal: (name: string, value: string, opts: import('./page/types.js').Cookie['options']) => void;
|
|
2829
|
+
* }} opts
|
|
2830
|
+
* @returns {typeof fetch}
|
|
2831
|
+
*/
|
|
2832
|
+
function create_fetch({ event, state, get_cookie_header, set_internal }) {
|
|
2833
|
+
/**
|
|
2834
|
+
* @type {typeof fetch}
|
|
2835
|
+
*/
|
|
2836
|
+
const server_fetch = async (info, init) => {
|
|
2837
|
+
const original_request = normalize_fetch_input(info, init, event.url);
|
|
2838
|
+
let mode = (info instanceof Request ? info.mode : init?.mode) ?? "cors";
|
|
2839
|
+
let credentials = (info instanceof Request ? info.credentials : init?.credentials) ?? "same-origin";
|
|
2840
|
+
return hooks.handleFetch({
|
|
2841
|
+
event,
|
|
2842
|
+
request: original_request,
|
|
2843
|
+
fetch: async (info, init) => {
|
|
2844
|
+
const request = normalize_fetch_input(info, init, event.url);
|
|
2845
|
+
const url = new URL(request.url);
|
|
2846
|
+
if (!request.headers.has("origin")) request.headers.set("origin", event.url.origin);
|
|
2847
|
+
if (info !== original_request) {
|
|
2848
|
+
mode = (info instanceof Request ? info.mode : init?.mode) ?? "cors";
|
|
2849
|
+
credentials = (info instanceof Request ? info.credentials : init?.credentials) ?? "same-origin";
|
|
2850
|
+
}
|
|
2851
|
+
if ((request.method === "GET" || request.method === "HEAD") && (mode === "no-cors" && url.origin !== event.url.origin || url.origin === event.url.origin)) request.headers.delete("origin");
|
|
2852
|
+
const decoded = decodeURIComponent(url.pathname);
|
|
2853
|
+
if (url.origin !== event.url.origin || "") {
|
|
2854
|
+
if (`.${url.hostname}`.endsWith(`.${event.url.hostname}`) && credentials !== "omit") {
|
|
2855
|
+
const cookie = get_cookie_header(url, request.headers.get("cookie"));
|
|
2856
|
+
if (cookie) request.headers.set("cookie", cookie);
|
|
2857
|
+
}
|
|
2858
|
+
return fetch(request);
|
|
2859
|
+
}
|
|
2860
|
+
const filename = (decoded.startsWith(assets) ? decoded.slice(assets.length) : decoded).slice(1);
|
|
2861
|
+
const filename_html = `${filename}/index.html`;
|
|
2862
|
+
const is_asset = manifest.assets.has(filename) || filename in manifest.server_assets;
|
|
2863
|
+
const is_asset_html = manifest.assets.has(filename_html) || filename_html in manifest.server_assets;
|
|
2864
|
+
if (is_asset || is_asset_html) {
|
|
2865
|
+
const file = is_asset ? filename : filename_html;
|
|
2866
|
+
if (state.read) {
|
|
2867
|
+
const type = is_asset ? manifest.mime_types[filename.slice(filename.lastIndexOf("."))] : "text/html";
|
|
2868
|
+
return new Response(state.read(file), { headers: type ? { "content-type": type } : {} });
|
|
2869
|
+
} else if (read_implementation && file in manifest.server_assets) {
|
|
2870
|
+
const length = manifest.server_assets[file];
|
|
2871
|
+
const type = manifest.mime_types[file.slice(file.lastIndexOf("."))];
|
|
2872
|
+
return new Response(read_implementation(file), { headers: {
|
|
2873
|
+
"Content-Length": "" + length,
|
|
2874
|
+
"Content-Type": type
|
|
2875
|
+
} });
|
|
2876
|
+
}
|
|
2877
|
+
return await fetch(request, { redirect: "manual" });
|
|
2878
|
+
}
|
|
2879
|
+
if (has_prerendered_path(decoded)) return await fetch(request, { redirect: "manual" });
|
|
2880
|
+
if (credentials !== "omit") {
|
|
2881
|
+
const cookie = get_cookie_header(url, request.headers.get("cookie"));
|
|
2882
|
+
if (cookie) request.headers.set("cookie", cookie);
|
|
2883
|
+
const authorization = event.request.headers.get("authorization");
|
|
2884
|
+
if (authorization && !request.headers.has("authorization")) request.headers.set("authorization", authorization);
|
|
2885
|
+
}
|
|
2886
|
+
if (!request.headers.has("accept")) request.headers.set("accept", "*/*");
|
|
2887
|
+
const accept_language = event.request.headers.get("accept-language");
|
|
2888
|
+
if (accept_language && !request.headers.has("accept-language")) request.headers.set("accept-language", accept_language);
|
|
2889
|
+
const response = await internal_fetch(request, state);
|
|
2890
|
+
for (const str of response.headers.getSetCookie()) {
|
|
2891
|
+
const { name, value, ...cookie_options } = parseSetCookie(str, { decode: (v) => v });
|
|
2892
|
+
set_internal(name, value, {
|
|
2893
|
+
path: cookie_options.path ?? (url.pathname.split("/").slice(0, -1).join("/") || "/"),
|
|
2894
|
+
encode: (value) => value,
|
|
2895
|
+
...cookie_options
|
|
2896
|
+
});
|
|
2897
|
+
}
|
|
2898
|
+
return response;
|
|
2899
|
+
}
|
|
2900
|
+
});
|
|
2901
|
+
};
|
|
2902
|
+
return (input, init) => {
|
|
2903
|
+
const response = server_fetch(input, init);
|
|
2904
|
+
response.catch(noop);
|
|
2905
|
+
return response;
|
|
2906
|
+
};
|
|
2907
|
+
}
|
|
2908
|
+
/**
|
|
2909
|
+
* @param {RequestInfo | URL} info
|
|
2910
|
+
* @param {RequestInit | undefined} init
|
|
2911
|
+
* @param {URL} url
|
|
2912
|
+
*/
|
|
2913
|
+
function normalize_fetch_input(info, init, url) {
|
|
2914
|
+
if (info instanceof Request) return info;
|
|
2915
|
+
return new Request(typeof info === "string" ? new URL(info, url) : info, init);
|
|
2916
|
+
}
|
|
2917
|
+
/**
|
|
2918
|
+
* @param {Request} request
|
|
2919
|
+
* @param {import('types').RequestState} state
|
|
2920
|
+
* @returns {Promise<Response>}
|
|
2921
|
+
*/
|
|
2922
|
+
async function internal_fetch(request, state) {
|
|
2923
|
+
if (request.signal?.aborted) throw new DOMException("The operation was aborted.", "AbortError");
|
|
2924
|
+
const subrequest_state = fork_state_for_subrequest(state);
|
|
2925
|
+
if (!request.signal) return await respond$1(request, subrequest_state);
|
|
2926
|
+
let remove_abort_listener = noop;
|
|
2927
|
+
/** @type {Promise<never>} */
|
|
2928
|
+
const abort_promise = new Promise((_, reject) => {
|
|
2929
|
+
const on_abort = () => {
|
|
2930
|
+
reject(new DOMException("The operation was aborted.", "AbortError"));
|
|
2931
|
+
};
|
|
2932
|
+
request.signal.addEventListener("abort", on_abort, { once: true });
|
|
2933
|
+
remove_abort_listener = () => request.signal.removeEventListener("abort", on_abort);
|
|
2934
|
+
});
|
|
2935
|
+
return Promise.race([respond$1(request, subrequest_state), abort_promise]).finally(remove_abort_listener);
|
|
2936
|
+
}
|
|
2937
|
+
//#endregion
|
|
2938
|
+
//#region node_modules/@sveltejs/kit/src/runtime/server/env_module.js
|
|
2939
|
+
/** @type {string} */
|
|
2940
|
+
var payload;
|
|
2941
|
+
/** @type {string} */
|
|
2942
|
+
var etag;
|
|
2943
|
+
/** @type {Headers} */
|
|
2944
|
+
var headers;
|
|
2945
|
+
/**
|
|
2946
|
+
* @param {Request} request
|
|
2947
|
+
* @returns {Response}
|
|
2948
|
+
*/
|
|
2949
|
+
function get_public_env(request) {
|
|
2950
|
+
payload ??= uneval$1(rendered_env);
|
|
2951
|
+
etag ??= `W/${Date.now()}`;
|
|
2952
|
+
headers ??= new Headers({
|
|
2953
|
+
"content-type": "application/javascript; charset=utf-8",
|
|
2954
|
+
etag
|
|
2955
|
+
});
|
|
2956
|
+
if (request.headers.get("if-none-match") === etag) return new Response(void 0, {
|
|
2957
|
+
status: 304,
|
|
2958
|
+
headers
|
|
2959
|
+
});
|
|
2960
|
+
return new Response(`export const env=${payload}`, { headers });
|
|
2961
|
+
}
|
|
2962
|
+
//#endregion
|
|
2963
|
+
//#region node_modules/@sveltejs/kit/src/runtime/server/respond.js
|
|
2964
|
+
/** @import { SSRNode } from 'types' */
|
|
2965
|
+
/** @type {import('types').RequiredResolveOptions['transformPageChunk']} */
|
|
2966
|
+
var default_transform = ({ html }) => html;
|
|
2967
|
+
/** @type {import('types').RequiredResolveOptions['filterSerializedResponseHeaders']} */
|
|
2968
|
+
var default_filter = () => false;
|
|
2969
|
+
/** @type {import('types').RequiredResolveOptions['preload']} */
|
|
2970
|
+
var default_preload = ({ type }) => type === "js" || type === "css";
|
|
2971
|
+
var non_html_fetch_destinations = /* @__PURE__ */ new Set([
|
|
2972
|
+
"audio",
|
|
2973
|
+
"audioworklet",
|
|
2974
|
+
"font",
|
|
2975
|
+
"image",
|
|
2976
|
+
"json",
|
|
2977
|
+
"manifest",
|
|
2978
|
+
"paintworklet",
|
|
2979
|
+
"report",
|
|
2980
|
+
"script",
|
|
2981
|
+
"serviceworker",
|
|
2982
|
+
"sharedworker",
|
|
2983
|
+
"style",
|
|
2984
|
+
"track",
|
|
2985
|
+
"video",
|
|
2986
|
+
"webidentity",
|
|
2987
|
+
"worker",
|
|
2988
|
+
"xslt"
|
|
2989
|
+
]);
|
|
2990
|
+
var page_methods = /* @__PURE__ */ new Set([
|
|
2991
|
+
"GET",
|
|
2992
|
+
"HEAD",
|
|
2993
|
+
"POST"
|
|
2994
|
+
]);
|
|
2995
|
+
var allowed_page_methods = /* @__PURE__ */ new Set([
|
|
2996
|
+
"GET",
|
|
2997
|
+
"HEAD",
|
|
2998
|
+
"OPTIONS"
|
|
2999
|
+
]);
|
|
3000
|
+
var respond$1 = propagate_context(internal_respond);
|
|
3001
|
+
/**
|
|
3002
|
+
* @param {Request} request
|
|
3003
|
+
* @param {import('types').RequestState} state
|
|
3004
|
+
* @returns {Promise<Response>}
|
|
3005
|
+
*/
|
|
3006
|
+
async function internal_respond(request, state) {
|
|
3007
|
+
/** URL but stripped from the potential `/__data.json` suffix and its search param */
|
|
3008
|
+
const url = new URL(request.url);
|
|
3009
|
+
const is_route_resolution_request = has_resolution_suffix(url.pathname);
|
|
3010
|
+
const is_data_request = has_data_suffix(url.pathname);
|
|
3011
|
+
const remote_id = get_remote_id(url);
|
|
3012
|
+
{
|
|
3013
|
+
const request_origin = request.headers.get("origin");
|
|
3014
|
+
const self_origin = get_self_origin(void 0, url.origin);
|
|
3015
|
+
if (remote_id) {
|
|
3016
|
+
if (is_remote_forbidden({
|
|
3017
|
+
request,
|
|
3018
|
+
request_origin,
|
|
3019
|
+
self_origin
|
|
3020
|
+
})) return Response.json({ message: "Cross-site remote requests are forbidden" }, { status: 403 });
|
|
3021
|
+
} else if (is_csrf_forbidden({
|
|
3022
|
+
request,
|
|
3023
|
+
request_origin,
|
|
3024
|
+
self_origin,
|
|
3025
|
+
trusted_origins: options.csrf_trusted_origins
|
|
3026
|
+
})) {
|
|
3027
|
+
const message = `Cross-site ${request.method} form submissions are forbidden`;
|
|
3028
|
+
const opts = { status: 403 };
|
|
3029
|
+
if (request.headers.get("accept") === "application/json") return Response.json({ message }, opts);
|
|
3030
|
+
return text(message, opts);
|
|
3031
|
+
}
|
|
3032
|
+
}
|
|
3033
|
+
/** @type {boolean[] | undefined} */
|
|
3034
|
+
let invalidated_data_nodes;
|
|
3035
|
+
let skip_route_resolution = false;
|
|
3036
|
+
/** Whether this is a `/${app_dir}/routes/<route_id>/__route.js` request, used by `preloadCode` */
|
|
3037
|
+
let is_route_id_resolution_request = false;
|
|
3038
|
+
if (is_route_resolution_request) {
|
|
3039
|
+
/**
|
|
3040
|
+
* If the request is for a route resolution, first modify the URL, then continue as normal
|
|
3041
|
+
* for path resolution, then return the route object as a JS file.
|
|
3042
|
+
*/
|
|
3043
|
+
url.pathname = strip_resolution_suffix(url.pathname);
|
|
3044
|
+
is_route_id_resolution_request = is_route_id_resolution_path(url.pathname);
|
|
3045
|
+
} else if (is_data_request) {
|
|
3046
|
+
url.pathname = strip_data_suffix(url.pathname) + (url.searchParams.get("x-sveltekit-trailing-slash") === "1" ? "/" : "") || "/";
|
|
3047
|
+
url.searchParams.delete(TRAILING_SLASH_PARAM);
|
|
3048
|
+
invalidated_data_nodes = url.searchParams.get(INVALIDATED_PARAM)?.split("").map((node) => node === "1");
|
|
3049
|
+
url.searchParams.delete(INVALIDATED_PARAM);
|
|
3050
|
+
} else if (remote_id) {
|
|
3051
|
+
const pathname = request.headers.get("x-sveltekit-pathname");
|
|
3052
|
+
if (pathname === null) skip_route_resolution = true;
|
|
3053
|
+
else {
|
|
3054
|
+
url.pathname = pathname;
|
|
3055
|
+
url.search = request.headers.get("x-sveltekit-search") ?? "";
|
|
3056
|
+
}
|
|
3057
|
+
}
|
|
3058
|
+
for (const key of url.searchParams.keys()) if (key.startsWith("x-sveltekit-")) return text(`Cannot use reserved query parameter "${key}"`, { status: 400 });
|
|
3059
|
+
/** @type {Record<string, string>} */
|
|
3060
|
+
const headers = {};
|
|
3061
|
+
const { cookies, new_cookies, get_cookie_header, set_internal, set_trailing_slash } = get_cookies(request, url);
|
|
3062
|
+
/** @type {import('@sveltejs/kit').RequestEvent} */
|
|
3063
|
+
const event = {
|
|
3064
|
+
cookies,
|
|
3065
|
+
fetch: null,
|
|
3066
|
+
getClientAddress: state.getClientAddress || (() => {
|
|
3067
|
+
client_address_unsupported({ adapter: "@sveltejs/adapter-node" });
|
|
3068
|
+
}),
|
|
3069
|
+
locals: {},
|
|
3070
|
+
params: {},
|
|
3071
|
+
platform: state.emulator?.platform ? await state.emulator.platform({
|
|
3072
|
+
config: {},
|
|
3073
|
+
prerender: !!state.prerendering?.fallback
|
|
3074
|
+
}) : state.platform,
|
|
3075
|
+
request,
|
|
3076
|
+
route: { id: null },
|
|
3077
|
+
setHeaders: (new_headers) => {
|
|
3078
|
+
for (const key in new_headers) {
|
|
3079
|
+
const lower = key.toLowerCase();
|
|
3080
|
+
const value = new_headers[key];
|
|
3081
|
+
if (lower === "set-cookie") set_headers_cookie();
|
|
3082
|
+
else if (lower in headers) {
|
|
3083
|
+
if (lower === "server-timing") headers[lower] += ", " + value;
|
|
3084
|
+
else header_already_set({ name: key });
|
|
3085
|
+
} else {
|
|
3086
|
+
headers[lower] = value;
|
|
3087
|
+
if (state.prerendering && lower === "cache-control") state.prerendering.cache = value;
|
|
3088
|
+
}
|
|
3089
|
+
}
|
|
3090
|
+
},
|
|
3091
|
+
url,
|
|
3092
|
+
isDataRequest: is_data_request,
|
|
3093
|
+
isSubRequest: state.depth > 0,
|
|
3094
|
+
isRemoteRequest: !!remote_id
|
|
3095
|
+
};
|
|
3096
|
+
event.fetch = create_fetch({
|
|
3097
|
+
event,
|
|
3098
|
+
state,
|
|
3099
|
+
get_cookie_header,
|
|
3100
|
+
set_internal
|
|
3101
|
+
});
|
|
3102
|
+
/** @type {string | null} */
|
|
3103
|
+
let resolved_path = url.pathname;
|
|
3104
|
+
if (!remote_id && !is_route_id_resolution_request) {
|
|
3105
|
+
const prerendering_reroute_state = state.prerendering?.inside_reroute;
|
|
3106
|
+
try {
|
|
3107
|
+
if (state.prerendering) state.prerendering.inside_reroute = true;
|
|
3108
|
+
resolved_path = await hooks.reroute({
|
|
3109
|
+
url: new URL(url),
|
|
3110
|
+
fetch: event.fetch
|
|
3111
|
+
}) ?? url.pathname;
|
|
3112
|
+
if (!manifest.routes.length && resolved_path !== url.pathname) state.rerouted_url = denormalise_url({
|
|
3113
|
+
request_url: request.url,
|
|
3114
|
+
resolved_path,
|
|
3115
|
+
is_data_request,
|
|
3116
|
+
is_route_resolution_request
|
|
3117
|
+
}).toString();
|
|
3118
|
+
} catch {
|
|
3119
|
+
return text("Internal Server Error", { status: 500 });
|
|
3120
|
+
} finally {
|
|
3121
|
+
if (state.prerendering) state.prerendering.inside_reroute = prerendering_reroute_state;
|
|
3122
|
+
}
|
|
3123
|
+
}
|
|
3124
|
+
/** @type {import('types').RequiredResolveOptions} */
|
|
3125
|
+
let resolve_opts = {
|
|
3126
|
+
transformPageChunk: default_transform,
|
|
3127
|
+
filterSerializedResponseHeaders: default_filter,
|
|
3128
|
+
preload: default_preload
|
|
3129
|
+
};
|
|
3130
|
+
/** @type {import('types').TrailingSlash} */
|
|
3131
|
+
let trailing_slash = "never";
|
|
3132
|
+
/** @type {PageNodes | undefined} */
|
|
3133
|
+
let page_nodes;
|
|
3134
|
+
try {
|
|
3135
|
+
resolved_path = decode_pathname(resolved_path);
|
|
3136
|
+
} catch {
|
|
3137
|
+
resolved_path = null;
|
|
3138
|
+
return await handle();
|
|
3139
|
+
}
|
|
3140
|
+
if (resolved_path !== decode_pathname(url.pathname) && !state.prerendering?.fallback && has_prerendered_path(resolved_path)) {
|
|
3141
|
+
const url = denormalise_url({
|
|
3142
|
+
request_url: request.url,
|
|
3143
|
+
resolved_path,
|
|
3144
|
+
is_data_request,
|
|
3145
|
+
is_route_resolution_request
|
|
3146
|
+
});
|
|
3147
|
+
try {
|
|
3148
|
+
const response = await fetch(new Request(url, request), { redirect: "manual" });
|
|
3149
|
+
const headers = new Headers(response.headers);
|
|
3150
|
+
if (headers.has("content-encoding")) {
|
|
3151
|
+
headers.delete("content-encoding");
|
|
3152
|
+
headers.delete("content-length");
|
|
3153
|
+
}
|
|
3154
|
+
return new Response(response.body, {
|
|
3155
|
+
headers,
|
|
3156
|
+
status: response.status,
|
|
3157
|
+
statusText: response.statusText
|
|
3158
|
+
});
|
|
3159
|
+
} catch (error) {
|
|
3160
|
+
return await handle_fatal_error(event, state, error);
|
|
3161
|
+
}
|
|
3162
|
+
}
|
|
3163
|
+
/** @type {import('types').SSRRoute | null} */
|
|
3164
|
+
let route = null;
|
|
3165
|
+
if (is_route_resolution_request) {
|
|
3166
|
+
if (is_route_id_resolution_request) return resolve_route_by_id(extract_route_id(resolved_path), new URL(request.url));
|
|
3167
|
+
return resolve_route(resolved_path, new URL(request.url));
|
|
3168
|
+
}
|
|
3169
|
+
if (resolved_path === `/_app/env.js`) return get_public_env(request);
|
|
3170
|
+
if (!remote_id && resolved_path.startsWith(`/_app`)) {
|
|
3171
|
+
const headers = new Headers();
|
|
3172
|
+
headers.set("cache-control", "public, max-age=0, must-revalidate");
|
|
3173
|
+
return text("Not found", {
|
|
3174
|
+
status: 404,
|
|
3175
|
+
headers
|
|
3176
|
+
});
|
|
3177
|
+
}
|
|
3178
|
+
if (!state.prerendering?.fallback && !skip_route_resolution) try {
|
|
3179
|
+
const matchers = await manifest.matchers();
|
|
3180
|
+
const result = find_route(resolved_path, manifest.routes, matchers);
|
|
3181
|
+
if (result) {
|
|
3182
|
+
route = result.route;
|
|
3183
|
+
event.route = { id: route.id };
|
|
3184
|
+
event.params = result.params;
|
|
3185
|
+
}
|
|
3186
|
+
} catch (e) {
|
|
3187
|
+
return await handle_fatal_error(event, state, e);
|
|
3188
|
+
}
|
|
3189
|
+
try {
|
|
3190
|
+
page_nodes = route?.page ? new PageNodes(await load_page_nodes(route.page)) : void 0;
|
|
3191
|
+
if (route && !remote_id) {
|
|
3192
|
+
if (url.pathname === "" || url.pathname === "/") trailing_slash = "always";
|
|
3193
|
+
else if (page_nodes) trailing_slash = page_nodes.trailing_slash();
|
|
3194
|
+
else if (route.endpoint) trailing_slash = (await route.endpoint()).trailingSlash ?? "never";
|
|
3195
|
+
if (!is_data_request) {
|
|
3196
|
+
const normalized = normalize_path(url.pathname, trailing_slash);
|
|
3197
|
+
if (normalized !== url.pathname && !state.prerendering?.fallback) return new Response(void 0, {
|
|
3198
|
+
status: 308,
|
|
3199
|
+
headers: {
|
|
3200
|
+
"x-sveltekit-normalize": "1",
|
|
3201
|
+
location: relative_pathname(url.pathname, normalized) + (url.search === "?" ? "" : url.search)
|
|
3202
|
+
}
|
|
3203
|
+
});
|
|
3204
|
+
}
|
|
3205
|
+
if (state.before_handle || state.emulator?.platform) {
|
|
3206
|
+
let config = {};
|
|
3207
|
+
/** @type {import('types').PrerenderOption} */
|
|
3208
|
+
let prerender = false;
|
|
3209
|
+
if (route.endpoint) {
|
|
3210
|
+
const node = await route.endpoint();
|
|
3211
|
+
config = node.config ?? config;
|
|
3212
|
+
prerender = node.prerender ?? prerender;
|
|
3213
|
+
} else if (page_nodes) {
|
|
3214
|
+
config = page_nodes.get_config() ?? config;
|
|
3215
|
+
prerender = state.prerender_default = page_nodes.prerender();
|
|
3216
|
+
}
|
|
3217
|
+
if (state.emulator?.platform) event.platform = await state.emulator.platform({
|
|
3218
|
+
config,
|
|
3219
|
+
prerender
|
|
3220
|
+
});
|
|
3221
|
+
if (state.before_handle) return await state.before_handle(event, config, prerender, handle);
|
|
3222
|
+
}
|
|
3223
|
+
}
|
|
3224
|
+
return await handle();
|
|
3225
|
+
} catch (e) {
|
|
3226
|
+
if (e instanceof Redirect) try {
|
|
3227
|
+
const response = is_data_request || remote_id ? redirect_json_response(e) : route?.page && is_action_json_request(event) ? action_json_redirect(e) : redirect_response(e.status, e.location);
|
|
3228
|
+
add_cookies_to_headers(response.headers, new_cookies.values());
|
|
3229
|
+
return response;
|
|
3230
|
+
} catch (err) {
|
|
3231
|
+
return await handle_fatal_error(event, state, err);
|
|
3232
|
+
}
|
|
3233
|
+
return await handle_fatal_error(event, state, e);
|
|
3234
|
+
}
|
|
3235
|
+
async function handle() {
|
|
3236
|
+
set_trailing_slash(trailing_slash);
|
|
3237
|
+
if (state.prerendering && !state.prerendering.fallback && !state.prerendering.inside_reroute) disable_search(url);
|
|
3238
|
+
const response = await record_span({
|
|
3239
|
+
name: "sveltekit.handle.root",
|
|
3240
|
+
attributes: {
|
|
3241
|
+
"http.route": event.route.id || "unknown",
|
|
3242
|
+
"http.method": event.request.method,
|
|
3243
|
+
"http.url": event.url.href,
|
|
3244
|
+
"sveltekit.is_data_request": is_data_request,
|
|
3245
|
+
"sveltekit.is_sub_request": event.isSubRequest
|
|
3246
|
+
},
|
|
3247
|
+
fn: async (root_span) => {
|
|
3248
|
+
const traced_event = {
|
|
3249
|
+
...event,
|
|
3250
|
+
tracing: {
|
|
3251
|
+
enabled: false,
|
|
3252
|
+
root: root_span,
|
|
3253
|
+
current: root_span
|
|
3254
|
+
}
|
|
3255
|
+
};
|
|
3256
|
+
return await with_request_store({
|
|
3257
|
+
event: traced_event,
|
|
3258
|
+
state
|
|
3259
|
+
}, () => hooks.handle({
|
|
3260
|
+
event: traced_event,
|
|
3261
|
+
resolve: (event, opts) => {
|
|
3262
|
+
return record_span({
|
|
3263
|
+
name: "sveltekit.resolve",
|
|
3264
|
+
attributes: { "http.route": event.route.id || "unknown" },
|
|
3265
|
+
fn: (resolve_span) => {
|
|
3266
|
+
return with_request_store(null, () => resolve(merge_tracing(event, resolve_span), page_nodes, opts).then((response) => {
|
|
3267
|
+
for (const key in headers) {
|
|
3268
|
+
const value = headers[key];
|
|
3269
|
+
response.headers.set(key, value);
|
|
3270
|
+
}
|
|
3271
|
+
add_cookies_to_headers(response.headers, new_cookies.values());
|
|
3272
|
+
if (state.prerendering && event.route.id !== null) response.headers.set("x-sveltekit-routeid", encodeURI(event.route.id));
|
|
3273
|
+
resolve_span.setAttributes({
|
|
3274
|
+
"http.response.status_code": response.status,
|
|
3275
|
+
"http.response.body.size": response.headers.get("content-length") || "unknown"
|
|
3276
|
+
});
|
|
3277
|
+
return response;
|
|
3278
|
+
}));
|
|
3279
|
+
}
|
|
3280
|
+
});
|
|
3281
|
+
}
|
|
3282
|
+
}));
|
|
3283
|
+
}
|
|
3284
|
+
});
|
|
3285
|
+
if (response.status === 200 && response.headers.has("etag")) {
|
|
3286
|
+
let if_none_match_value = request.headers.get("if-none-match");
|
|
3287
|
+
if (if_none_match_value?.startsWith("W/\"")) if_none_match_value = if_none_match_value.substring(2);
|
|
3288
|
+
const etag = response.headers.get("etag");
|
|
3289
|
+
if (if_none_match_value === etag) {
|
|
3290
|
+
const headers = new Headers({ etag });
|
|
3291
|
+
for (const key of [
|
|
3292
|
+
"cache-control",
|
|
3293
|
+
"content-location",
|
|
3294
|
+
"date",
|
|
3295
|
+
"expires",
|
|
3296
|
+
"vary"
|
|
3297
|
+
]) {
|
|
3298
|
+
const value = response.headers.get(key);
|
|
3299
|
+
if (value) headers.set(key, value);
|
|
3300
|
+
}
|
|
3301
|
+
for (const cookie of response.headers.getSetCookie()) headers.append("set-cookie", cookie);
|
|
3302
|
+
return new Response(void 0, {
|
|
3303
|
+
status: 304,
|
|
3304
|
+
headers
|
|
3305
|
+
});
|
|
3306
|
+
}
|
|
3307
|
+
}
|
|
3308
|
+
if (is_data_request && response.status >= 300 && response.status <= 308) {
|
|
3309
|
+
const location = response.headers.get("location");
|
|
3310
|
+
if (location) return redirect_json_response(new Redirect(response.status, location));
|
|
3311
|
+
}
|
|
3312
|
+
return response;
|
|
3313
|
+
}
|
|
3314
|
+
/**
|
|
3315
|
+
* @param {import('@sveltejs/kit').RequestEvent} event
|
|
3316
|
+
* @param {PageNodes | undefined} page_nodes
|
|
3317
|
+
* @param {import('@sveltejs/kit/hooks').ResolveOptions} [opts]
|
|
3318
|
+
*/
|
|
3319
|
+
async function resolve(event, page_nodes, opts) {
|
|
3320
|
+
try {
|
|
3321
|
+
if (opts) resolve_opts = {
|
|
3322
|
+
transformPageChunk: opts.transformPageChunk || default_transform,
|
|
3323
|
+
filterSerializedResponseHeaders: opts.filterSerializedResponseHeaders || default_filter,
|
|
3324
|
+
preload: opts.preload || default_preload
|
|
3325
|
+
};
|
|
3326
|
+
if (resolved_path === null) return await respond_with_error({
|
|
3327
|
+
event,
|
|
3328
|
+
state,
|
|
3329
|
+
error: new SvelteKitError(400, "Malformed URI", `Failed to decode URI: ${event.url.pathname}`),
|
|
3330
|
+
resolve_opts
|
|
3331
|
+
});
|
|
3332
|
+
if (state.prerendering?.fallback) return await render_response({
|
|
3333
|
+
event,
|
|
3334
|
+
state,
|
|
3335
|
+
page_config: {
|
|
3336
|
+
ssr: false,
|
|
3337
|
+
csr: true
|
|
3338
|
+
},
|
|
3339
|
+
status: 200,
|
|
3340
|
+
error: null,
|
|
3341
|
+
branch: [{
|
|
3342
|
+
node: await manifest.nodes[0](),
|
|
3343
|
+
data: null,
|
|
3344
|
+
server_data: null
|
|
3345
|
+
}],
|
|
3346
|
+
fetched: [],
|
|
3347
|
+
resolve_opts,
|
|
3348
|
+
data_serializer: server_data_serializer(event, state)
|
|
3349
|
+
});
|
|
3350
|
+
if (remote_id) return await handle_remote_call(event, state, remote_id);
|
|
3351
|
+
if (route) {
|
|
3352
|
+
const method = event.request.method;
|
|
3353
|
+
/** @type {Response} */
|
|
3354
|
+
let response;
|
|
3355
|
+
if (is_data_request) response = await render_data(event, state, route, invalidated_data_nodes, trailing_slash);
|
|
3356
|
+
else {
|
|
3357
|
+
let endpoint;
|
|
3358
|
+
if (route.endpoint && (!route.page || !state.prerendering && is_endpoint_request(event))) {
|
|
3359
|
+
endpoint = await route.endpoint();
|
|
3360
|
+
if (route.page && (method === "GET" || method === "HEAD" || method === "POST")) {
|
|
3361
|
+
if (!(method === "POST" ? !!(endpoint.POST || endpoint.fallback) : !!(endpoint.GET || endpoint.fallback || method === "HEAD" && endpoint.HEAD))) endpoint = void 0;
|
|
3362
|
+
}
|
|
3363
|
+
}
|
|
3364
|
+
if (endpoint) response = await render_endpoint(event, state, endpoint);
|
|
3365
|
+
else if (route.page) {
|
|
3366
|
+
if (!page_nodes) throw new Error("page_nodes not found. This should never happen");
|
|
3367
|
+
else if (page_methods.has(method)) response = await render_page(event, state, route.page, page_nodes, resolve_opts);
|
|
3368
|
+
else {
|
|
3369
|
+
const allowed_methods = new Set(allowed_page_methods);
|
|
3370
|
+
if ((await manifest.nodes[route.page.leaf]())?.server?.actions) allowed_methods.add("POST");
|
|
3371
|
+
if (method === "OPTIONS") response = new Response(null, {
|
|
3372
|
+
status: 204,
|
|
3373
|
+
headers: { allow: Array.from(allowed_methods.values()).join(", ") }
|
|
3374
|
+
});
|
|
3375
|
+
else {
|
|
3376
|
+
const mod = [...allowed_methods].reduce((acc, curr) => {
|
|
3377
|
+
acc[curr] = true;
|
|
3378
|
+
return acc;
|
|
3379
|
+
}, {});
|
|
3380
|
+
response = method_not_allowed(mod, method);
|
|
3381
|
+
}
|
|
3382
|
+
}
|
|
3383
|
+
} else throw new Error("Route is neither page nor endpoint. This should never happen");
|
|
3384
|
+
}
|
|
3385
|
+
if ((request.method === "GET" || request.method === "HEAD") && route.page && route.endpoint) {
|
|
3386
|
+
const vary = response.headers.get("vary")?.split(",")?.map((v) => v.trim().toLowerCase());
|
|
3387
|
+
if (!(vary?.includes("accept") || vary?.includes("*"))) {
|
|
3388
|
+
response = new Response(response.body, {
|
|
3389
|
+
status: response.status,
|
|
3390
|
+
statusText: response.statusText,
|
|
3391
|
+
headers: new Headers(response.headers)
|
|
3392
|
+
});
|
|
3393
|
+
response.headers.append("Vary", "Accept");
|
|
3394
|
+
}
|
|
3395
|
+
}
|
|
3396
|
+
return response;
|
|
3397
|
+
}
|
|
3398
|
+
if (state.error && event.isSubRequest) {
|
|
3399
|
+
const headers = new Headers(request.headers);
|
|
3400
|
+
headers.set("x-sveltekit-error", "true");
|
|
3401
|
+
return await fetch(request, {
|
|
3402
|
+
headers,
|
|
3403
|
+
redirect: "manual"
|
|
3404
|
+
});
|
|
3405
|
+
}
|
|
3406
|
+
if (state.error) return text("Internal Server Error", { status: 500 });
|
|
3407
|
+
if (state.depth === 0) {
|
|
3408
|
+
if (!state.prerendering && is_data_request && invalidated_data_nodes?.length === 1 && invalidated_data_nodes[0]) return await render_data(event, state, { page: {
|
|
3409
|
+
layouts: [],
|
|
3410
|
+
leaf: 0
|
|
3411
|
+
} }, invalidated_data_nodes, "ignore");
|
|
3412
|
+
if (non_html_fetch_destinations.has(event.request.headers.get("sec-fetch-dest") ?? "")) return text("Not Found", {
|
|
3413
|
+
status: 404,
|
|
3414
|
+
headers: { vary: "Sec-Fetch-Dest" }
|
|
3415
|
+
});
|
|
3416
|
+
return await respond_with_error({
|
|
3417
|
+
event,
|
|
3418
|
+
state,
|
|
3419
|
+
error: new SvelteKitError(404, "Not Found", `Not found: ${event.url.pathname}`),
|
|
3420
|
+
resolve_opts
|
|
3421
|
+
});
|
|
3422
|
+
}
|
|
3423
|
+
if (state.prerendering) return text("not found", { status: 404 });
|
|
3424
|
+
const response = await fetch(request, { redirect: "manual" });
|
|
3425
|
+
return new Response(response.body, response);
|
|
3426
|
+
} catch (e) {
|
|
3427
|
+
return await handle_fatal_error(event, state, e);
|
|
3428
|
+
} finally {
|
|
3429
|
+
event.cookies.set = () => {
|
|
3430
|
+
cookies_set_after_response();
|
|
3431
|
+
};
|
|
3432
|
+
event.setHeaders = () => {
|
|
3433
|
+
set_headers_after_response();
|
|
3434
|
+
};
|
|
3435
|
+
}
|
|
3436
|
+
}
|
|
3437
|
+
}
|
|
3438
|
+
/**
|
|
3439
|
+
* @param {import('types').PageNodeIndexes} page
|
|
3440
|
+
*/
|
|
3441
|
+
function load_page_nodes(page) {
|
|
3442
|
+
return Promise.all([...page.layouts.map((n) => n == void 0 ? n : manifest.nodes[n]()), manifest.nodes[page.leaf]()]);
|
|
3443
|
+
}
|
|
3444
|
+
/**
|
|
3445
|
+
* It's likely that, in a distributed system, there are spans starting outside the SvelteKit server -- eg.
|
|
3446
|
+
* started on the frontend client, or in a service that calls the SvelteKit server. There are standardized
|
|
3447
|
+
* ways to represent this context in HTTP headers, so we can extract that context and run our tracing inside of it
|
|
3448
|
+
* so that when our traces are exported, they are associated with the correct parent context.
|
|
3449
|
+
* @param {typeof internal_respond} fn
|
|
3450
|
+
* @returns {typeof internal_respond}
|
|
3451
|
+
*/
|
|
3452
|
+
function propagate_context(fn) {
|
|
3453
|
+
return async (req, ...rest) => {
|
|
3454
|
+
if (otel === null) return fn(req, ...rest);
|
|
3455
|
+
const { propagation, context } = await otel;
|
|
3456
|
+
const c = propagation.extract(context.active(), Object.fromEntries(req.headers));
|
|
3457
|
+
return context.with(c, async () => {
|
|
3458
|
+
return await fn(req, ...rest);
|
|
3459
|
+
});
|
|
3460
|
+
};
|
|
3461
|
+
}
|
|
3462
|
+
/**
|
|
3463
|
+
* @param {object} opts
|
|
3464
|
+
* @param {string} opts.request_url - The original request URL
|
|
3465
|
+
* @param {string} opts.resolved_path - The resolved pathname
|
|
3466
|
+
* @param {boolean} opts.is_data_request - Whether the request is a data request
|
|
3467
|
+
* @param {boolean} opts.is_route_resolution_request -
|
|
3468
|
+
* @returns {URL}
|
|
3469
|
+
*/
|
|
3470
|
+
function denormalise_url({ request_url, resolved_path, is_data_request, is_route_resolution_request }) {
|
|
3471
|
+
const url = new URL(request_url);
|
|
3472
|
+
url.pathname = is_data_request ? add_data_suffix(resolved_path) : is_route_resolution_request ? add_resolution_suffix(resolved_path) : resolved_path;
|
|
3473
|
+
return url;
|
|
3474
|
+
}
|
|
3475
|
+
//#endregion
|
|
3476
|
+
//#region node_modules/@sveltejs/kit/src/runtime/server/instance.js
|
|
3477
|
+
/** @type {Promise<any>} */
|
|
3478
|
+
var init_promise;
|
|
3479
|
+
/**
|
|
3480
|
+
* Loads the user's hooks, once, however many times an adapter calls it
|
|
3481
|
+
*/
|
|
3482
|
+
async function init() {
|
|
3483
|
+
await (init_promise ??= (async () => {
|
|
3484
|
+
try {
|
|
3485
|
+
const module = await get_hooks();
|
|
3486
|
+
set_hooks({
|
|
3487
|
+
handle: module.handle || (({ event, resolve }) => resolve(event)),
|
|
3488
|
+
handleError: module.handleError || (({ kind, error, issues }) => {
|
|
3489
|
+
if (kind === "validation") {
|
|
3490
|
+
console.error("Remote function schema validation failed:", issues);
|
|
3491
|
+
return;
|
|
3492
|
+
}
|
|
3493
|
+
if (kind !== "unknown") return;
|
|
3494
|
+
let e = error;
|
|
3495
|
+
while (e instanceof Error) {
|
|
3496
|
+
if (e.stack) console.error(e.stack);
|
|
3497
|
+
e = e.cause;
|
|
3498
|
+
}
|
|
3499
|
+
if (e) console.error(String(e));
|
|
3500
|
+
}),
|
|
3501
|
+
handleFetch: module.handleFetch || (({ request, fetch }) => fetch(request)),
|
|
3502
|
+
reroute: module.reroute || noop
|
|
3503
|
+
});
|
|
3504
|
+
init_transport(module.transport ?? {});
|
|
3505
|
+
if (module.init) await module.init();
|
|
3506
|
+
} catch (e) {
|
|
3507
|
+
throw e;
|
|
3508
|
+
}
|
|
3509
|
+
})());
|
|
3510
|
+
}
|
|
3511
|
+
/**
|
|
3512
|
+
* @param {Request} request
|
|
3513
|
+
* @param {import('types').InternalRequestOptions} options
|
|
3514
|
+
*/
|
|
3515
|
+
async function respond_to(request, options) {
|
|
3516
|
+
const request_state = create_request_state(options);
|
|
3517
|
+
const response = await respond$1(request, request_state);
|
|
3518
|
+
if (request_state.rerouted_url) response.headers.set(REROUTED_URL_HEADER, request_state.rerouted_url);
|
|
3519
|
+
if (request.method === "HEAD" && response.body !== null) {
|
|
3520
|
+
response.body.cancel().catch(noop);
|
|
3521
|
+
return new Response(null, response);
|
|
3522
|
+
}
|
|
3523
|
+
return response;
|
|
3524
|
+
}
|
|
3525
|
+
/**
|
|
3526
|
+
* AsyncLocalStorage does not work in webcontainers, so there `sync_store` is never reset
|
|
3527
|
+
* (see `src/exports/internal/server/event.js`) and requests are handled one at a time
|
|
3528
|
+
* @param {typeof respond_to} fn
|
|
3529
|
+
*/
|
|
3530
|
+
function serialise(fn) {
|
|
3531
|
+
/** @type {Promise<void> | null} */
|
|
3532
|
+
let current = null;
|
|
3533
|
+
/** @type {typeof respond_to} */
|
|
3534
|
+
return async (...args) => {
|
|
3535
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
3536
|
+
const previous = current;
|
|
3537
|
+
current = promise;
|
|
3538
|
+
await previous;
|
|
3539
|
+
return fn(...args).finally(resolve);
|
|
3540
|
+
};
|
|
3541
|
+
}
|
|
3542
|
+
var respond = IN_WEBCONTAINER ? serialise(respond_to) : respond_to;
|
|
3543
|
+
//#endregion
|
|
3544
|
+
export { init, respond, set_env };
|
|
3545
|
+
|
|
3546
|
+
//# sourceMappingURL=instance.js.map
|