@hot-updater/console 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.output/nitro.json +1 -1
- package/.output/public/assets/{ConsoleFeatureUnavailable-Bf8tgug-.js → ConsoleFeatureUnavailable-B-iNWpuE.js} +1 -1
- package/.output/public/assets/{EventDetails-CgtEWl-Y.js → EventDetails-CSX2ayg9.js} +1 -1
- package/.output/public/assets/{HashValueDisplay-DvXl147n.js → HashValueDisplay-BGkDPaYi.js} +1 -1
- package/.output/public/assets/{InsightsPageHeader-eViliItR.js → InsightsPageHeader-SYEOMClX.js} +1 -1
- package/.output/public/assets/{NotFoundPage-HomiHjdL.js → NotFoundPage-Cei6W2lm.js} +1 -1
- package/.output/public/assets/{alert-dialog-BSs_5Od-.js → alert-dialog-BtVg50WQ.js} +1 -1
- package/.output/public/assets/{api-DSWk32Mz.js → api-DoicFJfd.js} +1 -1
- package/.output/public/assets/{api-keys-CHA2X9W0.js → api-keys-BEdLKiib.js} +1 -1
- package/.output/public/assets/api-keys-TdTtKm2b.js +1 -0
- package/.output/public/assets/arrow-left-DsivSewE.js +1 -0
- package/.output/public/assets/arrow-up-right-B5aM0F7f.js +1 -0
- package/.output/public/assets/chevron-right-BnvHIJdZ.js +1 -0
- package/.output/public/assets/{clipboard-BYT_TJ0K.js → clipboard-DTkrlIMn.js} +1 -1
- package/.output/public/assets/console-features-api-DPE4C06Y.js +2 -0
- package/.output/public/assets/{dialog-YKZpU5St.js → dialog-CGKPxz3n.js} +1 -1
- package/.output/public/assets/{dist-B7eA4Mtf.js → dist-dDj-R6uh.js} +1 -1
- package/.output/public/assets/{empty-L3UcNk_l.js → empty-Bf4DanOL.js} +1 -1
- package/.output/public/assets/{field-DNqNwq7i.js → field-DBMkBfkD.js} +1 -1
- package/.output/public/assets/index-C5S4DrO2.js +10 -0
- package/.output/public/assets/{input-group-C9ZIjV0o.js → input-group-B4nrqIh0.js} +1 -1
- package/.output/public/assets/insights-BMKRCIg1.js +2 -0
- package/.output/public/assets/{insights-SVMoazdd.js → insights-CPyViuyC.js} +1 -1
- package/.output/public/assets/insights-D0PbX-Rm.js +1 -0
- package/.output/public/assets/{insights-api-BsX1zQDf.js → insights-api-Dmd_LgT3.js} +1 -1
- package/.output/public/assets/{insights-search-B-F2wop6.js → insights-search-DAa0f7Dr.js} +1 -1
- package/.output/public/assets/{insights-usage-rpc-CSAoKS_b.js → insights-usage-rpc-DTL0_Rp8.js} +1 -1
- package/.output/public/assets/insights_.distribution-BaOQlBV9.js +1 -0
- package/.output/public/assets/insights_.distribution-CxXMIEb5.js +2 -0
- package/.output/public/assets/{insights_.distribution-oxPmgcHr.js → insights_.distribution-EE5OqxyL.js} +1 -1
- package/.output/public/assets/installations-BgISglUQ.js +1 -0
- package/.output/public/assets/installations-DQbgRkSi.js +1 -0
- package/.output/public/assets/installations-we1IV0xp.js +2 -0
- package/.output/public/assets/{key-round-CrqLmblG.js → key-round-B4fI1psK.js} +1 -1
- package/.output/public/assets/{list-BSpjGUS6.js → list-Dtj7TtzV.js} +1 -1
- package/.output/public/assets/{refresh-cw-BMlpOsfM.js → refresh-cw-DjIKjmrS.js} +1 -1
- package/.output/public/assets/remote-config-AQmdmbT8.js +1 -0
- package/.output/public/assets/remote-config-DyTLPRKh.js +1 -0
- package/.output/public/assets/{remote-config-Cwwsatrr.js → remote-config-uBgCaI-p.js} +3 -3
- package/.output/public/assets/{routes-Bxu5_zNh.js → routes-Br26jzt9.js} +1 -1
- package/.output/public/assets/{routes-Bc3J564t.js → routes-CyirpG2O.js} +2 -2
- package/.output/public/assets/search-DuI1FBpg.js +1 -0
- package/.output/public/assets/{select-BE-xONpm.js → select-CV8nkfsf.js} +1 -1
- package/.output/public/assets/sidebar-BqX460IW.js +3 -0
- package/.output/public/assets/smartphone-CtsHuiIC.js +1 -0
- package/.output/public/assets/{switch-DR0WP2g8.js → switch-C8ycp9AH.js} +1 -1
- package/.output/public/assets/{table-DW0243Jw.js → table-DgGD67Fx.js} +1 -1
- package/.output/public/assets/{tabs-B4Ffq4fD.js → tabs-CgEH_fMT.js} +1 -1
- package/.output/public/assets/{undo-2-Dcq6sgUo.js → undo-2-DxXx9Zvr.js} +1 -1
- package/.output/public/assets/useCompositeListItem-B-UkrDlu.js +1 -0
- package/.output/public/assets/{valueToPercent-C-rPd_Or.js → valueToPercent-C4C1WZVn.js} +1 -1
- package/.output/server/{__23tanstack-start-server-fn-resolver-By_583eX.mjs → __23tanstack-start-server-fn-resolver-jmie-36L.mjs} +40 -40
- package/.output/server/_libs/@tanstack/react-router+[...].mjs +85 -91
- package/.output/server/_libs/@tanstack/react-router-ssr-query+[...].mjs +2 -2
- package/.output/server/_libs/tanstack__history.mjs +11 -16
- package/.output/server/_ssr/{BundleIdDisplay-BGTK1SRU.mjs → BundleIdDisplay-4jSO7w-V.mjs} +2 -2
- package/.output/server/_ssr/{ConsoleFeatureUnavailable-t5SKVtGP.mjs → ConsoleFeatureUnavailable-Br9nSv0f.mjs} +5 -5
- package/.output/server/_ssr/{EventDetails-Cu2tbML0.mjs → EventDetails-DvEKDuRM.mjs} +6 -6
- package/.output/server/_ssr/{HashValueDisplay-CZURXY1Z.mjs → HashValueDisplay-BEaPTxlK.mjs} +2 -2
- package/.output/server/_ssr/{InsightsPageHeader-CcwQUIfn.mjs → InsightsPageHeader-lv9lVo29.mjs} +5 -5
- package/.output/server/_ssr/{NotFoundPage-Cysokm3E.mjs → NotFoundPage-_ybIUFhU.mjs} +2 -2
- package/.output/server/_ssr/{alert-dialog-BRBa7ymh.mjs → alert-dialog-DIGB-_50.mjs} +1 -1
- package/.output/server/_ssr/{api-keys-DOWUq_vV.mjs → api-keys-CeyREjvb.mjs} +2 -2
- package/.output/server/_ssr/{api-keys-vg7KRvsN.mjs → api-keys-eO1EahwF.mjs} +8 -8
- package/.output/server/_ssr/{api-keys-rpc-CaxdpA_z.mjs → api-keys-rpc-B6jsUMOy.mjs} +5 -5
- package/.output/server/_ssr/{api-rpc-C3HJ2HXV.mjs → api-rpc-C6PKrZHs.mjs} +5 -5
- package/.output/server/_ssr/{api-CYCiImfa.mjs → api-rsoui6JK.mjs} +4 -4
- package/.output/server/_ssr/{auth-rpc-DtksW_Lx.mjs → auth-rpc-D1ebZxoP.mjs} +6 -6
- package/.output/server/_ssr/{auth.server-BQmSFKcj.mjs → auth.server-BNKPJ95k.mjs} +2 -2
- package/.output/server/_ssr/{config.server-Cib_keNb.mjs → config.server-CDc3T2Ik.mjs} +3 -3
- package/.output/server/_ssr/{console-access-CHYIzx-1.mjs → console-access-BTZBfsbE.mjs} +3 -3
- package/.output/server/_ssr/{console-features-api-BhZNLPMW.mjs → console-features-api-CvQD7xrZ.mjs} +4 -4
- package/.output/server/_ssr/{console-features-rpc-BPYpnW6t.mjs → console-features-rpc-4DFAhPjK.mjs} +5 -5
- package/.output/server/_ssr/createMiddleware-B1iPez7u.mjs +619 -0
- package/.output/server/_ssr/{createServerRpc-RLR4H-Fn.mjs → createServerRpc-BaDJLGBx.mjs} +2 -2
- package/.output/server/_ssr/{dialog-DKjEGDIF.mjs → dialog-DfjXyWGZ.mjs} +1 -1
- package/.output/server/_ssr/{empty-TCZt2Zz4.mjs → empty-CAll1ROu.mjs} +2 -2
- package/.output/server/_ssr/{empty-plugin-adapters-CPtwX8a7.mjs → empty-plugin-adapters-CpCHi1TV.mjs} +1 -1
- package/.output/server/_ssr/{field-CRkM5Gpp.mjs → field-DXfKM72E.mjs} +2 -2
- package/.output/server/_ssr/{input-group-CeG-Vrvl.mjs → input-group-JgNkHlo6.mjs} +1 -1
- package/.output/server/_ssr/{insights-BIeOvIcy.mjs → insights-Z9hNQzJz.mjs} +19 -19
- package/.output/server/_ssr/{insights-api-CK_r3twd.mjs → insights-api-BHP5zN92.mjs} +4 -4
- package/.output/server/_ssr/{insights-PrvRHPlv.mjs → insights-ddfefZlb.mjs} +5 -5
- package/.output/server/_ssr/{insights-failures-rpc-DP7D6u7J.mjs → insights-failures-rpc-B2Lq-cs5.mjs} +6 -6
- package/.output/server/_ssr/{insights-recovery-rpc-sJT8Jzlv.mjs → insights-recovery-rpc-DLDu-KiX.mjs} +5 -5
- package/.output/server/_ssr/{insights-rpc-LAA_7vQx.mjs → insights-rpc-Rg6L-Jvj.mjs} +5 -5
- package/.output/server/_ssr/{insights-search-CBqM1QE9.mjs → insights-search-B2u8wXrS.mjs} +2 -2
- package/.output/server/_ssr/{insights-usage-rpc-C3AyaMQm.mjs → insights-usage-rpc-DdafF6eA.mjs} +5 -5
- package/.output/server/_ssr/{insights-usage-rpc-B1XdI_qc.mjs → insights-usage-rpc-DoLbrAou.mjs} +4 -4
- package/.output/server/_ssr/{insights-2_RBazgs.mjs → insights-uzl3049G.mjs} +2 -2
- package/.output/server/_ssr/{insights_.distribution-COd-vmxE.mjs → insights_.distribution-6PcJu9QZ.mjs} +2 -2
- package/.output/server/_ssr/{insights_.distribution-x9oKinFG.mjs → insights_.distribution-BTVwfr_Q.mjs} +5 -5
- package/.output/server/_ssr/{insights_.distribution-CZbKU0p2.mjs → insights_.distribution-PtyLQdMn.mjs} +11 -11
- package/.output/server/_ssr/{installations-Bu1DN6Ft.mjs → installations-CXNxcPvc.mjs} +4 -4
- package/.output/server/_ssr/{installations-DpFiE_Jm.mjs → installations-DVhWilEc.mjs} +2 -2
- package/.output/server/_ssr/{installations-CBI4Hx2t.mjs → installations-v4nw05I-.mjs} +10 -10
- package/.output/server/_ssr/{release-adoption-rpc-DWKmiD2z.mjs → release-adoption-rpc-DRG07Y07.mjs} +7 -7
- package/.output/server/_ssr/{remote-config-CAgwia_L.mjs → remote-config-CCpkJZD6.mjs} +16 -16
- package/.output/server/_ssr/{remote-config-Bz9wVhh9.mjs → remote-config-Dt7E5KSB.mjs} +2 -2
- package/.output/server/_ssr/{remote-config-Bma6t5Kp.mjs → remote-config-H5FfUxiR.mjs} +2 -2
- package/.output/server/_ssr/{remote-config-rpc-DsUu2Jqx.mjs → remote-config-rpc-DmxSUh2f.mjs} +5 -5
- package/.output/server/_ssr/{router-CbcgKYjf.mjs → router-DzoZ6RiZ.mjs} +14 -14
- package/.output/server/_ssr/{routes-Q99ugDJT.mjs → routes-BcCBFt_B.mjs} +14 -14
- package/.output/server/_ssr/{routes-BdR48vdu.mjs → routes-hBT2gLcc.mjs} +9 -9
- package/.output/server/_ssr/{select-hk9KTEL0.mjs → select-B-_QqBKv.mjs} +1 -1
- package/.output/server/_ssr/{server-BfFN4fJ8.mjs → server-DLJxXUG3.mjs} +1228 -1963
- package/.output/server/_ssr/{sidebar-D_fMPxSt.mjs → sidebar-CvkhVxly.mjs} +3 -3
- package/.output/server/_ssr/ssr.mjs +2 -6
- package/.output/server/_ssr/start-B6ECIE_7.mjs +4 -0
- package/.output/server/_ssr/{switch-D55aVnok.mjs → switch-CcliGpYm.mjs} +2 -2
- package/.output/server/_ssr/{table-CfMnvhOO.mjs → table-BQwxbG7k.mjs} +1 -1
- package/.output/server/_ssr/{tabs-DgjSRe3I.mjs → tabs-CyNj4x4I.mjs} +2 -2
- package/.output/server/_tanstack-start-manifest_v-DTOQk1l4.mjs +135 -0
- package/.output/server/index.mjs +239 -239
- package/package.json +10 -10
- package/.output/public/assets/api-keys-D0yD891K.js +0 -1
- package/.output/public/assets/arrow-left-vK2qGQsd.js +0 -1
- package/.output/public/assets/arrow-up-right-Dz8o-Kab.js +0 -1
- package/.output/public/assets/chevron-right-CBl7aqu_.js +0 -1
- package/.output/public/assets/console-features-api-BD7j--gS.js +0 -1
- package/.output/public/assets/index-C-dDMnWK.js +0 -11
- package/.output/public/assets/insights-C54__dPi.js +0 -1
- package/.output/public/assets/insights-DM0CTj58.js +0 -2
- package/.output/public/assets/insights_.distribution-BAaD6rZK.js +0 -1
- package/.output/public/assets/insights_.distribution-C6tGV7qU.js +0 -2
- package/.output/public/assets/installations-1jALHnM3.js +0 -1
- package/.output/public/assets/installations-DUidui9Z.js +0 -1
- package/.output/public/assets/installations-RfpwK-ld.js +0 -2
- package/.output/public/assets/remote-config-BcoOZ9fs.js +0 -1
- package/.output/public/assets/remote-config-BtStN5bt.js +0 -1
- package/.output/public/assets/search-B_o3avCI.js +0 -1
- package/.output/public/assets/sidebar-CQ6iq0qe.js +0 -3
- package/.output/public/assets/smartphone--CTny1h9.js +0 -1
- package/.output/public/assets/useCompositeListItem-VmWjhZ9j.js +0 -1
- package/.output/server/_ssr/createMiddleware-Cm6Tn0_Y.mjs +0 -370
- package/.output/server/_ssr/start-BfFbHKMK.mjs +0 -4
- package/.output/server/_tanstack-start-manifest_v-DaM-WBL0.mjs +0 -139
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import "../_runtime.mjs";
|
|
2
|
-
import { _ as
|
|
3
|
-
import { t as getServerFnById } from "../__23tanstack-start-server-fn-resolver-
|
|
2
|
+
import { _ as parseSetCookie, a as TSS_SERVER_FUNCTION, b as serialize, c as createMiddleware, d as flattenMiddlewares, f as getStartContext, g as parse, h as mergeHeaders, i as TSS_FORMDATA_CONTEXT, l as createNullProtoObject, m as isRedirect, n as MAX_FRAME_PAYLOAD_SIZE, o as X_TSS_RAW_RESPONSE, p as getStartOptions, r as TSS_CONTENT_TYPE_FRAMED_VERSIONED, s as X_TSS_SERIALIZED, t as MAX_FRAMED_STREAMS, v as runWithStartContext, x as splitSetCookieString, y as safeObjectMerge } from "./createMiddleware-B1iPez7u.mjs";
|
|
3
|
+
import { t as getServerFnById } from "../__23tanstack-start-server-fn-resolver-jmie-36L.mjs";
|
|
4
4
|
import { _t as require_react, gt as require_jsx_runtime } from "../_libs/@base-ui/react+[...].mjs";
|
|
5
5
|
import { l as RouterProvider, n as renderRouterToString, r as defineHandlerCallback, t as renderRouterToStream } from "../_libs/@tanstack/react-router+[...].mjs";
|
|
6
6
|
import { t as __exportAll } from "./rolldown-runtime-rSIU-vHC.mjs";
|
|
7
|
-
import {
|
|
7
|
+
import { Readable } from "node:stream";
|
|
8
8
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
9
9
|
require_react();
|
|
10
10
|
var import_jsx_runtime = require_jsx_runtime();
|
|
@@ -22,1661 +22,12 @@ var defaultRenderHandler = defineHandlerCallback(({ router, responseHeaders }) =
|
|
|
22
22
|
responseHeaders,
|
|
23
23
|
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StartServer, { router })
|
|
24
24
|
}));
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
for (const key of [...Object.getOwnPropertyNames(source), ...Object.getOwnPropertySymbols(source)]) {
|
|
31
|
-
if (key === "constructor") continue;
|
|
32
|
-
const targetDesc = Object.getOwnPropertyDescriptor(target, key);
|
|
33
|
-
const desc = Object.getOwnPropertyDescriptor(source, key);
|
|
34
|
-
let modified = false;
|
|
35
|
-
if (desc.get) {
|
|
36
|
-
modified = true;
|
|
37
|
-
desc.get = targetDesc?.get || function() {
|
|
38
|
-
return this[sourceKey][key];
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
if (desc.set) {
|
|
42
|
-
modified = true;
|
|
43
|
-
desc.set = targetDesc?.set || function(value) {
|
|
44
|
-
this[sourceKey][key] = value;
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
if (!targetDesc?.value && typeof desc.value === "function") {
|
|
48
|
-
modified = true;
|
|
49
|
-
desc.value = function(...args) {
|
|
50
|
-
return this[sourceKey][key](...args);
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
if (modified) Object.defineProperty(target, key, desc);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
var _needsNormRE = /(?:(?:^|\/)(?:\.|\.\.|%2e|%2e\.|\.%2e|%2e%2e)(?:\/|$))|[\\^#"<>{}`\x80-\uffff]/i;
|
|
57
|
-
var _searchNeedsNormRE = /[#"'<>]/;
|
|
58
|
-
var FastURL = /* @__PURE__ */ (() => {
|
|
59
|
-
const NativeURL = globalThis.URL;
|
|
60
|
-
const FastURL = class URL {
|
|
61
|
-
#url;
|
|
62
|
-
#href;
|
|
63
|
-
#protocol;
|
|
64
|
-
#host;
|
|
65
|
-
#pathname;
|
|
66
|
-
#search;
|
|
67
|
-
#searchParams;
|
|
68
|
-
#pos;
|
|
69
|
-
constructor(url) {
|
|
70
|
-
if (typeof url === "string") {
|
|
71
|
-
const isOriginForm = url[0] === "/";
|
|
72
|
-
if (isOriginForm && !_searchNeedsNormRE.test(url)) this.#href = url;
|
|
73
|
-
else this.#url = new NativeURL(isOriginForm ? `http://localhost${url}` : url);
|
|
74
|
-
} else if (_needsNormRE.test(url.pathname) || url.search && _searchNeedsNormRE.test(url.search)) this.#url = new NativeURL(`${url.protocol || "http:"}//${url.host || "localhost"}${url.pathname}${url.search || ""}`);
|
|
75
|
-
else {
|
|
76
|
-
this.#protocol = url.protocol;
|
|
77
|
-
this.#host = url.host;
|
|
78
|
-
this.#pathname = url.pathname;
|
|
79
|
-
this.#search = url.search;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
static [Symbol.hasInstance](val) {
|
|
83
|
-
return val instanceof NativeURL;
|
|
84
|
-
}
|
|
85
|
-
get _url() {
|
|
86
|
-
if (this.#url) return this.#url;
|
|
87
|
-
this.#url = new NativeURL(this.href);
|
|
88
|
-
this.#href = void 0;
|
|
89
|
-
this.#protocol = void 0;
|
|
90
|
-
this.#host = void 0;
|
|
91
|
-
this.#pathname = void 0;
|
|
92
|
-
this.#search = void 0;
|
|
93
|
-
this.#searchParams = void 0;
|
|
94
|
-
this.#pos = void 0;
|
|
95
|
-
return this.#url;
|
|
96
|
-
}
|
|
97
|
-
get href() {
|
|
98
|
-
if (this.#url) return this.#url.href;
|
|
99
|
-
if (!this.#href) this.#href = `${this.#protocol || "http:"}//${this.#host || "localhost"}${this.#pathname || "/"}${this.#search || ""}`;
|
|
100
|
-
return this.#href;
|
|
101
|
-
}
|
|
102
|
-
#getPos() {
|
|
103
|
-
if (!this.#pos) {
|
|
104
|
-
const url = this.href;
|
|
105
|
-
const protoIndex = url.indexOf("://");
|
|
106
|
-
const pathnameIndex = protoIndex === -1 ? -1 : url.indexOf("/", protoIndex + 4);
|
|
107
|
-
this.#pos = [
|
|
108
|
-
protoIndex,
|
|
109
|
-
pathnameIndex,
|
|
110
|
-
pathnameIndex === -1 ? -1 : url.indexOf("?", pathnameIndex)
|
|
111
|
-
];
|
|
112
|
-
}
|
|
113
|
-
return this.#pos;
|
|
114
|
-
}
|
|
115
|
-
get pathname() {
|
|
116
|
-
if (this.#url) return this.#url.pathname;
|
|
117
|
-
if (this.#pathname === void 0) {
|
|
118
|
-
const [, pathnameIndex, queryIndex] = this.#getPos();
|
|
119
|
-
if (pathnameIndex === -1) return this._url.pathname;
|
|
120
|
-
this.#pathname = this.href.slice(pathnameIndex, queryIndex === -1 ? void 0 : queryIndex);
|
|
121
|
-
}
|
|
122
|
-
return this.#pathname;
|
|
123
|
-
}
|
|
124
|
-
get search() {
|
|
125
|
-
if (this.#url) return this.#url.search;
|
|
126
|
-
if (this.#search === void 0) {
|
|
127
|
-
const [, pathnameIndex, queryIndex] = this.#getPos();
|
|
128
|
-
if (pathnameIndex === -1) return this._url.search;
|
|
129
|
-
const url = this.href;
|
|
130
|
-
this.#search = queryIndex === -1 || queryIndex === url.length - 1 ? "" : url.slice(queryIndex);
|
|
131
|
-
}
|
|
132
|
-
return this.#search;
|
|
133
|
-
}
|
|
134
|
-
get searchParams() {
|
|
135
|
-
if (this.#url) return this.#url.searchParams;
|
|
136
|
-
if (!this.#searchParams) this.#searchParams = new URLSearchParams(this.search);
|
|
137
|
-
return this.#searchParams;
|
|
138
|
-
}
|
|
139
|
-
get protocol() {
|
|
140
|
-
if (this.#url) return this.#url.protocol;
|
|
141
|
-
if (this.#protocol === void 0) {
|
|
142
|
-
const [protocolIndex] = this.#getPos();
|
|
143
|
-
if (protocolIndex === -1) return this._url.protocol;
|
|
144
|
-
this.#protocol = this.href.slice(0, protocolIndex + 1);
|
|
145
|
-
}
|
|
146
|
-
return this.#protocol;
|
|
147
|
-
}
|
|
148
|
-
toString() {
|
|
149
|
-
return this.href;
|
|
150
|
-
}
|
|
151
|
-
toJSON() {
|
|
152
|
-
return this.href;
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
lazyInherit(FastURL.prototype, NativeURL.prototype, "_url");
|
|
156
|
-
Object.setPrototypeOf(FastURL.prototype, NativeURL.prototype);
|
|
157
|
-
Object.setPrototypeOf(FastURL, NativeURL);
|
|
158
|
-
return FastURL;
|
|
159
|
-
})();
|
|
160
|
-
var NodeResponse = /* @__PURE__ */ (() => {
|
|
161
|
-
const NativeResponse = globalThis.Response;
|
|
162
|
-
const STATUS_CODES = globalThis.process?.getBuiltinModule?.("node:http")?.STATUS_CODES || {};
|
|
163
|
-
class NodeResponse {
|
|
164
|
-
#body;
|
|
165
|
-
#init;
|
|
166
|
-
#headers;
|
|
167
|
-
#response;
|
|
168
|
-
constructor(body, init) {
|
|
169
|
-
this.#body = body;
|
|
170
|
-
this.#init = init;
|
|
171
|
-
}
|
|
172
|
-
static [Symbol.hasInstance](val) {
|
|
173
|
-
return val instanceof NativeResponse;
|
|
174
|
-
}
|
|
175
|
-
get status() {
|
|
176
|
-
return this.#response?.status || this.#init?.status || 200;
|
|
177
|
-
}
|
|
178
|
-
get statusText() {
|
|
179
|
-
return this.#response?.statusText || this.#init?.statusText || STATUS_CODES[this.status] || "";
|
|
180
|
-
}
|
|
181
|
-
get headers() {
|
|
182
|
-
if (this.#response) return this.#response.headers;
|
|
183
|
-
if (this.#headers) return this.#headers;
|
|
184
|
-
const initHeaders = this.#init?.headers;
|
|
185
|
-
return this.#headers = initHeaders instanceof Headers ? initHeaders : new Headers(initHeaders);
|
|
186
|
-
}
|
|
187
|
-
get ok() {
|
|
188
|
-
if (this.#response) return this.#response.ok;
|
|
189
|
-
const status = this.status;
|
|
190
|
-
return status >= 200 && status < 300;
|
|
191
|
-
}
|
|
192
|
-
get _response() {
|
|
193
|
-
if (this.#response) return this.#response;
|
|
194
|
-
let body = this.#body;
|
|
195
|
-
if (body && typeof body.pipe === "function" && !(body instanceof Readable)) {
|
|
196
|
-
const stream = new PassThrough();
|
|
197
|
-
body.pipe(stream);
|
|
198
|
-
const abort = body.abort;
|
|
199
|
-
if (abort) stream.once("close", () => abort());
|
|
200
|
-
body = stream;
|
|
201
|
-
}
|
|
202
|
-
this.#response = new NativeResponse(body, this.#headers ? {
|
|
203
|
-
...this.#init,
|
|
204
|
-
headers: this.#headers
|
|
205
|
-
} : this.#init);
|
|
206
|
-
this.#init = void 0;
|
|
207
|
-
this.#headers = void 0;
|
|
208
|
-
this.#body = void 0;
|
|
209
|
-
return this.#response;
|
|
210
|
-
}
|
|
211
|
-
_toNodeResponse() {
|
|
212
|
-
const status = this.status;
|
|
213
|
-
const statusText = this.statusText;
|
|
214
|
-
let body;
|
|
215
|
-
let contentType;
|
|
216
|
-
let contentLength;
|
|
217
|
-
if (this.#response) body = this.#response.body;
|
|
218
|
-
else if (this.#body) if (this.#body instanceof ReadableStream) body = this.#body;
|
|
219
|
-
else if (typeof this.#body === "string") {
|
|
220
|
-
body = this.#body;
|
|
221
|
-
contentType = "text/plain; charset=UTF-8";
|
|
222
|
-
contentLength = Buffer.byteLength(this.#body);
|
|
223
|
-
} else if (this.#body instanceof ArrayBuffer) {
|
|
224
|
-
body = Buffer.from(this.#body);
|
|
225
|
-
contentLength = this.#body.byteLength;
|
|
226
|
-
} else if (this.#body instanceof Uint8Array) {
|
|
227
|
-
body = this.#body;
|
|
228
|
-
contentLength = this.#body.byteLength;
|
|
229
|
-
} else if (this.#body instanceof DataView) {
|
|
230
|
-
body = Buffer.from(this.#body.buffer);
|
|
231
|
-
contentLength = this.#body.byteLength;
|
|
232
|
-
} else if (this.#body instanceof Blob) {
|
|
233
|
-
body = this.#body.stream();
|
|
234
|
-
contentType = this.#body.type;
|
|
235
|
-
contentLength = this.#body.size;
|
|
236
|
-
} else if (typeof this.#body.pipe === "function") body = this.#body;
|
|
237
|
-
else body = this._response.body;
|
|
238
|
-
const headers = [];
|
|
239
|
-
const initHeaders = this.#init?.headers;
|
|
240
|
-
const headerEntries = this.#response?.headers || this.#headers || (initHeaders ? Array.isArray(initHeaders) ? initHeaders : initHeaders?.entries ? initHeaders.entries() : Object.entries(initHeaders) : void 0);
|
|
241
|
-
let hasContentTypeHeader;
|
|
242
|
-
let hasContentLength;
|
|
243
|
-
if (headerEntries) for (const [key, value] of headerEntries) {
|
|
244
|
-
const lowerKey = typeof key === "string" ? key.toLowerCase() : String(key);
|
|
245
|
-
if (Array.isArray(value)) for (const v of value) headers.push(lowerKey, v);
|
|
246
|
-
else headers.push(lowerKey, value);
|
|
247
|
-
if (lowerKey === "content-type") hasContentTypeHeader = true;
|
|
248
|
-
else if (lowerKey === "content-length") hasContentLength = true;
|
|
249
|
-
}
|
|
250
|
-
if (contentType && !hasContentTypeHeader) headers.push("content-type", contentType);
|
|
251
|
-
if (contentLength && !hasContentLength) headers.push("content-length", String(contentLength));
|
|
252
|
-
this.#init = void 0;
|
|
253
|
-
this.#headers = void 0;
|
|
254
|
-
this.#response = void 0;
|
|
255
|
-
this.#body = void 0;
|
|
256
|
-
return {
|
|
257
|
-
status,
|
|
258
|
-
statusText,
|
|
259
|
-
headers,
|
|
260
|
-
body
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
lazyInherit(NodeResponse.prototype, NativeResponse.prototype, "_response");
|
|
265
|
-
Object.setPrototypeOf(NodeResponse, NativeResponse);
|
|
266
|
-
Object.setPrototypeOf(NodeResponse.prototype, NativeResponse.prototype);
|
|
267
|
-
return NodeResponse;
|
|
268
|
-
})();
|
|
269
|
-
function decodePathname(pathname) {
|
|
270
|
-
return decodeURI(pathname.includes("%25") ? pathname.replace(/%25/g, "%2525") : pathname);
|
|
271
|
-
}
|
|
272
|
-
var kEventNS = "h3.internal.event.";
|
|
273
|
-
var kEventRes = /* @__PURE__ */ Symbol.for(`${kEventNS}res`);
|
|
274
|
-
var kEventResHeaders = /* @__PURE__ */ Symbol.for(`${kEventNS}res.headers`);
|
|
275
|
-
var kEventResErrHeaders = /* @__PURE__ */ Symbol.for(`${kEventNS}res.err.headers`);
|
|
276
|
-
var H3Event = class {
|
|
277
|
-
app;
|
|
278
|
-
req;
|
|
279
|
-
url;
|
|
280
|
-
context;
|
|
281
|
-
static __is_event__ = true;
|
|
282
|
-
constructor(req, context, app) {
|
|
283
|
-
this.context = context || req.context || new NullProtoObj();
|
|
284
|
-
this.req = req;
|
|
285
|
-
this.app = app;
|
|
286
|
-
const _url = req._url;
|
|
287
|
-
const url = _url && _url instanceof URL ? _url : new FastURL(req.url);
|
|
288
|
-
if (url.pathname.includes("%")) url.pathname = decodePathname(url.pathname);
|
|
289
|
-
this.url = url;
|
|
290
|
-
}
|
|
291
|
-
get res() {
|
|
292
|
-
return this[kEventRes] ||= new H3EventResponse();
|
|
293
|
-
}
|
|
294
|
-
get runtime() {
|
|
295
|
-
return this.req.runtime;
|
|
296
|
-
}
|
|
297
|
-
waitUntil(promise) {
|
|
298
|
-
this.req.waitUntil?.(promise);
|
|
299
|
-
}
|
|
300
|
-
toString() {
|
|
301
|
-
return `[${this.req.method}] ${this.req.url}`;
|
|
302
|
-
}
|
|
303
|
-
toJSON() {
|
|
304
|
-
return this.toString();
|
|
305
|
-
}
|
|
306
|
-
get node() {
|
|
307
|
-
return this.req.runtime?.node;
|
|
308
|
-
}
|
|
309
|
-
get headers() {
|
|
310
|
-
return this.req.headers;
|
|
311
|
-
}
|
|
312
|
-
get path() {
|
|
313
|
-
return this.url.pathname + this.url.search;
|
|
314
|
-
}
|
|
315
|
-
get method() {
|
|
316
|
-
return this.req.method;
|
|
317
|
-
}
|
|
318
|
-
};
|
|
319
|
-
var H3EventResponse = class {
|
|
320
|
-
status;
|
|
321
|
-
statusText;
|
|
322
|
-
get headers() {
|
|
323
|
-
return this[kEventResHeaders] ||= new Headers();
|
|
324
|
-
}
|
|
325
|
-
get errHeaders() {
|
|
326
|
-
return this[kEventResErrHeaders] ||= new Headers();
|
|
327
|
-
}
|
|
328
|
-
};
|
|
329
|
-
var DISALLOWED_STATUS_CHARS = /[^\u0009\u0020-\u007E]/g;
|
|
330
|
-
function sanitizeStatusMessage(statusMessage = "") {
|
|
331
|
-
return statusMessage.replace(DISALLOWED_STATUS_CHARS, "");
|
|
332
|
-
}
|
|
333
|
-
function sanitizeStatusCode(statusCode, defaultStatusCode = 200) {
|
|
334
|
-
if (!statusCode) return defaultStatusCode;
|
|
335
|
-
if (typeof statusCode === "string") statusCode = +statusCode;
|
|
336
|
-
if (statusCode < 100 || statusCode > 599) return defaultStatusCode;
|
|
337
|
-
return statusCode;
|
|
338
|
-
}
|
|
339
|
-
var HTTPError = class HTTPError extends Error {
|
|
340
|
-
get name() {
|
|
341
|
-
return "HTTPError";
|
|
342
|
-
}
|
|
343
|
-
status;
|
|
344
|
-
statusText;
|
|
345
|
-
headers;
|
|
346
|
-
cause;
|
|
347
|
-
data;
|
|
348
|
-
body;
|
|
349
|
-
unhandled;
|
|
350
|
-
static isError(input) {
|
|
351
|
-
return input instanceof Error && input?.name === "HTTPError";
|
|
352
|
-
}
|
|
353
|
-
static status(status, statusText, details) {
|
|
354
|
-
return new HTTPError({
|
|
355
|
-
...details,
|
|
356
|
-
statusText,
|
|
357
|
-
status
|
|
358
|
-
});
|
|
359
|
-
}
|
|
360
|
-
constructor(arg1, arg2) {
|
|
361
|
-
let messageInput;
|
|
362
|
-
let details;
|
|
363
|
-
if (typeof arg1 === "string") {
|
|
364
|
-
messageInput = arg1;
|
|
365
|
-
details = arg2;
|
|
366
|
-
} else details = arg1;
|
|
367
|
-
const status = sanitizeStatusCode(details?.status || details?.statusCode || (details?.cause)?.status || (details?.cause)?.statusCode, 500);
|
|
368
|
-
const statusText = sanitizeStatusMessage(details?.statusText || details?.statusMessage || (details?.cause)?.statusText || (details?.cause)?.statusMessage);
|
|
369
|
-
const message = messageInput || details?.message || (details?.cause)?.message || details?.statusText || details?.statusMessage || [
|
|
370
|
-
"HTTPError",
|
|
371
|
-
status,
|
|
372
|
-
statusText
|
|
373
|
-
].filter(Boolean).join(" ");
|
|
374
|
-
super(message, { cause: details });
|
|
375
|
-
this.cause = details;
|
|
376
|
-
this.status = status;
|
|
377
|
-
this.statusText = statusText || void 0;
|
|
378
|
-
const rawHeaders = details?.headers || (details?.cause)?.headers;
|
|
379
|
-
this.headers = rawHeaders ? new Headers(rawHeaders) : void 0;
|
|
380
|
-
this.unhandled = details?.unhandled ?? (details?.cause)?.unhandled ?? void 0;
|
|
381
|
-
this.data = details?.data;
|
|
382
|
-
this.body = details?.body;
|
|
383
|
-
}
|
|
384
|
-
get statusCode() {
|
|
385
|
-
return this.status;
|
|
386
|
-
}
|
|
387
|
-
get statusMessage() {
|
|
388
|
-
return this.statusText;
|
|
389
|
-
}
|
|
390
|
-
toJSON() {
|
|
391
|
-
const unhandled = this.unhandled;
|
|
392
|
-
return {
|
|
393
|
-
status: this.status,
|
|
394
|
-
statusText: this.statusText,
|
|
395
|
-
unhandled,
|
|
396
|
-
message: unhandled ? "HTTPError" : this.message,
|
|
397
|
-
data: unhandled ? void 0 : this.data,
|
|
398
|
-
...unhandled ? void 0 : this.body
|
|
399
|
-
};
|
|
400
|
-
}
|
|
401
|
-
};
|
|
402
|
-
function isJSONSerializable(value, _type) {
|
|
403
|
-
if (value === null || value === void 0) return true;
|
|
404
|
-
if (_type !== "object") return _type === "boolean" || _type === "number" || _type === "string";
|
|
405
|
-
if (typeof value.toJSON === "function") return true;
|
|
406
|
-
if (Array.isArray(value)) return true;
|
|
407
|
-
if (typeof value.pipe === "function" || typeof value.pipeTo === "function") return false;
|
|
408
|
-
if (value instanceof NullProtoObj) return true;
|
|
409
|
-
const proto = Object.getPrototypeOf(value);
|
|
410
|
-
return proto === Object.prototype || proto === null;
|
|
411
|
-
}
|
|
412
|
-
var kNotFound = /* @__PURE__ */ Symbol.for("h3.notFound");
|
|
413
|
-
var kHandled = /* @__PURE__ */ Symbol.for("h3.handled");
|
|
414
|
-
function toResponse(val, event, config = {}) {
|
|
415
|
-
if (typeof val?.then === "function") return (val.catch?.((error) => error) || Promise.resolve(val)).then((resolvedVal) => toResponse(resolvedVal, event, config));
|
|
416
|
-
const response = prepareResponse(val, event, config);
|
|
417
|
-
if (typeof response?.then === "function") return toResponse(response, event, config);
|
|
418
|
-
const { onResponse } = config;
|
|
419
|
-
return onResponse ? Promise.resolve(onResponse(response, event)).then(() => response) : response;
|
|
420
|
-
}
|
|
421
|
-
var HTTPResponse = class {
|
|
422
|
-
#headers;
|
|
423
|
-
#init;
|
|
424
|
-
body;
|
|
425
|
-
constructor(body, init) {
|
|
426
|
-
this.body = body;
|
|
427
|
-
this.#init = init;
|
|
428
|
-
}
|
|
429
|
-
get status() {
|
|
430
|
-
return this.#init?.status || 200;
|
|
431
|
-
}
|
|
432
|
-
get statusText() {
|
|
433
|
-
return this.#init?.statusText || "OK";
|
|
434
|
-
}
|
|
435
|
-
get headers() {
|
|
436
|
-
return this.#headers ||= new Headers(this.#init?.headers);
|
|
437
|
-
}
|
|
438
|
-
};
|
|
439
|
-
function prepareResponse(val, event, config, nested) {
|
|
440
|
-
if (val === kHandled) return new NodeResponse(null);
|
|
441
|
-
if (val === kNotFound) val = new HTTPError({
|
|
442
|
-
status: 404,
|
|
443
|
-
message: `Cannot find any route matching [${event.req.method}] ${event.url}`
|
|
444
|
-
});
|
|
445
|
-
if (val && val instanceof Error) {
|
|
446
|
-
const isHTTPError = HTTPError.isError(val);
|
|
447
|
-
const error = isHTTPError ? val : new HTTPError(val);
|
|
448
|
-
if (!isHTTPError) {
|
|
449
|
-
error.unhandled = true;
|
|
450
|
-
if (val?.stack) error.stack = val.stack;
|
|
451
|
-
}
|
|
452
|
-
if (error.unhandled && !config.silent) console.error(error);
|
|
453
|
-
const { onError } = config;
|
|
454
|
-
const errHeaders = event[kEventRes]?.[kEventResErrHeaders];
|
|
455
|
-
return onError && !nested ? Promise.resolve(onError(error, event)).catch((error) => error).then((newVal) => prepareResponse(newVal ?? val, event, config, true)) : errorResponse(error, config.debug, errHeaders);
|
|
456
|
-
}
|
|
457
|
-
const preparedRes = event[kEventRes];
|
|
458
|
-
const preparedHeaders = preparedRes?.[kEventResHeaders];
|
|
459
|
-
event[kEventRes] = void 0;
|
|
460
|
-
if (!(val instanceof Response)) {
|
|
461
|
-
const res = prepareResponseBody(val, event, config);
|
|
462
|
-
const status = res.status || preparedRes?.status;
|
|
463
|
-
return new NodeResponse(nullBody(event.req.method, status) ? null : res.body, {
|
|
464
|
-
status,
|
|
465
|
-
statusText: res.statusText || preparedRes?.statusText,
|
|
466
|
-
headers: res.headers && preparedHeaders ? mergeHeaders$1(res.headers, preparedHeaders) : res.headers || preparedHeaders
|
|
467
|
-
});
|
|
468
|
-
}
|
|
469
|
-
if (!preparedHeaders || nested || !val.ok) return val;
|
|
470
|
-
try {
|
|
471
|
-
mergeHeaders$1(val.headers, preparedHeaders, val.headers);
|
|
472
|
-
return val;
|
|
473
|
-
} catch {
|
|
474
|
-
return new NodeResponse(nullBody(event.req.method, val.status) ? null : val.body, {
|
|
475
|
-
status: val.status,
|
|
476
|
-
statusText: val.statusText,
|
|
477
|
-
headers: mergeHeaders$1(val.headers, preparedHeaders)
|
|
478
|
-
});
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
function mergeHeaders$1(base, overrides, target = new Headers(base)) {
|
|
482
|
-
for (const [name, value] of overrides) if (name === "set-cookie") target.append(name, value);
|
|
483
|
-
else target.set(name, value);
|
|
484
|
-
return target;
|
|
485
|
-
}
|
|
486
|
-
var frozen = (name) => (...args) => {
|
|
487
|
-
throw new Error(`Headers are frozen (${name} ${args.join(", ")})`);
|
|
488
|
-
};
|
|
489
|
-
var FrozenHeaders = class extends Headers {
|
|
490
|
-
set = frozen("set");
|
|
491
|
-
append = frozen("append");
|
|
492
|
-
delete = frozen("delete");
|
|
493
|
-
};
|
|
494
|
-
var emptyHeaders = /* @__PURE__ */ new FrozenHeaders({ "content-length": "0" });
|
|
495
|
-
var jsonHeaders = /* @__PURE__ */ new FrozenHeaders({ "content-type": "application/json;charset=UTF-8" });
|
|
496
|
-
function prepareResponseBody(val, event, config) {
|
|
497
|
-
if (val === null || val === void 0) return {
|
|
498
|
-
body: "",
|
|
499
|
-
headers: emptyHeaders
|
|
500
|
-
};
|
|
501
|
-
const valType = typeof val;
|
|
502
|
-
if (valType === "string") return { body: val };
|
|
503
|
-
if (val instanceof Uint8Array) {
|
|
504
|
-
event.res.headers.set("content-length", val.byteLength.toString());
|
|
505
|
-
return { body: val };
|
|
506
|
-
}
|
|
507
|
-
if (val instanceof HTTPResponse || val?.constructor?.name === "HTTPResponse") return val;
|
|
508
|
-
if (isJSONSerializable(val, valType)) return {
|
|
509
|
-
body: JSON.stringify(val, void 0, config.debug ? 2 : void 0),
|
|
510
|
-
headers: jsonHeaders
|
|
511
|
-
};
|
|
512
|
-
if (valType === "bigint") return {
|
|
513
|
-
body: val.toString(),
|
|
514
|
-
headers: jsonHeaders
|
|
515
|
-
};
|
|
516
|
-
if (val instanceof Blob) {
|
|
517
|
-
const headers = new Headers({
|
|
518
|
-
"content-type": val.type,
|
|
519
|
-
"content-length": val.size.toString()
|
|
520
|
-
});
|
|
521
|
-
let filename = val.name;
|
|
522
|
-
if (filename) {
|
|
523
|
-
filename = encodeURIComponent(filename);
|
|
524
|
-
headers.set("content-disposition", `filename="${filename}"; filename*=UTF-8''${filename}`);
|
|
525
|
-
}
|
|
526
|
-
return {
|
|
527
|
-
body: val.stream(),
|
|
528
|
-
headers
|
|
529
|
-
};
|
|
530
|
-
}
|
|
531
|
-
if (valType === "symbol") return { body: val.toString() };
|
|
532
|
-
if (valType === "function") return { body: `${val.name}()` };
|
|
533
|
-
return { body: val };
|
|
534
|
-
}
|
|
535
|
-
function nullBody(method, status) {
|
|
536
|
-
return method === "HEAD" || status === 100 || status === 101 || status === 102 || status === 204 || status === 205 || status === 304;
|
|
537
|
-
}
|
|
538
|
-
function errorResponse(error, debug, errHeaders) {
|
|
539
|
-
let headers = error.headers ? mergeHeaders$1(jsonHeaders, error.headers) : new Headers(jsonHeaders);
|
|
540
|
-
if (errHeaders) headers = mergeHeaders$1(headers, errHeaders);
|
|
541
|
-
return new NodeResponse(JSON.stringify({
|
|
542
|
-
...error.toJSON(),
|
|
543
|
-
stack: debug && error.stack ? error.stack.split("\n").map((l) => l.trim()) : void 0
|
|
544
|
-
}, void 0, debug ? 2 : void 0), {
|
|
545
|
-
status: error.status,
|
|
546
|
-
statusText: error.statusText,
|
|
547
|
-
headers
|
|
548
|
-
});
|
|
549
|
-
}
|
|
550
|
-
var plusRegex = /\+/g;
|
|
551
|
-
function parseQuery(input) {
|
|
552
|
-
const params = new NullProtoObj();
|
|
553
|
-
if (!input || input === "?") return params;
|
|
554
|
-
const inputLength = input.length;
|
|
555
|
-
let key = "";
|
|
556
|
-
let value = "";
|
|
557
|
-
let startingIndex = -1;
|
|
558
|
-
let equalityIndex = -1;
|
|
559
|
-
let shouldDecodeKey = false;
|
|
560
|
-
let shouldDecodeValue = false;
|
|
561
|
-
let keyHasPlus = false;
|
|
562
|
-
let valueHasPlus = false;
|
|
563
|
-
let hasBothKeyValuePair = false;
|
|
564
|
-
let c = 0;
|
|
565
|
-
for (let i = 0; i < inputLength + 1; i++) {
|
|
566
|
-
c = i === inputLength ? 38 : input.charCodeAt(i);
|
|
567
|
-
switch (c) {
|
|
568
|
-
case 38:
|
|
569
|
-
hasBothKeyValuePair = equalityIndex > startingIndex;
|
|
570
|
-
if (!hasBothKeyValuePair) equalityIndex = i;
|
|
571
|
-
key = input.slice(startingIndex + 1, equalityIndex);
|
|
572
|
-
if (hasBothKeyValuePair || key.length > 0) {
|
|
573
|
-
if (keyHasPlus) key = key.replace(plusRegex, " ");
|
|
574
|
-
if (shouldDecodeKey) try {
|
|
575
|
-
key = decodeURIComponent(key);
|
|
576
|
-
} catch {}
|
|
577
|
-
if (hasBothKeyValuePair) {
|
|
578
|
-
value = input.slice(equalityIndex + 1, i);
|
|
579
|
-
if (valueHasPlus) value = value.replace(plusRegex, " ");
|
|
580
|
-
if (shouldDecodeValue) try {
|
|
581
|
-
value = decodeURIComponent(value);
|
|
582
|
-
} catch {}
|
|
583
|
-
}
|
|
584
|
-
const currentValue = params[key];
|
|
585
|
-
if (currentValue === void 0) params[key] = value;
|
|
586
|
-
else if (Array.isArray(currentValue)) currentValue.push(value);
|
|
587
|
-
else params[key] = [currentValue, value];
|
|
588
|
-
}
|
|
589
|
-
value = "";
|
|
590
|
-
startingIndex = i;
|
|
591
|
-
equalityIndex = i;
|
|
592
|
-
shouldDecodeKey = false;
|
|
593
|
-
shouldDecodeValue = false;
|
|
594
|
-
keyHasPlus = false;
|
|
595
|
-
valueHasPlus = false;
|
|
596
|
-
break;
|
|
597
|
-
case 61:
|
|
598
|
-
if (equalityIndex <= startingIndex) equalityIndex = i;
|
|
599
|
-
else shouldDecodeValue = true;
|
|
600
|
-
break;
|
|
601
|
-
case 43:
|
|
602
|
-
if (equalityIndex > startingIndex) valueHasPlus = true;
|
|
603
|
-
else keyHasPlus = true;
|
|
604
|
-
break;
|
|
605
|
-
case 37:
|
|
606
|
-
if (equalityIndex > startingIndex) shouldDecodeValue = true;
|
|
607
|
-
else shouldDecodeKey = true;
|
|
608
|
-
break;
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
return params;
|
|
612
|
-
}
|
|
613
|
-
var VALIDATION_FAILED = "Validation failed";
|
|
614
|
-
async function validateData(data, fn, options) {
|
|
615
|
-
if ("~standard" in fn) {
|
|
616
|
-
const result = await fn["~standard"].validate(data);
|
|
617
|
-
if (result.issues) throw createValidationError(options?.onError?.(result) || {
|
|
618
|
-
message: VALIDATION_FAILED,
|
|
619
|
-
issues: result.issues
|
|
620
|
-
});
|
|
621
|
-
return result.value;
|
|
622
|
-
}
|
|
623
|
-
try {
|
|
624
|
-
const res = await fn(data);
|
|
625
|
-
if (res === false) throw createValidationError(options?.onError?.({ issues: [{ message: VALIDATION_FAILED }] }) || { message: VALIDATION_FAILED });
|
|
626
|
-
if (res === true) return data;
|
|
627
|
-
return res ?? data;
|
|
628
|
-
} catch (error) {
|
|
629
|
-
throw createValidationError(error);
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
function createValidationError(cause) {
|
|
633
|
-
return HTTPError.isError(cause) ? cause : new HTTPError({
|
|
634
|
-
cause,
|
|
635
|
-
status: cause?.status || 400,
|
|
636
|
-
statusText: cause?.statusText || VALIDATION_FAILED,
|
|
637
|
-
message: cause?.message || VALIDATION_FAILED,
|
|
638
|
-
data: {
|
|
639
|
-
issues: cause?.issues,
|
|
640
|
-
message: cause instanceof Error ? VALIDATION_FAILED : cause?.message || VALIDATION_FAILED
|
|
641
|
-
}
|
|
642
|
-
});
|
|
643
|
-
}
|
|
644
|
-
function getEventContext(event) {
|
|
645
|
-
if (event.context) return event.context;
|
|
646
|
-
event.req.context ??= {};
|
|
647
|
-
return event.req.context;
|
|
648
|
-
}
|
|
649
|
-
function getQuery(event) {
|
|
650
|
-
return parseQuery((event.url || new URL(event.req.url)).search.slice(1));
|
|
651
|
-
}
|
|
652
|
-
function getValidatedQuery$1(event, validate, options) {
|
|
653
|
-
return validateData(getQuery(event), validate, options);
|
|
654
|
-
}
|
|
655
|
-
function getRequestHost$1(event, opts = {}) {
|
|
656
|
-
if (opts.xForwardedHost) {
|
|
657
|
-
const xForwardedHost = (event.req.headers.get("x-forwarded-host") || "").split(",").shift()?.trim();
|
|
658
|
-
if (xForwardedHost) return xForwardedHost;
|
|
659
|
-
}
|
|
660
|
-
return event.req.headers.get("host") || "";
|
|
661
|
-
}
|
|
662
|
-
function getRequestProtocol$1(event, opts = {}) {
|
|
663
|
-
if (opts.xForwardedProto !== false) {
|
|
664
|
-
const forwardedProto = event.req.headers.get("x-forwarded-proto");
|
|
665
|
-
if (forwardedProto === "https") return "https";
|
|
666
|
-
if (forwardedProto === "http") return "http";
|
|
667
|
-
}
|
|
668
|
-
return (event.url || new URL(event.req.url)).protocol.slice(0, -1);
|
|
669
|
-
}
|
|
670
|
-
function getRequestURL(event, opts = {}) {
|
|
671
|
-
const url = new URL(event.url || event.req.url);
|
|
672
|
-
url.protocol = getRequestProtocol$1(event, opts);
|
|
673
|
-
if (opts.xForwardedHost) {
|
|
674
|
-
const host = getRequestHost$1(event, opts);
|
|
675
|
-
if (host) {
|
|
676
|
-
url.host = host;
|
|
677
|
-
if (!/:\d+$/.test(host)) url.port = "";
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
return url;
|
|
681
|
-
}
|
|
682
|
-
function getRequestIP$1(event, opts = {}) {
|
|
683
|
-
if (opts.xForwardedFor) {
|
|
684
|
-
const _header = event.req.headers.get("x-forwarded-for");
|
|
685
|
-
if (_header) {
|
|
686
|
-
const xForwardedFor = _header.split(",")[0].trim();
|
|
687
|
-
if (xForwardedFor) return xForwardedFor;
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
return event.req.context?.clientAddress || event.req.ip || void 0;
|
|
691
|
-
}
|
|
692
|
-
var textEncoder$4 = /* @__PURE__ */ new TextEncoder();
|
|
693
|
-
var textDecoder$1 = /* @__PURE__ */ new TextDecoder();
|
|
694
|
-
var base64Code = [
|
|
695
|
-
65,
|
|
696
|
-
66,
|
|
697
|
-
67,
|
|
698
|
-
68,
|
|
699
|
-
69,
|
|
700
|
-
70,
|
|
701
|
-
71,
|
|
702
|
-
72,
|
|
703
|
-
73,
|
|
704
|
-
74,
|
|
705
|
-
75,
|
|
706
|
-
76,
|
|
707
|
-
77,
|
|
708
|
-
78,
|
|
709
|
-
79,
|
|
710
|
-
80,
|
|
711
|
-
81,
|
|
712
|
-
82,
|
|
713
|
-
83,
|
|
714
|
-
84,
|
|
715
|
-
85,
|
|
716
|
-
86,
|
|
717
|
-
87,
|
|
718
|
-
88,
|
|
719
|
-
89,
|
|
720
|
-
90,
|
|
721
|
-
97,
|
|
722
|
-
98,
|
|
723
|
-
99,
|
|
724
|
-
100,
|
|
725
|
-
101,
|
|
726
|
-
102,
|
|
727
|
-
103,
|
|
728
|
-
104,
|
|
729
|
-
105,
|
|
730
|
-
106,
|
|
731
|
-
107,
|
|
732
|
-
108,
|
|
733
|
-
109,
|
|
734
|
-
110,
|
|
735
|
-
111,
|
|
736
|
-
112,
|
|
737
|
-
113,
|
|
738
|
-
114,
|
|
739
|
-
115,
|
|
740
|
-
116,
|
|
741
|
-
117,
|
|
742
|
-
118,
|
|
743
|
-
119,
|
|
744
|
-
120,
|
|
745
|
-
121,
|
|
746
|
-
122,
|
|
747
|
-
48,
|
|
748
|
-
49,
|
|
749
|
-
50,
|
|
750
|
-
51,
|
|
751
|
-
52,
|
|
752
|
-
53,
|
|
753
|
-
54,
|
|
754
|
-
55,
|
|
755
|
-
56,
|
|
756
|
-
57,
|
|
757
|
-
45,
|
|
758
|
-
95
|
|
759
|
-
];
|
|
760
|
-
function base64Encode(data) {
|
|
761
|
-
const buff = validateBinaryLike(data);
|
|
762
|
-
if (globalThis.Buffer) return globalThis.Buffer.from(buff).toString("base64url");
|
|
763
|
-
const bytes = [];
|
|
764
|
-
let i;
|
|
765
|
-
const len = buff.length;
|
|
766
|
-
for (i = 2; i < len; i += 3) bytes.push(base64Code[buff[i - 2] >> 2], base64Code[(buff[i - 2] & 3) << 4 | buff[i - 1] >> 4], base64Code[(buff[i - 1] & 15) << 2 | buff[i] >> 6], base64Code[buff[i] & 63]);
|
|
767
|
-
if (i === len + 1) bytes.push(base64Code[buff[i - 2] >> 2], base64Code[(buff[i - 2] & 3) << 4]);
|
|
768
|
-
if (i === len) bytes.push(base64Code[buff[i - 2] >> 2], base64Code[(buff[i - 2] & 3) << 4 | buff[i - 1] >> 4], base64Code[(buff[i - 1] & 15) << 2]);
|
|
769
|
-
return String.fromCharCode(...bytes);
|
|
770
|
-
}
|
|
771
|
-
function base64Decode(b64Url) {
|
|
772
|
-
if (globalThis.Buffer) return new Uint8Array(globalThis.Buffer.from(b64Url, "base64url"));
|
|
773
|
-
const b64 = b64Url.replace(/-/g, "+").replace(/_/g, "/");
|
|
774
|
-
const binString = atob(b64);
|
|
775
|
-
const size = binString.length;
|
|
776
|
-
const bytes = new Uint8Array(size);
|
|
777
|
-
for (let i = 0; i < size; i++) bytes[i] = binString.charCodeAt(i);
|
|
778
|
-
return bytes;
|
|
779
|
-
}
|
|
780
|
-
function validateBinaryLike(source) {
|
|
781
|
-
if (typeof source === "string") return textEncoder$4.encode(source);
|
|
782
|
-
else if (source instanceof Uint8Array) return source;
|
|
783
|
-
else if (source instanceof ArrayBuffer) return new Uint8Array(source);
|
|
784
|
-
throw new TypeError(`The input must be a Uint8Array, a string, or an ArrayBuffer.`);
|
|
785
|
-
}
|
|
786
|
-
var COOKIE_MAX_AGE_LIMIT = 3456e4;
|
|
787
|
-
function endIndex(str, min, len) {
|
|
788
|
-
const index = str.indexOf(";", min);
|
|
789
|
-
return index === -1 ? len : index;
|
|
790
|
-
}
|
|
791
|
-
function eqIndex(str, min, max) {
|
|
792
|
-
const index = str.indexOf("=", min);
|
|
793
|
-
return index < max ? index : -1;
|
|
794
|
-
}
|
|
795
|
-
function valueSlice(str, min, max) {
|
|
796
|
-
if (min === max) return "";
|
|
797
|
-
let start = min;
|
|
798
|
-
let end = max;
|
|
799
|
-
do {
|
|
800
|
-
const code = str.charCodeAt(start);
|
|
801
|
-
if (code !== 32 && code !== 9) break;
|
|
802
|
-
} while (++start < end);
|
|
803
|
-
while (end > start) {
|
|
804
|
-
const code = str.charCodeAt(end - 1);
|
|
805
|
-
if (code !== 32 && code !== 9) break;
|
|
806
|
-
end--;
|
|
807
|
-
}
|
|
808
|
-
return str.slice(start, end);
|
|
809
|
-
}
|
|
810
|
-
var NullObject = /* @__PURE__ */ (() => {
|
|
811
|
-
const C = function() {};
|
|
812
|
-
C.prototype = Object.create(null);
|
|
813
|
-
return C;
|
|
814
|
-
})();
|
|
815
|
-
function parse(str, options) {
|
|
816
|
-
const obj = new NullObject();
|
|
817
|
-
const len = str.length;
|
|
818
|
-
if (len < 2) return obj;
|
|
819
|
-
const dec = options?.decode || decode;
|
|
820
|
-
const allowMultiple = options?.allowMultiple || false;
|
|
821
|
-
let index = 0;
|
|
822
|
-
do {
|
|
823
|
-
const eqIdx = eqIndex(str, index, len);
|
|
824
|
-
if (eqIdx === -1) break;
|
|
825
|
-
const endIdx = endIndex(str, index, len);
|
|
826
|
-
if (eqIdx > endIdx) {
|
|
827
|
-
index = str.lastIndexOf(";", eqIdx - 1) + 1;
|
|
828
|
-
continue;
|
|
829
|
-
}
|
|
830
|
-
const key = valueSlice(str, index, eqIdx);
|
|
831
|
-
if (options?.filter && !options.filter(key)) {
|
|
832
|
-
index = endIdx + 1;
|
|
833
|
-
continue;
|
|
834
|
-
}
|
|
835
|
-
const val = dec(valueSlice(str, eqIdx + 1, endIdx));
|
|
836
|
-
if (allowMultiple) {
|
|
837
|
-
const existing = obj[key];
|
|
838
|
-
if (existing === void 0) obj[key] = val;
|
|
839
|
-
else if (Array.isArray(existing)) existing.push(val);
|
|
840
|
-
else obj[key] = [existing, val];
|
|
841
|
-
} else if (obj[key] === void 0) obj[key] = val;
|
|
842
|
-
index = endIdx + 1;
|
|
843
|
-
} while (index < len);
|
|
844
|
-
return obj;
|
|
845
|
-
}
|
|
846
|
-
function decode(str) {
|
|
847
|
-
if (!str.includes("%")) return str;
|
|
848
|
-
try {
|
|
849
|
-
return decodeURIComponent(str);
|
|
850
|
-
} catch {
|
|
851
|
-
return str;
|
|
852
|
-
}
|
|
853
|
-
}
|
|
854
|
-
var cookieNameRegExp = /^[\u0021-\u003A\u003C\u003E-\u007E]+$/;
|
|
855
|
-
var cookieValueRegExp = /^[\u0021-\u003A\u003C-\u007E]*$/;
|
|
856
|
-
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;
|
|
857
|
-
var pathValueRegExp = /^[\u0020-\u003A\u003C-\u007E]*$/;
|
|
858
|
-
var __toString = Object.prototype.toString;
|
|
859
|
-
function serialize(_a0, _a1, _a2) {
|
|
860
|
-
const isObj = typeof _a0 === "object" && _a0 !== null;
|
|
861
|
-
const options = isObj ? _a1 : _a2;
|
|
862
|
-
const stringify = options?.stringify || JSON.stringify;
|
|
863
|
-
const cookie = isObj ? _a0 : {
|
|
864
|
-
..._a2,
|
|
865
|
-
name: _a0,
|
|
866
|
-
value: _a1 == void 0 ? "" : typeof _a1 === "string" ? _a1 : stringify(_a1)
|
|
867
|
-
};
|
|
868
|
-
const enc = options?.encode || encodeURIComponent;
|
|
869
|
-
if (!cookieNameRegExp.test(cookie.name)) throw new TypeError(`argument name is invalid: ${cookie.name}`);
|
|
870
|
-
const value = cookie.value ? enc(cookie.value) : "";
|
|
871
|
-
if (!cookieValueRegExp.test(value)) throw new TypeError(`argument val is invalid: ${cookie.value}`);
|
|
872
|
-
if (!cookie.secure) {
|
|
873
|
-
if (cookie.partitioned) throw new TypeError(`Partitioned cookies must have the Secure attribute`);
|
|
874
|
-
if (cookie.sameSite && String(cookie.sameSite).toLowerCase() === "none") throw new TypeError(`SameSite=None cookies must have the Secure attribute`);
|
|
875
|
-
if (cookie.name.length > 9 && cookie.name.charCodeAt(0) === 95 && cookie.name.charCodeAt(1) === 95) {
|
|
876
|
-
const nameLower = cookie.name.toLowerCase();
|
|
877
|
-
if (nameLower.startsWith("__secure-") || nameLower.startsWith("__host-")) throw new TypeError(`${cookie.name} cookies must have the Secure attribute`);
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
if (cookie.name.length > 7 && cookie.name.charCodeAt(0) === 95 && cookie.name.charCodeAt(1) === 95 && cookie.name.toLowerCase().startsWith("__host-")) {
|
|
881
|
-
if (cookie.path !== "/") throw new TypeError(`__Host- cookies must have Path=/`);
|
|
882
|
-
if (cookie.domain) throw new TypeError(`__Host- cookies must not have a Domain attribute`);
|
|
883
|
-
}
|
|
884
|
-
let str = cookie.name + "=" + value;
|
|
885
|
-
if (cookie.maxAge !== void 0) {
|
|
886
|
-
if (!Number.isInteger(cookie.maxAge)) throw new TypeError(`option maxAge is invalid: ${cookie.maxAge}`);
|
|
887
|
-
str += "; Max-Age=" + Math.max(0, Math.min(cookie.maxAge, COOKIE_MAX_AGE_LIMIT));
|
|
888
|
-
}
|
|
889
|
-
if (cookie.domain) {
|
|
890
|
-
if (!domainValueRegExp.test(cookie.domain)) throw new TypeError(`option domain is invalid: ${cookie.domain}`);
|
|
891
|
-
str += "; Domain=" + cookie.domain;
|
|
892
|
-
}
|
|
893
|
-
if (cookie.path) {
|
|
894
|
-
if (!pathValueRegExp.test(cookie.path)) throw new TypeError(`option path is invalid: ${cookie.path}`);
|
|
895
|
-
str += "; Path=" + cookie.path;
|
|
896
|
-
}
|
|
897
|
-
if (cookie.expires) {
|
|
898
|
-
if (!isDate(cookie.expires) || !Number.isFinite(cookie.expires.valueOf())) throw new TypeError(`option expires is invalid: ${cookie.expires}`);
|
|
899
|
-
str += "; Expires=" + cookie.expires.toUTCString();
|
|
900
|
-
}
|
|
901
|
-
if (cookie.httpOnly) str += "; HttpOnly";
|
|
902
|
-
if (cookie.secure) str += "; Secure";
|
|
903
|
-
if (cookie.partitioned) str += "; Partitioned";
|
|
904
|
-
if (cookie.priority) switch (typeof cookie.priority === "string" ? cookie.priority.toLowerCase() : void 0) {
|
|
905
|
-
case "low":
|
|
906
|
-
str += "; Priority=Low";
|
|
907
|
-
break;
|
|
908
|
-
case "medium":
|
|
909
|
-
str += "; Priority=Medium";
|
|
910
|
-
break;
|
|
911
|
-
case "high":
|
|
912
|
-
str += "; Priority=High";
|
|
913
|
-
break;
|
|
914
|
-
default: throw new TypeError(`option priority is invalid: ${cookie.priority}`);
|
|
915
|
-
}
|
|
916
|
-
if (cookie.sameSite) switch (typeof cookie.sameSite === "string" ? cookie.sameSite.toLowerCase() : cookie.sameSite) {
|
|
917
|
-
case true:
|
|
918
|
-
case "strict":
|
|
919
|
-
str += "; SameSite=Strict";
|
|
920
|
-
break;
|
|
921
|
-
case "lax":
|
|
922
|
-
str += "; SameSite=Lax";
|
|
923
|
-
break;
|
|
924
|
-
case "none":
|
|
925
|
-
str += "; SameSite=None";
|
|
926
|
-
break;
|
|
927
|
-
default: throw new TypeError(`option sameSite is invalid: ${cookie.sameSite}`);
|
|
928
|
-
}
|
|
929
|
-
return str;
|
|
930
|
-
}
|
|
931
|
-
function isDate(val) {
|
|
932
|
-
return __toString.call(val) === "[object Date]";
|
|
933
|
-
}
|
|
934
|
-
var maxAgeRegExp = /^-?\d+$/;
|
|
935
|
-
var _nullProto = /* @__PURE__ */ Object.getPrototypeOf({});
|
|
936
|
-
function parseSetCookie(str, options) {
|
|
937
|
-
const len = str.length;
|
|
938
|
-
let _endIdx = len;
|
|
939
|
-
let eqIdx = -1;
|
|
940
|
-
for (let i = 0; i < len; i++) {
|
|
941
|
-
const c = str.charCodeAt(i);
|
|
942
|
-
if (c === 59) {
|
|
943
|
-
_endIdx = i;
|
|
944
|
-
break;
|
|
945
|
-
}
|
|
946
|
-
if (c === 61 && eqIdx === -1) eqIdx = i;
|
|
947
|
-
}
|
|
948
|
-
if (eqIdx >= _endIdx) eqIdx = -1;
|
|
949
|
-
const name = eqIdx === -1 ? "" : _trim(str, 0, eqIdx);
|
|
950
|
-
if (name && name in _nullProto) return void 0;
|
|
951
|
-
let value = eqIdx === -1 ? _trim(str, 0, _endIdx) : _trim(str, eqIdx + 1, _endIdx);
|
|
952
|
-
if (!name && !value) return void 0;
|
|
953
|
-
if (name.length + value.length > 4096) return void 0;
|
|
954
|
-
if (options?.decode !== false) value = _decode(value, options?.decode);
|
|
955
|
-
const setCookie = {
|
|
956
|
-
name,
|
|
957
|
-
value
|
|
958
|
-
};
|
|
959
|
-
let index = _endIdx + 1;
|
|
960
|
-
while (index < len) {
|
|
961
|
-
let endIdx = len;
|
|
962
|
-
let attrEqIdx = -1;
|
|
963
|
-
for (let i = index; i < len; i++) {
|
|
964
|
-
const c = str.charCodeAt(i);
|
|
965
|
-
if (c === 59) {
|
|
966
|
-
endIdx = i;
|
|
967
|
-
break;
|
|
968
|
-
}
|
|
969
|
-
if (c === 61 && attrEqIdx === -1) attrEqIdx = i;
|
|
970
|
-
}
|
|
971
|
-
if (attrEqIdx >= endIdx) attrEqIdx = -1;
|
|
972
|
-
const attr = attrEqIdx === -1 ? _trim(str, index, endIdx) : _trim(str, index, attrEqIdx);
|
|
973
|
-
const val = attrEqIdx === -1 ? void 0 : _trim(str, attrEqIdx + 1, endIdx);
|
|
974
|
-
if (val === void 0 || val.length <= 1024) switch (attr.toLowerCase()) {
|
|
975
|
-
case "httponly":
|
|
976
|
-
setCookie.httpOnly = true;
|
|
977
|
-
break;
|
|
978
|
-
case "secure":
|
|
979
|
-
setCookie.secure = true;
|
|
980
|
-
break;
|
|
981
|
-
case "partitioned":
|
|
982
|
-
setCookie.partitioned = true;
|
|
983
|
-
break;
|
|
984
|
-
case "domain":
|
|
985
|
-
if (val) setCookie.domain = (val.charCodeAt(0) === 46 ? val.slice(1) : val).toLowerCase();
|
|
986
|
-
break;
|
|
987
|
-
case "path":
|
|
988
|
-
setCookie.path = val;
|
|
989
|
-
break;
|
|
990
|
-
case "max-age":
|
|
991
|
-
if (val && maxAgeRegExp.test(val)) setCookie.maxAge = Math.min(Number(val), COOKIE_MAX_AGE_LIMIT);
|
|
992
|
-
break;
|
|
993
|
-
case "expires": {
|
|
994
|
-
if (!val) break;
|
|
995
|
-
const date = new Date(val);
|
|
996
|
-
if (Number.isFinite(date.valueOf())) {
|
|
997
|
-
const maxDate = new Date(Date.now() + COOKIE_MAX_AGE_LIMIT * 1e3);
|
|
998
|
-
setCookie.expires = date > maxDate ? maxDate : date;
|
|
999
|
-
}
|
|
1000
|
-
break;
|
|
1001
|
-
}
|
|
1002
|
-
case "priority": {
|
|
1003
|
-
if (!val) break;
|
|
1004
|
-
const priority = val.toLowerCase();
|
|
1005
|
-
if (priority === "low" || priority === "medium" || priority === "high") setCookie.priority = priority;
|
|
1006
|
-
break;
|
|
1007
|
-
}
|
|
1008
|
-
case "samesite": {
|
|
1009
|
-
if (!val) break;
|
|
1010
|
-
const sameSite = val.toLowerCase();
|
|
1011
|
-
if (sameSite === "lax" || sameSite === "strict" || sameSite === "none") setCookie.sameSite = sameSite;
|
|
1012
|
-
else setCookie.sameSite = "lax";
|
|
1013
|
-
break;
|
|
1014
|
-
}
|
|
1015
|
-
default: {
|
|
1016
|
-
const attrLower = attr.toLowerCase();
|
|
1017
|
-
if (attrLower && !(attrLower in _nullProto)) setCookie[attrLower] = val;
|
|
1018
|
-
}
|
|
1019
|
-
}
|
|
1020
|
-
index = endIdx + 1;
|
|
1021
|
-
}
|
|
1022
|
-
return setCookie;
|
|
1023
|
-
}
|
|
1024
|
-
function _trim(str, start, end) {
|
|
1025
|
-
if (start === end) return "";
|
|
1026
|
-
let s = start;
|
|
1027
|
-
let e = end;
|
|
1028
|
-
while (s < e && (str.charCodeAt(s) === 32 || str.charCodeAt(s) === 9)) s++;
|
|
1029
|
-
while (e > s && (str.charCodeAt(e - 1) === 32 || str.charCodeAt(e - 1) === 9)) e--;
|
|
1030
|
-
return str.slice(s, e);
|
|
1031
|
-
}
|
|
1032
|
-
function _decode(value, decode) {
|
|
1033
|
-
if (!decode && !value.includes("%")) return value;
|
|
1034
|
-
try {
|
|
1035
|
-
return (decode || decodeURIComponent)(value);
|
|
1036
|
-
} catch {
|
|
1037
|
-
return value;
|
|
1038
|
-
}
|
|
1039
|
-
}
|
|
1040
|
-
var CHUNKED_COOKIE = "__chunked__";
|
|
1041
|
-
var CHUNKS_MAX_LENGTH = 4e3;
|
|
1042
|
-
function parseCookies(event) {
|
|
1043
|
-
return parse(event.req.headers.get("cookie") || "");
|
|
1044
|
-
}
|
|
1045
|
-
function getCookie$1(event, name) {
|
|
1046
|
-
return parseCookies(event)[name];
|
|
1047
|
-
}
|
|
1048
|
-
function setCookie$1(event, name, value, options) {
|
|
1049
|
-
const newCookie = serialize({
|
|
1050
|
-
name,
|
|
1051
|
-
value,
|
|
1052
|
-
path: "/",
|
|
1053
|
-
...options
|
|
1054
|
-
});
|
|
1055
|
-
const currentCookies = event.res.headers.getSetCookie();
|
|
1056
|
-
if (currentCookies.length === 0) {
|
|
1057
|
-
event.res.headers.set("set-cookie", newCookie);
|
|
1058
|
-
return;
|
|
1059
|
-
}
|
|
1060
|
-
const newCookieKey = _getDistinctCookieKey(name, options || {});
|
|
1061
|
-
event.res.headers.delete("set-cookie");
|
|
1062
|
-
for (const cookie of currentCookies) {
|
|
1063
|
-
const parsed = parseSetCookie(cookie);
|
|
1064
|
-
if (!parsed) continue;
|
|
1065
|
-
if (_getDistinctCookieKey(cookie.split("=")?.[0], parsed) === newCookieKey) continue;
|
|
1066
|
-
event.res.headers.append("set-cookie", cookie);
|
|
1067
|
-
}
|
|
1068
|
-
event.res.headers.append("set-cookie", newCookie);
|
|
1069
|
-
}
|
|
1070
|
-
function deleteCookie$1(event, name, serializeOptions) {
|
|
1071
|
-
setCookie$1(event, name, "", {
|
|
1072
|
-
...serializeOptions,
|
|
1073
|
-
maxAge: 0
|
|
1074
|
-
});
|
|
1075
|
-
}
|
|
1076
|
-
function getChunkedCookie(event, name) {
|
|
1077
|
-
const mainCookie = getCookie$1(event, name);
|
|
1078
|
-
if (!mainCookie || !mainCookie.startsWith(CHUNKED_COOKIE)) return mainCookie;
|
|
1079
|
-
const chunksCount = getChunkedCookieCount(mainCookie);
|
|
1080
|
-
if (chunksCount === 0) return;
|
|
1081
|
-
const chunks = [];
|
|
1082
|
-
for (let i = 1; i <= chunksCount; i++) {
|
|
1083
|
-
const chunk = getCookie$1(event, chunkCookieName(name, i));
|
|
1084
|
-
if (!chunk) return;
|
|
1085
|
-
chunks.push(chunk);
|
|
1086
|
-
}
|
|
1087
|
-
return chunks.join("");
|
|
1088
|
-
}
|
|
1089
|
-
function setChunkedCookie(event, name, value, options) {
|
|
1090
|
-
const chunkMaxLength = options?.chunkMaxLength || CHUNKS_MAX_LENGTH;
|
|
1091
|
-
const chunkCount = Math.ceil(value.length / chunkMaxLength);
|
|
1092
|
-
const previousCookie = getCookie$1(event, name);
|
|
1093
|
-
if (previousCookie?.startsWith(CHUNKED_COOKIE)) {
|
|
1094
|
-
const previousChunkCount = getChunkedCookieCount(previousCookie);
|
|
1095
|
-
if (previousChunkCount > chunkCount) for (let i = chunkCount; i <= previousChunkCount; i++) deleteCookie$1(event, chunkCookieName(name, i), options);
|
|
1096
|
-
}
|
|
1097
|
-
if (chunkCount <= 1) {
|
|
1098
|
-
setCookie$1(event, name, value, options);
|
|
1099
|
-
return;
|
|
1100
|
-
}
|
|
1101
|
-
setCookie$1(event, name, `${CHUNKED_COOKIE}${chunkCount}`, options);
|
|
1102
|
-
for (let i = 1; i <= chunkCount; i++) {
|
|
1103
|
-
const start = (i - 1) * chunkMaxLength;
|
|
1104
|
-
const end = start + chunkMaxLength;
|
|
1105
|
-
const chunkValue = value.slice(start, end);
|
|
1106
|
-
setCookie$1(event, chunkCookieName(name, i), chunkValue, options);
|
|
1107
|
-
}
|
|
1108
|
-
}
|
|
1109
|
-
function deleteChunkedCookie(event, name, serializeOptions) {
|
|
1110
|
-
const mainCookie = getCookie$1(event, name);
|
|
1111
|
-
deleteCookie$1(event, name, serializeOptions);
|
|
1112
|
-
const chunksCount = getChunkedCookieCount(mainCookie);
|
|
1113
|
-
if (chunksCount >= 0) for (let i = 0; i < chunksCount; i++) deleteCookie$1(event, chunkCookieName(name, i + 1), serializeOptions);
|
|
1114
|
-
}
|
|
1115
|
-
function _getDistinctCookieKey(name, options) {
|
|
1116
|
-
return [
|
|
1117
|
-
name,
|
|
1118
|
-
options.domain || "",
|
|
1119
|
-
options.path || "/"
|
|
1120
|
-
].join(";");
|
|
1121
|
-
}
|
|
1122
|
-
var MAX_CHUNKED_COOKIE_COUNT = 100;
|
|
1123
|
-
function getChunkedCookieCount(cookie) {
|
|
1124
|
-
if (!cookie?.startsWith(CHUNKED_COOKIE)) return NaN;
|
|
1125
|
-
const count = Number.parseInt(cookie.slice(11));
|
|
1126
|
-
if (Number.isNaN(count) || count < 0 || count > MAX_CHUNKED_COOKIE_COUNT) return NaN;
|
|
1127
|
-
return count;
|
|
1128
|
-
}
|
|
1129
|
-
function chunkCookieName(name, chunkNumber) {
|
|
1130
|
-
return `${name}.${chunkNumber}`;
|
|
1131
|
-
}
|
|
1132
|
-
var defaults = /* @__PURE__ */ Object.freeze({
|
|
1133
|
-
ttl: 0,
|
|
1134
|
-
timestampSkewSec: 60,
|
|
1135
|
-
localtimeOffsetMsec: 0,
|
|
1136
|
-
encryption: /* @__PURE__ */ Object.freeze({
|
|
1137
|
-
saltBits: 256,
|
|
1138
|
-
algorithm: "aes-256-cbc",
|
|
1139
|
-
iterations: 1,
|
|
1140
|
-
minPasswordlength: 32
|
|
1141
|
-
}),
|
|
1142
|
-
integrity: /* @__PURE__ */ Object.freeze({
|
|
1143
|
-
saltBits: 256,
|
|
1144
|
-
algorithm: "sha256",
|
|
1145
|
-
iterations: 1,
|
|
1146
|
-
minPasswordlength: 32
|
|
1147
|
-
})
|
|
1148
|
-
});
|
|
1149
|
-
var algorithms = /* @__PURE__ */ Object.freeze({
|
|
1150
|
-
"aes-128-ctr": /* @__PURE__ */ Object.freeze({
|
|
1151
|
-
keyBits: 128,
|
|
1152
|
-
ivBits: 128,
|
|
1153
|
-
name: "AES-CTR"
|
|
1154
|
-
}),
|
|
1155
|
-
"aes-256-cbc": /* @__PURE__ */ Object.freeze({
|
|
1156
|
-
keyBits: 256,
|
|
1157
|
-
ivBits: 128,
|
|
1158
|
-
name: "AES-CBC"
|
|
1159
|
-
}),
|
|
1160
|
-
sha256: /* @__PURE__ */ Object.freeze({
|
|
1161
|
-
keyBits: 256,
|
|
1162
|
-
ivBits: 128,
|
|
1163
|
-
name: "SHA-256"
|
|
1164
|
-
})
|
|
1165
|
-
});
|
|
1166
|
-
var macPrefix = "Fe26.2";
|
|
1167
|
-
async function seal(object, password, opts) {
|
|
1168
|
-
const now = Date.now() + (opts.localtimeOffsetMsec || 0);
|
|
1169
|
-
if (!password) throw new Error("Empty password");
|
|
1170
|
-
const { id = "", encryption, integrity } = normalizePassword(password);
|
|
1171
|
-
if (id && !/^\w+$/.test(id)) throw new Error("Invalid password id");
|
|
1172
|
-
const { encrypted, key } = await encrypt(encryption, opts.encryption, JSON.stringify(object));
|
|
1173
|
-
const encryptedB64 = base64Encode(encrypted);
|
|
1174
|
-
const iv = base64Encode(key.iv);
|
|
1175
|
-
const expiration = opts.ttl ? now + opts.ttl : "";
|
|
1176
|
-
const macBaseString = `${macPrefix}*${id}*${key.salt}*${iv}*${encryptedB64}*${expiration}`;
|
|
1177
|
-
const mac = await hmacWithPassword(integrity, opts.integrity, macBaseString);
|
|
1178
|
-
return `${macBaseString}*${mac.salt}*${mac.digest}`;
|
|
1179
|
-
}
|
|
1180
|
-
async function unseal(sealed, password, opts) {
|
|
1181
|
-
const now = Date.now() + (opts.localtimeOffsetMsec || 0);
|
|
1182
|
-
if (!password) throw new Error("Empty password");
|
|
1183
|
-
const parts = sealed.split("*");
|
|
1184
|
-
if (parts.length !== 8) throw new Error("Incorrect number of sealed components");
|
|
1185
|
-
const [prefix, passwordId, encryptionSalt, encryptionIv, encryptedB64, expiration, hmacSalt, hmac] = parts;
|
|
1186
|
-
const macBaseString = `${prefix}*${passwordId}*${encryptionSalt}*${encryptionIv}*${encryptedB64}*${expiration}`;
|
|
1187
|
-
if ("Fe26.2" !== prefix) throw new Error("Wrong mac prefix");
|
|
1188
|
-
if (expiration) {
|
|
1189
|
-
if (!/^\d+$/.test(expiration)) throw new Error("Invalid expiration");
|
|
1190
|
-
if (Number.parseInt(expiration, 10) <= now - opts.timestampSkewSec * 1e3) throw new Error("Expired seal");
|
|
1191
|
-
}
|
|
1192
|
-
let pass = "";
|
|
1193
|
-
const _passwordId = passwordId || "default";
|
|
1194
|
-
if (typeof password === "string" || password instanceof Uint8Array) pass = password;
|
|
1195
|
-
else if (_passwordId in password) pass = password[_passwordId];
|
|
1196
|
-
else throw new Error(`Cannot find password: ${_passwordId}`);
|
|
1197
|
-
pass = normalizePassword(pass);
|
|
1198
|
-
if (!fixedTimeComparison((await hmacWithPassword(pass.integrity, {
|
|
1199
|
-
...opts.integrity,
|
|
1200
|
-
salt: hmacSalt
|
|
1201
|
-
}, macBaseString)).digest, hmac)) throw new Error("Bad hmac value");
|
|
1202
|
-
const encrypted = base64Decode(encryptedB64);
|
|
1203
|
-
const decryptOptions = {
|
|
1204
|
-
...opts.encryption,
|
|
1205
|
-
salt: encryptionSalt,
|
|
1206
|
-
iv: base64Decode(encryptionIv)
|
|
1207
|
-
};
|
|
1208
|
-
const decrypted = await decrypt(pass.encryption, decryptOptions, encrypted);
|
|
1209
|
-
return decrypted ? JSON.parse(decrypted) : null;
|
|
1210
|
-
}
|
|
1211
|
-
async function hmacWithPassword(password, options, data) {
|
|
1212
|
-
const key = await generateKey(password, {
|
|
1213
|
-
...options,
|
|
1214
|
-
hmac: true
|
|
1215
|
-
});
|
|
1216
|
-
const textBuffer = textEncoder$4.encode(data);
|
|
1217
|
-
const signed = await crypto.subtle.sign({ name: "HMAC" }, key.key, textBuffer);
|
|
1218
|
-
return {
|
|
1219
|
-
digest: base64Encode(new Uint8Array(signed)),
|
|
1220
|
-
salt: key.salt
|
|
1221
|
-
};
|
|
1222
|
-
}
|
|
1223
|
-
async function generateKey(password, options) {
|
|
1224
|
-
if (!password?.length) throw new Error("Empty password");
|
|
1225
|
-
if (options == null || typeof options !== "object") throw new Error("Bad options");
|
|
1226
|
-
if (!(options.algorithm in algorithms)) throw new Error(`Unknown algorithm: ${options.algorithm}`);
|
|
1227
|
-
const algorithm = algorithms[options.algorithm];
|
|
1228
|
-
let resultKey;
|
|
1229
|
-
let resultSalt;
|
|
1230
|
-
let resultIV;
|
|
1231
|
-
const hmac = options.hmac ?? false;
|
|
1232
|
-
const id = hmac ? {
|
|
1233
|
-
name: "HMAC",
|
|
1234
|
-
hash: algorithm.name
|
|
1235
|
-
} : { name: algorithm.name };
|
|
1236
|
-
const usage = hmac ? ["sign", "verify"] : ["encrypt", "decrypt"];
|
|
1237
|
-
if (typeof password === "string") {
|
|
1238
|
-
if (password.length < options.minPasswordlength) throw new Error(`Password string too short (min ${options.minPasswordlength} characters required)`);
|
|
1239
|
-
let { salt = "" } = options;
|
|
1240
|
-
if (!salt) {
|
|
1241
|
-
const { saltBits = 0 } = options;
|
|
1242
|
-
if (!saltBits) throw new Error("Missing salt and saltBits options");
|
|
1243
|
-
const randomSalt = randomBits(saltBits);
|
|
1244
|
-
salt = [...new Uint8Array(randomSalt)].map((x) => x.toString(16).padStart(2, "0")).join("");
|
|
1245
|
-
}
|
|
1246
|
-
const derivedKey = await pbkdf2(password, salt, options.iterations, algorithm.keyBits / 8, "SHA-1");
|
|
1247
|
-
resultKey = await crypto.subtle.importKey("raw", derivedKey, id, false, usage);
|
|
1248
|
-
resultSalt = salt;
|
|
1249
|
-
} else {
|
|
1250
|
-
if (password.length < algorithm.keyBits / 8) throw new Error("Key buffer (password) too small");
|
|
1251
|
-
resultKey = await crypto.subtle.importKey("raw", password, id, false, usage);
|
|
1252
|
-
resultSalt = "";
|
|
1253
|
-
}
|
|
1254
|
-
if (options.iv) resultIV = options.iv;
|
|
1255
|
-
else if ("ivBits" in algorithm) resultIV = randomBits(algorithm.ivBits);
|
|
1256
|
-
else throw new Error("Missing IV");
|
|
1257
|
-
return {
|
|
1258
|
-
key: resultKey,
|
|
1259
|
-
salt: resultSalt,
|
|
1260
|
-
iv: resultIV
|
|
1261
|
-
};
|
|
1262
|
-
}
|
|
1263
|
-
async function pbkdf2(password, salt, iterations, keyLength, hash) {
|
|
1264
|
-
const passwordBuffer = textEncoder$4.encode(password);
|
|
1265
|
-
const importedKey = await crypto.subtle.importKey("raw", passwordBuffer, { name: "PBKDF2" }, false, ["deriveBits"]);
|
|
1266
|
-
const params = {
|
|
1267
|
-
name: "PBKDF2",
|
|
1268
|
-
hash,
|
|
1269
|
-
salt: textEncoder$4.encode(salt),
|
|
1270
|
-
iterations
|
|
1271
|
-
};
|
|
1272
|
-
return await crypto.subtle.deriveBits(params, importedKey, keyLength * 8);
|
|
1273
|
-
}
|
|
1274
|
-
async function encrypt(password, options, data) {
|
|
1275
|
-
const key = await generateKey(password, options);
|
|
1276
|
-
const encrypted = await crypto.subtle.encrypt(...getEncryptParams(options.algorithm, key, data));
|
|
1277
|
-
return {
|
|
1278
|
-
encrypted: new Uint8Array(encrypted),
|
|
1279
|
-
key
|
|
1280
|
-
};
|
|
1281
|
-
}
|
|
1282
|
-
async function decrypt(password, options, data) {
|
|
1283
|
-
const key = await generateKey(password, options);
|
|
1284
|
-
const decrypted = await crypto.subtle.decrypt(...getEncryptParams(options.algorithm, key, data));
|
|
1285
|
-
return textDecoder$1.decode(decrypted);
|
|
1286
|
-
}
|
|
1287
|
-
function getEncryptParams(algorithm, key, data) {
|
|
1288
|
-
return [
|
|
1289
|
-
algorithm === "aes-128-ctr" ? {
|
|
1290
|
-
name: "AES-CTR",
|
|
1291
|
-
counter: key.iv,
|
|
1292
|
-
length: 128
|
|
1293
|
-
} : {
|
|
1294
|
-
name: "AES-CBC",
|
|
1295
|
-
iv: key.iv
|
|
1296
|
-
},
|
|
1297
|
-
key.key,
|
|
1298
|
-
typeof data === "string" ? textEncoder$4.encode(data) : data
|
|
1299
|
-
];
|
|
1300
|
-
}
|
|
1301
|
-
function fixedTimeComparison(a, b) {
|
|
1302
|
-
let mismatch = a.length === b.length ? 0 : 1;
|
|
1303
|
-
if (mismatch) b = a;
|
|
1304
|
-
for (let i = 0; i < a.length; i += 1) mismatch |= a.charCodeAt(i) ^ b.charCodeAt(i);
|
|
1305
|
-
return mismatch === 0;
|
|
1306
|
-
}
|
|
1307
|
-
function normalizePassword(password) {
|
|
1308
|
-
if (typeof password === "string" || password instanceof Uint8Array) return {
|
|
1309
|
-
encryption: password,
|
|
1310
|
-
integrity: password
|
|
1311
|
-
};
|
|
1312
|
-
if ("secret" in password) return {
|
|
1313
|
-
id: password.id,
|
|
1314
|
-
encryption: password.secret,
|
|
1315
|
-
integrity: password.secret
|
|
1316
|
-
};
|
|
1317
|
-
return {
|
|
1318
|
-
id: password.id,
|
|
1319
|
-
encryption: password.encryption,
|
|
1320
|
-
integrity: password.integrity
|
|
1321
|
-
};
|
|
1322
|
-
}
|
|
1323
|
-
function randomBits(bits) {
|
|
1324
|
-
if (bits < 1) throw new Error("Invalid random bits count");
|
|
1325
|
-
return randomBytes(Math.ceil(bits / 8));
|
|
1326
|
-
}
|
|
1327
|
-
function randomBytes(size) {
|
|
1328
|
-
const bytes = new Uint8Array(size);
|
|
1329
|
-
crypto.getRandomValues(bytes);
|
|
1330
|
-
return bytes;
|
|
1331
|
-
}
|
|
1332
|
-
var kGetSession = /* @__PURE__ */ Symbol.for("h3.internal.session.promise");
|
|
1333
|
-
var DEFAULT_SESSION_COOKIE = {
|
|
1334
|
-
path: "/",
|
|
1335
|
-
secure: true,
|
|
1336
|
-
httpOnly: true
|
|
1337
|
-
};
|
|
1338
|
-
async function useSession$1(event, config) {
|
|
1339
|
-
const sessionName = config.name || "h3";
|
|
1340
|
-
await getSession$1(event, config);
|
|
1341
|
-
const sessionManager = {
|
|
1342
|
-
get id() {
|
|
1343
|
-
return getEventContext(event)?.sessions?.[sessionName]?.id;
|
|
1344
|
-
},
|
|
1345
|
-
get data() {
|
|
1346
|
-
return getEventContext(event).sessions?.[sessionName]?.data || {};
|
|
1347
|
-
},
|
|
1348
|
-
update: async (update) => {
|
|
1349
|
-
await updateSession$1(event, config, update);
|
|
1350
|
-
return sessionManager;
|
|
1351
|
-
},
|
|
1352
|
-
clear: () => {
|
|
1353
|
-
clearSession$1(event, config);
|
|
1354
|
-
return Promise.resolve(sessionManager);
|
|
1355
|
-
}
|
|
1356
|
-
};
|
|
1357
|
-
return sessionManager;
|
|
1358
|
-
}
|
|
1359
|
-
async function getSession$1(event, config) {
|
|
1360
|
-
const sessionName = config.name || "h3";
|
|
1361
|
-
const context = getEventContext(event);
|
|
1362
|
-
if (!context.sessions) context.sessions = new NullProtoObj();
|
|
1363
|
-
const existingSession = context.sessions[sessionName];
|
|
1364
|
-
if (existingSession) return existingSession[kGetSession] || existingSession;
|
|
1365
|
-
const session = {
|
|
1366
|
-
id: "",
|
|
1367
|
-
createdAt: 0,
|
|
1368
|
-
data: new NullProtoObj()
|
|
1369
|
-
};
|
|
1370
|
-
context.sessions[sessionName] = session;
|
|
1371
|
-
let sealedSession;
|
|
1372
|
-
if (config.sessionHeader !== false) {
|
|
1373
|
-
const headerName = typeof config.sessionHeader === "string" ? config.sessionHeader.toLowerCase() : `x-${sessionName.toLowerCase()}-session`;
|
|
1374
|
-
const headerValue = event.req.headers.get(headerName);
|
|
1375
|
-
if (typeof headerValue === "string") sealedSession = headerValue;
|
|
1376
|
-
}
|
|
1377
|
-
if (!sealedSession) sealedSession = getChunkedCookie(event, sessionName);
|
|
1378
|
-
if (sealedSession) {
|
|
1379
|
-
const promise = unsealSession$1(event, config, sealedSession).catch(() => {}).then((unsealed) => {
|
|
1380
|
-
Object.assign(session, unsealed);
|
|
1381
|
-
delete context.sessions[sessionName][kGetSession];
|
|
1382
|
-
return session;
|
|
1383
|
-
});
|
|
1384
|
-
context.sessions[sessionName][kGetSession] = promise;
|
|
1385
|
-
await promise;
|
|
1386
|
-
}
|
|
1387
|
-
if (!session.id) {
|
|
1388
|
-
session.id = config.generateId?.() ?? (config.crypto || crypto).randomUUID();
|
|
1389
|
-
session.createdAt = Date.now();
|
|
1390
|
-
await updateSession$1(event, config);
|
|
1391
|
-
}
|
|
1392
|
-
return session;
|
|
1393
|
-
}
|
|
1394
|
-
async function updateSession$1(event, config, update) {
|
|
1395
|
-
const sessionName = config.name || "h3";
|
|
1396
|
-
const session = getEventContext(event).sessions?.[sessionName] || await getSession$1(event, config);
|
|
1397
|
-
if (typeof update === "function") update = update(session.data);
|
|
1398
|
-
if (update) Object.assign(session.data, update);
|
|
1399
|
-
if (config.cookie !== false && event.res) setChunkedCookie(event, sessionName, await sealSession$1(event, config), {
|
|
1400
|
-
...DEFAULT_SESSION_COOKIE,
|
|
1401
|
-
expires: config.maxAge ? new Date(session.createdAt + config.maxAge * 1e3) : void 0,
|
|
1402
|
-
...config.cookie
|
|
1403
|
-
});
|
|
1404
|
-
return session;
|
|
1405
|
-
}
|
|
1406
|
-
async function sealSession$1(event, config) {
|
|
1407
|
-
const sessionName = config.name || "h3";
|
|
1408
|
-
return await seal(getEventContext(event).sessions?.[sessionName] || await getSession$1(event, config), config.password, {
|
|
1409
|
-
...defaults,
|
|
1410
|
-
ttl: config.maxAge ? config.maxAge * 1e3 : 0,
|
|
1411
|
-
...config.seal
|
|
1412
|
-
});
|
|
1413
|
-
}
|
|
1414
|
-
async function unsealSession$1(_event, config, sealed) {
|
|
1415
|
-
const unsealed = await unseal(sealed, config.password, {
|
|
1416
|
-
...defaults,
|
|
1417
|
-
ttl: config.maxAge ? config.maxAge * 1e3 : 0,
|
|
1418
|
-
...config.seal
|
|
1419
|
-
});
|
|
1420
|
-
if (config.maxAge) {
|
|
1421
|
-
if (Date.now() - (unsealed.createdAt || Number.NEGATIVE_INFINITY) > config.maxAge * 1e3) throw new Error("Session expired!");
|
|
1422
|
-
}
|
|
1423
|
-
return unsealed;
|
|
1424
|
-
}
|
|
1425
|
-
function clearSession$1(event, config) {
|
|
1426
|
-
const context = getEventContext(event);
|
|
1427
|
-
const sessionName = config.name || "h3";
|
|
1428
|
-
if (context.sessions?.[sessionName]) delete context.sessions[sessionName];
|
|
1429
|
-
if (event.res && config.cookie !== false) deleteChunkedCookie(event, sessionName, {
|
|
1430
|
-
...DEFAULT_SESSION_COOKIE,
|
|
1431
|
-
...config.cookie
|
|
1432
|
-
});
|
|
1433
|
-
return Promise.resolve();
|
|
1434
|
-
}
|
|
1435
|
-
var GLOBAL_EVENT_STORAGE_KEY = Symbol.for("tanstack-start:event-storage");
|
|
1436
|
-
var globalObj = globalThis;
|
|
1437
|
-
if (!globalObj[GLOBAL_EVENT_STORAGE_KEY]) globalObj[GLOBAL_EVENT_STORAGE_KEY] = new AsyncLocalStorage();
|
|
1438
|
-
var eventStorage = globalObj[GLOBAL_EVENT_STORAGE_KEY];
|
|
1439
|
-
function isPromiseLike(value) {
|
|
1440
|
-
return (typeof value === "object" || typeof value === "function") && value !== null && typeof value.then === "function";
|
|
1441
|
-
}
|
|
1442
|
-
function getSetCookieValues(headers) {
|
|
1443
|
-
const headersWithSetCookie = headers;
|
|
1444
|
-
if (typeof headersWithSetCookie.getSetCookie === "function") return headersWithSetCookie.getSetCookie();
|
|
1445
|
-
const value = headers.get("set-cookie");
|
|
1446
|
-
return value ? [value] : [];
|
|
1447
|
-
}
|
|
1448
|
-
function mergeEventResponseHeaders(response, event) {
|
|
1449
|
-
if (response.ok) return;
|
|
1450
|
-
const eventSetCookies = getSetCookieValues(event.res.headers);
|
|
1451
|
-
if (eventSetCookies.length === 0) return;
|
|
1452
|
-
const responseSetCookies = getSetCookieValues(response.headers);
|
|
1453
|
-
response.headers.delete("set-cookie");
|
|
1454
|
-
for (const cookie of responseSetCookies) response.headers.append("set-cookie", cookie);
|
|
1455
|
-
for (const cookie of eventSetCookies) response.headers.append("set-cookie", cookie);
|
|
1456
|
-
}
|
|
1457
|
-
function finalizeResponse(value, event) {
|
|
1458
|
-
const response = ensureResponse(value);
|
|
1459
|
-
mergeEventResponseHeaders(response, event);
|
|
1460
|
-
return response;
|
|
1461
|
-
}
|
|
1462
|
-
function finalizeMaybeResponse(value, event) {
|
|
1463
|
-
if (isPromiseLike(value)) return Promise.resolve(value).then((resolved) => finalizeResponse(resolved, event), (error) => finalizeResponse(handleResponseError(error), event));
|
|
1464
|
-
return finalizeResponse(value, event);
|
|
1465
|
-
}
|
|
1466
|
-
function ensureResponse(value) {
|
|
1467
|
-
if (value instanceof Response) return value;
|
|
1468
|
-
return new Response("Internal Server Error", { status: 500 });
|
|
1469
|
-
}
|
|
1470
|
-
function handleResponseError(error) {
|
|
1471
|
-
if (error instanceof Response) return error;
|
|
1472
|
-
if (error instanceof Error) throw error;
|
|
1473
|
-
return new Response("Internal Server Error", { status: 500 });
|
|
1474
|
-
}
|
|
1475
|
-
function requestHandler(handler) {
|
|
1476
|
-
return (request, requestOpts) => {
|
|
1477
|
-
let h3Event;
|
|
1478
|
-
try {
|
|
1479
|
-
h3Event = new H3Event(request);
|
|
1480
|
-
} catch (error) {
|
|
1481
|
-
if (error instanceof URIError) return new Response(null, {
|
|
1482
|
-
status: 400,
|
|
1483
|
-
statusText: "Bad Request"
|
|
1484
|
-
});
|
|
1485
|
-
throw error;
|
|
1486
|
-
}
|
|
1487
|
-
let response;
|
|
1488
|
-
try {
|
|
1489
|
-
response = eventStorage.run({ h3Event }, () => handler(request, requestOpts));
|
|
1490
|
-
} catch (error) {
|
|
1491
|
-
response = handleResponseError(error);
|
|
1492
|
-
}
|
|
1493
|
-
return toResponse(finalizeMaybeResponse(response, h3Event), h3Event);
|
|
1494
|
-
};
|
|
1495
|
-
}
|
|
1496
|
-
function getH3Event() {
|
|
1497
|
-
const event = eventStorage.getStore();
|
|
1498
|
-
if (!event) throw new Error(`No StartEvent found in AsyncLocalStorage. Make sure you are using the function within the server runtime.`);
|
|
1499
|
-
return event.h3Event;
|
|
1500
|
-
}
|
|
1501
|
-
function getRequest() {
|
|
1502
|
-
return getH3Event().req;
|
|
1503
|
-
}
|
|
1504
|
-
function getRequestHeaders$1() {
|
|
1505
|
-
return getH3Event().req.headers;
|
|
1506
|
-
}
|
|
1507
|
-
function getRequestHeader(name) {
|
|
1508
|
-
return getRequestHeaders$1().get(name) || void 0;
|
|
1509
|
-
}
|
|
1510
|
-
function getRequestIP(opts) {
|
|
1511
|
-
return getRequestIP$1(getH3Event(), opts);
|
|
1512
|
-
}
|
|
1513
|
-
/**
|
|
1514
|
-
* Get the request hostname.
|
|
1515
|
-
*
|
|
1516
|
-
* If `xForwardedHost` is `true`, it will use the `x-forwarded-host` header if it exists.
|
|
1517
|
-
*
|
|
1518
|
-
* If no host header is found, it will default to "localhost".
|
|
1519
|
-
*/
|
|
1520
|
-
function getRequestHost(opts) {
|
|
1521
|
-
return getRequestHost$1(getH3Event(), opts);
|
|
1522
|
-
}
|
|
1523
|
-
/**
|
|
1524
|
-
* Get the full incoming request URL.
|
|
1525
|
-
*
|
|
1526
|
-
* If `xForwardedHost` is `true`, it will use the `x-forwarded-host` header if it exists.
|
|
1527
|
-
*
|
|
1528
|
-
* If `xForwardedProto` is `false`, it will not use the `x-forwarded-proto` header.
|
|
1529
|
-
*/
|
|
1530
|
-
function getRequestUrl(opts) {
|
|
1531
|
-
return getRequestURL(getH3Event(), opts);
|
|
1532
|
-
}
|
|
1533
|
-
/**
|
|
1534
|
-
* Get the request protocol.
|
|
1535
|
-
*
|
|
1536
|
-
* If `x-forwarded-proto` header is set to "https", it will return "https". You can disable this behavior by setting `xForwardedProto` to `false`.
|
|
1537
|
-
*
|
|
1538
|
-
* If protocol cannot be determined, it will default to "http".
|
|
1539
|
-
*/
|
|
1540
|
-
function getRequestProtocol(opts) {
|
|
1541
|
-
return getRequestProtocol$1(getH3Event(), opts);
|
|
1542
|
-
}
|
|
1543
|
-
function setResponseHeaders(headers) {
|
|
1544
|
-
const event = getH3Event();
|
|
1545
|
-
if (event.res.headers === headers) return;
|
|
1546
|
-
let previousName = "";
|
|
1547
|
-
for (const [name, value] of headers) {
|
|
1548
|
-
event.res.headers[name === previousName ? "append" : "set"](name, value);
|
|
1549
|
-
previousName = name;
|
|
1550
|
-
}
|
|
1551
|
-
}
|
|
1552
|
-
function getResponseHeaders() {
|
|
1553
|
-
return getH3Event().res.headers;
|
|
1554
|
-
}
|
|
1555
|
-
function getResponseHeader(name) {
|
|
1556
|
-
return getH3Event().res.headers.get(name) || void 0;
|
|
1557
|
-
}
|
|
1558
|
-
function setResponseHeader(name, value) {
|
|
1559
|
-
const event = getH3Event();
|
|
1560
|
-
if (Array.isArray(value)) {
|
|
1561
|
-
event.res.headers.delete(name);
|
|
1562
|
-
for (const valueItem of value) event.res.headers.append(name, valueItem);
|
|
1563
|
-
} else event.res.headers.set(name, value);
|
|
1564
|
-
}
|
|
1565
|
-
function removeResponseHeader(name) {
|
|
1566
|
-
getH3Event().res.headers.delete(name);
|
|
1567
|
-
}
|
|
1568
|
-
function clearResponseHeaders(headerNames) {
|
|
1569
|
-
const event = getH3Event();
|
|
1570
|
-
if (headerNames && headerNames.length > 0) for (const name of headerNames) event.res.headers.delete(name);
|
|
1571
|
-
else for (const name of event.res.headers.keys()) event.res.headers.delete(name);
|
|
1572
|
-
}
|
|
1573
|
-
function getResponseStatus() {
|
|
1574
|
-
return getH3Event().res.status || 200;
|
|
1575
|
-
}
|
|
1576
|
-
function setResponseStatus(code, text) {
|
|
1577
|
-
const event = getH3Event();
|
|
1578
|
-
if (code) event.res.status = sanitizeStatusCode(code, event.res.status);
|
|
1579
|
-
if (text) event.res.statusText = sanitizeStatusMessage(text);
|
|
1580
|
-
}
|
|
1581
|
-
/**
|
|
1582
|
-
* Parse the request to get HTTP Cookie header string and return an object of all cookie name-value pairs.
|
|
1583
|
-
* @returns Object of cookie name-value pairs
|
|
1584
|
-
* ```ts
|
|
1585
|
-
* const cookies = getCookies()
|
|
1586
|
-
* ```
|
|
1587
|
-
*/
|
|
1588
|
-
function getCookies() {
|
|
1589
|
-
const cookies = parseCookies(getH3Event());
|
|
1590
|
-
const definedCookies = Object.create(null);
|
|
1591
|
-
for (const [name, value] of Object.entries(cookies)) if (value !== void 0) definedCookies[name] = value;
|
|
1592
|
-
return definedCookies;
|
|
1593
|
-
}
|
|
1594
|
-
/**
|
|
1595
|
-
* Get a cookie value by name.
|
|
1596
|
-
* @param name Name of the cookie to get
|
|
1597
|
-
* @returns {*} Value of the cookie (String or undefined)
|
|
1598
|
-
* ```ts
|
|
1599
|
-
* const authorization = getCookie('Authorization')
|
|
1600
|
-
* ```
|
|
1601
|
-
*/
|
|
1602
|
-
function getCookie(name) {
|
|
1603
|
-
return getCookies()[name];
|
|
1604
|
-
}
|
|
1605
|
-
/**
|
|
1606
|
-
* Set a cookie value by name.
|
|
1607
|
-
* @param name Name of the cookie to set
|
|
1608
|
-
* @param value Value of the cookie to set
|
|
1609
|
-
* @param options {CookieSerializeOptions} Options for serializing the cookie
|
|
1610
|
-
* ```ts
|
|
1611
|
-
* setCookie('Authorization', '1234567')
|
|
1612
|
-
* ```
|
|
1613
|
-
*/
|
|
1614
|
-
function setCookie(name, value, options) {
|
|
1615
|
-
setCookie$1(getH3Event(), name, value, options);
|
|
1616
|
-
}
|
|
1617
|
-
/**
|
|
1618
|
-
* Remove a cookie by name.
|
|
1619
|
-
* @param name Name of the cookie to delete
|
|
1620
|
-
* @param serializeOptions {CookieSerializeOptions} Cookie options
|
|
1621
|
-
* ```ts
|
|
1622
|
-
* deleteCookie('SessionId')
|
|
1623
|
-
* ```
|
|
1624
|
-
*/
|
|
1625
|
-
function deleteCookie(name, options) {
|
|
1626
|
-
deleteCookie$1(getH3Event(), name, options);
|
|
1627
|
-
}
|
|
1628
|
-
function getDefaultSessionConfig(config) {
|
|
1629
|
-
return {
|
|
1630
|
-
name: "start",
|
|
1631
|
-
...config
|
|
1632
|
-
};
|
|
1633
|
-
}
|
|
1634
|
-
/**
|
|
1635
|
-
* Create a session manager for the current request.
|
|
1636
|
-
*/
|
|
1637
|
-
function useSession(config) {
|
|
1638
|
-
return useSession$1(getH3Event(), getDefaultSessionConfig(config));
|
|
1639
|
-
}
|
|
1640
|
-
/**
|
|
1641
|
-
* Get the session for the current request
|
|
1642
|
-
*/
|
|
1643
|
-
function getSession(config) {
|
|
1644
|
-
return getSession$1(getH3Event(), getDefaultSessionConfig(config));
|
|
1645
|
-
}
|
|
1646
|
-
/**
|
|
1647
|
-
* Update the session data for the current request.
|
|
1648
|
-
*/
|
|
1649
|
-
function updateSession(config, update) {
|
|
1650
|
-
return updateSession$1(getH3Event(), getDefaultSessionConfig(config), update);
|
|
1651
|
-
}
|
|
1652
|
-
/**
|
|
1653
|
-
* Encrypt and sign the session data for the current request.
|
|
1654
|
-
*/
|
|
1655
|
-
function sealSession(config) {
|
|
1656
|
-
return sealSession$1(getH3Event(), getDefaultSessionConfig(config));
|
|
1657
|
-
}
|
|
1658
|
-
/**
|
|
1659
|
-
* Decrypt and verify the session data for the current request.
|
|
1660
|
-
*/
|
|
1661
|
-
function unsealSession(config, sealed) {
|
|
1662
|
-
return unsealSession$1(getH3Event(), getDefaultSessionConfig(config), sealed);
|
|
1663
|
-
}
|
|
1664
|
-
/**
|
|
1665
|
-
* Clear the session data for the current request.
|
|
1666
|
-
*/
|
|
1667
|
-
function clearSession(config) {
|
|
1668
|
-
return clearSession$1(getH3Event(), {
|
|
1669
|
-
name: "start",
|
|
1670
|
-
...config
|
|
1671
|
-
});
|
|
1672
|
-
}
|
|
1673
|
-
function getResponse() {
|
|
1674
|
-
return getH3Event().res;
|
|
1675
|
-
}
|
|
1676
|
-
function getValidatedQuery(schema) {
|
|
1677
|
-
return getValidatedQuery$1(getH3Event(), schema);
|
|
25
|
+
function getSetCookieValues(headers) {
|
|
26
|
+
const headersWithSetCookie = headers;
|
|
27
|
+
if (typeof headersWithSetCookie.getSetCookie === "function") return headersWithSetCookie.getSetCookie();
|
|
28
|
+
const value = headers.get("set-cookie");
|
|
29
|
+
return value ? splitSetCookieString(value) : [];
|
|
1678
30
|
}
|
|
1679
|
-
var HEADERS = { TSS_SHELL: "X-TSS_SHELL" };
|
|
1680
31
|
/** Determine if a value is a TanStack Router not-found error. */
|
|
1681
32
|
function isNotFound(obj) {
|
|
1682
33
|
return obj?.isNotFound === true;
|
|
@@ -1684,7 +35,7 @@ function isNotFound(obj) {
|
|
|
1684
35
|
/** Stable identifier used for the root route in a route tree. */
|
|
1685
36
|
var rootRouteId = "__root__";
|
|
1686
37
|
function dehydrateSsrMatchId(id) {
|
|
1687
|
-
return id.replaceAll("
|
|
38
|
+
return id.replaceAll("/", "#");
|
|
1688
39
|
}
|
|
1689
40
|
/**
|
|
1690
41
|
* A fixed-capacity cache using the SIEVE eviction algorithm
|
|
@@ -1743,15 +94,6 @@ function createSieveCache(max) {
|
|
|
1743
94
|
function invariant() {
|
|
1744
95
|
throw new Error("Invariant failed");
|
|
1745
96
|
}
|
|
1746
|
-
/** Execute a location input rewrite if provided. */
|
|
1747
|
-
function executeRewriteInput(rewrite, url) {
|
|
1748
|
-
const res = rewrite?.input?.({ url });
|
|
1749
|
-
if (res) {
|
|
1750
|
-
if (typeof res === "string") return new URL(res);
|
|
1751
|
-
else if (res instanceof URL) return res;
|
|
1752
|
-
}
|
|
1753
|
-
return url;
|
|
1754
|
-
}
|
|
1755
97
|
var stateIndexKey = "__TSR_index";
|
|
1756
98
|
/**
|
|
1757
99
|
* Turn protocol-relative inputs such as "//evil.example" into paths
|
|
@@ -1824,14 +166,14 @@ function parseHref(href, state) {
|
|
|
1824
166
|
}
|
|
1825
167
|
return {
|
|
1826
168
|
href: sanitizedHref,
|
|
1827
|
-
pathname: sanitizedHref.
|
|
1828
|
-
hash: hashIndex > -1 ? sanitizedHref.
|
|
169
|
+
pathname: sanitizedHref.slice(0, hashIndex > -1 ? searchIndex > -1 ? Math.min(hashIndex, searchIndex) : hashIndex : searchIndex > -1 ? searchIndex : sanitizedHref.length),
|
|
170
|
+
hash: hashIndex > -1 ? sanitizedHref.slice(hashIndex) : "",
|
|
1829
171
|
search: searchIndex > -1 ? sanitizedHref.slice(searchIndex, hashIndex === -1 ? void 0 : hashIndex) : "",
|
|
1830
172
|
state
|
|
1831
173
|
};
|
|
1832
174
|
}
|
|
1833
175
|
function createRandomKey() {
|
|
1834
|
-
return (Math.random() + 1).toString(36).
|
|
176
|
+
return (Math.random() + 1).toString(36).slice(7);
|
|
1835
177
|
}
|
|
1836
178
|
/** Return the structural lane through the first terminal render boundary. */
|
|
1837
179
|
function _getRenderedMatches(matches) {
|
|
@@ -4803,56 +3145,817 @@ function fromJSON(source, options = {}) {
|
|
|
4803
3145
|
disabledFeatures
|
|
4804
3146
|
}), source.t);
|
|
4805
3147
|
}
|
|
4806
|
-
/** Create a Seroval plugin for client/server symmetric (de)serialization. */
|
|
4807
|
-
/* @__NO_SIDE_EFFECTS__ */
|
|
4808
|
-
function makeSerovalPlugin(serializationAdapter) {
|
|
4809
|
-
return /* @__PURE__ */ createPlugin({
|
|
4810
|
-
tag: "$TSR/t/" + serializationAdapter.key,
|
|
4811
|
-
test: serializationAdapter.test,
|
|
4812
|
-
parse: {
|
|
4813
|
-
sync(value, ctx) {
|
|
4814
|
-
return { v: ctx.parse(serializationAdapter.toSerializable(value)) };
|
|
4815
|
-
},
|
|
4816
|
-
async async(value, ctx) {
|
|
4817
|
-
return { v: await ctx.parse(serializationAdapter.toSerializable(value)) };
|
|
4818
|
-
},
|
|
4819
|
-
stream(value, ctx) {
|
|
4820
|
-
return { v: ctx.parse(serializationAdapter.toSerializable(value)) };
|
|
4821
|
-
}
|
|
4822
|
-
},
|
|
4823
|
-
serialize: void 0,
|
|
4824
|
-
deserialize(node, ctx) {
|
|
4825
|
-
return serializationAdapter.fromSerializable(ctx.deserialize(node.v));
|
|
3148
|
+
/** Create a Seroval plugin for client/server symmetric (de)serialization. */
|
|
3149
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
3150
|
+
function makeSerovalPlugin(serializationAdapter) {
|
|
3151
|
+
return /* @__PURE__ */ createPlugin({
|
|
3152
|
+
tag: "$TSR/t/" + serializationAdapter.key,
|
|
3153
|
+
test: serializationAdapter.test,
|
|
3154
|
+
parse: {
|
|
3155
|
+
sync(value, ctx) {
|
|
3156
|
+
return { v: ctx.parse(serializationAdapter.toSerializable(value)) };
|
|
3157
|
+
},
|
|
3158
|
+
async async(value, ctx) {
|
|
3159
|
+
return { v: await ctx.parse(serializationAdapter.toSerializable(value)) };
|
|
3160
|
+
},
|
|
3161
|
+
stream(value, ctx) {
|
|
3162
|
+
return { v: ctx.parse(serializationAdapter.toSerializable(value)) };
|
|
3163
|
+
}
|
|
3164
|
+
},
|
|
3165
|
+
serialize: void 0,
|
|
3166
|
+
deserialize(node, ctx) {
|
|
3167
|
+
return serializationAdapter.fromSerializable(ctx.deserialize(node.v));
|
|
3168
|
+
}
|
|
3169
|
+
});
|
|
3170
|
+
}
|
|
3171
|
+
/**
|
|
3172
|
+
* Marker class for ReadableStream<Uint8Array> that should be serialized
|
|
3173
|
+
* with base64/text encoding (JSON and SSR) or binary framing
|
|
3174
|
+
* (server-function responses).
|
|
3175
|
+
*
|
|
3176
|
+
* Wrap your binary streams with this to get efficient serialization:
|
|
3177
|
+
* ```ts
|
|
3178
|
+
* // For binary data (files, images, etc.)
|
|
3179
|
+
* return { data: new RawStream(file.stream()) }
|
|
3180
|
+
*
|
|
3181
|
+
* // For text-heavy data (RSC payloads, etc.)
|
|
3182
|
+
* return { data: new RawStream(rscStream, { hint: 'text' }) }
|
|
3183
|
+
* ```
|
|
3184
|
+
*
|
|
3185
|
+
* RawStreams returned from one server function share one ordered response.
|
|
3186
|
+
* Arbitrary or sequential consumption can require potentially unbounded client
|
|
3187
|
+
* buffering for unread data. Cancelling one RawStream discards it locally;
|
|
3188
|
+
* abort the whole server-function call to cancel the response and server work.
|
|
3189
|
+
* Consume streams concurrently, cancel unused streams promptly, or use separate
|
|
3190
|
+
* calls when independent backpressure is required.
|
|
3191
|
+
*/
|
|
3192
|
+
var RawStream = class {
|
|
3193
|
+
constructor(stream, options) {
|
|
3194
|
+
this.stream = stream;
|
|
3195
|
+
this.hint = options?.hint ?? "binary";
|
|
3196
|
+
}
|
|
3197
|
+
};
|
|
3198
|
+
var GLOBAL_EVENT_STORAGE_KEY = Symbol.for("tanstack-start:event-storage");
|
|
3199
|
+
var globalObj = globalThis;
|
|
3200
|
+
if (!globalObj[GLOBAL_EVENT_STORAGE_KEY]) globalObj[GLOBAL_EVENT_STORAGE_KEY] = new AsyncLocalStorage();
|
|
3201
|
+
var eventStorage = globalObj[GLOBAL_EVENT_STORAGE_KEY];
|
|
3202
|
+
var PROTECTED_RESPONSE_HEADERS = Symbol.for("tanstack-start:protected-response-headers");
|
|
3203
|
+
function getProtectedResponseHeaders(response) {
|
|
3204
|
+
return response[PROTECTED_RESPONSE_HEADERS];
|
|
3205
|
+
}
|
|
3206
|
+
function installProtectedResponseHeaders(response, headers) {
|
|
3207
|
+
Object.defineProperty(response, PROTECTED_RESPONSE_HEADERS, {
|
|
3208
|
+
value: headers,
|
|
3209
|
+
configurable: true
|
|
3210
|
+
});
|
|
3211
|
+
}
|
|
3212
|
+
/** Transport requirements belong to the encoded body, not its wrapper. */
|
|
3213
|
+
function transferResponseProtocol(source, target) {
|
|
3214
|
+
const protectedHeaders = getProtectedResponseHeaders(source);
|
|
3215
|
+
if (protectedHeaders && getProtectedResponseHeaders(target) !== protectedHeaders) installProtectedResponseHeaders(target, protectedHeaders);
|
|
3216
|
+
}
|
|
3217
|
+
/** Preserve metadata when Start reconstructs an existing response. */
|
|
3218
|
+
function transferResponseMetadata(source, target) {
|
|
3219
|
+
transferResponseProtocol(source, target);
|
|
3220
|
+
const event = eventStorage.getStore();
|
|
3221
|
+
const appliedHeaderAppends = event?.responseHeaderAppends?.get(source);
|
|
3222
|
+
if (appliedHeaderAppends) event.responseHeaderAppends.set(target, appliedHeaderAppends);
|
|
3223
|
+
}
|
|
3224
|
+
function normalizeHeaderName(name) {
|
|
3225
|
+
return name.toLowerCase();
|
|
3226
|
+
}
|
|
3227
|
+
function sanitizeStatusMessage(statusMessage) {
|
|
3228
|
+
return statusMessage.replace(/[^\t\x20-\x7e]/g, "");
|
|
3229
|
+
}
|
|
3230
|
+
function sanitizeStatusCode(statusCode) {
|
|
3231
|
+
const code = typeof statusCode === "string" ? Number(statusCode) : statusCode;
|
|
3232
|
+
if (code === void 0 || !Number.isInteger(code) || code < 200 || code > 599) return;
|
|
3233
|
+
return code;
|
|
3234
|
+
}
|
|
3235
|
+
function getObjectProperty(value, key) {
|
|
3236
|
+
if (typeof value === "object" && value || typeof value === "function") return value[key];
|
|
3237
|
+
}
|
|
3238
|
+
function getStatusCodeProperty(value, key) {
|
|
3239
|
+
const property = getObjectProperty(value, key);
|
|
3240
|
+
if (typeof property === "string" || typeof property === "number") return property;
|
|
3241
|
+
}
|
|
3242
|
+
function getErrorStatus(error) {
|
|
3243
|
+
const cause = getObjectProperty(error, "cause");
|
|
3244
|
+
return sanitizeStatusCode(getStatusCodeProperty(error, "status") ?? getStatusCodeProperty(error, "statusCode") ?? getStatusCodeProperty(cause, "status") ?? getStatusCodeProperty(cause, "statusCode"));
|
|
3245
|
+
}
|
|
3246
|
+
function getErrorStatusText(error) {
|
|
3247
|
+
const cause = getObjectProperty(error, "cause");
|
|
3248
|
+
const statusText = getObjectProperty(error, "statusText") ?? getObjectProperty(error, "statusMessage") ?? getObjectProperty(cause, "statusText") ?? getObjectProperty(cause, "statusMessage");
|
|
3249
|
+
if (typeof statusText === "string") return sanitizeStatusMessage(statusText);
|
|
3250
|
+
}
|
|
3251
|
+
var GENERATED_BODY_EXCLUDED_HEADERS = /* @__PURE__ */ new Set([
|
|
3252
|
+
"connection",
|
|
3253
|
+
"content-encoding",
|
|
3254
|
+
"content-length",
|
|
3255
|
+
"keep-alive",
|
|
3256
|
+
"proxy-connection",
|
|
3257
|
+
"te",
|
|
3258
|
+
"trailer",
|
|
3259
|
+
"transfer-encoding"
|
|
3260
|
+
]);
|
|
3261
|
+
function isResponse(value) {
|
|
3262
|
+
return value instanceof Response || Object.prototype.toString.call(value) === "[object Response]";
|
|
3263
|
+
}
|
|
3264
|
+
function getErrorHeaders(error) {
|
|
3265
|
+
let init = getObjectProperty(error, "headers");
|
|
3266
|
+
if (!init) {
|
|
3267
|
+
const cause = getObjectProperty(error, "cause");
|
|
3268
|
+
if (isResponse(cause)) return;
|
|
3269
|
+
init = getObjectProperty(cause, "headers");
|
|
3270
|
+
}
|
|
3271
|
+
if (!init) return;
|
|
3272
|
+
let headers;
|
|
3273
|
+
try {
|
|
3274
|
+
headers = new Headers(init);
|
|
3275
|
+
} catch {
|
|
3276
|
+
return;
|
|
3277
|
+
}
|
|
3278
|
+
for (const name of GENERATED_BODY_EXCLUDED_HEADERS) headers.delete(name);
|
|
3279
|
+
return headers;
|
|
3280
|
+
}
|
|
3281
|
+
function getResponseState(event) {
|
|
3282
|
+
return event.responseState ||= {
|
|
3283
|
+
headers: new Headers(),
|
|
3284
|
+
clearHeaders: false
|
|
3285
|
+
};
|
|
3286
|
+
}
|
|
3287
|
+
function setHeaderState(event, name, value) {
|
|
3288
|
+
const state = getResponseState(event);
|
|
3289
|
+
const normalizedName = normalizeHeaderName(name);
|
|
3290
|
+
state.headers.set(name, value);
|
|
3291
|
+
state.headerAppends?.delete(normalizedName);
|
|
3292
|
+
state.removedHeaders?.delete(normalizedName);
|
|
3293
|
+
if (normalizedName === "set-cookie") state.setCookieBehavior = "replace";
|
|
3294
|
+
}
|
|
3295
|
+
function appendHeaderState(event, name, value) {
|
|
3296
|
+
const state = getResponseState(event);
|
|
3297
|
+
const normalizedName = normalizeHeaderName(name);
|
|
3298
|
+
const appendToReturnedHeader = normalizedName !== "set-cookie" && !state.clearHeaders && !state.removedHeaders?.has(normalizedName) && (!state.headers.has(normalizedName) || state.headerAppends?.has(normalizedName));
|
|
3299
|
+
state.headers.append(name, value);
|
|
3300
|
+
if (appendToReturnedHeader) {
|
|
3301
|
+
const appends = state.headerAppends ||= /* @__PURE__ */ new Map();
|
|
3302
|
+
appends.set(normalizedName, {
|
|
3303
|
+
value,
|
|
3304
|
+
previous: appends.get(normalizedName)
|
|
3305
|
+
});
|
|
3306
|
+
}
|
|
3307
|
+
state.removedHeaders?.delete(normalizedName);
|
|
3308
|
+
if (normalizedName === "set-cookie" && state.setCookieBehavior !== "replace") state.setCookieBehavior = "merge";
|
|
3309
|
+
}
|
|
3310
|
+
function deleteHeaderState(event, name) {
|
|
3311
|
+
const state = getResponseState(event);
|
|
3312
|
+
const normalizedName = normalizeHeaderName(name);
|
|
3313
|
+
state.headers.delete(name);
|
|
3314
|
+
state.headerAppends?.delete(normalizedName);
|
|
3315
|
+
(state.removedHeaders ||= /* @__PURE__ */ new Set()).add(normalizedName);
|
|
3316
|
+
if (normalizedName === "set-cookie") state.setCookieBehavior = "replace";
|
|
3317
|
+
}
|
|
3318
|
+
function getDistinctCookieKey(name, options, defaultPath = "") {
|
|
3319
|
+
return [
|
|
3320
|
+
name,
|
|
3321
|
+
options.domain || "",
|
|
3322
|
+
options.path ?? defaultPath
|
|
3323
|
+
].join(";");
|
|
3324
|
+
}
|
|
3325
|
+
function getDistinctCookieKeyFromHeader(cookie) {
|
|
3326
|
+
const parsed = parseSetCookie(cookie);
|
|
3327
|
+
return parsed ? getDistinctCookieKey(parsed.name, parsed) : `\0${cookie}`;
|
|
3328
|
+
}
|
|
3329
|
+
function replaceSetCookieValues(headers, cookies) {
|
|
3330
|
+
headers.delete("set-cookie");
|
|
3331
|
+
for (const cookie of cookies) headers.append("set-cookie", cookie);
|
|
3332
|
+
}
|
|
3333
|
+
function getCookieKey(state, cookie) {
|
|
3334
|
+
const keys = state.setCookieKeys ||= /* @__PURE__ */ new Map();
|
|
3335
|
+
let key = keys.get(cookie);
|
|
3336
|
+
if (key === void 0) {
|
|
3337
|
+
key = getDistinctCookieKeyFromHeader(cookie);
|
|
3338
|
+
keys.set(cookie, key);
|
|
3339
|
+
}
|
|
3340
|
+
return key;
|
|
3341
|
+
}
|
|
3342
|
+
function getMergedSetCookieValues(state, currentCookies, cookiesToMerge) {
|
|
3343
|
+
if (currentCookies.length === 0) return cookiesToMerge;
|
|
3344
|
+
const cookieKeysToMerge = /* @__PURE__ */ new Set();
|
|
3345
|
+
for (const cookie of cookiesToMerge) cookieKeysToMerge.add(getCookieKey(state, cookie));
|
|
3346
|
+
return currentCookies.filter((cookie) => !cookieKeysToMerge.has(getCookieKey(state, cookie))).concat(cookiesToMerge);
|
|
3347
|
+
}
|
|
3348
|
+
function mergeStartSetCookieValues(event, cookies) {
|
|
3349
|
+
if (cookies.length === 0) return;
|
|
3350
|
+
const state = getResponseState(event);
|
|
3351
|
+
state.removedHeaders?.delete("set-cookie");
|
|
3352
|
+
if (state.setCookieBehavior !== "replace") state.setCookieBehavior = "merge";
|
|
3353
|
+
replaceSetCookieValues(state.headers, getMergedSetCookieValues(state, getSetCookieValues(state.headers), cookies));
|
|
3354
|
+
}
|
|
3355
|
+
function hasProtectedHeaderChanges(response, protectedHeaders) {
|
|
3356
|
+
const headers = response.headers;
|
|
3357
|
+
for (const [name, value] of protectedHeaders) if (headers.get(name) !== value) return true;
|
|
3358
|
+
return false;
|
|
3359
|
+
}
|
|
3360
|
+
function applyProtectedHeaders(protectedHeaders, headers) {
|
|
3361
|
+
for (const [name, value] of protectedHeaders) if (value === null) headers.delete(name);
|
|
3362
|
+
else headers.set(name, value);
|
|
3363
|
+
}
|
|
3364
|
+
function applyHeaderState(target, state, generatedBody, protectedHeaders, appliedHeaderAppends) {
|
|
3365
|
+
let headers = target;
|
|
3366
|
+
const mutableHeaders = () => {
|
|
3367
|
+
if (headers === target) headers = new Headers(target);
|
|
3368
|
+
return headers;
|
|
3369
|
+
};
|
|
3370
|
+
if (state.clearHeaders) {
|
|
3371
|
+
for (const name of Array.from(target.keys())) if (!protectedHeaders?.has(name)) mutableHeaders().delete(name);
|
|
3372
|
+
}
|
|
3373
|
+
if (!state.clearHeaders && state.removedHeaders) {
|
|
3374
|
+
for (const name of state.removedHeaders) if (!protectedHeaders?.has(name) && headers.has(name)) mutableHeaders().delete(name);
|
|
3375
|
+
}
|
|
3376
|
+
for (const [name, value] of state.headers) if (name !== "set-cookie" && !protectedHeaders?.has(name) && !(generatedBody && GENERATED_BODY_EXCLUDED_HEADERS.has(name))) {
|
|
3377
|
+
let append = state.headerAppends?.get(name);
|
|
3378
|
+
if (!append) {
|
|
3379
|
+
if (headers.get(name) !== value) mutableHeaders().set(name, value);
|
|
3380
|
+
continue;
|
|
3381
|
+
}
|
|
3382
|
+
const applied = appliedHeaderAppends?.get(name);
|
|
3383
|
+
const pending = [];
|
|
3384
|
+
while (append && append !== applied) {
|
|
3385
|
+
pending.push(append.value);
|
|
3386
|
+
append = append.previous;
|
|
3387
|
+
}
|
|
3388
|
+
for (let index = pending.length - 1; index >= 0; index--) mutableHeaders().append(name, pending[index]);
|
|
3389
|
+
}
|
|
3390
|
+
if (state.setCookieBehavior && !protectedHeaders?.has("set-cookie")) {
|
|
3391
|
+
const eventSetCookies = getSetCookieValues(state.headers);
|
|
3392
|
+
const currentCookies = getSetCookieValues(headers);
|
|
3393
|
+
const cookies = state.setCookieBehavior === "replace" ? eventSetCookies : getMergedSetCookieValues(state, currentCookies, eventSetCookies);
|
|
3394
|
+
if (cookies.length !== currentCookies.length || cookies.some((cookie, index) => cookie !== currentCookies[index])) replaceSetCookieValues(mutableHeaders(), cookies);
|
|
3395
|
+
}
|
|
3396
|
+
return headers;
|
|
3397
|
+
}
|
|
3398
|
+
function canHaveBody(method, status) {
|
|
3399
|
+
return method !== "HEAD" && status !== 204 && status !== 205 && status !== 304;
|
|
3400
|
+
}
|
|
3401
|
+
/** A protected content type marks a Start-serialized body the client decodes. */
|
|
3402
|
+
function isSerializedResponse(protectedHeaders) {
|
|
3403
|
+
return typeof protectedHeaders?.get("content-type") === "string";
|
|
3404
|
+
}
|
|
3405
|
+
/**
|
|
3406
|
+
* A helper status that forbids a body never applies to a serialized
|
|
3407
|
+
* server-function reply, because the client must decode it. Only a HEAD request
|
|
3408
|
+
* drops its body.
|
|
3409
|
+
*/
|
|
3410
|
+
function getHelperStatus(state, serialized) {
|
|
3411
|
+
const status = state?.status;
|
|
3412
|
+
if (!serialized || status === void 0 || canHaveBody("GET", status)) return status;
|
|
3413
|
+
}
|
|
3414
|
+
/** Helper status text describes the helper status and is ignored with it. */
|
|
3415
|
+
function getHelperStatusText(state, helperStatus) {
|
|
3416
|
+
return helperStatus === state?.status ? state?.statusText : void 0;
|
|
3417
|
+
}
|
|
3418
|
+
function cancelDroppedBody(response, reason) {
|
|
3419
|
+
try {
|
|
3420
|
+
response.body?.cancel(reason).catch(() => {});
|
|
3421
|
+
} catch {}
|
|
3422
|
+
}
|
|
3423
|
+
function createReconciledResponse(body, status, statusText, headers) {
|
|
3424
|
+
try {
|
|
3425
|
+
return new Response(body, {
|
|
3426
|
+
status,
|
|
3427
|
+
statusText,
|
|
3428
|
+
headers
|
|
3429
|
+
});
|
|
3430
|
+
} catch (cause) {
|
|
3431
|
+
throw new Error("Unable to reconcile response because its body has already been consumed or locked.", { cause });
|
|
3432
|
+
}
|
|
3433
|
+
}
|
|
3434
|
+
/** Apply helper state to a response that leaves Start. */
|
|
3435
|
+
function finalizeResponse(response, event) {
|
|
3436
|
+
return applyResponseState(response, event, event.request.method);
|
|
3437
|
+
}
|
|
3438
|
+
/**
|
|
3439
|
+
* Apply helper state with the body rules of `method`. Request middleware still
|
|
3440
|
+
* reads a HEAD response's body, so the pipeline applies GET rules and strips a
|
|
3441
|
+
* HEAD body only when the response leaves it.
|
|
3442
|
+
*/
|
|
3443
|
+
function applyResponseState(response, event, method, disposeBody) {
|
|
3444
|
+
const protectedHeaders = getProtectedResponseHeaders(response);
|
|
3445
|
+
const serialized = isSerializedResponse(protectedHeaders);
|
|
3446
|
+
let helperStatus = getHelperStatus(event.responseState, serialized);
|
|
3447
|
+
const mustDropBody = !canHaveBody(method, helperStatus ?? response.status) && response.body !== null;
|
|
3448
|
+
if (mustDropBody) {
|
|
3449
|
+
const reason = method === "HEAD" ? "HEAD body stripped" : "Response body dropped by Start reconciliation";
|
|
3450
|
+
if (disposeBody) disposeBody(reason);
|
|
3451
|
+
else cancelDroppedBody(response, reason);
|
|
3452
|
+
helperStatus = getHelperStatus(event.responseState, serialized);
|
|
3453
|
+
}
|
|
3454
|
+
const state = event.responseState;
|
|
3455
|
+
if (!state && !mustDropBody) {
|
|
3456
|
+
event.currentResponse = response;
|
|
3457
|
+
return response;
|
|
3458
|
+
}
|
|
3459
|
+
const status = helperStatus ?? response.status;
|
|
3460
|
+
const statusText = getHelperStatusText(state, helperStatus) ?? response.statusText;
|
|
3461
|
+
const statusChanged = status !== response.status;
|
|
3462
|
+
const statusTextChanged = statusText !== response.statusText;
|
|
3463
|
+
const headers = state ? applyHeaderState(response.headers, state, serialized, protectedHeaders, event.responseHeaderAppends?.get(response)) : response.headers;
|
|
3464
|
+
const reconciled = statusChanged || statusTextChanged || mustDropBody || headers !== response.headers ? createReconciledResponse(mustDropBody ? null : response.body, status, statusText, headers) : response;
|
|
3465
|
+
if (protectedHeaders && reconciled !== response) installProtectedResponseHeaders(reconciled, protectedHeaders);
|
|
3466
|
+
return publishResponse(reconciled, event);
|
|
3467
|
+
}
|
|
3468
|
+
function publishResponse(response, event) {
|
|
3469
|
+
const headerAppends = event.responseState?.headerAppends;
|
|
3470
|
+
if (headerAppends?.size) (event.responseHeaderAppends ||= /* @__PURE__ */ new WeakMap()).set(response, new Map(headerAppends));
|
|
3471
|
+
event.currentResponse = response;
|
|
3472
|
+
return response;
|
|
3473
|
+
}
|
|
3474
|
+
function getHttpErrorStatus(status) {
|
|
3475
|
+
return status !== void 0 && status >= 400 ? status : void 0;
|
|
3476
|
+
}
|
|
3477
|
+
/**
|
|
3478
|
+
* Status for a response built from an uncaught error. Only an error status
|
|
3479
|
+
* (400-599) from a helper or from error metadata describes the failure, so a
|
|
3480
|
+
* success or redirect status set before the throw cannot hide it. The error is
|
|
3481
|
+
* logged unless its own metadata marks it as an HTTP error. Reporting runs
|
|
3482
|
+
* before helper state is read, so hooks that write helpers are included.
|
|
3483
|
+
*/
|
|
3484
|
+
function resolveErrorStatus(error, event) {
|
|
3485
|
+
const metadataStatus = getErrorStatus(error);
|
|
3486
|
+
const errorStatus = getHttpErrorStatus(metadataStatus);
|
|
3487
|
+
if (errorStatus === void 0) console.error(error);
|
|
3488
|
+
const state = event?.responseState;
|
|
3489
|
+
const helperStatus = getHttpErrorStatus(state?.status);
|
|
3490
|
+
const status = helperStatus ?? errorStatus ?? 500;
|
|
3491
|
+
const statusText = getHelperStatusText(state, helperStatus) ?? (status === errorStatus || metadataStatus === void 0 ? getErrorStatusText(error) : void 0) ?? "";
|
|
3492
|
+
if (state && state.status !== helperStatus) {
|
|
3493
|
+
state.status = void 0;
|
|
3494
|
+
state.statusText = void 0;
|
|
3495
|
+
}
|
|
3496
|
+
return {
|
|
3497
|
+
status,
|
|
3498
|
+
statusText
|
|
3499
|
+
};
|
|
3500
|
+
}
|
|
3501
|
+
/**
|
|
3502
|
+
* Internal: status and status text for a serialized server-function error.
|
|
3503
|
+
* Logs the error and discards a non-error helper status, like any error
|
|
3504
|
+
* response Start builds.
|
|
3505
|
+
*/
|
|
3506
|
+
function resolveErrorResponseStatus(error) {
|
|
3507
|
+
return resolveErrorStatus(error, eventStorage.getStore());
|
|
3508
|
+
}
|
|
3509
|
+
function createErrorResponse(error, event) {
|
|
3510
|
+
let headers = getErrorHeaders(error) ?? new Headers();
|
|
3511
|
+
const { status, statusText } = resolveErrorStatus(error, event);
|
|
3512
|
+
const state = event.responseState;
|
|
3513
|
+
const body = canHaveBody(event.request.method, status) ? JSON.stringify({
|
|
3514
|
+
status,
|
|
3515
|
+
statusText,
|
|
3516
|
+
unhandled: true,
|
|
3517
|
+
message: "HTTPError"
|
|
3518
|
+
}) : null;
|
|
3519
|
+
if (!headers.has("content-type")) headers.set("content-type", "application/json");
|
|
3520
|
+
if (state) headers = applyHeaderState(headers, state, true);
|
|
3521
|
+
return publishResponse(new Response(body !== null && !headers.has("content-type") ? new TextEncoder().encode(body) : body, {
|
|
3522
|
+
status,
|
|
3523
|
+
statusText,
|
|
3524
|
+
headers
|
|
3525
|
+
}), event);
|
|
3526
|
+
}
|
|
3527
|
+
function finalizeError(error, event) {
|
|
3528
|
+
if (error instanceof Response) return finalizeResponse(error, event);
|
|
3529
|
+
return createErrorResponse(error, event);
|
|
3530
|
+
}
|
|
3531
|
+
function handleStartError(error) {
|
|
3532
|
+
const event = eventStorage.getStore();
|
|
3533
|
+
if (event) return finalizeError(error, event);
|
|
3534
|
+
if (error instanceof Response) return error;
|
|
3535
|
+
const request = new Request("http://localhost");
|
|
3536
|
+
return createErrorResponse(error, {
|
|
3537
|
+
request,
|
|
3538
|
+
requestUrl: new URL(request.url)
|
|
3539
|
+
});
|
|
3540
|
+
}
|
|
3541
|
+
/** Apply helper state to a response inside the request middleware pipeline. */
|
|
3542
|
+
function reconcileResponse(response, event, disposeBody) {
|
|
3543
|
+
if (!event.responseState && (response === event.currentResponse || canHaveBody("GET", response.status)) || isRedirect(response)) {
|
|
3544
|
+
event.currentResponse = response;
|
|
3545
|
+
return response;
|
|
3546
|
+
}
|
|
3547
|
+
return applyResponseState(response, event, "GET", disposeBody);
|
|
3548
|
+
}
|
|
3549
|
+
/**
|
|
3550
|
+
* Restore protocol headers that middleware changed directly on the response.
|
|
3551
|
+
* Start does this once, when the response leaves the request middleware
|
|
3552
|
+
* pipeline; helper writes never override them.
|
|
3553
|
+
*/
|
|
3554
|
+
function restoreResponseProtocol(response, event) {
|
|
3555
|
+
const protectedHeaders = getProtectedResponseHeaders(response);
|
|
3556
|
+
if (!protectedHeaders || !hasProtectedHeaderChanges(response, protectedHeaders)) return response;
|
|
3557
|
+
const headers = new Headers(response.headers);
|
|
3558
|
+
applyProtectedHeaders(protectedHeaders, headers);
|
|
3559
|
+
const restored = createReconciledResponse(response.body, response.status, response.statusText, headers);
|
|
3560
|
+
transferResponseMetadata(response, restored);
|
|
3561
|
+
event.currentResponse = restored;
|
|
3562
|
+
return restored;
|
|
3563
|
+
}
|
|
3564
|
+
/**
|
|
3565
|
+
* Build a Start-owned serialized reply with already normalized protocol
|
|
3566
|
+
* headers. A bodyless helper status never applies to it; only a HEAD request
|
|
3567
|
+
* drops its body.
|
|
3568
|
+
*/
|
|
3569
|
+
function createFinalizedResponse(body, headers, protectedHeaders, event) {
|
|
3570
|
+
const state = event.responseState;
|
|
3571
|
+
let status = 200;
|
|
3572
|
+
let statusText = "";
|
|
3573
|
+
if (state) {
|
|
3574
|
+
const helperStatus = getHelperStatus(state, true);
|
|
3575
|
+
status = helperStatus ?? 200;
|
|
3576
|
+
statusText = getHelperStatusText(state, helperStatus) ?? "";
|
|
3577
|
+
headers = applyHeaderState(headers, state, true, protectedHeaders);
|
|
3578
|
+
}
|
|
3579
|
+
const response = new Response(canHaveBody(event.request.method, status) ? body : null, {
|
|
3580
|
+
status,
|
|
3581
|
+
statusText,
|
|
3582
|
+
headers
|
|
3583
|
+
});
|
|
3584
|
+
installProtectedResponseHeaders(response, protectedHeaders);
|
|
3585
|
+
return publishResponse(response, event);
|
|
3586
|
+
}
|
|
3587
|
+
function protectResponseHeaders(response, headers) {
|
|
3588
|
+
const previous = getProtectedResponseHeaders(response);
|
|
3589
|
+
if (previous === headers) return;
|
|
3590
|
+
if (previous) {
|
|
3591
|
+
const merged = new Map(previous);
|
|
3592
|
+
for (const [name, value] of headers) merged.set(name, value);
|
|
3593
|
+
headers = merged;
|
|
3594
|
+
}
|
|
3595
|
+
installProtectedResponseHeaders(response, headers);
|
|
3596
|
+
}
|
|
3597
|
+
/**
|
|
3598
|
+
* Set and protect transport headers on a new response. Reuse the body stream
|
|
3599
|
+
* without cloning or teeing it; callers transfer ownership to the result.
|
|
3600
|
+
*/
|
|
3601
|
+
function setProtectedResponseHeaders(response, headers) {
|
|
3602
|
+
let next;
|
|
3603
|
+
try {
|
|
3604
|
+
next = new Response(response.body, response);
|
|
3605
|
+
applyProtectedHeaders(headers, next.headers);
|
|
3606
|
+
} catch (cause) {
|
|
3607
|
+
throw new Error("Unable to set response header because its body has already been consumed or locked.", { cause });
|
|
3608
|
+
}
|
|
3609
|
+
transferResponseMetadata(response, next);
|
|
3610
|
+
protectResponseHeaders(next, headers);
|
|
3611
|
+
return next;
|
|
3612
|
+
}
|
|
3613
|
+
function decodePathname(pathname) {
|
|
3614
|
+
try {
|
|
3615
|
+
return decodeURI(pathname);
|
|
3616
|
+
} catch (error) {
|
|
3617
|
+
if (error instanceof URIError) return;
|
|
3618
|
+
throw error;
|
|
3619
|
+
}
|
|
3620
|
+
}
|
|
3621
|
+
function runInStartRequest(request, requestOpts, handler) {
|
|
3622
|
+
let requestUrl;
|
|
3623
|
+
try {
|
|
3624
|
+
requestUrl = new URL(request.url);
|
|
3625
|
+
} catch (error) {
|
|
3626
|
+
if (error instanceof TypeError) return new Response(null, {
|
|
3627
|
+
status: 400,
|
|
3628
|
+
statusText: "Bad Request"
|
|
3629
|
+
});
|
|
3630
|
+
throw error;
|
|
3631
|
+
}
|
|
3632
|
+
const pathname = requestUrl.pathname;
|
|
3633
|
+
if (pathname.includes("%") && decodePathname(pathname) === void 0) return new Response(null, {
|
|
3634
|
+
status: 400,
|
|
3635
|
+
statusText: "Bad Request"
|
|
3636
|
+
});
|
|
3637
|
+
const event = {
|
|
3638
|
+
request,
|
|
3639
|
+
requestUrl
|
|
3640
|
+
};
|
|
3641
|
+
return eventStorage.run(event, handler, request, requestOpts, event);
|
|
3642
|
+
}
|
|
3643
|
+
/**
|
|
3644
|
+
* Keep the complete server entry, including custom error handling, inside one
|
|
3645
|
+
* request scope. A custom returned response is used as-is; call handleStartError
|
|
3646
|
+
* in a custom catch to preserve Start's response helper state.
|
|
3647
|
+
*/
|
|
3648
|
+
function createServerEntry(entry) {
|
|
3649
|
+
return { fetch: withStartRequest(async (request, requestOpts) => {
|
|
3650
|
+
try {
|
|
3651
|
+
return await entry.fetch(request, requestOpts);
|
|
3652
|
+
} catch (error) {
|
|
3653
|
+
return handleStartError(error);
|
|
3654
|
+
}
|
|
3655
|
+
}) };
|
|
3656
|
+
}
|
|
3657
|
+
/**
|
|
3658
|
+
* Establish request scope; the response pipeline owns reconciliation. A nested
|
|
3659
|
+
* handler delegating the same request participates in its scope. Independent
|
|
3660
|
+
* fetch invocations and different requests get a fresh event.
|
|
3661
|
+
*/
|
|
3662
|
+
function withStartRequest(handler) {
|
|
3663
|
+
return (request, requestOpts) => {
|
|
3664
|
+
const event = eventStorage.getStore();
|
|
3665
|
+
if (event?.request === request) return handler(request, requestOpts, event);
|
|
3666
|
+
return runInStartRequest(request, requestOpts, handler);
|
|
3667
|
+
};
|
|
3668
|
+
}
|
|
3669
|
+
function getStartEvent() {
|
|
3670
|
+
const event = eventStorage.getStore();
|
|
3671
|
+
if (!event) throw new Error(`No StartEvent found in AsyncLocalStorage. Make sure you are using the function within the server runtime.`);
|
|
3672
|
+
return event;
|
|
3673
|
+
}
|
|
3674
|
+
/**
|
|
3675
|
+
* Internal: returns the per-request parsed URL for `request`, memoized on the
|
|
3676
|
+
* Start event so the framework parses each request URL only once. Falls back
|
|
3677
|
+
* to parsing when called outside a Start event (e.g. in unit tests) or for a
|
|
3678
|
+
* foreign request. Callers MUST NOT mutate the returned URL.
|
|
3679
|
+
*/
|
|
3680
|
+
function getParsedRequestUrl(request) {
|
|
3681
|
+
const event = eventStorage.getStore();
|
|
3682
|
+
if (event && event.request === request) return event.requestUrl;
|
|
3683
|
+
return new URL(request.url);
|
|
3684
|
+
}
|
|
3685
|
+
function getRequest() {
|
|
3686
|
+
return getStartEvent().request;
|
|
3687
|
+
}
|
|
3688
|
+
function getRequestHeaders$1() {
|
|
3689
|
+
return getStartEvent().request.headers;
|
|
3690
|
+
}
|
|
3691
|
+
function getRequestHeader(name) {
|
|
3692
|
+
return getRequestHeaders$1().get(name) ?? void 0;
|
|
3693
|
+
}
|
|
3694
|
+
function getRequestIP(opts) {
|
|
3695
|
+
const request = getRequest();
|
|
3696
|
+
if (opts?.xForwardedFor) {
|
|
3697
|
+
const forwardedIp = request.headers.get("x-forwarded-for")?.split(",", 1)[0]?.trim();
|
|
3698
|
+
if (forwardedIp) return forwardedIp;
|
|
3699
|
+
}
|
|
3700
|
+
return request.context?.clientAddress || request.ip || void 0;
|
|
3701
|
+
}
|
|
3702
|
+
/**
|
|
3703
|
+
* Get the request hostname.
|
|
3704
|
+
*
|
|
3705
|
+
* If `xForwardedHost` is `true`, it will use the `x-forwarded-host` header if it exists.
|
|
3706
|
+
*
|
|
3707
|
+
* If no host header is found, it uses the request URL's host.
|
|
3708
|
+
*/
|
|
3709
|
+
function getRequestHost(opts) {
|
|
3710
|
+
const headers = getRequestHeaders$1();
|
|
3711
|
+
if (opts?.xForwardedHost) {
|
|
3712
|
+
const host = headers.get("x-forwarded-host")?.split(",", 1)[0]?.trim();
|
|
3713
|
+
if (host) return host;
|
|
3714
|
+
}
|
|
3715
|
+
return headers.get("host") || getStartEvent().requestUrl.host || "localhost";
|
|
3716
|
+
}
|
|
3717
|
+
/**
|
|
3718
|
+
* Get the full incoming request URL.
|
|
3719
|
+
*
|
|
3720
|
+
* If `xForwardedHost` is `true`, it will use the `x-forwarded-host` header if it exists.
|
|
3721
|
+
*
|
|
3722
|
+
* If `xForwardedProto` is `false`, it will not use the `x-forwarded-proto` header.
|
|
3723
|
+
*/
|
|
3724
|
+
function getRequestUrl(opts) {
|
|
3725
|
+
const event = getStartEvent();
|
|
3726
|
+
const url = new URL(event.requestUrl);
|
|
3727
|
+
url.protocol = getRequestProtocol(opts);
|
|
3728
|
+
if (opts?.xForwardedHost) {
|
|
3729
|
+
const host = getRequestHost(opts);
|
|
3730
|
+
if (host) {
|
|
3731
|
+
url.host = host;
|
|
3732
|
+
if (!/:\d+$/.test(host)) url.port = "";
|
|
3733
|
+
}
|
|
3734
|
+
}
|
|
3735
|
+
return url;
|
|
3736
|
+
}
|
|
3737
|
+
/**
|
|
3738
|
+
* Get the request protocol.
|
|
3739
|
+
*
|
|
3740
|
+
* If `x-forwarded-proto` header is set to "https", it will return "https". You can disable this behavior by setting `xForwardedProto` to `false`.
|
|
3741
|
+
*
|
|
3742
|
+
* If protocol cannot be determined, it will default to "http".
|
|
3743
|
+
*/
|
|
3744
|
+
function getRequestProtocol(opts) {
|
|
3745
|
+
const request = getRequest();
|
|
3746
|
+
if (opts?.xForwardedProto !== false) {
|
|
3747
|
+
const forwardedProto = request.headers.get("x-forwarded-proto")?.split(",", 1)[0]?.trim().toLowerCase();
|
|
3748
|
+
if (forwardedProto === "https") return "https";
|
|
3749
|
+
if (forwardedProto === "http") return "http";
|
|
3750
|
+
}
|
|
3751
|
+
return getStartEvent().requestUrl.protocol.slice(0, -1);
|
|
3752
|
+
}
|
|
3753
|
+
function setResponseHeaders(headers) {
|
|
3754
|
+
if (headers instanceof Headers) {
|
|
3755
|
+
for (const [name, value] of headers) if (name !== "set-cookie") setResponseHeader(name, value);
|
|
3756
|
+
const cookies = getSetCookieValues(headers);
|
|
3757
|
+
if (cookies.length > 0) setResponseHeader("set-cookie", cookies.length === 1 ? cookies[0] : cookies);
|
|
3758
|
+
return;
|
|
3759
|
+
}
|
|
3760
|
+
if (!Array.isArray(headers)) {
|
|
3761
|
+
for (const [name, value] of Object.entries(headers)) setResponseHeader(name, value);
|
|
3762
|
+
return;
|
|
3763
|
+
}
|
|
3764
|
+
const groupedHeaders = /* @__PURE__ */ new Map();
|
|
3765
|
+
const addHeader = (name, value) => {
|
|
3766
|
+
const normalizedName = normalizeHeaderName(name);
|
|
3767
|
+
let header = groupedHeaders.get(normalizedName);
|
|
3768
|
+
if (!header) {
|
|
3769
|
+
header = {
|
|
3770
|
+
name,
|
|
3771
|
+
values: []
|
|
3772
|
+
};
|
|
3773
|
+
groupedHeaders.set(normalizedName, header);
|
|
4826
3774
|
}
|
|
4827
|
-
|
|
3775
|
+
header.values.push(value);
|
|
3776
|
+
};
|
|
3777
|
+
for (const [name, value] of headers) addHeader(name, value);
|
|
3778
|
+
for (const { name, values } of groupedHeaders.values()) setResponseHeader(name, values.length === 1 ? values[0] : values);
|
|
4828
3779
|
}
|
|
4829
3780
|
/**
|
|
4830
|
-
*
|
|
4831
|
-
*
|
|
4832
|
-
*
|
|
3781
|
+
* Outside production, return the snapshot as a Headers subclass that warns when
|
|
3782
|
+
* code tries to change the outgoing response through it. Its contents and
|
|
3783
|
+
* behavior are identical to the production snapshot.
|
|
3784
|
+
*/
|
|
3785
|
+
function toResponseHeadersSnapshot(headers) {
|
|
3786
|
+
return headers;
|
|
3787
|
+
}
|
|
3788
|
+
/**
|
|
3789
|
+
* Read a detached snapshot of the effective response headers.
|
|
3790
|
+
* Use response header and cookie helpers to change the outgoing response.
|
|
3791
|
+
*/
|
|
3792
|
+
function getResponseHeaders() {
|
|
3793
|
+
const event = getStartEvent();
|
|
3794
|
+
const state = event.responseState;
|
|
3795
|
+
const currentResponse = event.currentResponse;
|
|
3796
|
+
if (!currentResponse) return toResponseHeadersSnapshot(state ? new Headers(state.headers) : new Headers());
|
|
3797
|
+
const protectedHeaders = getProtectedResponseHeaders(currentResponse);
|
|
3798
|
+
let headers = currentResponse.headers;
|
|
3799
|
+
if (state) headers = applyHeaderState(headers, state, isSerializedResponse(protectedHeaders), protectedHeaders, event.responseHeaderAppends?.get(currentResponse));
|
|
3800
|
+
if (headers === currentResponse.headers) headers = new Headers(headers);
|
|
3801
|
+
if (protectedHeaders) applyProtectedHeaders(protectedHeaders, headers);
|
|
3802
|
+
return toResponseHeadersSnapshot(headers);
|
|
3803
|
+
}
|
|
3804
|
+
function getResponseHeader(name) {
|
|
3805
|
+
const event = getStartEvent();
|
|
3806
|
+
const normalizedName = normalizeHeaderName(name);
|
|
3807
|
+
if (normalizedName === "set-cookie" || event.responseState?.headerAppends?.has(normalizedName)) return getResponseHeaders().get(name) ?? void 0;
|
|
3808
|
+
const currentResponse = event.currentResponse;
|
|
3809
|
+
const protectedHeaders = currentResponse ? getProtectedResponseHeaders(currentResponse) : void 0;
|
|
3810
|
+
if (protectedHeaders?.has(normalizedName)) return protectedHeaders.get(normalizedName) ?? void 0;
|
|
3811
|
+
if (GENERATED_BODY_EXCLUDED_HEADERS.has(normalizedName) && isSerializedResponse(protectedHeaders)) return currentResponse.headers.get(name) ?? void 0;
|
|
3812
|
+
const state = event.responseState;
|
|
3813
|
+
if (state) {
|
|
3814
|
+
const stateValue = state.headers.get(name);
|
|
3815
|
+
if (stateValue !== null) return stateValue;
|
|
3816
|
+
if (state.clearHeaders) return;
|
|
3817
|
+
if (state.removedHeaders?.has(normalizedName)) return;
|
|
3818
|
+
}
|
|
3819
|
+
return currentResponse?.headers.get(name) ?? void 0;
|
|
3820
|
+
}
|
|
3821
|
+
function setResponseHeader(name, value) {
|
|
3822
|
+
const event = getStartEvent();
|
|
3823
|
+
if (Array.isArray(value)) {
|
|
3824
|
+
deleteHeaderState(event, name);
|
|
3825
|
+
for (const valueItem of value) appendHeaderState(event, name, valueItem);
|
|
3826
|
+
} else setHeaderState(event, name, value);
|
|
3827
|
+
}
|
|
3828
|
+
/**
|
|
3829
|
+
* Append a response header value without replacing existing values.
|
|
4833
3830
|
*
|
|
4834
|
-
*
|
|
4835
|
-
*
|
|
4836
|
-
*
|
|
4837
|
-
*
|
|
3831
|
+
* Ordinary values are appended once per returned response. Start transfers
|
|
3832
|
+
* that application state when it reconstructs a response. A new response
|
|
3833
|
+
* created by application code is fresh input: copying already-reconciled
|
|
3834
|
+
* headers into it also copies their appended values, and helper appends apply
|
|
3835
|
+
* again. Mutate the current response or pass its middleware result through
|
|
3836
|
+
* when preserving an existing response's headers.
|
|
4838
3837
|
*
|
|
4839
|
-
*
|
|
4840
|
-
*
|
|
4841
|
-
*
|
|
3838
|
+
* For `set-cookie`, values must be fully serialized cookie strings; they are
|
|
3839
|
+
* merged into the outgoing cookies and deduped by cookie identity
|
|
3840
|
+
* (name + domain + path), exactly like `setCookie`. A value that cannot be
|
|
3841
|
+
* parsed is identified by its exact string. This is the primitive to
|
|
3842
|
+
* use when bridging external session/auth libraries that produce raw
|
|
3843
|
+
* `Set-Cookie` strings.
|
|
4842
3844
|
*
|
|
4843
|
-
*
|
|
4844
|
-
*
|
|
4845
|
-
*
|
|
4846
|
-
* abort the whole server-function call to cancel the response and server work.
|
|
4847
|
-
* Consume streams concurrently, cancel unused streams promptly, or use separate
|
|
4848
|
-
* calls when independent backpressure is required.
|
|
3845
|
+
* ```ts
|
|
3846
|
+
* appendResponseHeader('set-cookie', await externalLib.commitSession(session))
|
|
3847
|
+
* ```
|
|
4849
3848
|
*/
|
|
4850
|
-
|
|
4851
|
-
|
|
4852
|
-
|
|
4853
|
-
|
|
3849
|
+
function appendResponseHeader(name, value) {
|
|
3850
|
+
const event = getStartEvent();
|
|
3851
|
+
const values = Array.isArray(value) ? value : [value];
|
|
3852
|
+
if (normalizeHeaderName(name) === "set-cookie") {
|
|
3853
|
+
for (const valueItem of values) mergeStartSetCookieValues(event, getSetCookieValues(new Headers({ "set-cookie": valueItem })));
|
|
3854
|
+
return;
|
|
4854
3855
|
}
|
|
4855
|
-
|
|
3856
|
+
for (const valueItem of values) appendHeaderState(event, name, valueItem);
|
|
3857
|
+
}
|
|
3858
|
+
function removeResponseHeader(name) {
|
|
3859
|
+
deleteHeaderState(getStartEvent(), name);
|
|
3860
|
+
}
|
|
3861
|
+
function clearResponseHeaders(headerNames) {
|
|
3862
|
+
const event = getStartEvent();
|
|
3863
|
+
if (headerNames && headerNames.length > 0) {
|
|
3864
|
+
for (const name of headerNames) deleteHeaderState(event, name);
|
|
3865
|
+
return;
|
|
3866
|
+
}
|
|
3867
|
+
const state = getResponseState(event);
|
|
3868
|
+
state.clearHeaders = true;
|
|
3869
|
+
state.headers = new Headers();
|
|
3870
|
+
state.headerAppends = void 0;
|
|
3871
|
+
}
|
|
3872
|
+
function getResponseStatus() {
|
|
3873
|
+
const event = getStartEvent();
|
|
3874
|
+
const currentResponse = event.currentResponse;
|
|
3875
|
+
const serialized = !!currentResponse && isSerializedResponse(getProtectedResponseHeaders(currentResponse));
|
|
3876
|
+
return getHelperStatus(event.responseState, serialized) ?? currentResponse?.status ?? 200;
|
|
3877
|
+
}
|
|
3878
|
+
function setResponseStatus(code, text) {
|
|
3879
|
+
const event = getStartEvent();
|
|
3880
|
+
if (code !== void 0) {
|
|
3881
|
+
const status = sanitizeStatusCode(code);
|
|
3882
|
+
if (status === void 0) return;
|
|
3883
|
+
getResponseState(event).status = status;
|
|
3884
|
+
}
|
|
3885
|
+
if (text) getResponseState(event).statusText = sanitizeStatusMessage(text);
|
|
3886
|
+
}
|
|
3887
|
+
/**
|
|
3888
|
+
* Parse the request to get HTTP Cookie header string and return an object of all cookie name-value pairs.
|
|
3889
|
+
* @returns Object of cookie name-value pairs
|
|
3890
|
+
* ```ts
|
|
3891
|
+
* const cookies = getCookies()
|
|
3892
|
+
* ```
|
|
3893
|
+
*/
|
|
3894
|
+
function getCookies() {
|
|
3895
|
+
const cookies = parse(getRequestHeaders$1().get("cookie") || "");
|
|
3896
|
+
const definedCookies = Object.create(null);
|
|
3897
|
+
for (const [name, value] of Object.entries(cookies)) if (value !== void 0) definedCookies[name] = value;
|
|
3898
|
+
return definedCookies;
|
|
3899
|
+
}
|
|
3900
|
+
/**
|
|
3901
|
+
* Get a cookie value by name.
|
|
3902
|
+
* @param name Name of the cookie to get
|
|
3903
|
+
* @returns {*} Value of the cookie (String or undefined)
|
|
3904
|
+
* ```ts
|
|
3905
|
+
* const authorization = getCookie('Authorization')
|
|
3906
|
+
* ```
|
|
3907
|
+
*/
|
|
3908
|
+
function getCookie(name) {
|
|
3909
|
+
return getCookies()[name];
|
|
3910
|
+
}
|
|
3911
|
+
/**
|
|
3912
|
+
* Set a cookie value by name.
|
|
3913
|
+
* @param name Name of the cookie to set
|
|
3914
|
+
* @param value Value of the cookie to set
|
|
3915
|
+
* @param options {CookieSerializeOptions} Options for serializing the cookie
|
|
3916
|
+
* ```ts
|
|
3917
|
+
* setCookie('Authorization', '1234567')
|
|
3918
|
+
* ```
|
|
3919
|
+
*/
|
|
3920
|
+
function setCookie(name, value, options) {
|
|
3921
|
+
const { encode, stringify, ...attrs } = options ?? {};
|
|
3922
|
+
mergeStartSetCookieValues(getStartEvent(), [serialize({
|
|
3923
|
+
name,
|
|
3924
|
+
value,
|
|
3925
|
+
path: "/",
|
|
3926
|
+
...attrs
|
|
3927
|
+
}, {
|
|
3928
|
+
encode,
|
|
3929
|
+
stringify
|
|
3930
|
+
})]);
|
|
3931
|
+
}
|
|
3932
|
+
/**
|
|
3933
|
+
* Remove a cookie by name.
|
|
3934
|
+
* @param name Name of the cookie to delete
|
|
3935
|
+
* @param serializeOptions {CookieSerializeOptions} Cookie options
|
|
3936
|
+
* ```ts
|
|
3937
|
+
* deleteCookie('SessionId')
|
|
3938
|
+
* ```
|
|
3939
|
+
*/
|
|
3940
|
+
function deleteCookie(name, options) {
|
|
3941
|
+
setCookie(name, "", {
|
|
3942
|
+
...options,
|
|
3943
|
+
maxAge: 0
|
|
3944
|
+
});
|
|
3945
|
+
}
|
|
3946
|
+
/**
|
|
3947
|
+
* Internal: helper status state for a serialized server-function reply.
|
|
3948
|
+
* Bodyless statuses never apply to it and are omitted with their status text.
|
|
3949
|
+
*/
|
|
3950
|
+
function getSerializedResponseState() {
|
|
3951
|
+
const state = getStartEvent().responseState;
|
|
3952
|
+
const status = getHelperStatus(state, true);
|
|
3953
|
+
return {
|
|
3954
|
+
status,
|
|
3955
|
+
statusText: getHelperStatusText(state, status)
|
|
3956
|
+
};
|
|
3957
|
+
}
|
|
3958
|
+
var HEADERS = { TSS_SHELL: "X-TSS_SHELL" };
|
|
4856
3959
|
/**
|
|
4857
3960
|
* @description Returns the router manifest data that should be sent to the client.
|
|
4858
3961
|
* This includes only the assets and preloads for the current route and any
|
|
@@ -4863,7 +3966,7 @@ var RawStream = class {
|
|
|
4863
3966
|
* the dev styles URL for route-scoped CSS collection.
|
|
4864
3967
|
*/
|
|
4865
3968
|
async function getStartManifest(matchedRoutes) {
|
|
4866
|
-
const { tsrStartManifest } = await import("../_tanstack-start-manifest_v-
|
|
3969
|
+
const { tsrStartManifest } = await import("../_tanstack-start-manifest_v-DTOQk1l4.mjs");
|
|
4867
3970
|
const startManifest = tsrStartManifest();
|
|
4868
3971
|
let routes = startManifest.routes;
|
|
4869
3972
|
routes[rootRouteId];
|
|
@@ -5223,7 +4326,7 @@ function getSerovalPlugins(routerPlugins) {
|
|
|
5223
4326
|
/** Cached TextEncoder for frame encoding */
|
|
5224
4327
|
var textEncoder$2 = new TextEncoder();
|
|
5225
4328
|
/** Shared empty payload for END frames - avoids allocation per call */
|
|
5226
|
-
var EMPTY_PAYLOAD = new Uint8Array(0);
|
|
4329
|
+
var EMPTY_PAYLOAD = /* @__PURE__ */ new Uint8Array(0);
|
|
5227
4330
|
var MAX_ERROR_MESSAGE_CODE_UNITS = 4096;
|
|
5228
4331
|
/**
|
|
5229
4332
|
* Encodes a single frame with header and payload.
|
|
@@ -5409,19 +4512,33 @@ function createMultiplexedStream(recordStream, options = {}) {
|
|
|
5409
4512
|
});
|
|
5410
4513
|
}
|
|
5411
4514
|
var innerCreateCsrfMiddleware = (opts = {}) => {
|
|
5412
|
-
|
|
4515
|
+
const continueRequest = (result, ctx) => {
|
|
4516
|
+
return isValidationResultAllowed(result, opts) ? ctx.next() : getFailureResponse(opts, ctx);
|
|
4517
|
+
};
|
|
4518
|
+
const validateRequest = (ctx) => {
|
|
4519
|
+
const result = validateCsrfRequest(opts, ctx);
|
|
4520
|
+
if (isPromise(result)) return result.then((result) => continueRequest(result, ctx));
|
|
4521
|
+
return continueRequest(result, ctx);
|
|
4522
|
+
};
|
|
4523
|
+
return createMiddleware().server((ctx) => {
|
|
5413
4524
|
const csrfCtx = ctx;
|
|
5414
|
-
|
|
5415
|
-
|
|
5416
|
-
|
|
4525
|
+
try {
|
|
4526
|
+
if (opts.filter) {
|
|
4527
|
+
const shouldValidate = opts.filter(csrfCtx);
|
|
4528
|
+
if (isPromise(shouldValidate)) return shouldValidate.then((shouldValidate) => shouldValidate ? validateRequest(csrfCtx) : ctx.next());
|
|
4529
|
+
if (!shouldValidate) return ctx.next();
|
|
4530
|
+
}
|
|
4531
|
+
return validateRequest(csrfCtx);
|
|
4532
|
+
} catch (error) {
|
|
4533
|
+
return Promise.reject(error);
|
|
4534
|
+
}
|
|
5417
4535
|
});
|
|
5418
4536
|
};
|
|
5419
4537
|
var createCsrfMiddleware = innerCreateCsrfMiddleware;
|
|
5420
|
-
|
|
5421
|
-
const result = await getCsrfRequestValidationResult(opts, ctx);
|
|
4538
|
+
function isValidationResultAllowed(result, opts) {
|
|
5422
4539
|
return result === true || result === void 0 && opts.allowRequestsWithoutOriginCheck === true;
|
|
5423
4540
|
}
|
|
5424
|
-
|
|
4541
|
+
function validateCsrfRequest(opts, ctx) {
|
|
5425
4542
|
const fetchSite = ctx.request.headers.get("Sec-Fetch-Site");
|
|
5426
4543
|
if (fetchSite !== null) return matchValue(opts.secFetchSite ?? "same-origin", fetchSite, ctx);
|
|
5427
4544
|
const origin = ctx.request.headers.get("Origin");
|
|
@@ -5438,7 +4555,7 @@ async function getCsrfRequestValidationResult(opts, ctx) {
|
|
|
5438
4555
|
}
|
|
5439
4556
|
return isRefererSameOrigin(referer, new URL(ctx.request.url).origin);
|
|
5440
4557
|
}
|
|
5441
|
-
|
|
4558
|
+
function matchValue(matcher, value, ctx) {
|
|
5442
4559
|
if (typeof matcher === "function") return matcher(value, ctx);
|
|
5443
4560
|
if (Array.isArray(matcher)) return matcher.includes(value);
|
|
5444
4561
|
return value === matcher;
|
|
@@ -5457,7 +4574,7 @@ function isRefererSameOrigin(referer, requestOrigin) {
|
|
|
5457
4574
|
const code = referer.charCodeAt(requestOrigin.length);
|
|
5458
4575
|
return code === 47 || code === 63 || code === 35;
|
|
5459
4576
|
}
|
|
5460
|
-
|
|
4577
|
+
function getFailureResponse(opts, ctx) {
|
|
5461
4578
|
if (typeof opts.failureResponse === "function") return opts.failureResponse(ctx);
|
|
5462
4579
|
return opts.failureResponse?.clone() ?? new Response("Forbidden", { status: 403 });
|
|
5463
4580
|
}
|
|
@@ -5555,12 +4672,12 @@ function getExactBytesPrefixAtEnd(value, pattern, startIndex = 0) {
|
|
|
5555
4672
|
}
|
|
5556
4673
|
var encoder = new TextEncoder();
|
|
5557
4674
|
var SOURCE_SEPARATOR = ";";
|
|
5558
|
-
var MAX_INITIAL_SOURCE_CODE_UNITS =
|
|
5559
|
-
var MAX_BACKLOG_CODE_UNITS =
|
|
4675
|
+
var MAX_INITIAL_SOURCE_CODE_UNITS = 16384;
|
|
4676
|
+
var MAX_BACKLOG_CODE_UNITS = 16777216;
|
|
5560
4677
|
var MAX_BACKLOG_SOURCES = 4096;
|
|
5561
4678
|
var MIN_OUTPUT_BYTES = 256;
|
|
5562
|
-
var MAX_DIRECT_CODE_UNITS =
|
|
5563
|
-
var MAX_HYDRATION_OUTPUT_CHUNK_BYTES =
|
|
4679
|
+
var MAX_DIRECT_CODE_UNITS = 16384;
|
|
4680
|
+
var MAX_HYDRATION_OUTPUT_CHUNK_BYTES = 65536;
|
|
5564
4681
|
var MAX_DYNAMIC_RECORD_CODE_UNITS = MAX_HYDRATION_OUTPUT_CHUNK_BYTES;
|
|
5565
4682
|
var STREAM_PART_ATTRIBUTE = "data-tsr-stream-part";
|
|
5566
4683
|
var INITIAL_CLEANUP_SOURCE = `{let s=document.currentScript,p;while((p=s.previousElementSibling)&&p.hasAttribute('${STREAM_PART_ATTRIBUTE}'))p.remove();s.remove()}`;
|
|
@@ -6319,8 +5436,7 @@ function getOrigin(request) {
|
|
|
6319
5436
|
return "http://localhost";
|
|
6320
5437
|
}
|
|
6321
5438
|
function getNormalizedURL(url, base) {
|
|
6322
|
-
|
|
6323
|
-
const rawUrl = new URL(url, base);
|
|
5439
|
+
const rawUrl = typeof url === "string" ? new URL(url.replace("\\", "%5C"), base) : url;
|
|
6324
5440
|
const handledProtocolRelativeURL = rawUrl.pathname.startsWith("//");
|
|
6325
5441
|
const decodedPathname = decodePath(handledProtocolRelativeURL ? rawUrl.pathname.replace(/^\/+/, "/") : rawUrl.pathname);
|
|
6326
5442
|
const searchParams = new URLSearchParams(rawUrl.search);
|
|
@@ -6380,13 +5496,6 @@ function bindSsrResponseToRequest(router, result, signal) {
|
|
|
6380
5496
|
});
|
|
6381
5497
|
return ssrResponse;
|
|
6382
5498
|
}
|
|
6383
|
-
function replaceSsrResponse(result, response, reason) {
|
|
6384
|
-
disposeSsrResponse(result, reason);
|
|
6385
|
-
return {
|
|
6386
|
-
response,
|
|
6387
|
-
serverSsrCleanup: "none"
|
|
6388
|
-
};
|
|
6389
|
-
}
|
|
6390
5499
|
function stripSsrResponseBody(result, reason) {
|
|
6391
5500
|
const ssrResponse = normalizeSsrResponse(result);
|
|
6392
5501
|
disposeSsrResponse(ssrResponse, reason);
|
|
@@ -6423,7 +5532,10 @@ function createRequestHandler({ createRouter, request, getRouterManifest }) {
|
|
|
6423
5532
|
history,
|
|
6424
5533
|
origin: router.options.origin ?? origin
|
|
6425
5534
|
});
|
|
6426
|
-
await router.load({
|
|
5535
|
+
await router.load({
|
|
5536
|
+
_signal: signal,
|
|
5537
|
+
_skipLocationUpdate: true
|
|
5538
|
+
});
|
|
6427
5539
|
signal.throwIfAborted();
|
|
6428
5540
|
const result = router._serverResult;
|
|
6429
5541
|
if (result?.type === "redirect") return result.redirect;
|
|
@@ -6455,7 +5567,7 @@ function transformPipeableStreamWithRouter(router, routerStream, opts) {
|
|
|
6455
5567
|
}
|
|
6456
5568
|
var DEFAULT_SERIALIZATION_TIMEOUT_MS = 6e4;
|
|
6457
5569
|
var MIN_APPLICATION_STRING_CHUNK_BYTES = 256;
|
|
6458
|
-
var MAX_APPLICATION_STRING_CHUNK_BYTES =
|
|
5570
|
+
var MAX_APPLICATION_STRING_CHUNK_BYTES = 65536;
|
|
6459
5571
|
var ApplicationPhase = {
|
|
6460
5572
|
BeforeBoundary: 0,
|
|
6461
5573
|
Merge: 1,
|
|
@@ -6943,11 +6055,42 @@ function makeMergeStream(serverSsr, reader, hydrationOutput, opts) {
|
|
|
6943
6055
|
disarmLifecycle = armStreamLifecycle(serverSsr, opts, () => terminal, terminate);
|
|
6944
6056
|
return stream;
|
|
6945
6057
|
}
|
|
6946
|
-
var
|
|
6947
|
-
|
|
6058
|
+
var SERIALIZED_JSON_HEADERS = /* @__PURE__ */ new Map([
|
|
6059
|
+
["content-type", "application/json"],
|
|
6060
|
+
[X_TSS_SERIALIZED, "true"],
|
|
6061
|
+
[X_TSS_RAW_RESPONSE, null],
|
|
6062
|
+
["location", null]
|
|
6063
|
+
]);
|
|
6064
|
+
var SERIALIZED_JSON_HEADER_INIT = new Headers({
|
|
6065
|
+
"content-type": "application/json",
|
|
6066
|
+
[X_TSS_SERIALIZED]: "true"
|
|
6067
|
+
});
|
|
6068
|
+
/** Completed bytes own no stream until the request pipeline accepts them. */
|
|
6069
|
+
var DeferredResponse = class {
|
|
6070
|
+
constructor(body) {
|
|
6071
|
+
this.body = body;
|
|
6072
|
+
}
|
|
6073
|
+
createResponse(event) {
|
|
6074
|
+
return createFinalizedResponse(this.body, SERIALIZED_JSON_HEADER_INIT, SERIALIZED_JSON_HEADERS, event);
|
|
6075
|
+
}
|
|
6076
|
+
};
|
|
6077
|
+
var SERIALIZED_FRAMED_HEADERS = /* @__PURE__ */ new Map([
|
|
6078
|
+
["content-type", TSS_CONTENT_TYPE_FRAMED_VERSIONED],
|
|
6079
|
+
[X_TSS_SERIALIZED, "true"],
|
|
6080
|
+
[X_TSS_RAW_RESPONSE, null],
|
|
6081
|
+
["location", null]
|
|
6082
|
+
]);
|
|
6083
|
+
var NOT_FOUND_HEADERS = /* @__PURE__ */ new Map([
|
|
6084
|
+
["content-type", "application/json"],
|
|
6085
|
+
[X_TSS_SERIALIZED, null],
|
|
6086
|
+
[X_TSS_RAW_RESPONSE, null],
|
|
6087
|
+
["location", null]
|
|
6088
|
+
]);
|
|
6089
|
+
var RAW_RESPONSE_HEADERS = /* @__PURE__ */ new Map([[X_TSS_RAW_RESPONSE, "true"]]);
|
|
6090
|
+
var THROWN_RESPONSE_HEADERS = /* @__PURE__ */ new Map([[X_TSS_RAW_RESPONSE, "thrown"]]);
|
|
6948
6091
|
var MAX_PAYLOAD_SIZE = 1e6;
|
|
6949
6092
|
var MAX_PENDING_SERIALIZATION_RECORDS = 1024;
|
|
6950
|
-
var MAX_PENDING_SERIALIZATION_BYTES =
|
|
6093
|
+
var MAX_PENDING_SERIALIZATION_BYTES = 33554432;
|
|
6951
6094
|
var textEncoder = new TextEncoder();
|
|
6952
6095
|
function encodeSerializationRecord(value) {
|
|
6953
6096
|
return textEncoder.encode(JSON.stringify(value));
|
|
@@ -6963,86 +6106,103 @@ function runSerializationCleanup(dispose) {
|
|
|
6963
6106
|
function cancelRawStream(stream, reason) {
|
|
6964
6107
|
stream.cancel(reason).catch(() => {});
|
|
6965
6108
|
}
|
|
6966
|
-
|
|
6109
|
+
/**
|
|
6110
|
+
* Marks a Response thrown during a server-function request so the client
|
|
6111
|
+
* rejects the call with it. Redirects keep their own protocol.
|
|
6112
|
+
*/
|
|
6113
|
+
function toThrownServerFnResponse(response) {
|
|
6114
|
+
return isRedirect(response) ? response : setProtectedResponseHeaders(response, THROWN_RESPONSE_HEADERS);
|
|
6115
|
+
}
|
|
6116
|
+
/**
|
|
6117
|
+
* Builds the reply for a server-function request that failed outside the
|
|
6118
|
+
* function, such as in request middleware. Like a failed call, it carries
|
|
6119
|
+
* only the thrown value under an `error` key, so the client rethrows it.
|
|
6120
|
+
*/
|
|
6121
|
+
async function createServerFnErrorResponse(error, serovalPlugins) {
|
|
6122
|
+
if (isNotFound(error)) return isNotFoundResponse(error);
|
|
6123
|
+
const headers = getErrorHeaders(error) ?? new Headers();
|
|
6124
|
+
const { status, statusText } = resolveErrorResponseStatus(error);
|
|
6125
|
+
headers.set("Content-Type", "application/json");
|
|
6126
|
+
headers.set(X_TSS_SERIALIZED, "true");
|
|
6127
|
+
headers.delete(X_TSS_RAW_RESPONSE);
|
|
6128
|
+
headers.delete("location");
|
|
6129
|
+
const plugins = serovalPlugins ?? getSerovalPlugins(defaultSerovalDeserializerPlugins);
|
|
6130
|
+
let serializedError;
|
|
6131
|
+
try {
|
|
6132
|
+
serializedError = JSON.stringify(await toCrossJSONAsync({ error }, {
|
|
6133
|
+
refs: /* @__PURE__ */ new Map(),
|
|
6134
|
+
plugins
|
|
6135
|
+
}));
|
|
6136
|
+
} catch (serializationError) {
|
|
6137
|
+
serializedError = JSON.stringify(await toCrossJSONAsync({ error: serializationError }, {
|
|
6138
|
+
refs: /* @__PURE__ */ new Map(),
|
|
6139
|
+
plugins
|
|
6140
|
+
}));
|
|
6141
|
+
}
|
|
6142
|
+
const errorResponse = new Response(serializedError, {
|
|
6143
|
+
status,
|
|
6144
|
+
statusText,
|
|
6145
|
+
headers
|
|
6146
|
+
});
|
|
6147
|
+
protectResponseHeaders(errorResponse, SERIALIZED_JSON_HEADERS);
|
|
6148
|
+
return errorResponse;
|
|
6149
|
+
}
|
|
6150
|
+
var handleServerAction = async ({ request, serverFnId }) => {
|
|
6967
6151
|
const methodUpper = request.method.toUpperCase();
|
|
6968
|
-
const url = new URL(request.url);
|
|
6969
6152
|
const action = await getServerFnById(serverFnId, { origin: "client" });
|
|
6970
6153
|
if (action.method && methodUpper !== action.method) return new Response(`expected ${action.method} method. Got ${methodUpper}`, {
|
|
6971
6154
|
status: 405,
|
|
6972
6155
|
headers: { Allow: action.method }
|
|
6973
6156
|
});
|
|
6974
|
-
const
|
|
6975
|
-
|
|
6976
|
-
|
|
6157
|
+
const headers = request.headers;
|
|
6158
|
+
const isServerFn = headers.get("x-tsr-serverfn") === "true";
|
|
6159
|
+
let serovalPlugins;
|
|
6160
|
+
const getRequestSerovalPlugins = () => {
|
|
6161
|
+
return serovalPlugins ??= getSerovalPlugins(defaultSerovalDeserializerPlugins);
|
|
6162
|
+
};
|
|
6163
|
+
const contentType = headers.get("content-type");
|
|
6977
6164
|
try {
|
|
6978
6165
|
let res;
|
|
6979
|
-
if (
|
|
6166
|
+
if (contentType && (contentType.includes("multipart/form-data") || contentType.includes("application/x-www-form-urlencoded"))) {
|
|
6980
6167
|
if (methodUpper === "GET") invariant();
|
|
6981
6168
|
const formData = await request.formData();
|
|
6982
6169
|
const serializedContext = formData.get(TSS_FORMDATA_CONTEXT);
|
|
6983
6170
|
formData.delete(TSS_FORMDATA_CONTEXT);
|
|
6984
6171
|
const params = {
|
|
6985
|
-
context,
|
|
6986
6172
|
data: formData,
|
|
6987
6173
|
method: methodUpper
|
|
6988
6174
|
};
|
|
6989
6175
|
if (typeof serializedContext === "string") try {
|
|
6990
|
-
const deserializedContext = fromJSON(JSON.parse(serializedContext), { plugins:
|
|
6991
|
-
if (typeof deserializedContext === "object" && deserializedContext) params.context =
|
|
6176
|
+
const deserializedContext = fromJSON(JSON.parse(serializedContext), { plugins: getRequestSerovalPlugins() });
|
|
6177
|
+
if (typeof deserializedContext === "object" && deserializedContext) params.context = deserializedContext;
|
|
6992
6178
|
} catch (e) {}
|
|
6993
6179
|
res = await action(params);
|
|
6994
|
-
} else if (methodUpper === "GET") {
|
|
6995
|
-
const payloadParam = url.searchParams.get("payload");
|
|
6996
|
-
if (payloadParam && payloadParam.length > MAX_PAYLOAD_SIZE) throw new Error("Payload too large");
|
|
6997
|
-
const payload = payloadParam ? fromJSON(JSON.parse(payloadParam), { plugins: serovalPlugins }) : void 0;
|
|
6998
|
-
res = await action({
|
|
6999
|
-
data: payload?.data,
|
|
7000
|
-
context: safeObjectMerge(payload?.context, context),
|
|
7001
|
-
method: methodUpper
|
|
7002
|
-
});
|
|
7003
6180
|
} else {
|
|
7004
|
-
|
|
6181
|
+
let json;
|
|
6182
|
+
if (methodUpper === "GET") {
|
|
6183
|
+
const payloadParam = getParsedRequestUrl(request).searchParams.get("payload");
|
|
6184
|
+
if (payloadParam && payloadParam.length > MAX_PAYLOAD_SIZE) throw new Error("Payload too large");
|
|
6185
|
+
json = payloadParam ? JSON.parse(payloadParam) : void 0;
|
|
6186
|
+
} else if (contentType?.includes("application/json")) json = await request.json();
|
|
6187
|
+
const payload = json === void 0 ? void 0 : fromJSON(json, { plugins: getRequestSerovalPlugins() });
|
|
7005
6188
|
res = await action({
|
|
7006
6189
|
data: payload?.data,
|
|
7007
|
-
context:
|
|
6190
|
+
context: payload?.context,
|
|
7008
6191
|
method: methodUpper
|
|
7009
6192
|
});
|
|
7010
6193
|
}
|
|
7011
|
-
const
|
|
7012
|
-
|
|
6194
|
+
const failed = "error" in res;
|
|
6195
|
+
const unwrapped = failed ? res.error : res.result;
|
|
7013
6196
|
if (!isServerFn && (unwrapped instanceof Response || unwrapped === null || typeof unwrapped !== "object")) return unwrapped;
|
|
7014
6197
|
if (unwrapped instanceof Response) {
|
|
6198
|
+
if (failed) return toThrownServerFnResponse(unwrapped);
|
|
7015
6199
|
if (isRedirect(unwrapped)) return unwrapped;
|
|
7016
|
-
unwrapped
|
|
7017
|
-
return unwrapped;
|
|
6200
|
+
return setProtectedResponseHeaders(unwrapped, RAW_RESPONSE_HEADERS);
|
|
7018
6201
|
}
|
|
7019
|
-
return serializeResult(res, request
|
|
6202
|
+
return serializeResult(res, request, getRequestSerovalPlugins());
|
|
7020
6203
|
} catch (error) {
|
|
7021
6204
|
if (error instanceof Response) return error;
|
|
7022
|
-
|
|
7023
|
-
console.error("Server Fn Error!", error);
|
|
7024
|
-
const serializedError = JSON.stringify(await toCrossJSONAsync(error, {
|
|
7025
|
-
refs: /* @__PURE__ */ new Map(),
|
|
7026
|
-
plugins: serovalPlugins
|
|
7027
|
-
}));
|
|
7028
|
-
const response = getResponse();
|
|
7029
|
-
const headers = {
|
|
7030
|
-
"Content-Type": "application/json",
|
|
7031
|
-
[X_TSS_SERIALIZED]: "true"
|
|
7032
|
-
};
|
|
7033
|
-
try {
|
|
7034
|
-
return new Response(serializedError, {
|
|
7035
|
-
status: response.status ?? 500,
|
|
7036
|
-
statusText: response.statusText,
|
|
7037
|
-
headers
|
|
7038
|
-
});
|
|
7039
|
-
} catch {
|
|
7040
|
-
return new Response(serializedError, {
|
|
7041
|
-
status: 500,
|
|
7042
|
-
statusText: "",
|
|
7043
|
-
headers
|
|
7044
|
-
});
|
|
7045
|
-
}
|
|
6205
|
+
return createServerFnErrorResponse(error, serovalPlugins);
|
|
7046
6206
|
}
|
|
7047
6207
|
};
|
|
7048
6208
|
/**
|
|
@@ -7050,8 +6210,7 @@ var handleServerAction = async ({ request, context, serverFnId }) => {
|
|
|
7050
6210
|
* synchronously without RawStreams becomes plain JSON; everything else is a
|
|
7051
6211
|
* framed response whose records and raw streams are multiplexed in order.
|
|
7052
6212
|
*/
|
|
7053
|
-
function serializeResult(res,
|
|
7054
|
-
const alsResponse = getResponse();
|
|
6213
|
+
function serializeResult(res, request, plugins) {
|
|
7055
6214
|
const initialRecords = [];
|
|
7056
6215
|
let initialBytes = 0;
|
|
7057
6216
|
const pendingRawStreams = [];
|
|
@@ -7110,14 +6269,7 @@ function serializeResult(res, signal, plugins) {
|
|
|
7110
6269
|
throw serializationFailure[0];
|
|
7111
6270
|
}
|
|
7112
6271
|
if (!done) disposeSerialization = dispose;
|
|
7113
|
-
if (done && pendingRawStreams.length === 0 && initialRecords.length === 1) return new
|
|
7114
|
-
status: alsResponse.status,
|
|
7115
|
-
statusText: alsResponse.statusText,
|
|
7116
|
-
headers: {
|
|
7117
|
-
"Content-Type": "application/json",
|
|
7118
|
-
[X_TSS_SERIALIZED]: "true"
|
|
7119
|
-
}
|
|
7120
|
-
});
|
|
6272
|
+
if (done && pendingRawStreams.length === 0 && initialRecords.length === 1) return new DeferredResponse(initialRecords[0]);
|
|
7121
6273
|
if (done && initialRecords.length === 1) {
|
|
7122
6274
|
const json = initialRecords[0];
|
|
7123
6275
|
if (json.byteLength > 16777216) {
|
|
@@ -7138,7 +6290,7 @@ function serializeResult(res, signal, plugins) {
|
|
|
7138
6290
|
cancel(reason) {
|
|
7139
6291
|
for (const registration of rawStreams) cancelRawStream(registration.stream, reason);
|
|
7140
6292
|
}
|
|
7141
|
-
}), { signal });
|
|
6293
|
+
}), { signal: request.signal });
|
|
7142
6294
|
}
|
|
7143
6295
|
const { readable, writable } = new TransformStream();
|
|
7144
6296
|
const writer = writable.getWriter();
|
|
@@ -7211,37 +6363,49 @@ function serializeResult(res, signal, plugins) {
|
|
|
7211
6363
|
abortRecordStream(error);
|
|
7212
6364
|
});
|
|
7213
6365
|
return createFramedResponse(readable, {
|
|
7214
|
-
signal: AbortSignal.any([recordAbortController.signal, signal]),
|
|
6366
|
+
signal: AbortSignal.any([recordAbortController.signal, request.signal]),
|
|
7215
6367
|
onCancel: abortRecordStream
|
|
7216
6368
|
});
|
|
7217
|
-
|
|
7218
|
-
|
|
7219
|
-
|
|
7220
|
-
|
|
7221
|
-
|
|
7222
|
-
|
|
7223
|
-
|
|
7224
|
-
|
|
7225
|
-
|
|
7226
|
-
|
|
7227
|
-
|
|
7228
|
-
|
|
7229
|
-
|
|
7230
|
-
|
|
7231
|
-
|
|
6369
|
+
}
|
|
6370
|
+
function createFramedResponse(records, options) {
|
|
6371
|
+
const multiplexedStream = createMultiplexedStream(records, options);
|
|
6372
|
+
const { status, statusText } = getSerializedResponseState();
|
|
6373
|
+
try {
|
|
6374
|
+
const response = new Response(multiplexedStream, {
|
|
6375
|
+
status,
|
|
6376
|
+
statusText,
|
|
6377
|
+
headers: {
|
|
6378
|
+
"Content-Type": TSS_CONTENT_TYPE_FRAMED_VERSIONED,
|
|
6379
|
+
[X_TSS_SERIALIZED]: "true"
|
|
6380
|
+
}
|
|
6381
|
+
});
|
|
6382
|
+
protectResponseHeaders(response, SERIALIZED_FRAMED_HEADERS);
|
|
6383
|
+
return response;
|
|
6384
|
+
} catch (error) {
|
|
6385
|
+
cancelRawStream(multiplexedStream, error);
|
|
6386
|
+
throw error;
|
|
7232
6387
|
}
|
|
7233
6388
|
}
|
|
7234
6389
|
function isNotFoundResponse(error) {
|
|
7235
6390
|
const { headers, ...rest } = error;
|
|
6391
|
+
let responseHeaders;
|
|
6392
|
+
if (headers) {
|
|
6393
|
+
const copiedHeaders = new Headers(headers);
|
|
6394
|
+
copiedHeaders.set("Content-Type", "application/json");
|
|
6395
|
+
copiedHeaders.delete(X_TSS_SERIALIZED);
|
|
6396
|
+
copiedHeaders.delete(X_TSS_RAW_RESPONSE);
|
|
6397
|
+
copiedHeaders.delete("location");
|
|
6398
|
+
responseHeaders = copiedHeaders;
|
|
6399
|
+
} else responseHeaders = { "Content-Type": "application/json" };
|
|
7236
6400
|
const response = new Response(JSON.stringify(rest), {
|
|
7237
6401
|
status: 404,
|
|
7238
|
-
headers
|
|
6402
|
+
headers: responseHeaders
|
|
7239
6403
|
});
|
|
7240
|
-
response
|
|
6404
|
+
protectResponseHeaders(response, NOT_FOUND_HEADERS);
|
|
7241
6405
|
return response;
|
|
7242
6406
|
}
|
|
7243
6407
|
var LINK_PARAM_TOKEN_RE = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
|
|
7244
|
-
var PRELOAD_AS_VALUES = new Set([
|
|
6408
|
+
var PRELOAD_AS_VALUES = /* @__PURE__ */ new Set([
|
|
7245
6409
|
"fetch",
|
|
7246
6410
|
"font",
|
|
7247
6411
|
"image",
|
|
@@ -7645,14 +6809,20 @@ function buildManifest(source, opts) {
|
|
|
7645
6809
|
routes: { ...source.routes }
|
|
7646
6810
|
};
|
|
7647
6811
|
}
|
|
7648
|
-
|
|
6812
|
+
/**
|
|
6813
|
+
* The inline-CSS choice that needs no handler callback: a request override
|
|
6814
|
+
* wins, then a static handler option, then the default. Undefined when a
|
|
6815
|
+
* handler callback has to decide.
|
|
6816
|
+
*/
|
|
6817
|
+
function getStaticInlineCss(requestInlineCss, handlerInlineCss) {
|
|
6818
|
+
if (requestInlineCss !== void 0) return requestInlineCss;
|
|
7649
6819
|
if (typeof handlerInlineCss === "function") return;
|
|
7650
6820
|
return handlerInlineCss ?? true;
|
|
7651
6821
|
}
|
|
7652
6822
|
async function resolveInlineCssForRequest(opts) {
|
|
7653
|
-
|
|
7654
|
-
if (
|
|
7655
|
-
return opts.handlerInlineCss
|
|
6823
|
+
const inlineCss = getStaticInlineCss(opts.requestInlineCss, opts.handlerInlineCss);
|
|
6824
|
+
if (inlineCss !== void 0) return inlineCss;
|
|
6825
|
+
return await opts.handlerInlineCss({ request: opts.request });
|
|
7656
6826
|
}
|
|
7657
6827
|
function createCachedBaseManifestLoader(loadBaseManifest) {
|
|
7658
6828
|
let baseManifestPromise;
|
|
@@ -7691,7 +6861,7 @@ function createFinalManifestTransformResolver(transformAssets, opts) {
|
|
|
7691
6861
|
function createFinalManifestResolver(opts) {
|
|
7692
6862
|
const finalManifestCache = /* @__PURE__ */ new Map();
|
|
7693
6863
|
const transformResolver = createFinalManifestTransformResolver(opts.transformAssets, { cacheCreateTransform: opts.cacheCreateTransform });
|
|
7694
|
-
const handlerDefaultInlineCss =
|
|
6864
|
+
const handlerDefaultInlineCss = getStaticInlineCss(void 0, opts.inlineCss);
|
|
7695
6865
|
const getRequestManifestOptions = async (requestOpts) => {
|
|
7696
6866
|
const transformFn = await transformResolver.getTransformFn({
|
|
7697
6867
|
warmup: false,
|
|
@@ -7725,25 +6895,35 @@ function createFinalManifestResolver(opts) {
|
|
|
7725
6895
|
getTransformFn: () => transformResolver.getTransformFn({ warmup: true }),
|
|
7726
6896
|
onError: transformResolver.clearCachedCreateTransform
|
|
7727
6897
|
}),
|
|
7728
|
-
resolveCached: (requestOpts) =>
|
|
6898
|
+
resolveCached: (requestOpts) => {
|
|
6899
|
+
const inlineCss = getStaticInlineCss(requestOpts.requestInlineCss, opts.inlineCss);
|
|
6900
|
+
if (transformResolver.cache && inlineCss !== void 0) {
|
|
6901
|
+
const cached = finalManifestCache.get(getFinalManifestCacheKey(inlineCss));
|
|
6902
|
+
if (cached) return cached;
|
|
6903
|
+
}
|
|
6904
|
+
return resolveRequest(requestOpts, finalManifestCache);
|
|
6905
|
+
},
|
|
7729
6906
|
resolveUncached: (requestOpts) => resolveRequest(requestOpts, void 0)
|
|
7730
6907
|
};
|
|
7731
6908
|
}
|
|
7732
6909
|
function getFinalManifestCacheKey(inlineCss) {
|
|
7733
6910
|
return inlineCss ? "inline-css" : "linked-css";
|
|
7734
6911
|
}
|
|
7735
|
-
function cacheFinalManifestPromise(
|
|
7736
|
-
const
|
|
7737
|
-
if (
|
|
6912
|
+
function cacheFinalManifestPromise(finalManifestCache, cacheKey, promise) {
|
|
6913
|
+
const cachedPromise = promise.then((manifest) => {
|
|
6914
|
+
if (finalManifestCache.get(cacheKey) === cachedPromise) finalManifestCache.set(cacheKey, manifest);
|
|
6915
|
+
return manifest;
|
|
6916
|
+
}, (error) => {
|
|
6917
|
+
if (finalManifestCache.get(cacheKey) === cachedPromise) finalManifestCache.delete(cacheKey);
|
|
7738
6918
|
throw error;
|
|
7739
6919
|
});
|
|
7740
|
-
|
|
7741
|
-
return
|
|
6920
|
+
finalManifestCache.set(cacheKey, cachedPromise);
|
|
6921
|
+
return cachedPromise;
|
|
7742
6922
|
}
|
|
7743
|
-
function
|
|
7744
|
-
const
|
|
7745
|
-
if (
|
|
7746
|
-
return cacheFinalManifestPromise(
|
|
6923
|
+
function getOrCreateCachedFinalManifest(finalManifestCache, cacheKey, computeFinalManifest) {
|
|
6924
|
+
const cached = finalManifestCache.get(cacheKey);
|
|
6925
|
+
if (cached) return cached;
|
|
6926
|
+
return cacheFinalManifestPromise(finalManifestCache, cacheKey, Promise.resolve().then(computeFinalManifest));
|
|
7747
6927
|
}
|
|
7748
6928
|
async function buildFinalManifest(opts) {
|
|
7749
6929
|
return opts.transformFn ? await transformManifestAssets(opts.base, opts.transformFn, { inlineCss: opts.inlineCss }) : buildManifest(opts.base, { inlineCss: opts.inlineCss });
|
|
@@ -7756,20 +6936,20 @@ async function resolveFinalManifest(opts) {
|
|
|
7756
6936
|
inlineCss: opts.inlineCss
|
|
7757
6937
|
});
|
|
7758
6938
|
};
|
|
7759
|
-
if (opts.finalManifestCache && (!opts.transformFn || opts.cache)) return
|
|
6939
|
+
if (opts.finalManifestCache && (!opts.transformFn || opts.cache)) return getOrCreateCachedFinalManifest(opts.finalManifestCache, getFinalManifestCacheKey(opts.inlineCss), computeFinalManifest);
|
|
7760
6940
|
return computeFinalManifest();
|
|
7761
6941
|
}
|
|
7762
6942
|
function warmupFinalManifest(opts) {
|
|
7763
6943
|
if (!opts.enabled || opts.handlerDefaultInlineCss === void 0 || !opts.cache) return;
|
|
7764
6944
|
const inlineCss = opts.handlerDefaultInlineCss;
|
|
7765
|
-
const warmupPromise =
|
|
6945
|
+
const warmupPromise = cacheFinalManifestPromise(opts.finalManifestCache, getFinalManifestCacheKey(inlineCss), Promise.resolve().then(async () => {
|
|
7766
6946
|
const [base, transformFn] = await Promise.all([opts.getBaseManifest(), opts.getTransformFn()]);
|
|
7767
6947
|
return buildFinalManifest({
|
|
7768
6948
|
base,
|
|
7769
6949
|
transformFn,
|
|
7770
6950
|
inlineCss
|
|
7771
6951
|
});
|
|
7772
|
-
});
|
|
6952
|
+
}));
|
|
7773
6953
|
if (opts.onError) warmupPromise.catch(opts.onError);
|
|
7774
6954
|
return warmupPromise;
|
|
7775
6955
|
}
|
|
@@ -7789,18 +6969,18 @@ var ServerFunctionSerializationAdapter = createSerializationAdapter({
|
|
|
7789
6969
|
context: opts?.context,
|
|
7790
6970
|
method: serverFn.method ?? "GET"
|
|
7791
6971
|
}, signal);
|
|
7792
|
-
if (
|
|
6972
|
+
if ("error" in result) throw result.error;
|
|
7793
6973
|
return result.result;
|
|
7794
6974
|
};
|
|
7795
6975
|
return fn;
|
|
7796
6976
|
}
|
|
7797
6977
|
});
|
|
7798
|
-
function getStartResponseHeaders(
|
|
7799
|
-
|
|
7800
|
-
|
|
7801
|
-
|
|
6978
|
+
function getStartResponseHeaders(router) {
|
|
6979
|
+
const headers = new Headers({ "content-type": "text/html; charset=utf-8" });
|
|
6980
|
+
const matches = _getRenderedMatches(router.stores.matches.get());
|
|
6981
|
+
return matches.some((match) => match.headers) ? mergeHeaders(headers, ...matches.map((match) => match.headers)) : headers;
|
|
7802
6982
|
}
|
|
7803
|
-
var
|
|
6983
|
+
var cachedEntries;
|
|
7804
6984
|
var defaultCsrfMiddleware = createCsrfMiddleware({ filter: (ctx) => ctx.handlerType === "serverFn" });
|
|
7805
6985
|
var getCachedBaseManifest = createCachedBaseManifestLoader(() => getStartManifest());
|
|
7806
6986
|
var getProdBaseManifest = () => getCachedBaseManifest();
|
|
@@ -7808,9 +6988,9 @@ var getBaseManifest = getProdBaseManifest;
|
|
|
7808
6988
|
var createEarlyHintsForRequest = createEarlyHintsCollector;
|
|
7809
6989
|
async function loadEntries() {
|
|
7810
6990
|
const [routerEntry, startEntry, pluginAdapters] = await Promise.all([
|
|
7811
|
-
import("./router-
|
|
7812
|
-
import("./start-
|
|
7813
|
-
import("./empty-plugin-adapters-
|
|
6991
|
+
import("./router-DzoZ6RiZ.mjs"),
|
|
6992
|
+
import("./start-B6ECIE_7.mjs"),
|
|
6993
|
+
import("./empty-plugin-adapters-CpCHi1TV.mjs")
|
|
7814
6994
|
]);
|
|
7815
6995
|
return {
|
|
7816
6996
|
routerEntry,
|
|
@@ -7819,8 +6999,11 @@ async function loadEntries() {
|
|
|
7819
6999
|
};
|
|
7820
7000
|
}
|
|
7821
7001
|
function getEntries() {
|
|
7822
|
-
if (!
|
|
7823
|
-
|
|
7002
|
+
if (!cachedEntries) cachedEntries = loadEntries().then((entries) => {
|
|
7003
|
+
cachedEntries = entries;
|
|
7004
|
+
return entries;
|
|
7005
|
+
});
|
|
7006
|
+
return cachedEntries;
|
|
7824
7007
|
}
|
|
7825
7008
|
var ROUTER_BASEPATH = "/";
|
|
7826
7009
|
var SERVER_FN_BASE = "/_serverFn/";
|
|
@@ -7838,25 +7021,21 @@ function throwIfMayNotDefer() {
|
|
|
7838
7021
|
function getResponseFromResult(result) {
|
|
7839
7022
|
return isSsrResponse(result) || result instanceof Response ? result : result?.response;
|
|
7840
7023
|
}
|
|
7841
|
-
var responseBodySources = /* @__PURE__ */ new WeakMap();
|
|
7842
7024
|
function disposeResponseResult(result, reason) {
|
|
7843
7025
|
const response = getResponseFromResult(result);
|
|
7844
7026
|
if (isSsrResponse(response) || response instanceof Response) disposeSsrResponse(response, reason);
|
|
7845
7027
|
}
|
|
7846
7028
|
/**
|
|
7847
|
-
*
|
|
7848
|
-
*
|
|
7029
|
+
* A new body continues the owned one when it is the same stream, or when the
|
|
7030
|
+
* owned body is already being read, as by a pipe, a tee, or a `Response` that
|
|
7031
|
+
* copies a body by reading it (Bun, or a wrapped global `Response`). Start
|
|
7032
|
+
* cannot tell such a reader from one that stops early, so it disposes only an
|
|
7033
|
+
* unread body. A stream whose reader stops early ends with the request's abort
|
|
7034
|
+
* or the SSR stream's lifetime limit.
|
|
7849
7035
|
*/
|
|
7850
|
-
function
|
|
7851
|
-
|
|
7852
|
-
|
|
7853
|
-
return response;
|
|
7854
|
-
}
|
|
7855
|
-
function hasResponseBody(value) {
|
|
7856
|
-
return value instanceof Response && value.body !== null;
|
|
7857
|
-
}
|
|
7858
|
-
function inheritsResponseOwnership(ownership, candidate) {
|
|
7859
|
-
return hasResponseBody(candidate) && (candidate.body === ownership.response.body || responseBodySources.get(candidate) === ownership.response);
|
|
7036
|
+
function inheritsResponseOwnership(ownership, body) {
|
|
7037
|
+
const ownedBody = ownership.response.body;
|
|
7038
|
+
return body === ownedBody || ownedBody.locked;
|
|
7860
7039
|
}
|
|
7861
7040
|
function disposeResponseOwnership(ownership, reason) {
|
|
7862
7041
|
const { response, sourceBody, streamResponse } = ownership;
|
|
@@ -7886,54 +7065,80 @@ function createLateResponseDisposer(signal) {
|
|
|
7886
7065
|
* Compose middleware around a terminal response handler. With no middleware
|
|
7887
7066
|
* the terminal runs directly.
|
|
7888
7067
|
*/
|
|
7889
|
-
async function executeMiddleware(middlewares, terminal, ctx, signal, terminalNext) {
|
|
7068
|
+
async function executeMiddleware(middlewares, terminal, ctx, signal, event, terminalNext) {
|
|
7890
7069
|
let index = -1;
|
|
7891
7070
|
let responseOwnership;
|
|
7892
|
-
let
|
|
7071
|
+
let returnedDepth = Infinity;
|
|
7893
7072
|
const disposeAbandonedResult = createLateResponseDisposer(signal);
|
|
7894
|
-
const
|
|
7895
|
-
const ssrResponse = isSsrResponse(response) ? response : void 0;
|
|
7896
|
-
const streamResponse = ssrResponse?.serverSsrCleanup === "stream" ? ssrResponse : void 0;
|
|
7897
|
-
const exposed = ssrResponse ? ssrResponse.response : response;
|
|
7073
|
+
const adoptResponse = (exposed, streamResponse) => {
|
|
7898
7074
|
const current = responseOwnership;
|
|
7899
|
-
|
|
7900
|
-
|
|
7901
|
-
|
|
7902
|
-
}
|
|
7075
|
+
const body = exposed instanceof Response ? exposed.body : null;
|
|
7076
|
+
const response = exposed;
|
|
7077
|
+
if (streamResponse && !body && streamResponse !== current?.streamResponse) streamResponse.dispose("Response body dropped by Start reconciliation");
|
|
7903
7078
|
if (current && current.response === exposed) current.streamResponse ??= streamResponse;
|
|
7904
|
-
else if (current && inheritsResponseOwnership(current,
|
|
7905
|
-
current.response
|
|
7079
|
+
else if (current && body && inheritsResponseOwnership(current, body)) {
|
|
7080
|
+
if (body === current.response.body) transferResponseProtocol(current.response, response);
|
|
7081
|
+
current.response = response;
|
|
7906
7082
|
current.streamResponse ??= streamResponse;
|
|
7907
7083
|
} else {
|
|
7908
|
-
if (current)
|
|
7909
|
-
|
|
7910
|
-
response
|
|
7911
|
-
|
|
7084
|
+
if (current) {
|
|
7085
|
+
responseOwnership = void 0;
|
|
7086
|
+
disposeResponseOwnership(current, "middleware response replaced");
|
|
7087
|
+
}
|
|
7088
|
+
responseOwnership = body ? {
|
|
7089
|
+
response,
|
|
7090
|
+
sourceBody: body,
|
|
7912
7091
|
streamResponse
|
|
7913
|
-
};
|
|
7914
|
-
else responseOwnership = void 0;
|
|
7092
|
+
} : void 0;
|
|
7915
7093
|
}
|
|
7916
7094
|
ctx.response = exposed;
|
|
7917
7095
|
};
|
|
7918
|
-
const
|
|
7919
|
-
|
|
7096
|
+
const disposeCurrentBody = (reason) => {
|
|
7097
|
+
const current = responseOwnership;
|
|
7098
|
+
responseOwnership = void 0;
|
|
7099
|
+
if (current) disposeResponseOwnership(current, reason);
|
|
7100
|
+
};
|
|
7101
|
+
const setResponse = (response, caller) => {
|
|
7102
|
+
const owned = response !== void 0 && response === responseOwnership?.response;
|
|
7103
|
+
const ssrResponse = !owned && isSsrResponse(response) ? response : void 0;
|
|
7104
|
+
const exposed = ssrResponse ? ssrResponse.response : response;
|
|
7105
|
+
if (returnedDepth <= caller) {
|
|
7106
|
+
if (exposed !== ctx.response) disposeResponseResult(response, "late middleware response");
|
|
7107
|
+
return;
|
|
7108
|
+
}
|
|
7109
|
+
if (!owned) adoptResponse(exposed, ssrResponse?.serverSsrCleanup === "stream" ? ssrResponse : void 0);
|
|
7110
|
+
if (exposed instanceof Response) {
|
|
7111
|
+
const reconciled = reconcileResponse(exposed, event, disposeCurrentBody);
|
|
7112
|
+
if (reconciled !== exposed) adoptRebuilt(exposed, reconciled);
|
|
7113
|
+
}
|
|
7114
|
+
};
|
|
7115
|
+
const adoptRebuilt = (exposed, rebuilt) => {
|
|
7116
|
+
const current = responseOwnership;
|
|
7117
|
+
if (current?.response === exposed && rebuilt.body) {
|
|
7118
|
+
current.response = rebuilt;
|
|
7119
|
+
ctx.response = rebuilt;
|
|
7120
|
+
} else adoptResponse(rebuilt);
|
|
7920
7121
|
};
|
|
7921
7122
|
let nextPromise;
|
|
7922
7123
|
function next(nextCtx) {
|
|
7923
|
-
const result = runNext(nextCtx);
|
|
7124
|
+
const result = runNext(index, nextCtx);
|
|
7924
7125
|
nextPromise = result;
|
|
7925
7126
|
return result;
|
|
7926
7127
|
}
|
|
7927
|
-
async function runNext(nextCtx) {
|
|
7128
|
+
async function runNext(caller, nextCtx) {
|
|
7928
7129
|
signal.throwIfAborted();
|
|
7929
7130
|
if (nextCtx) {
|
|
7930
7131
|
if (nextCtx.context) ctx.context = safeObjectMerge(ctx.context, nextCtx.context);
|
|
7931
|
-
|
|
7932
|
-
|
|
7132
|
+
const keys = Object.keys(nextCtx);
|
|
7133
|
+
for (let i = 0; i < keys.length; i++) {
|
|
7134
|
+
const key = keys[i];
|
|
7135
|
+
if (key === "response") setResponse(nextCtx.response, caller);
|
|
7136
|
+
else if (key !== "context") ctx[key] = nextCtx[key];
|
|
7137
|
+
}
|
|
7933
7138
|
}
|
|
7934
|
-
index
|
|
7935
|
-
const isTerminal =
|
|
7936
|
-
const middleware =
|
|
7139
|
+
const depth = ++index;
|
|
7140
|
+
const isTerminal = depth === middlewares.length;
|
|
7141
|
+
const middleware = depth < middlewares.length ? middlewares[depth] : isTerminal ? terminal : void 0;
|
|
7937
7142
|
const middlewareNext = isTerminal && terminalNext ? terminalNext : next;
|
|
7938
7143
|
if (!middleware) return ctx;
|
|
7939
7144
|
let result;
|
|
@@ -7944,45 +7149,61 @@ async function executeMiddleware(middlewares, terminal, ctx, signal, terminalNex
|
|
|
7944
7149
|
});
|
|
7945
7150
|
if (nextPromise && pending === nextPromise) {
|
|
7946
7151
|
nextPromise = void 0;
|
|
7947
|
-
await pending;
|
|
7948
|
-
|
|
7949
|
-
return ctx;
|
|
7152
|
+
result = await pending;
|
|
7153
|
+
signal.throwIfAborted();
|
|
7950
7154
|
} else if (!isPromise(pending)) {
|
|
7951
7155
|
result = pending;
|
|
7952
7156
|
signal.throwIfAborted();
|
|
7953
7157
|
} else result = await waitForReason(pending, signal, disposeAbandonedResult, disposeAbandonedResult);
|
|
7954
7158
|
} catch (err) {
|
|
7955
|
-
|
|
7159
|
+
if (depth < returnedDepth) returnedDepth = depth;
|
|
7160
|
+
if (returnedDepth > caller) adoptResponse(ctx.response);
|
|
7956
7161
|
if (signal.aborted) {
|
|
7957
7162
|
if (result !== void 0) disposeAbandonedResult(result);
|
|
7958
7163
|
if (err !== signal.reason) disposeAbandonedResult(err);
|
|
7959
7164
|
throw signal.reason;
|
|
7960
7165
|
}
|
|
7961
7166
|
if (err instanceof Response) {
|
|
7962
|
-
setResponse(err);
|
|
7167
|
+
setResponse(ctx.handlerType === "serverFn" ? toThrownServerFnResponse(err) : err, caller);
|
|
7963
7168
|
return ctx;
|
|
7964
7169
|
}
|
|
7965
7170
|
throw err;
|
|
7966
7171
|
}
|
|
7172
|
+
if (depth < returnedDepth) returnedDepth = depth;
|
|
7967
7173
|
if (isTerminal && terminalNext && !result) throwRouteHandlerError();
|
|
7968
|
-
|
|
7174
|
+
if (isTerminal && !terminalNext && result instanceof DeferredResponse) {
|
|
7175
|
+
if (returnedDepth > caller) {
|
|
7176
|
+
adoptResponse(void 0);
|
|
7177
|
+
adoptResponse(result.createResponse(event));
|
|
7178
|
+
}
|
|
7179
|
+
return ctx;
|
|
7180
|
+
}
|
|
7969
7181
|
if (result && result !== ctx) {
|
|
7970
7182
|
const response = getResponseFromResult(result);
|
|
7971
|
-
if (response !== void 0
|
|
7972
|
-
|
|
7973
|
-
|
|
7183
|
+
if (response !== void 0) {
|
|
7184
|
+
if (ctx.response !== responseOwnership?.response && ctx.response !== response && returnedDepth > caller) adoptResponse(ctx.response);
|
|
7185
|
+
setResponse(response, caller);
|
|
7186
|
+
} else setResponse(ctx.response, caller);
|
|
7187
|
+
if (returnedDepth > caller && response !== result && result.context && result.context !== ctx.context) ctx.context = safeObjectMerge(ctx.context, result.context);
|
|
7188
|
+
} else setResponse(ctx.response, caller);
|
|
7974
7189
|
return ctx;
|
|
7975
7190
|
}
|
|
7976
7191
|
try {
|
|
7977
|
-
await runNext();
|
|
7978
|
-
|
|
7192
|
+
await runNext(-1);
|
|
7193
|
+
let response = ctx.response;
|
|
7979
7194
|
if (!response) throwRouteHandlerError();
|
|
7980
|
-
reconcileCtxResponse();
|
|
7981
7195
|
if (signal.aborted) throw signal.reason;
|
|
7982
|
-
|
|
7196
|
+
returnedDepth = -1;
|
|
7197
|
+
if (middlewares.length && ctx.handlerType === "serverFn") {
|
|
7198
|
+
const restored = restoreResponseProtocol(response, event);
|
|
7199
|
+
if (restored !== response) {
|
|
7200
|
+
adoptRebuilt(response, restored);
|
|
7201
|
+
response = restored;
|
|
7202
|
+
}
|
|
7203
|
+
}
|
|
7983
7204
|
return responseOwnership ? getOwnedResponse(responseOwnership) : response;
|
|
7984
7205
|
} catch (err) {
|
|
7985
|
-
|
|
7206
|
+
returnedDepth = -1;
|
|
7986
7207
|
if (responseOwnership) disposeResponseOwnership(responseOwnership, signal.aborted ? signal.reason : err);
|
|
7987
7208
|
throw err;
|
|
7988
7209
|
}
|
|
@@ -8026,18 +7247,24 @@ function createStartHandler(cbOrOptions) {
|
|
|
8026
7247
|
});
|
|
8027
7248
|
const resolveManifestForRequest = finalManifestResolver.resolveCached;
|
|
8028
7249
|
finalManifestResolver.warmup({ getBaseManifest: () => getBaseManifest(void 0) });
|
|
8029
|
-
const startRequestResolver = async (request, requestOpts) => {
|
|
7250
|
+
const startRequestResolver = async (request, requestOpts, event) => {
|
|
8030
7251
|
const signal = request.signal;
|
|
8031
7252
|
let router;
|
|
8032
7253
|
let routerPromise;
|
|
8033
7254
|
let responseOwnsCleanup = false;
|
|
7255
|
+
let response;
|
|
8034
7256
|
try {
|
|
8035
7257
|
signal.throwIfAborted();
|
|
8036
|
-
const
|
|
8037
|
-
|
|
8038
|
-
const
|
|
8039
|
-
if (
|
|
8040
|
-
|
|
7258
|
+
const requestUrl = event.requestUrl;
|
|
7259
|
+
let url = requestUrl;
|
|
7260
|
+
const pathname = url.pathname;
|
|
7261
|
+
if (!SERVER_FN_BASE || !pathname.startsWith(SERVER_FN_BASE) || pathname.includes("%") || pathname.startsWith("//")) {
|
|
7262
|
+
const normalized = getNormalizedURL(requestUrl);
|
|
7263
|
+
url = normalized.url;
|
|
7264
|
+
if (normalized.handledProtocolRelativeURL) return finalizeResponse(Response.redirect(url, 308), event);
|
|
7265
|
+
}
|
|
7266
|
+
const pendingEntries = getEntries();
|
|
7267
|
+
const entries = isPromise(pendingEntries) ? await waitForReason(pendingEntries, signal) : pendingEntries;
|
|
8041
7268
|
const isServerFnRequest = !!SERVER_FN_BASE && url.pathname.startsWith(SERVER_FN_BASE);
|
|
8042
7269
|
const startInstance = entries.startEntry.startInstance;
|
|
8043
7270
|
let startOptions;
|
|
@@ -8057,22 +7284,29 @@ function createStartHandler(cbOrOptions) {
|
|
|
8057
7284
|
requestMiddleware: startInstance ? startOptions.requestMiddleware : isServerFnRequest ? [defaultCsrfMiddleware] : void 0,
|
|
8058
7285
|
serializationAdapters
|
|
8059
7286
|
};
|
|
8060
|
-
const
|
|
8061
|
-
|
|
7287
|
+
const requestMiddleware = requestStartOptions.requestMiddleware;
|
|
7288
|
+
let executedRequestMiddlewares;
|
|
7289
|
+
let flattenedRequestMiddlewares = [];
|
|
7290
|
+
if (requestMiddleware?.length) {
|
|
7291
|
+
executedRequestMiddlewares = /* @__PURE__ */ new Set();
|
|
7292
|
+
flattenedRequestMiddlewares = flattenMiddlewares(requestMiddleware, void 0, executedRequestMiddlewares);
|
|
7293
|
+
}
|
|
8062
7294
|
const getRouter = () => {
|
|
8063
7295
|
routerPromise ??= (async () => {
|
|
8064
7296
|
signal.throwIfAborted();
|
|
8065
|
-
const
|
|
7297
|
+
const routerUrl = url === requestUrl ? getNormalizedURL(url).url : url;
|
|
7298
|
+
const pendingRouter = entries.routerEntry.getRouter();
|
|
7299
|
+
const requestRouter = isPromise(pendingRouter) ? await waitForReason(pendingRouter, signal) : pendingRouter;
|
|
8066
7300
|
let isShell = IS_SHELL_ENV;
|
|
8067
7301
|
if (IS_PRERENDERING && !isShell) isShell = request.headers.get(HEADERS.TSS_SHELL) === "true";
|
|
8068
|
-
const history = createServerHistory(
|
|
7302
|
+
const history = createServerHistory(routerUrl.pathname + routerUrl.search + routerUrl.hash);
|
|
8069
7303
|
requestRouter.update({
|
|
8070
7304
|
history,
|
|
8071
7305
|
isShell,
|
|
8072
7306
|
isPrerendering: IS_PRERENDERING,
|
|
8073
|
-
origin: requestRouter.options.origin ?? origin,
|
|
7307
|
+
origin: requestRouter.options.origin ?? routerUrl.origin,
|
|
8074
7308
|
defaultSsr: requestStartOptions.defaultSsr,
|
|
8075
|
-
serializationAdapters: [...requestStartOptions.serializationAdapters, ...requestRouter.options.serializationAdapters
|
|
7309
|
+
serializationAdapters: requestRouter.options.serializationAdapters?.length ? [...requestStartOptions.serializationAdapters, ...requestRouter.options.serializationAdapters] : requestStartOptions.serializationAdapters,
|
|
8076
7310
|
basepath: ROUTER_BASEPATH
|
|
8077
7311
|
});
|
|
8078
7312
|
router = requestRouter;
|
|
@@ -8097,51 +7331,49 @@ function createStartHandler(cbOrOptions) {
|
|
|
8097
7331
|
contextAfterGlobalMiddlewares: context
|
|
8098
7332
|
}, () => handleServerAction({
|
|
8099
7333
|
request,
|
|
8100
|
-
context: requestOpts?.context,
|
|
8101
7334
|
serverFnId
|
|
8102
7335
|
}));
|
|
8103
7336
|
} else {
|
|
8104
|
-
const executeRouter = async (serverContext, matchedRoutes) => {
|
|
7337
|
+
const executeRouter = async (serverContext, matchedRoutes, routerInstance) => {
|
|
8105
7338
|
if (!/(^|,)\s*(\*\/\*|text\/html)/.test(request.headers.get("Accept") || "*/*")) return normalizeSsrResponse(Response.json({ error: "Only HTML requests are supported here" }, { status: 406 }));
|
|
8106
|
-
const
|
|
7339
|
+
const pendingManifest = resolveManifestForRequest({
|
|
8107
7340
|
request,
|
|
8108
7341
|
requestInlineCss: requestOpts?.inlineCss,
|
|
8109
7342
|
getBaseManifest: () => getBaseManifest(matchedRoutes)
|
|
8110
|
-
}), signal);
|
|
8111
|
-
const earlyHints = createEarlyHintsForRequest({
|
|
8112
|
-
onEarlyHints: requestOpts?.onEarlyHints,
|
|
8113
|
-
responseLinkHeader: requestOpts?.responseLinkHeader
|
|
8114
7343
|
});
|
|
7344
|
+
const manifest = isPromise(pendingManifest) ? await waitForReason(pendingManifest, signal) : pendingManifest;
|
|
7345
|
+
const earlyHints = createEarlyHintsForRequest(requestOpts);
|
|
8115
7346
|
earlyHints?.collectStatic({
|
|
8116
7347
|
manifest,
|
|
8117
7348
|
matchedRoutes
|
|
8118
7349
|
});
|
|
8119
|
-
const
|
|
7350
|
+
const storedStartContext = getStartContext({ throwIfNotFound: false });
|
|
8120
7351
|
attachRouterServerSsrUtils({
|
|
8121
7352
|
router: routerInstance,
|
|
8122
7353
|
manifest,
|
|
8123
|
-
getRequestAssets: () =>
|
|
7354
|
+
getRequestAssets: () => storedStartContext?.requestAssets
|
|
8124
7355
|
});
|
|
8125
7356
|
routerInstance.options.additionalContext = { serverContext };
|
|
8126
|
-
await routerInstance.load({
|
|
7357
|
+
await routerInstance.load({
|
|
7358
|
+
_signal: signal,
|
|
7359
|
+
_skipLocationUpdate: true
|
|
7360
|
+
});
|
|
8127
7361
|
signal.throwIfAborted();
|
|
8128
7362
|
if (routerInstance._serverResult?.type === "redirect") return normalizeSsrResponse(routerInstance._serverResult.redirect);
|
|
8129
7363
|
earlyHints?.collectDynamic(_getRenderedMatches(routerInstance.stores.matches.get()));
|
|
8130
|
-
const ctx = getStartContext({ throwIfNotFound: false });
|
|
8131
7364
|
await routerInstance.serverSsr.dehydrate({
|
|
8132
|
-
requestAssets:
|
|
7365
|
+
requestAssets: storedStartContext?.requestAssets,
|
|
8133
7366
|
signal
|
|
8134
7367
|
});
|
|
8135
7368
|
signal.throwIfAborted();
|
|
8136
|
-
const responseHeaders = getStartResponseHeaders(
|
|
7369
|
+
const responseHeaders = getStartResponseHeaders(routerInstance);
|
|
8137
7370
|
earlyHints?.appendResponseHeaders(responseHeaders);
|
|
8138
7371
|
signal.throwIfAborted();
|
|
8139
|
-
|
|
8140
|
-
return normalizeSsrResponse(await waitForReason(cb({
|
|
7372
|
+
return normalizeSsrResponse(await cb({
|
|
8141
7373
|
request,
|
|
8142
7374
|
router: routerInstance,
|
|
8143
7375
|
responseHeaders
|
|
8144
|
-
})
|
|
7376
|
+
}));
|
|
8145
7377
|
};
|
|
8146
7378
|
terminal = ({ context }) => runWithStartContext({
|
|
8147
7379
|
...startContext,
|
|
@@ -8149,22 +7381,45 @@ function createStartHandler(cbOrOptions) {
|
|
|
8149
7381
|
}, () => handleServerRoutes({
|
|
8150
7382
|
getRouter,
|
|
8151
7383
|
request,
|
|
8152
|
-
url,
|
|
8153
7384
|
executeRouter,
|
|
8154
7385
|
context,
|
|
8155
|
-
executedRequestMiddlewares
|
|
7386
|
+
executedRequestMiddlewares,
|
|
7387
|
+
signal,
|
|
7388
|
+
event
|
|
8156
7389
|
}));
|
|
8157
7390
|
}
|
|
8158
|
-
const
|
|
7391
|
+
const middlewareCtx = {
|
|
8159
7392
|
request,
|
|
8160
7393
|
pathname: url.pathname,
|
|
8161
7394
|
handlerType,
|
|
8162
7395
|
context: createNullProtoObject(requestOpts?.context)
|
|
8163
|
-
}
|
|
7396
|
+
};
|
|
7397
|
+
let middlewareResponse;
|
|
7398
|
+
try {
|
|
7399
|
+
if (!isServerFnRequest && flattenedRequestMiddlewares.length === 0) middlewareResponse = await terminal(middlewareCtx);
|
|
7400
|
+
else middlewareResponse = await executeMiddleware(flattenedRequestMiddlewares.map((d) => d.options.server), terminal, middlewareCtx, signal, event);
|
|
7401
|
+
} catch (error) {
|
|
7402
|
+
if (signal.aborted) throw error;
|
|
7403
|
+
if (error instanceof Response) middlewareResponse = reconcileResponse(error, event);
|
|
7404
|
+
else if (!isServerFnRequest) throw error;
|
|
7405
|
+
else {
|
|
7406
|
+
const disposeLate = createLateResponseDisposer(signal);
|
|
7407
|
+
middlewareResponse = await waitForReason(runWithStartContext({
|
|
7408
|
+
...startContext,
|
|
7409
|
+
contextAfterGlobalMiddlewares: middlewareCtx.context
|
|
7410
|
+
}, () => createServerFnErrorResponse(error)), signal, disposeLate, disposeLate);
|
|
7411
|
+
middlewareResponse = reconcileResponse(middlewareResponse, event);
|
|
7412
|
+
}
|
|
7413
|
+
}
|
|
8164
7414
|
let result;
|
|
8165
7415
|
try {
|
|
8166
|
-
result =
|
|
8167
|
-
if (
|
|
7416
|
+
result = normalizeSsrResponse(middlewareResponse);
|
|
7417
|
+
if (isRedirect(result.response)) result = await handleRedirectResponse(result, getRouter, signal, isServerFnRequest && request.headers.get("x-tsr-serverFn") === "true", event);
|
|
7418
|
+
if (request.method === "HEAD" && result.response.body !== null) {
|
|
7419
|
+
const source = result.response;
|
|
7420
|
+
result = stripSsrResponseBody(result, "HEAD body stripped");
|
|
7421
|
+
transferResponseMetadata(source, result.response);
|
|
7422
|
+
}
|
|
8168
7423
|
} catch (error) {
|
|
8169
7424
|
disposeResponseResult(middlewareResponse, signal.aborted ? signal.reason : error);
|
|
8170
7425
|
throw error;
|
|
@@ -8172,17 +7427,26 @@ function createStartHandler(cbOrOptions) {
|
|
|
8172
7427
|
bindSsrResponseToRequest(router, result, signal);
|
|
8173
7428
|
signal.throwIfAborted();
|
|
8174
7429
|
responseOwnsCleanup = result.serverSsrCleanup === "stream";
|
|
8175
|
-
|
|
7430
|
+
response = result.response;
|
|
8176
7431
|
} finally {
|
|
8177
|
-
if (router?.serverSsr && !responseOwnsCleanup)
|
|
7432
|
+
if (router?.serverSsr && !responseOwnsCleanup) {
|
|
7433
|
+
router.serverSsr.cleanup();
|
|
7434
|
+
if (response) response = finalizeResponse(response, event);
|
|
7435
|
+
}
|
|
8178
7436
|
}
|
|
7437
|
+
return response;
|
|
8179
7438
|
};
|
|
8180
|
-
return
|
|
7439
|
+
return withStartRequest(startRequestResolver);
|
|
8181
7440
|
}
|
|
8182
7441
|
var relativeRedirectProtocols = /* @__PURE__ */ new Set();
|
|
8183
|
-
|
|
7442
|
+
var SERIALIZED_REDIRECT_HEADERS = /* @__PURE__ */ new Map([
|
|
7443
|
+
["content-type", "application/json"],
|
|
7444
|
+
["location", null],
|
|
7445
|
+
[X_TSS_RAW_RESPONSE, null],
|
|
7446
|
+
[X_TSS_SERIALIZED, null]
|
|
7447
|
+
]);
|
|
7448
|
+
async function handleRedirectResponse(ssrResponse, getRouter, signal, serializeRedirect, event) {
|
|
8184
7449
|
signal.throwIfAborted();
|
|
8185
|
-
const ssrResponse = normalizeSsrResponse(response);
|
|
8186
7450
|
const redirect = ssrResponse.response;
|
|
8187
7451
|
if (!isRedirect(redirect)) return ssrResponse;
|
|
8188
7452
|
const opts = redirect.options;
|
|
@@ -8205,13 +7469,21 @@ async function handleRedirectResponse(response, getRouter, signal, serializeRedi
|
|
|
8205
7469
|
if (serializeRedirect) {
|
|
8206
7470
|
const redirectOptions = { ...opts };
|
|
8207
7471
|
delete redirectOptions.headers;
|
|
7472
|
+
redirectOptions.isSerializedRedirect = true;
|
|
8208
7473
|
const responseHeaders = new Headers(redirect.headers);
|
|
8209
7474
|
responseHeaders.set("content-type", "application/json");
|
|
8210
|
-
|
|
8211
|
-
|
|
8212
|
-
|
|
8213
|
-
|
|
7475
|
+
responseHeaders.delete("location");
|
|
7476
|
+
responseHeaders.delete(X_TSS_RAW_RESPONSE);
|
|
7477
|
+
responseHeaders.delete(X_TSS_SERIALIZED);
|
|
7478
|
+
const body = JSON.stringify(redirectOptions);
|
|
7479
|
+
if (body === void 0) throw new TypeError("Value is not JSON serializable");
|
|
7480
|
+
disposeSsrResponse(ssrResponse, "redirect response replaced");
|
|
7481
|
+
return {
|
|
7482
|
+
response: createFinalizedResponse(body, responseHeaders, SERIALIZED_REDIRECT_HEADERS, event),
|
|
7483
|
+
serverSsrCleanup: "none"
|
|
7484
|
+
};
|
|
8214
7485
|
}
|
|
7486
|
+
ssrResponse.response = finalizeResponse(redirect, event);
|
|
8215
7487
|
return ssrResponse;
|
|
8216
7488
|
}
|
|
8217
7489
|
function withParsedParams(handler, matchedRoutes) {
|
|
@@ -8228,19 +7500,19 @@ function withParsedParams(handler, matchedRoutes) {
|
|
|
8228
7500
|
});
|
|
8229
7501
|
};
|
|
8230
7502
|
}
|
|
8231
|
-
async function handleServerRoutes({ getRouter, request,
|
|
7503
|
+
async function handleServerRoutes({ getRouter, request, executeRouter, context, executedRequestMiddlewares, signal, event }) {
|
|
8232
7504
|
const router = await getRouter();
|
|
8233
|
-
const pathname =
|
|
7505
|
+
const { pathname } = router.latestLocation;
|
|
8234
7506
|
const [matchedRoutes, rawParams, foundRoute] = router.getMatchedRoutes(pathname);
|
|
8235
7507
|
const isExactMatch = foundRoute && rawParams["**"] === void 0;
|
|
8236
7508
|
const routeMiddlewares = [];
|
|
8237
|
-
let terminalHandler = (ctx) => executeRouter(ctx.context, matchedRoutes);
|
|
7509
|
+
let terminalHandler = (ctx) => executeRouter(ctx.context, matchedRoutes, router);
|
|
8238
7510
|
let terminalNext;
|
|
8239
7511
|
for (const route of matchedRoutes) {
|
|
8240
7512
|
const serverMiddleware = route.options.server?.middleware;
|
|
8241
7513
|
if (serverMiddleware) {
|
|
8242
7514
|
const flattened = flattenMiddlewares(serverMiddleware);
|
|
8243
|
-
for (const m of flattened) if (!executedRequestMiddlewares
|
|
7515
|
+
for (const m of flattened) if (!executedRequestMiddlewares?.has(m)) routeMiddlewares.push(m.options.server);
|
|
8244
7516
|
}
|
|
8245
7517
|
}
|
|
8246
7518
|
const server = foundRoute?.options.server;
|
|
@@ -8272,7 +7544,7 @@ async function handleServerRoutes({ getRouter, request, url, executeRouter, cont
|
|
|
8272
7544
|
params: rawParams,
|
|
8273
7545
|
pathname,
|
|
8274
7546
|
handlerType: "router"
|
|
8275
|
-
},
|
|
7547
|
+
}, signal, event, terminalNext));
|
|
8276
7548
|
}
|
|
8277
7549
|
var VIRTUAL_MODULES = {
|
|
8278
7550
|
startManifest: "tanstack-start-manifest:v",
|
|
@@ -8283,10 +7555,11 @@ var server_exports = /* @__PURE__ */ __exportAll({
|
|
|
8283
7555
|
HEADERS: () => HEADERS,
|
|
8284
7556
|
StartServer: () => StartServer,
|
|
8285
7557
|
VIRTUAL_MODULES: () => VIRTUAL_MODULES,
|
|
7558
|
+
appendResponseHeader: () => appendResponseHeader,
|
|
8286
7559
|
attachRouterServerSsrUtils: () => attachRouterServerSsrUtils,
|
|
8287
7560
|
clearResponseHeaders: () => clearResponseHeaders,
|
|
8288
|
-
clearSession: () => clearSession,
|
|
8289
7561
|
createRequestHandler: () => createRequestHandler,
|
|
7562
|
+
createServerEntry: () => createServerEntry,
|
|
8290
7563
|
createStartHandler: () => createStartHandler,
|
|
8291
7564
|
defaultRenderHandler: () => defaultRenderHandler,
|
|
8292
7565
|
defaultStreamHandler: () => defaultStreamHandler,
|
|
@@ -8301,25 +7574,17 @@ var server_exports = /* @__PURE__ */ __exportAll({
|
|
|
8301
7574
|
getRequestIP: () => getRequestIP,
|
|
8302
7575
|
getRequestProtocol: () => getRequestProtocol,
|
|
8303
7576
|
getRequestUrl: () => getRequestUrl,
|
|
8304
|
-
getResponse: () => getResponse,
|
|
8305
7577
|
getResponseHeader: () => getResponseHeader,
|
|
8306
7578
|
getResponseHeaders: () => getResponseHeaders,
|
|
8307
7579
|
getResponseStatus: () => getResponseStatus,
|
|
8308
|
-
|
|
8309
|
-
getValidatedQuery: () => getValidatedQuery,
|
|
7580
|
+
handleStartError: () => handleStartError,
|
|
8310
7581
|
removeResponseHeader: () => removeResponseHeader,
|
|
8311
|
-
requestHandler: () => requestHandler,
|
|
8312
|
-
sealSession: () => sealSession,
|
|
8313
7582
|
setCookie: () => setCookie,
|
|
8314
7583
|
setResponseHeader: () => setResponseHeader,
|
|
8315
7584
|
setResponseHeaders: () => setResponseHeaders,
|
|
8316
7585
|
setResponseStatus: () => setResponseStatus,
|
|
8317
|
-
transferResponseBodyOwnership: () => transferResponseBodyOwnership,
|
|
8318
7586
|
transformPipeableStreamWithRouter: () => transformPipeableStreamWithRouter,
|
|
8319
|
-
transformReadableStreamWithRouter: () => transformReadableStreamWithRouter
|
|
8320
|
-
unsealSession: () => unsealSession,
|
|
8321
|
-
updateSession: () => updateSession,
|
|
8322
|
-
useSession: () => useSession
|
|
7587
|
+
transformReadableStreamWithRouter: () => transformReadableStreamWithRouter
|
|
8323
7588
|
});
|
|
8324
7589
|
//#endregion
|
|
8325
|
-
export { defaultStreamHandler as i, createStartHandler as n,
|
|
7590
|
+
export { defaultStreamHandler as a, getRequest as i, createStartHandler as n, createServerEntry as r, server_exports as t };
|