@betterportal/framework 11.0.1 → 11.0.3
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/lib/adapters/formBody.d.ts +3 -0
- package/lib/adapters/formBody.d.ts.map +1 -0
- package/lib/adapters/formBody.js +96 -0
- package/lib/adapters/formBody.js.map +1 -0
- package/lib/adapters/h3.d.ts.map +1 -1
- package/lib/adapters/h3.js +88 -32
- package/lib/adapters/h3.js.map +1 -1
- package/lib/contracts/chrome.d.ts +3 -1
- package/lib/contracts/chrome.d.ts.map +1 -1
- package/lib/contracts/chrome.js +4 -2
- package/lib/contracts/chrome.js.map +1 -1
- package/lib/contracts/manifest.d.ts +6 -2
- package/lib/contracts/manifest.d.ts.map +1 -1
- package/lib/contracts/platformConfig.d.ts +15 -5
- package/lib/contracts/platformConfig.d.ts.map +1 -1
- package/lib/contracts/project.d.ts +3 -1
- package/lib/contracts/project.d.ts.map +1 -1
- package/lib/contracts/route.d.ts +18 -0
- package/lib/contracts/route.d.ts.map +1 -1
- package/lib/contracts/route.js.map +1 -1
- package/lib/contracts/view.d.ts +6 -2
- package/lib/contracts/view.d.ts.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/runtime/auth/jwks.d.ts.map +1 -1
- package/lib/runtime/auth/jwks.js +38 -1
- package/lib/runtime/auth/jwks.js.map +1 -1
- package/lib/runtime/auth/redirect.d.ts.map +1 -1
- package/lib/runtime/auth/redirect.js +21 -3
- package/lib/runtime/auth/redirect.js.map +1 -1
- package/lib/runtime/configProvider.d.ts +24 -0
- package/lib/runtime/configProvider.d.ts.map +1 -1
- package/lib/runtime/configProvider.js +56 -3
- package/lib/runtime/configProvider.js.map +1 -1
- package/lib/runtime/h3.d.ts +1 -0
- package/lib/runtime/h3.d.ts.map +1 -1
- package/lib/runtime/h3.js +23 -109
- package/lib/runtime/h3.js.map +1 -1
- package/lib/runtime/llms.d.ts.map +1 -1
- package/lib/runtime/llms.js +4 -3
- package/lib/runtime/llms.js.map +1 -1
- package/lib/runtime/requestBody.d.ts +5 -0
- package/lib/runtime/requestBody.d.ts.map +1 -0
- package/lib/runtime/requestBody.js +79 -0
- package/lib/runtime/requestBody.js.map +1 -0
- package/lib/runtime/serviceConfig.d.ts.map +1 -1
- package/lib/runtime/serviceConfig.js +4 -1
- package/lib/runtime/serviceConfig.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formBody.d.ts","sourceRoot":"","sources":["../../src/adapters/formBody.ts"],"names":[],"mappings":"AA4DA,+FAA+F;AAC/F,wBAAgB,cAAc,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA6BtE"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
const MAX_FORM_FIELDS = 10_000;
|
|
2
|
+
const MAX_FORM_NODES = 10_000;
|
|
3
|
+
const MAX_FORM_DEPTH = 32;
|
|
4
|
+
const MAX_FORM_INDEX = 999;
|
|
5
|
+
const MAX_FORM_NAME_LENGTH = 1024;
|
|
6
|
+
const UNSAFE_SEGMENTS = new Set(["__proto__", "prototype", "constructor"]);
|
|
7
|
+
class InvalidFormError extends Error {
|
|
8
|
+
}
|
|
9
|
+
function fieldPath(name) {
|
|
10
|
+
if (!name || name.length > MAX_FORM_NAME_LENGTH)
|
|
11
|
+
throw new InvalidFormError("Invalid form field name length");
|
|
12
|
+
if (Array.from(name).some(char => char.charCodeAt(0) < 32 || char.charCodeAt(0) === 127)) {
|
|
13
|
+
throw new InvalidFormError("Invalid form property name");
|
|
14
|
+
}
|
|
15
|
+
const path = [];
|
|
16
|
+
let offset = 0;
|
|
17
|
+
const property = () => {
|
|
18
|
+
const segment = /^[^.[\]]+/u.exec(name.slice(offset))?.[0];
|
|
19
|
+
if (!segment || UNSAFE_SEGMENTS.has(segment))
|
|
20
|
+
throw new InvalidFormError("Invalid form property name");
|
|
21
|
+
path.push(segment);
|
|
22
|
+
offset += segment.length;
|
|
23
|
+
};
|
|
24
|
+
property();
|
|
25
|
+
while (offset < name.length) {
|
|
26
|
+
if (name[offset] === ".") {
|
|
27
|
+
offset++;
|
|
28
|
+
property();
|
|
29
|
+
}
|
|
30
|
+
else if (name[offset] === "[") {
|
|
31
|
+
const index = /^\[(0|[1-9]\d*)\]/u.exec(name.slice(offset));
|
|
32
|
+
if (!index || Number(index[1]) > MAX_FORM_INDEX)
|
|
33
|
+
throw new InvalidFormError("Invalid form array index");
|
|
34
|
+
path.push(Number(index[1]));
|
|
35
|
+
offset += index[0].length;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
throw new InvalidFormError("Invalid form field path");
|
|
39
|
+
}
|
|
40
|
+
if (path.length > MAX_FORM_DEPTH)
|
|
41
|
+
throw new InvalidFormError("Form field path exceeds maximum depth");
|
|
42
|
+
}
|
|
43
|
+
return path;
|
|
44
|
+
}
|
|
45
|
+
function materialize(node) {
|
|
46
|
+
if (node.kind === "value")
|
|
47
|
+
return node.values.length === 1 ? node.values[0] : node.values;
|
|
48
|
+
if (node.kind === "object") {
|
|
49
|
+
return Object.fromEntries(Array.from(node.children, ([key, child]) => [key, materialize(child)]));
|
|
50
|
+
}
|
|
51
|
+
// Check density before allocating an array; sparse input must not bypass schema validation.
|
|
52
|
+
const result = [];
|
|
53
|
+
for (let index = 0; index < node.children.size; index++) {
|
|
54
|
+
const child = node.children.get(index);
|
|
55
|
+
if (!child)
|
|
56
|
+
throw new InvalidFormError("Form array indices must be contiguous starting at zero");
|
|
57
|
+
result.push(materialize(child));
|
|
58
|
+
}
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
/** Decode native form names before request-schema validation; file values remain filenames. */
|
|
62
|
+
export function decodeFormBody(form) {
|
|
63
|
+
const root = { kind: "object", children: new Map() };
|
|
64
|
+
let fields = 0;
|
|
65
|
+
let nodes = 0;
|
|
66
|
+
for (const [name, value] of form) {
|
|
67
|
+
if (++fields > MAX_FORM_FIELDS)
|
|
68
|
+
throw new InvalidFormError("Form exceeds maximum field count");
|
|
69
|
+
const path = fieldPath(name);
|
|
70
|
+
let node = root;
|
|
71
|
+
for (let depth = 0; depth < path.length; depth++) {
|
|
72
|
+
const key = path[depth];
|
|
73
|
+
if (node.kind === "value" || (node.kind === "array") !== (typeof key === "number")) {
|
|
74
|
+
throw new InvalidFormError("Conflicting form field paths");
|
|
75
|
+
}
|
|
76
|
+
const kind = depth === path.length - 1 ? "value"
|
|
77
|
+
: typeof path[depth + 1] === "number" ? "array" : "object";
|
|
78
|
+
let child = node.children.get(key);
|
|
79
|
+
if (!child) {
|
|
80
|
+
if (++nodes > MAX_FORM_NODES)
|
|
81
|
+
throw new InvalidFormError("Form exceeds maximum structure size");
|
|
82
|
+
const created = kind === "value" ? { kind, values: [] } : { kind, children: new Map() };
|
|
83
|
+
node.children.set(key, created);
|
|
84
|
+
child = created;
|
|
85
|
+
}
|
|
86
|
+
else if (child.kind !== kind) {
|
|
87
|
+
throw new InvalidFormError("Conflicting form field paths");
|
|
88
|
+
}
|
|
89
|
+
node = child;
|
|
90
|
+
}
|
|
91
|
+
if (node.kind === "value")
|
|
92
|
+
node.values.push(typeof value === "string" ? value : value.name);
|
|
93
|
+
}
|
|
94
|
+
return materialize(root);
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=formBody.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formBody.js","sourceRoot":"","sources":["../../src/adapters/formBody.ts"],"names":[],"mappings":"AAAA,MAAM,eAAe,GAAG,MAAM,CAAC;AAC/B,MAAM,cAAc,GAAG,MAAM,CAAC;AAC9B,MAAM,cAAc,GAAG,EAAE,CAAC;AAC1B,MAAM,cAAc,GAAG,GAAG,CAAC;AAC3B,MAAM,oBAAoB,GAAG,IAAI,CAAC;AAClC,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC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EAAE,iBAAiB,EACtB,QAAQ,EAAE,cAAc,EACxB,QAAQ,EAAE,cAAc,EACxB,OAAO,GAAE;IACP,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,QAAQ,GAAG,SAAS,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAC;IAC5F,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,gBAAgB,GAAG,IAAI,CAAC;CAChE,GACL,IAAI,CAoEN"}
|
package/lib/adapters/h3.js
CHANGED
|
@@ -2,10 +2,12 @@ import { createRouteResult, viewRouteResolver } from "../runtime/routeResult.js"
|
|
|
2
2
|
import { routeMountServicePath, safeServiceBaseUrl } from "../runtime/configProvider.js";
|
|
3
3
|
import { ElevationRequired, requireElevation, elevationResponse } from "../runtime/auth/elevation.js";
|
|
4
4
|
import { createEventStream, getRequestIP, getRequestURL } from "h3";
|
|
5
|
+
import { decodeFormBody } from "./formBody.js";
|
|
5
6
|
import { renderThemeLlmsDrop } from "../runtime/llms.js";
|
|
7
|
+
import { BetterPortalRouteChromeSchema } from "../contracts/chrome.js";
|
|
6
8
|
import { isStreamHandler } from "../contracts/streaming.js";
|
|
7
9
|
import { driveStream, driveStreamBuffered, ndjsonStreamResponse } from "../runtime/stream.js";
|
|
8
|
-
import { acceptHeaderFromEvent, annotateCoreHttpOutcome, annotateHttpOutcome, ensureCoreHttpOutcome, eventObservability, htmlResponse, jsonResponse, withCoreHttpOutcome } from "../runtime/h3.js";
|
|
10
|
+
import { acceptHeaderFromEvent, annotateCoreHttpOutcome, annotateHttpOutcome, ensureCoreHttpOutcome, eventObservability, htmlResponse, jsonResponse, redactTelemetryUrl, withCoreHttpOutcome } from "../runtime/h3.js";
|
|
9
11
|
import { buildHostCandidates, hostFromHeaderValue, toHtmlString } from "../runtime/http.js";
|
|
10
12
|
import { parseAcceptHeader, resolveRequestedRepresentation } from "../runtime/media.js";
|
|
11
13
|
import { resolveRenderer } from "../runtime/registry.js";
|
|
@@ -13,13 +15,53 @@ import { createBpHeadersCollector } from "../runtime/bpHeaders.js";
|
|
|
13
15
|
import { isServiceToken } from "../runtime/auth/serviceToken.js";
|
|
14
16
|
import { resolveStatusRenderer, shouldFallThroughToDefaultRenderer, statusForbidsBody } from "../runtime/statusViews.js";
|
|
15
17
|
const METHOD_WRITE_BODY = new Set(["POST", "PUT", "PATCH"]);
|
|
18
|
+
const MAX_JSON_BODY_BYTES = 1024 * 1024;
|
|
16
19
|
const MAX_BUFFERED_MULTIPART_BYTES = 25 * 1024 * 1024;
|
|
20
|
+
const MAX_MULTIPART_BODY_BYTES = MAX_BUFFERED_MULTIPART_BYTES + 128 * 1024;
|
|
17
21
|
const PLATFORM_ROOT_PERMISSION_ROLE_ID = "*";
|
|
18
22
|
class MultipartTooLargeError extends Error {
|
|
19
23
|
constructor() {
|
|
20
24
|
super("Multipart payload exceeds buffered upload limit");
|
|
21
25
|
}
|
|
22
26
|
}
|
|
27
|
+
async function readBoundedRouteBody(event, maxBytes) {
|
|
28
|
+
const declaredLength = event.req.headers.get("content-length");
|
|
29
|
+
if (declaredLength !== null && /^\d+$/.test(declaredLength) && Number(declaredLength) > maxBytes) {
|
|
30
|
+
void event.req.body?.cancel().catch(() => undefined);
|
|
31
|
+
return coreJsonResponse({ error: "Request body too large" }, 413, "request.body.too_large", "Request body too large");
|
|
32
|
+
}
|
|
33
|
+
const reader = event.req.body?.getReader();
|
|
34
|
+
if (!reader)
|
|
35
|
+
return new Uint8Array();
|
|
36
|
+
const chunks = [];
|
|
37
|
+
let used = 0;
|
|
38
|
+
try {
|
|
39
|
+
while (true) {
|
|
40
|
+
const { done, value } = await reader.read();
|
|
41
|
+
if (done)
|
|
42
|
+
break;
|
|
43
|
+
if (value.byteLength > maxBytes - used) {
|
|
44
|
+
void reader.cancel().catch(() => undefined);
|
|
45
|
+
return coreJsonResponse({ error: "Request body too large" }, 413, "request.body.too_large", "Request body too large");
|
|
46
|
+
}
|
|
47
|
+
chunks.push(value);
|
|
48
|
+
used += value.byteLength;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return coreJsonResponse({ error: "Invalid request body" }, 400, "request.body.invalid", "Invalid request body");
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
reader.releaseLock();
|
|
56
|
+
}
|
|
57
|
+
const body = new Uint8Array(used);
|
|
58
|
+
let offset = 0;
|
|
59
|
+
for (const chunk of chunks) {
|
|
60
|
+
body.set(chunk, offset);
|
|
61
|
+
offset += chunk.byteLength;
|
|
62
|
+
}
|
|
63
|
+
return body;
|
|
64
|
+
}
|
|
23
65
|
function methodRegistrar(app, method) {
|
|
24
66
|
switch (method) {
|
|
25
67
|
case "GET": return (p, h) => app.get(p, h);
|
|
@@ -100,12 +142,12 @@ function fileResponseHelper(body, options = {}) {
|
|
|
100
142
|
return new Response(body, { status: options.status ?? 200, headers });
|
|
101
143
|
}
|
|
102
144
|
async function formDataToRequest(fd) {
|
|
103
|
-
const body =
|
|
145
|
+
const body = decodeFormBody(fd);
|
|
104
146
|
const fields = {};
|
|
105
147
|
const files = {};
|
|
106
148
|
let totalFileBytes = 0;
|
|
107
149
|
const pushValue = (target, key, value) => {
|
|
108
|
-
const existing = target[key];
|
|
150
|
+
const existing = Object.hasOwn(target, key) ? target[key] : undefined;
|
|
109
151
|
if (existing === undefined)
|
|
110
152
|
target[key] = value;
|
|
111
153
|
else if (Array.isArray(existing))
|
|
@@ -113,31 +155,25 @@ async function formDataToRequest(fd) {
|
|
|
113
155
|
else
|
|
114
156
|
target[key] = [existing, value];
|
|
115
157
|
};
|
|
116
|
-
const
|
|
117
|
-
fd.forEach((value, key) => {
|
|
158
|
+
for (const [key, value] of fd) {
|
|
118
159
|
if (typeof value === "string") {
|
|
119
|
-
body[key] = value;
|
|
120
160
|
pushValue(fields, key, value);
|
|
121
161
|
}
|
|
122
162
|
else {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
};
|
|
136
|
-
pushValue(files, key, file);
|
|
137
|
-
})());
|
|
163
|
+
totalFileBytes += value.size;
|
|
164
|
+
if (totalFileBytes > MAX_BUFFERED_MULTIPART_BYTES) {
|
|
165
|
+
throw new MultipartTooLargeError();
|
|
166
|
+
}
|
|
167
|
+
const file = {
|
|
168
|
+
fieldName: key,
|
|
169
|
+
filename: value.name,
|
|
170
|
+
contentType: value.type || "application/octet-stream",
|
|
171
|
+
size: value.size,
|
|
172
|
+
data: new Uint8Array(await value.arrayBuffer())
|
|
173
|
+
};
|
|
174
|
+
pushValue(files, key, file);
|
|
138
175
|
}
|
|
139
|
-
}
|
|
140
|
-
await Promise.all(pendingFiles);
|
|
176
|
+
}
|
|
141
177
|
return { body, multipart: { fields, files } };
|
|
142
178
|
}
|
|
143
179
|
async function resolveRequiredHandlerContext(event, routerOptions, route) {
|
|
@@ -171,7 +207,7 @@ function chromeContentTypeParams(chrome) {
|
|
|
171
207
|
return "";
|
|
172
208
|
const params = [];
|
|
173
209
|
for (const [rawKey, value] of Object.entries(chrome)) {
|
|
174
|
-
if (!["string", "number", "boolean"].includes(typeof value))
|
|
210
|
+
if (!["string", "number", "boolean"].includes(typeof value) && !Array.isArray(value))
|
|
175
211
|
continue;
|
|
176
212
|
if (typeof value === "number" && !Number.isFinite(value))
|
|
177
213
|
continue;
|
|
@@ -181,8 +217,11 @@ function chromeContentTypeParams(chrome) {
|
|
|
181
217
|
.toLowerCase();
|
|
182
218
|
if (!/^[a-z][a-z0-9-]*$/.test(key))
|
|
183
219
|
continue;
|
|
184
|
-
const stringValue =
|
|
220
|
+
const stringValue = Array.isArray(value) ? encodeURIComponent(JSON.stringify(value))
|
|
221
|
+
: typeof value === "string" ? encodeURIComponent(value) : String(value);
|
|
185
222
|
params.push(`bp-chrome-${key}=${stringValue}`);
|
|
223
|
+
if (Array.isArray(value))
|
|
224
|
+
params.push(`bp-array-chrome-${key}=true`);
|
|
186
225
|
}
|
|
187
226
|
return params.length ? `; ${params.join("; ")}` : "";
|
|
188
227
|
}
|
|
@@ -249,6 +288,7 @@ async function prepareSseContext(registryRoutes, dependencyAliases, route, event
|
|
|
249
288
|
serviceId: routerOptions.serviceId,
|
|
250
289
|
route: createRouteResolver(event, registryRoutes, extraContext, dependencyAliases, routerOptions.resolveRouteServiceId?.() ?? routerOptions.serviceId, { path: url.pathname.replace(/\/__sse\/?$/, ""), template: route.path, method: "GET", params, query: queryResult.value }),
|
|
251
290
|
diagnostic: (diagnostic) => annotateHttpOutcome(event, diagnostic),
|
|
291
|
+
chrome: (chrome) => { BetterPortalRouteChromeSchema.parse(chrome); },
|
|
252
292
|
response: responseHelper,
|
|
253
293
|
file: fileResponseHelper,
|
|
254
294
|
...(obs ? { obs } : {})
|
|
@@ -347,7 +387,7 @@ function requestAttributes(event, route, method, extra = {}) {
|
|
|
347
387
|
const requestIp = getRequestIP(event, { xForwardedFor: true });
|
|
348
388
|
return {
|
|
349
389
|
"http.request.method": method,
|
|
350
|
-
"url.full": requestUrl
|
|
390
|
+
"url.full": redactTelemetryUrl(requestUrl),
|
|
351
391
|
"url.path": requestUrl.pathname,
|
|
352
392
|
"network.protocol.name": requestUrl.protocol.replace(":", ""),
|
|
353
393
|
"bp.route.path": route.path,
|
|
@@ -886,11 +926,18 @@ async function handleRouteRequest(registryRoutes, dependencyAliases, route, meth
|
|
|
886
926
|
let rawBody = {};
|
|
887
927
|
let rawMultipart;
|
|
888
928
|
if (METHOD_WRITE_BODY.has(method)) {
|
|
889
|
-
const
|
|
929
|
+
const rawContentType = event.req.headers.get("content-type") || "";
|
|
930
|
+
const contentType = rawContentType.toLowerCase();
|
|
931
|
+
const maxBodyBytes = contentType.includes("multipart/form-data")
|
|
932
|
+
? MAX_MULTIPART_BODY_BYTES
|
|
933
|
+
: MAX_JSON_BODY_BYTES;
|
|
934
|
+
const bodyBytes = await readBoundedRouteBody(event, maxBodyBytes);
|
|
935
|
+
if (bodyBytes instanceof Response)
|
|
936
|
+
return bodyBytes;
|
|
890
937
|
if (contentType.includes("application/x-www-form-urlencoded") || contentType.includes("multipart/form-data")) {
|
|
891
|
-
//
|
|
938
|
+
// Decode native dotted/indexed form names before schema validation (incl. plain hx-post).
|
|
892
939
|
try {
|
|
893
|
-
const fd = await
|
|
940
|
+
const fd = await new Response(bodyBytes.buffer, { headers: { "content-type": rawContentType } }).formData();
|
|
894
941
|
const parsedForm = await formDataToRequest(fd);
|
|
895
942
|
rawBody = parsedForm.body;
|
|
896
943
|
rawMultipart = parsedForm.multipart;
|
|
@@ -899,11 +946,16 @@ async function handleRouteRequest(registryRoutes, dependencyAliases, route, meth
|
|
|
899
946
|
if (err instanceof MultipartTooLargeError) {
|
|
900
947
|
return coreJsonResponse({ error: "Multipart payload too large" }, 413, "request.multipart.too_large", err.message);
|
|
901
948
|
}
|
|
902
|
-
|
|
949
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
950
|
+
return coreJsonResponse({ error: "Invalid form request", detail: reason }, 400, "request.body.invalid", reason, { "bp.request.validation_target": "request body" });
|
|
903
951
|
}
|
|
904
952
|
}
|
|
905
953
|
else {
|
|
906
|
-
|
|
954
|
+
let parsed = null;
|
|
955
|
+
try {
|
|
956
|
+
parsed = JSON.parse(new TextDecoder().decode(bodyBytes));
|
|
957
|
+
}
|
|
958
|
+
catch { /* Invalid JSON remains an empty body for schema validation. */ }
|
|
907
959
|
rawBody = (parsed && typeof parsed === "object" && !Array.isArray(parsed))
|
|
908
960
|
? parsed
|
|
909
961
|
: {};
|
|
@@ -1010,6 +1062,7 @@ async function handleRouteRequest(registryRoutes, dependencyAliases, route, meth
|
|
|
1010
1062
|
}
|
|
1011
1063
|
// -- Build context and invoke handler -----------------------------
|
|
1012
1064
|
const bpHeaders = createBpHeadersCollector();
|
|
1065
|
+
let pageChrome = methodRoute.chrome;
|
|
1013
1066
|
const ctx = {
|
|
1014
1067
|
params,
|
|
1015
1068
|
query: query,
|
|
@@ -1030,6 +1083,7 @@ async function handleRouteRequest(registryRoutes, dependencyAliases, route, meth
|
|
|
1030
1083
|
responseHeaders: event.res.headers,
|
|
1031
1084
|
setStatus: (status) => { event.res.status = status; },
|
|
1032
1085
|
diagnostic: (diagnostic) => annotateHttpOutcome(event, diagnostic),
|
|
1086
|
+
chrome: (chrome) => { pageChrome = { ...pageChrome, ...BetterPortalRouteChromeSchema.parse(chrome) }; },
|
|
1033
1087
|
serviceId: routerOptions.serviceId,
|
|
1034
1088
|
route: routeResolver,
|
|
1035
1089
|
response: responseHelper,
|
|
@@ -1243,7 +1297,9 @@ async function handleRouteRequest(registryRoutes, dependencyAliases, route, meth
|
|
|
1243
1297
|
"bp.view.kind": "page"
|
|
1244
1298
|
}, () => resolved.renderer.render(data, renderContext)));
|
|
1245
1299
|
const mode = representation.mode ?? "page";
|
|
1246
|
-
|
|
1300
|
+
const chrome = mode === "page" && method === "GET" && handlerStatus >= 200 && handlerStatus < 300
|
|
1301
|
+
? pageChrome : methodRoute.chrome;
|
|
1302
|
+
return htmlResponse(toHtmlString(html), handlerStatus, htmlContentType(mode, chrome));
|
|
1247
1303
|
}
|
|
1248
1304
|
/**
|
|
1249
1305
|
* Handle representations that stream, returning null for buffered ones so the
|