@trebired/frontend 6.5.0 → 6.6.1
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/CHANGELOG.md +10 -0
- package/dist/server/assets.d.ts +28 -0
- package/dist/server/assets.d.ts.map +1 -0
- package/dist/server/assets.js +157 -0
- package/dist/server/assets.js.map +1 -0
- package/dist/server/index.d.ts +4 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +4 -0
- package/dist/server/index.js.map +1 -1
- package/dist/server/locale.d.ts +22 -0
- package/dist/server/locale.d.ts.map +1 -0
- package/dist/server/locale.js +74 -0
- package/dist/server/locale.js.map +1 -0
- package/dist/server/page-task.d.ts +36 -0
- package/dist/server/page-task.d.ts.map +1 -0
- package/dist/server/page-task.js +91 -0
- package/dist/server/page-task.js.map +1 -0
- package/dist/server/react/document.d.ts +29 -0
- package/dist/server/react/document.d.ts.map +1 -0
- package/dist/server/react/document.js +123 -0
- package/dist/server/react/document.js.map +1 -0
- package/dist/server/react/render.d.ts +15 -0
- package/dist/server/react/render.d.ts.map +1 -0
- package/dist/server/react/render.js +60 -0
- package/dist/server/react/render.js.map +1 -0
- package/dist/server/react/shell.d.ts +7 -0
- package/dist/server/react/shell.d.ts.map +1 -0
- package/dist/server/react/shell.js +49 -0
- package/dist/server/react/shell.js.map +1 -0
- package/dist/server/react/types.d.ts +71 -0
- package/dist/server/react/types.d.ts.map +1 -0
- package/dist/server/react/types.js +2 -0
- package/dist/server/react/types.js.map +1 -0
- package/dist/src/server/assets.d.ts +28 -0
- package/dist/src/server/assets.d.ts.map +1 -0
- package/dist/src/server/assets.js +157 -0
- package/dist/src/server/assets.js.map +1 -0
- package/dist/src/server/index.d.ts +4 -0
- package/dist/src/server/index.d.ts.map +1 -1
- package/dist/src/server/index.js +4 -0
- package/dist/src/server/index.js.map +1 -1
- package/dist/src/server/locale.d.ts +22 -0
- package/dist/src/server/locale.d.ts.map +1 -0
- package/dist/src/server/locale.js +74 -0
- package/dist/src/server/locale.js.map +1 -0
- package/dist/src/server/page-task.d.ts +36 -0
- package/dist/src/server/page-task.d.ts.map +1 -0
- package/dist/src/server/page-task.js +91 -0
- package/dist/src/server/page-task.js.map +1 -0
- package/dist/src/server/react/document.d.ts +29 -0
- package/dist/src/server/react/document.d.ts.map +1 -0
- package/dist/src/server/react/document.js +123 -0
- package/dist/src/server/react/document.js.map +1 -0
- package/dist/src/server/react/render.d.ts +15 -0
- package/dist/src/server/react/render.d.ts.map +1 -0
- package/dist/src/server/react/render.js +60 -0
- package/dist/src/server/react/render.js.map +1 -0
- package/dist/src/server/react/shell.d.ts +7 -0
- package/dist/src/server/react/shell.d.ts.map +1 -0
- package/dist/src/server/react/shell.js +49 -0
- package/dist/src/server/react/shell.js.map +1 -0
- package/dist/src/server/react/types.d.ts +71 -0
- package/dist/src/server/react/types.d.ts.map +1 -0
- package/dist/src/server/react/types.js +2 -0
- package/dist/src/server/react/types.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type ServerRequestLike, type ServerResponseLike } from "./http.js";
|
|
2
|
+
type LocaleState = {
|
|
3
|
+
effective: string;
|
|
4
|
+
request: string;
|
|
5
|
+
user: string;
|
|
6
|
+
};
|
|
7
|
+
type LocaleMiddlewareOptions = {
|
|
8
|
+
defaultLocale?: string;
|
|
9
|
+
localsKey?: string;
|
|
10
|
+
normalize?: (value: unknown) => string;
|
|
11
|
+
readUserLocale?: (req: ServerRequestLike, res: ServerResponseLike) => unknown;
|
|
12
|
+
};
|
|
13
|
+
declare function normalizeIntlLocale(input: unknown): string;
|
|
14
|
+
declare function readRequestLocale(req: ServerRequestLike | null | undefined, normalize?: (value: unknown) => string): string;
|
|
15
|
+
declare function createLocaleState(req: ServerRequestLike, res: ServerResponseLike, options?: LocaleMiddlewareOptions): LocaleState;
|
|
16
|
+
declare function applyLocaleToLocals(req: ServerRequestLike, res: ServerResponseLike, options?: LocaleMiddlewareOptions): LocaleState;
|
|
17
|
+
declare function createLocaleMiddleware(options?: LocaleMiddlewareOptions): (req: ServerRequestLike, res: ServerResponseLike, next: () => unknown) => unknown;
|
|
18
|
+
declare function attachLocaleMiddleware(app: unknown, options?: LocaleMiddlewareOptions): void;
|
|
19
|
+
declare const normalizeLocale: typeof normalizeIntlLocale;
|
|
20
|
+
export { applyLocaleToLocals, attachLocaleMiddleware, createLocaleMiddleware, createLocaleState, normalizeLocale, readRequestLocale, };
|
|
21
|
+
export type { LocaleMiddlewareOptions, LocaleState };
|
|
22
|
+
//# sourceMappingURL=locale.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locale.d.ts","sourceRoot":"","sources":["../../../src/server/locale.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACxB,MAAM,WAAW,CAAC;AAEnB,KAAK,WAAW,GAAG;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,KAAK,uBAAuB,GAAG;IAC7B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,CAAC;IACvC,cAAc,CAAC,EAAE,CAAC,GAAG,EAAE,iBAAiB,EAAE,GAAG,EAAE,kBAAkB,KAAK,OAAO,CAAC;CAC/E,CAAC;AAEF,iBAAS,mBAAmB,CAAC,KAAK,EAAE,OAAO,UAQ1C;AASD,iBAAS,iBAAiB,CACxB,GAAG,EAAE,iBAAiB,GAAG,IAAI,GAAG,SAAS,EACzC,SAAS,GAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAA4B,UAc5D;AAYD,iBAAS,iBAAiB,CACxB,GAAG,EAAE,iBAAiB,EACtB,GAAG,EAAE,kBAAkB,EACvB,OAAO,GAAE,uBAA4B,GACpC,WAAW,CAWb;AAED,iBAAS,mBAAmB,CAC1B,GAAG,EAAE,iBAAiB,EACtB,GAAG,EAAE,kBAAkB,EACvB,OAAO,GAAE,uBAA4B,eAMtC;AAED,iBAAS,sBAAsB,CAAC,OAAO,GAAE,uBAA4B,IAEjE,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,MAAM,MAAM,OAAO,aAKtB;AAED,iBAAS,sBAAsB,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,GAAE,uBAA4B,QAIlF;AAED,QAAA,MAAM,eAAe,4BAAsB,CAAC;AAE5C,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,sBAAsB,EACtB,iBAAiB,EACjB,eAAe,EACf,iBAAiB,GAClB,CAAC;AACF,YAAY,EAAE,uBAAuB,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { requestHeader, } from "./http.js";
|
|
2
|
+
function normalizeIntlLocale(input) {
|
|
3
|
+
const raw = String(input == null ? "" : input).trim();
|
|
4
|
+
if (!raw)
|
|
5
|
+
return "";
|
|
6
|
+
try {
|
|
7
|
+
return Intl.DateTimeFormat.supportedLocalesOf([raw])[0] || "";
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return "";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function localeWeight(entry) {
|
|
14
|
+
const match = entry.match(/(?:^|;)\s*q=([0-9.]+)/i);
|
|
15
|
+
if (!match)
|
|
16
|
+
return 1;
|
|
17
|
+
const parsed = Number(match[1]);
|
|
18
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
19
|
+
}
|
|
20
|
+
function readRequestLocale(req, normalize = normalizeIntlLocale) {
|
|
21
|
+
const raw = requestHeader(req, "accept-language");
|
|
22
|
+
if (!raw)
|
|
23
|
+
return "";
|
|
24
|
+
const entries = raw
|
|
25
|
+
.split(",")
|
|
26
|
+
.map((entry) => entry.trim())
|
|
27
|
+
.filter(Boolean)
|
|
28
|
+
.sort((left, right) => localeWeight(right) - localeWeight(left));
|
|
29
|
+
for (const entry of entries) {
|
|
30
|
+
const locale = normalize(entry.split(";")[0]);
|
|
31
|
+
if (locale)
|
|
32
|
+
return locale;
|
|
33
|
+
}
|
|
34
|
+
return "";
|
|
35
|
+
}
|
|
36
|
+
function defaultUserLocale(req, res) {
|
|
37
|
+
const viewer = req?.viewer && typeof req.viewer === "object"
|
|
38
|
+
? req.viewer
|
|
39
|
+
: res?.locals?.viewer && typeof res.locals.viewer === "object"
|
|
40
|
+
? res.locals.viewer
|
|
41
|
+
: null;
|
|
42
|
+
return viewer && typeof viewer === "object" ? viewer.locale : "";
|
|
43
|
+
}
|
|
44
|
+
function createLocaleState(req, res, options = {}) {
|
|
45
|
+
const normalize = options.normalize || normalizeIntlLocale;
|
|
46
|
+
const user = normalize(options.readUserLocale ? options.readUserLocale(req, res) : defaultUserLocale(req, res));
|
|
47
|
+
const request = readRequestLocale(req, normalize);
|
|
48
|
+
return {
|
|
49
|
+
effective: user || request || normalize(options.defaultLocale),
|
|
50
|
+
request,
|
|
51
|
+
user,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function applyLocaleToLocals(req, res, options = {}) {
|
|
55
|
+
if (!res.locals || typeof res.locals !== "object")
|
|
56
|
+
res.locals = {};
|
|
57
|
+
const state = createLocaleState(req, res, options);
|
|
58
|
+
res.locals[options.localsKey || "locale"] = state;
|
|
59
|
+
return state;
|
|
60
|
+
}
|
|
61
|
+
function createLocaleMiddleware(options = {}) {
|
|
62
|
+
return function localeMiddleware(req, res, next) {
|
|
63
|
+
applyLocaleToLocals(req, res, options);
|
|
64
|
+
return next();
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function attachLocaleMiddleware(app, options = {}) {
|
|
68
|
+
if (app && typeof app.use === "function") {
|
|
69
|
+
app.use(createLocaleMiddleware(options));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const normalizeLocale = normalizeIntlLocale;
|
|
73
|
+
export { applyLocaleToLocals, attachLocaleMiddleware, createLocaleMiddleware, createLocaleState, normalizeLocale, readRequestLocale, };
|
|
74
|
+
//# sourceMappingURL=locale.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locale.js","sourceRoot":"","sources":["../../../src/server/locale.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,GAGd,MAAM,WAAW,CAAC;AAenB,SAAS,mBAAmB,CAAC,KAAc;IACzC,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;IACtD,IAAI,CAAC,GAAG;QAAE,OAAO,EAAE,CAAC;IACpB,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,cAAc,CAAC,kBAAkB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAChE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAED,SAAS,YAAY,CAAC,KAAa;IACjC,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;IACpD,IAAI,CAAC,KAAK;QAAE,OAAO,CAAC,CAAC;IACrB,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAChC,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9C,CAAC;AAED,SAAS,iBAAiB,CACxB,GAAyC,EACzC,YAAwC,mBAAmB;IAE3D,MAAM,GAAG,GAAG,aAAa,CAAC,GAAG,EAAE,iBAAiB,CAAC,CAAC;IAClD,IAAI,CAAC,GAAG;QAAE,OAAO,EAAE,CAAC;IACpB,MAAM,OAAO,GAAG,GAAG;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ACf,iBAAiB,GAClB,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
type PageTaskFailure = {
|
|
2
|
+
details: string;
|
|
3
|
+
ok: false;
|
|
4
|
+
status: number;
|
|
5
|
+
status_code: string;
|
|
6
|
+
};
|
|
7
|
+
type PageTaskFailureContext = {
|
|
8
|
+
entityId: string;
|
|
9
|
+
message: string;
|
|
10
|
+
operation: string;
|
|
11
|
+
page: string;
|
|
12
|
+
status: number;
|
|
13
|
+
statusCode: string;
|
|
14
|
+
timeoutMs: number;
|
|
15
|
+
};
|
|
16
|
+
type PageTaskOptions<TFailure = PageTaskFailure> = {
|
|
17
|
+
entityId?: unknown;
|
|
18
|
+
fail?: (context: PageTaskFailureContext) => TFailure;
|
|
19
|
+
failureMessage?: (context: {
|
|
20
|
+
operation: string;
|
|
21
|
+
status: number;
|
|
22
|
+
statusCode: string;
|
|
23
|
+
}) => string;
|
|
24
|
+
logger?: {
|
|
25
|
+
error?: (scope: string, message: string, metadata?: Record<string, unknown>) => unknown;
|
|
26
|
+
warn?: (scope: string, message: string, metadata?: Record<string, unknown>) => unknown;
|
|
27
|
+
};
|
|
28
|
+
operation: unknown;
|
|
29
|
+
page: unknown;
|
|
30
|
+
timeoutMs?: unknown;
|
|
31
|
+
};
|
|
32
|
+
declare const DEFAULT_PAGE_TASK_TIMEOUT_MS = 15000;
|
|
33
|
+
declare function runPageTask<T, TFailure = PageTaskFailure>(task: () => Promise<T>, options: PageTaskOptions<TFailure>): Promise<T | TFailure>;
|
|
34
|
+
export { DEFAULT_PAGE_TASK_TIMEOUT_MS, runPageTask };
|
|
35
|
+
export type { PageTaskFailure, PageTaskFailureContext, PageTaskOptions };
|
|
36
|
+
//# sourceMappingURL=page-task.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-task.d.ts","sourceRoot":"","sources":["../../../src/server/page-task.ts"],"names":[],"mappings":"AAEA,KAAK,eAAe,GAAG;IACrB,OAAO,EAAE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,MAAM,OAAO,CAAC,CAAC,CAAC,EACtB,OAAO,EAAE,eAAe,CAAC,QAAQ,CAAC,GACjC,OAAO,CAAC,CAAC,GAAG,QAAQ,CAAC,CAmCvB;AAED,OAAO,EAAE,4BAA4B,EAAE,WAAW,EAAE,CAAC;AACrD,YAAY,EAAE,eAAe,EAAE,sBAAsB,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { toText } from "../../components/index.js";
|
|
2
|
+
const DEFAULT_PAGE_TASK_TIMEOUT_MS = 15000;
|
|
3
|
+
function pageTaskTimeoutMs(input) {
|
|
4
|
+
const parsed = Number(input);
|
|
5
|
+
return Math.max(1, Number.isFinite(parsed) ? Math.floor(parsed) : DEFAULT_PAGE_TASK_TIMEOUT_MS);
|
|
6
|
+
}
|
|
7
|
+
function pageTaskErrorStatus(error) {
|
|
8
|
+
const status = error && typeof error === "object" && "status" in error
|
|
9
|
+
? Number(error.status)
|
|
10
|
+
: 0;
|
|
11
|
+
return Number.isFinite(status) && status > 0 ? status : 500;
|
|
12
|
+
}
|
|
13
|
+
function pageTaskErrorCode(error, status) {
|
|
14
|
+
return (toText(error && typeof error === "object" && "status_code" in error
|
|
15
|
+
? error.status_code
|
|
16
|
+
: "") || (status === 504 ? "page-route-timeout" : "page-route-load-failed"));
|
|
17
|
+
}
|
|
18
|
+
function defaultFailureMessage(status, operation) {
|
|
19
|
+
return status === 504
|
|
20
|
+
? `Timed out while loading ${operation}.`
|
|
21
|
+
: `Failed to load ${operation}.`;
|
|
22
|
+
}
|
|
23
|
+
function pageTaskErrorMessage(error, context, options) {
|
|
24
|
+
return (toText(error && typeof error === "object" && "message" in error
|
|
25
|
+
? error.message
|
|
26
|
+
: "") ||
|
|
27
|
+
options.failureMessage?.(context) ||
|
|
28
|
+
defaultFailureMessage(context.status, context.operation));
|
|
29
|
+
}
|
|
30
|
+
function pageTaskFailure(context, options) {
|
|
31
|
+
if (options.fail)
|
|
32
|
+
return options.fail(context);
|
|
33
|
+
return {
|
|
34
|
+
details: context.message,
|
|
35
|
+
ok: false,
|
|
36
|
+
status: context.status,
|
|
37
|
+
status_code: context.statusCode,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function logPageTaskFailure(context, options) {
|
|
41
|
+
const level = context.status >= 500 && context.status !== 504 ? "error" : "warn";
|
|
42
|
+
options.logger?.[level]?.("frontend.page", "page task failed", {
|
|
43
|
+
entity_id: context.entityId,
|
|
44
|
+
message: context.message,
|
|
45
|
+
operation: context.operation,
|
|
46
|
+
page: context.page,
|
|
47
|
+
status: context.status,
|
|
48
|
+
status_code: context.statusCode,
|
|
49
|
+
timeout_ms: context.timeoutMs,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function createPageTaskTimeout(operation) {
|
|
53
|
+
const error = new Error(defaultFailureMessage(504, operation));
|
|
54
|
+
error.status = 504;
|
|
55
|
+
error.status_code = "page-route-timeout";
|
|
56
|
+
return error;
|
|
57
|
+
}
|
|
58
|
+
async function runPageTask(task, options) {
|
|
59
|
+
const operation = toText(options.operation, "page task");
|
|
60
|
+
const timeoutMs = pageTaskTimeoutMs(options.timeoutMs);
|
|
61
|
+
let timer = null;
|
|
62
|
+
try {
|
|
63
|
+
return await Promise.race([
|
|
64
|
+
Promise.resolve().then(task),
|
|
65
|
+
new Promise((_, reject) => {
|
|
66
|
+
timer = setTimeout(() => reject(createPageTaskTimeout(operation)), timeoutMs);
|
|
67
|
+
}),
|
|
68
|
+
]);
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
const status = pageTaskErrorStatus(error);
|
|
72
|
+
const statusCode = pageTaskErrorCode(error, status);
|
|
73
|
+
const context = {
|
|
74
|
+
entityId: toText(options.entityId),
|
|
75
|
+
message: pageTaskErrorMessage(error, { operation, status, statusCode }, options),
|
|
76
|
+
operation,
|
|
77
|
+
page: toText(options.page, "unknown"),
|
|
78
|
+
status,
|
|
79
|
+
statusCode,
|
|
80
|
+
timeoutMs,
|
|
81
|
+
};
|
|
82
|
+
logPageTaskFailure(context, options);
|
|
83
|
+
return pageTaskFailure(context, options);
|
|
84
|
+
}
|
|
85
|
+
finally {
|
|
86
|
+
if (timer)
|
|
87
|
+
clearTimeout(timer);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
export { DEFAULT_PAGE_TASK_TIMEOUT_MS, runPageTask };
|
|
91
|
+
//# sourceMappingURL=page-task.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-task.js","sourceRoot":"","sources":["../../../src/server/page-task.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAoCvC,MAAM,4BAA4B,GAAG,KAAK,CAAC;AAE3C,SAAS,iBAAiB,CAAC,KAAc;IACvC,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC7B,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,4BAA4B,CAAC,CAAC;AAClG,CAAC;AAED,SAAS,mBAAmB,CAAC,KAAc;IACzC,MAAM,MAAM,GACZ,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,QAAQ,IAAG,KAAK;QACtD,CAAC,CAAC,MAAM,CAAE,KAAa,CAAC,MAAM,CAAC;QAC/B,CAAC,CAAC,CAAC,CAAC;IACJ,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC;AAC9D,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAc,EAAE,MAAc;IACvD,OAAO,CACL,MAAM,CACJ,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,aAAa,IAAG,KAAK;QAC3D,C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AAC,CAAC;QAC1C,MAAM,UAAU,GAAG,iBAAiB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACpD,MAAM,OAAO,GAAG;YACd,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC;YAClC,OAAO,EAAE,oBAAoB,CAC3B,KAAK,EACL,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,EACjC,OAAO,CACR;YACD,SAAS;YACT,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC;YACrC,MAAM;YACN,UAAU;YACV,SAAS;SACV,CAAC;QACF,kBAAkB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACrC,OAAO,eAAe,CAAC,OAAO,EAAE,OAAO,CAAa,CAAC;IACvD,CAAC;YAAS,CAAC;QACT,IAAI,KAAK;YAAE,YAAY,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;AACH,CAAC;AAED,OAAO,EAAE,4BAA4B,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type ServerResponseLike } from "../../../server/http.d.ts";
|
|
2
|
+
import type { FrontendDocumentContext, FrontendReactRendererOptions, FrontendRenderShell } from "../../../server/react/types.d.ts";
|
|
3
|
+
declare function defaultNormalizePageId(pageId: unknown): string;
|
|
4
|
+
declare function applyScriptNonce(html: string, nonce: unknown): string;
|
|
5
|
+
declare function countHtmlTags(html: string, tagName: string): number;
|
|
6
|
+
declare function readResponseRequestRoute(res: ServerResponseLike | null | undefined): string;
|
|
7
|
+
declare function buildDocumentContext(res: ServerResponseLike, pageId: string, componentId: string, props: Record<string, unknown>, options: FrontendReactRendererOptions, shellInput?: FrontendRenderShell): FrontendDocumentContext;
|
|
8
|
+
declare function rootDocumentProps(body: unknown, context: FrontendDocumentContext, options: FrontendReactRendererOptions): {
|
|
9
|
+
body: unknown;
|
|
10
|
+
cssLinks: string;
|
|
11
|
+
csrfToken: string;
|
|
12
|
+
currentUrl: string;
|
|
13
|
+
faviconHref: string;
|
|
14
|
+
fontPreloadLinks: string;
|
|
15
|
+
jsLinks: string;
|
|
16
|
+
lang: string;
|
|
17
|
+
nonce: string;
|
|
18
|
+
pageId: string;
|
|
19
|
+
pageTitle: string;
|
|
20
|
+
seo: Record<string, unknown>;
|
|
21
|
+
shell: FrontendRenderShell;
|
|
22
|
+
theme: string;
|
|
23
|
+
themeKey: string;
|
|
24
|
+
title: string;
|
|
25
|
+
viewerId: string;
|
|
26
|
+
};
|
|
27
|
+
declare function logDocumentStart(context: FrontendDocumentContext, res: ServerResponseLike, options: FrontendReactRendererOptions): void;
|
|
28
|
+
export { applyScriptNonce, buildDocumentContext, countHtmlTags, defaultNormalizePageId, logDocumentStart, readResponseRequestRoute, rootDocumentProps, };
|
|
29
|
+
//# sourceMappingURL=document.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../../../../src/server/react/document.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,kBAAkB,EACxB,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,EACV,uBAAuB,EACvB,4BAA4B,EAC5B,mBAAmB,EACpB,MAAM,eAAe,CAAC;AAEvB,iBAAS,sBAAsB,CAAC,MAAM,EAAE,OAAO,UAY9C;AAED,iBAAS,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,UAQrD;AAED,iBAAS,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,UAInD;AAED,iBAAS,wBAAwB,CAAC,GAAG,EAAE,kBAAkB,GAAG,IAAI,GAAG,SAAS,UAG3E;AAwCD,iBAAS,oBAAoB,CAC3B,GAAG,EAAE,kBAAkB,EACvB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,OAAO,EAAE,4BAA4B,EACrC,UAAU,CAAC,EAAE,mBAAmB,GAC/B,uBAAuB,CAoBzB;AAkBD,iBAAS,iBAAiB,CACxB,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,uBAAuB,EAChC,OAAO,EAAE,4BAA4B;;;;;;;;;;;;;;;;;;EAqBtC;AAED,iBAAS,gBAAgB,CACvB,OAAO,EAAE,uBAAuB,EAChC,GAAG,EAAE,kBAAkB,EACvB,OAAO,EAAE,4BAA4B,QActC;AAED,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,aAAa,EACb,sBAAsB,EACtB,gBAAgB,EAChB,wBAAwB,EACxB,iBAAiB,GAClB,CAAC"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { escapeHtml, toText } from "../../../components/index.js";
|
|
2
|
+
import { serverObject, } from "../../../server/http.js";
|
|
3
|
+
import { buildReactRenderShell } from "../../../server/react/shell.js";
|
|
4
|
+
function defaultNormalizePageId(pageId) {
|
|
5
|
+
const normalized = toText(pageId)
|
|
6
|
+
.replace(/\\/g, "/")
|
|
7
|
+
.replace(/^\/+|\/+$/g, "");
|
|
8
|
+
if (!normalized)
|
|
9
|
+
return "";
|
|
10
|
+
const parts = normalized.split("/").filter(Boolean);
|
|
11
|
+
for (const part of parts) {
|
|
12
|
+
if (!part || part === "." || part === "..") {
|
|
13
|
+
throw new Error(`Invalid React page id: ${toText(pageId)}`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return parts.join("/");
|
|
17
|
+
}
|
|
18
|
+
function applyScriptNonce(html, nonce) {
|
|
19
|
+
const nextNonce = toText(nonce);
|
|
20
|
+
if (!nextNonce)
|
|
21
|
+
return String(html || "");
|
|
22
|
+
const escaped = escapeHtml(nextNonce);
|
|
23
|
+
return String(html || "").replace(/<script\b(?![^>]*\bnonce\s*=)([^>]*)>/gi, (_match, attrs) => `<script nonce="${escaped}"${String(attrs || "")}>`);
|
|
24
|
+
}
|
|
25
|
+
function countHtmlTags(html, tagName) {
|
|
26
|
+
const normalizedTag = toText(tagName).toLowerCase();
|
|
27
|
+
if (!normalizedTag)
|
|
28
|
+
return 0;
|
|
29
|
+
return String(html || "").match(new RegExp(`<${normalizedTag}\\b`, "gi"))?.length || 0;
|
|
30
|
+
}
|
|
31
|
+
function readResponseRequestRoute(res) {
|
|
32
|
+
const request = res?.req || null;
|
|
33
|
+
return toText(request?.originalUrl || request?.url || request?.path, "/");
|
|
34
|
+
}
|
|
35
|
+
function documentEntries(pageId, componentId, normalizePageId) {
|
|
36
|
+
const normalizedPageId = normalizePageId(pageId);
|
|
37
|
+
const normalizedComponentId = normalizePageId(componentId);
|
|
38
|
+
return {
|
|
39
|
+
componentId: normalizedComponentId,
|
|
40
|
+
entryIds: normalizedComponentId !== normalizedPageId
|
|
41
|
+
? [normalizedPageId, normalizedComponentId]
|
|
42
|
+
: [normalizedPageId],
|
|
43
|
+
pageId: normalizedPageId,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function fallbackPageTitle(pageId) {
|
|
47
|
+
return (pageId
|
|
48
|
+
.split("/")
|
|
49
|
+
.filter(Boolean)
|
|
50
|
+
.pop()
|
|
51
|
+
?.replace(/[-_]+/g, " ") || "Page");
|
|
52
|
+
}
|
|
53
|
+
function pageTitleForContext(context, options) {
|
|
54
|
+
return (toText(context.seo.title) ||
|
|
55
|
+
toText(options.resolvePageTitle?.(context)) ||
|
|
56
|
+
fallbackPageTitle(context.pageId));
|
|
57
|
+
}
|
|
58
|
+
function buildDocumentContext(res, pageId, componentId, props, options, shellInput) {
|
|
59
|
+
const normalize = options.normalizePageId || defaultNormalizePageId;
|
|
60
|
+
const entries = documentEntries(pageId, componentId, normalize);
|
|
61
|
+
const shell = buildReactRenderShell(res, props, options, shellInput);
|
|
62
|
+
const links = options.buildAssetLinks(entries.entryIds);
|
|
63
|
+
const context = {
|
|
64
|
+
...entries,
|
|
65
|
+
currentUrl: readResponseRequestRoute(res),
|
|
66
|
+
cssLinks: toText(links.cssLinks),
|
|
67
|
+
fontPreloadLinks: toText(links.fontPreloadLinks),
|
|
68
|
+
jsLinks: toText(links.jsLinks),
|
|
69
|
+
locale: serverObject(shell.locale),
|
|
70
|
+
pageTitle: "",
|
|
71
|
+
security: serverObject(shell.security),
|
|
72
|
+
seo: serverObject(shell.seo),
|
|
73
|
+
shell,
|
|
74
|
+
ui: serverObject(shell.ui),
|
|
75
|
+
};
|
|
76
|
+
context.pageTitle = pageTitleForContext(context, options);
|
|
77
|
+
return context;
|
|
78
|
+
}
|
|
79
|
+
function documentTitleForContext(context, options) {
|
|
80
|
+
return toText(options.resolveTitle?.(context), context.pageTitle);
|
|
81
|
+
}
|
|
82
|
+
function faviconHrefForContext(context, options) {
|
|
83
|
+
return typeof options.faviconHref === "function"
|
|
84
|
+
? options.faviconHref(context)
|
|
85
|
+
: toText(options.faviconHref, "/favicon.svg");
|
|
86
|
+
}
|
|
87
|
+
function rootDocumentProps(body, context, options) {
|
|
88
|
+
return {
|
|
89
|
+
body,
|
|
90
|
+
cssLinks: context.cssLinks,
|
|
91
|
+
csrfToken: toText(context.security.csrfToken),
|
|
92
|
+
currentUrl: context.currentUrl,
|
|
93
|
+
faviconHref: faviconHrefForContext(context, options),
|
|
94
|
+
fontPreloadLinks: context.fontPreloadLinks,
|
|
95
|
+
jsLinks: context.jsLinks,
|
|
96
|
+
lang: toText(context.shell.lang || context.locale.effective, options.defaultLang || "en"),
|
|
97
|
+
nonce: toText(context.shell.nonce),
|
|
98
|
+
pageId: context.pageId,
|
|
99
|
+
pageTitle: context.pageTitle,
|
|
100
|
+
seo: context.seo,
|
|
101
|
+
shell: context.shell,
|
|
102
|
+
theme: toText(context.shell.theme),
|
|
103
|
+
themeKey: toText(context.shell.theme || context.ui.theme, options.defaultTheme || "dark"),
|
|
104
|
+
title: documentTitleForContext(context, options),
|
|
105
|
+
viewerId: toText(context.shell.viewer?.id),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function logDocumentStart(context, res, options) {
|
|
109
|
+
options.log?.info?.("rendering react document", {
|
|
110
|
+
component_id: context.componentId,
|
|
111
|
+
css_link_count: countHtmlTags(context.cssLinks, "link"),
|
|
112
|
+
js_link_count: countHtmlTags(context.jsLinks, "script"),
|
|
113
|
+
locale: toText(context.locale.effective),
|
|
114
|
+
method: toText(res?.req?.method),
|
|
115
|
+
page_id: context.pageId,
|
|
116
|
+
route: context.currentUrl,
|
|
117
|
+
status: Number(res?.statusCode) || 200,
|
|
118
|
+
theme: toText(context.shell.theme || context.ui.theme),
|
|
119
|
+
viewer_id: toText(context.shell.viewer?.id),
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
export { applyScriptNonce, buildDocumentContext, countHtmlTags, defaultNormalizePageId, logDocumentStart, readResponseRequestRoute, rootDocumentProps, };
|
|
123
|
+
//# sourceMappingURL=document.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document.js","sourceRoot":"","sources":["../../../../src/server/react/document.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EACL,YAAY,GAEb,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAOtD,SAAS,sBAAsB,CAAC,MAAe;IAC7C,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC;SAChC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;SACnB,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;IAC3B,IAAI,CAAC,UAAU;QAAE,OAAO,EAAE,CAAC;IAC3B,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACpD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,IAAI,IAAI,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YAC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W,EAAE,GAAG,EAAE,MAAM,CAAC;QACzC,OAAO,EAAE,OAAO,CAAC,MAAM;QACvB,KAAK,EAAE,OAAO,CAAC,UAAU;QACzB,MAAM,EAAE,MAAM,CAAE,GAAW,EAAE,UAAU,CAAC,IAAI,GAAG;QAC/C,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,IAAI,OAAO,CAAC,EAAE,CAAC,KAAK,CAAC;QACtD,SAAS,EAAE,MAAM,CAAE,OAAO,CAAC,KAAK,CAAC,MAAc,EAAE,EAAE,CAAC;KACvD,CAAC,CAAC;AACL,CAAC;AAED,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,aAAa,EACb,sBAAsB,EACtB,gBAAgB,EAChB,wBAAwB,EACxB,iBAAiB,GAClB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { defaultNormalizePageId } from "../../../server/react/document.d.ts";
|
|
2
|
+
import { buildReactRenderShell } from "../../../server/react/shell.d.ts";
|
|
3
|
+
import type { FrontendReactRendererOptions, FrontendRenderShell, RenderReactPageOptions } from "../../../server/react/types.d.ts";
|
|
4
|
+
import type { ServerResponseLike } from "../../../server/http.d.ts";
|
|
5
|
+
declare function sendDocument(res: ServerResponseLike, pageId: string, body: unknown, componentId: string, props: Record<string, unknown>, options: FrontendReactRendererOptions, shellInput?: FrontendRenderShell): unknown;
|
|
6
|
+
declare function renderPage(res: ServerResponseLike, pageId: string, propsInput: Record<string, unknown>, options: FrontendReactRendererOptions, renderOptions?: RenderReactPageOptions): unknown;
|
|
7
|
+
declare function createFrontendReactRenderer(options: FrontendReactRendererOptions): {
|
|
8
|
+
buildShell: typeof buildReactRenderShell;
|
|
9
|
+
renderFragment: (component: any, props: Record<string, unknown>) => string;
|
|
10
|
+
renderPage: (res: ServerResponseLike, pageId: string, props: Record<string, unknown>, renderOptions?: RenderReactPageOptions) => unknown;
|
|
11
|
+
sendDocument: (res: ServerResponseLike, pageId: string, body: unknown, componentId: string, props: Record<string, unknown>, shellInput?: FrontendRenderShell) => unknown;
|
|
12
|
+
};
|
|
13
|
+
export { buildReactRenderShell, createFrontendReactRenderer, defaultNormalizePageId, renderPage as renderFrontendReactPage, sendDocument as sendFrontendReactDocument, };
|
|
14
|
+
export type { FrontendAssetLinkSet, FrontendDocumentContext, FrontendReactRendererOptions, FrontendRenderShell, RenderReactPageOptions, } from "../../../server/react/types.d.ts";
|
|
15
|
+
//# sourceMappingURL=render.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../../../src/server/react/render.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,sBAAsB,EAGvB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,qBAAqB,EACtB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EACV,4BAA4B,EAC5B,mBAAmB,EACnB,sBAAsB,EACvB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAsDxD,iBAAS,YAAY,CACnB,GAAG,EAAE,kBAAkB,EACvB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,EACb,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,OAAO,EAAE,4BAA4B,EACrC,UAAU,CAAC,EAAE,mBAAmB,WAgBjC;AAED,iBAAS,UAAU,CACjB,GAAG,EAAE,kBAAkB,EACvB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnC,OAAO,EAAE,4BAA4B,EACrC,aAAa,GAAE,sBAA2B,WAiB3C;AAED,iBAAS,2BAA2B,CAAC,OAAO,EAAE,4BAA4B;;gCAG1C,GAAG,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;sBAGxD,kBAAkB,UACf,MAAM,SACP,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,kBACf,sBAAsB;wBAGhC,kBAAkB,UACf,MAAM,QACR,OAAO,eACA,MAAM,SACZ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,eACjB,mBAAmB;EAGrC;AAED,OAAO,EACL,qBAAqB,EACrB,2BAA2B,EAC3B,sBAAsB,EACtB,UAAU,IAAI,uBAAuB,EACrC,YAAY,IAAI,yBAAyB,GAC1C,CAAC;AACF,YAAY,EACV,oBAAoB,EACpB,uBAAuB,EACvB,4BAA4B,EAC5B,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { withIconServerRenderer } from "../../../icons/server-context.js";
|
|
2
|
+
import { applyScriptNonce, buildDocumentContext, defaultNormalizePageId, logDocumentStart, rootDocumentProps, } from "../../../server/react/document.js";
|
|
3
|
+
import { buildReactRenderShell, } from "../../../server/react/shell.js";
|
|
4
|
+
function renderWithIcons(render, iconRenderer) {
|
|
5
|
+
return withIconServerRenderer(iconRenderer, render);
|
|
6
|
+
}
|
|
7
|
+
function timedRender(render, options) {
|
|
8
|
+
const startedAt = performance.now();
|
|
9
|
+
try {
|
|
10
|
+
return render();
|
|
11
|
+
}
|
|
12
|
+
finally {
|
|
13
|
+
options.recordRender?.(Math.max(0, performance.now() - startedAt));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function renderBody(componentId, props, options) {
|
|
17
|
+
return options.createElement(options.resolvePageComponent(componentId), props);
|
|
18
|
+
}
|
|
19
|
+
function renderFragment(component, props, options) {
|
|
20
|
+
if (!options.renderToStaticMarkup) {
|
|
21
|
+
throw new Error("React static markup renderer is not configured.");
|
|
22
|
+
}
|
|
23
|
+
return timedRender(() => renderWithIcons(() => options.renderToStaticMarkup(options.createElement(component, props)), options.createIconRenderer?.()), options);
|
|
24
|
+
}
|
|
25
|
+
function withAutoPageLang(res, propsInput) {
|
|
26
|
+
const props = propsInput && typeof propsInput === "object" ? propsInput : {};
|
|
27
|
+
if ("lang" in props)
|
|
28
|
+
return props;
|
|
29
|
+
const lang = res?.locals && typeof res.locals === "object" ? res.locals.lang : undefined;
|
|
30
|
+
return lang ? { ...props, lang } : props;
|
|
31
|
+
}
|
|
32
|
+
function sendDocument(res, pageId, body, componentId, props, options, shellInput) {
|
|
33
|
+
const context = buildDocumentContext(res, pageId, componentId, props, options, shellInput);
|
|
34
|
+
const root = options.resolveRootDocument();
|
|
35
|
+
logDocumentStart(context, res, options);
|
|
36
|
+
const html = timedRender(() => renderWithIcons(() => options.renderToString(options.createElement(root, rootDocumentProps(body, context, options))), options.createIconRenderer?.()), options);
|
|
37
|
+
if (typeof res.type === "function")
|
|
38
|
+
res.type("html");
|
|
39
|
+
return res.send?.(`<!DOCTYPE html>${applyScriptNonce(html, context.shell.nonce)}`);
|
|
40
|
+
}
|
|
41
|
+
function renderPage(res, pageId, propsInput, options, renderOptions = {}) {
|
|
42
|
+
const normalizePageId = options.normalizePageId || defaultNormalizePageId;
|
|
43
|
+
const normalizedPageId = normalizePageId(pageId);
|
|
44
|
+
const componentId = normalizePageId(renderOptions.componentId || normalizedPageId);
|
|
45
|
+
const props = withAutoPageLang(res, propsInput);
|
|
46
|
+
if (!res.locals || typeof res.locals !== "object")
|
|
47
|
+
res.locals = {};
|
|
48
|
+
res.locals.reactPageProps = props;
|
|
49
|
+
return sendDocument(res, normalizedPageId, renderBody(componentId, props, options), componentId, props, options, renderOptions.shell);
|
|
50
|
+
}
|
|
51
|
+
function createFrontendReactRenderer(options) {
|
|
52
|
+
return {
|
|
53
|
+
buildShell: buildReactRenderShell,
|
|
54
|
+
renderFragment: (component, props) => renderFragment(component, props, options),
|
|
55
|
+
renderPage: (res, pageId, props, renderOptions = {}) => renderPage(res, pageId, props, options, renderOptions),
|
|
56
|
+
sendDocument: (res, pageId, body, componentId, props, shellInput) => sendDocument(res, pageId, body, componentId, props, options, shellInput),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export { buildReactRenderShell, createFrontendReactRenderer, defaultNormalizePageId, renderPage as renderFrontendReactPage, sendDocument as sendFrontendReactDocument, };
|
|
60
|
+
//# sourceMappingURL=render.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.js","sourceRoot":"","sources":["../../../../src/server/react/render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,sBAAsB,EACtB,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,qBAAqB,GACtB,MAAM,eAAe,CAAC;AAQvB,SAAS,eAAe,CACtB,MAAoB,EACpB,YAAsD;IAEtD,OAAO,sBAAsB,CAAC,YAAmB,EAAE,MAAM,CAAC,CAAC;AAC7D,CAAC;AAED,SAAS,WAAW,CAAC,MAAoB,EAAE,OAAqC;IAC9E,MAAM,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IACpC,IAAI,CAAC;QACH,OAAO,MAAM,EAAE,CAAC;IAClB,CAAC;YAAS,CAAC;QACT,OAAO,CAAC,YAAY,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC,CAAC,CAAC;IACrE,CAAC;AACH,CAAC;AAED,SAAS,UAAU,CACjB,WAAmB,EACnB,KAA8B,EAC9B,OAAqC;IAErC,OAAO,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,oBAAoB,CAAC,WAAW,CAAC,EAAE,KAAK,CAAC,CAAC;AACjF,CAAC;AAED,SAAS,cAAc,CACrB,SAAc,EACd,KAA8B,EAC9B,OAAqC;IAErC,IAAI,CAAC,OAAO,CAAC,oBAAoB,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IACrE,CAAC;IACD,OAAO,WAAW,CAChB,GAAG,EAAE,CAAC,eA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,EACvB,MAAc,EACd,KAA8B,EAC9B,gBAAwC,EAAE,EAC1C,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,aAAa,CAAC;QAC3D,YAAY,EAAE,CACZ,GAAuB,EACvB,MAAc,EACd,IAAa,EACb,WAAmB,EACnB,KAA8B,EAC9B,UAAgC,EAChC,EAAE,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,CAAC;KAC9E,CAAC;AACJ,CAAC;AAED,OAAO,EACL,qBAAqB,EACrB,2BAA2B,EAC3B,sBAAsB,EACtB,UAAU,IAAI,uBAAuB,EACrC,YAAY,IAAI,yBAAyB,GAC1C,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ServerResponseLike } from "../../../server/http.d.ts";
|
|
2
|
+
import type { FrontendReactRendererOptions, FrontendRenderShell } from "../../../server/react/types.d.ts";
|
|
3
|
+
declare function objectWithFallback(value: unknown, fallback: unknown): Record<string, unknown>;
|
|
4
|
+
declare function readDefaultUi(options: FrontendReactRendererOptions): Record<string, unknown>;
|
|
5
|
+
declare function buildReactRenderShell(res: ServerResponseLike, props: Record<string, unknown>, options: FrontendReactRendererOptions, shellInput?: FrontendRenderShell): FrontendRenderShell;
|
|
6
|
+
export { buildReactRenderShell, objectWithFallback, readDefaultUi };
|
|
7
|
+
//# sourceMappingURL=shell.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell.d.ts","sourceRoot":"","sources":["../../../../src/server/react/shell.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,KAAK,kBAAkB,EACxB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EACV,4BAA4B,EAC5B,mBAAmB,EACpB,MAAM,eAAe,CAAC;AAEvB,iBAAS,kBAAkB,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,2BAG5D;AAED,iBAAS,aAAa,CAAC,OAAO,EAAE,4BAA4B,2BAI3D;AA8BD,iBAAS,qBAAqB,CAC5B,GAAG,EAAE,kBAAkB,EACvB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,OAAO,EAAE,4BAA4B,EACrC,UAAU,CAAC,EAAE,mBAAmB,GAC/B,mBAAmB,CAqBrB;AAED,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,aAAa,EAAE,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { toText } from "../../../components/index.js";
|
|
2
|
+
import { defaultNavigationState, } from "../../../server/navigation.js";
|
|
3
|
+
import { serverObject, } from "../../../server/http.js";
|
|
4
|
+
function objectWithFallback(value, fallback) {
|
|
5
|
+
const object = serverObject(value);
|
|
6
|
+
return Object.keys(object).length ? object : serverObject(fallback);
|
|
7
|
+
}
|
|
8
|
+
function readDefaultUi(options) {
|
|
9
|
+
return typeof options.defaultUi === "function"
|
|
10
|
+
? options.defaultUi()
|
|
11
|
+
: options.defaultUi || {};
|
|
12
|
+
}
|
|
13
|
+
function shellPageProps(shellInput, props) {
|
|
14
|
+
return objectWithFallback(shellInput?.pageProps, props);
|
|
15
|
+
}
|
|
16
|
+
function shellSecurity(locals, shellInput, nonce) {
|
|
17
|
+
return objectWithFallback(shellInput?.security, {
|
|
18
|
+
csrfToken: locals.csrfToken ?? null,
|
|
19
|
+
nonce,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function shellPermissionState(res, options, shellInput) {
|
|
23
|
+
return shellInput?.permissionState && typeof shellInput.permissionState === "object"
|
|
24
|
+
? shellInput.permissionState
|
|
25
|
+
: options.buildPermissionState?.({ res, shellInput }) || {};
|
|
26
|
+
}
|
|
27
|
+
function buildReactRenderShell(res, props, options, shellInput) {
|
|
28
|
+
const locals = serverObject(res?.locals);
|
|
29
|
+
const nonce = typeof shellInput?.nonce === "string" ? shellInput.nonce : toText(locals.nonce);
|
|
30
|
+
return {
|
|
31
|
+
dev: objectWithFallback(shellInput?.dev, options.dev || {}),
|
|
32
|
+
lang: typeof shellInput?.lang === "string" ? shellInput.lang : toText(locals.lang, options.defaultLang || "en"),
|
|
33
|
+
locale: objectWithFallback(shellInput?.locale, locals.locale),
|
|
34
|
+
navigation: objectWithFallback(shellInput?.navigation, locals.navigation || defaultNavigationState),
|
|
35
|
+
nonce,
|
|
36
|
+
pageProps: shellPageProps(shellInput, props),
|
|
37
|
+
permissionState: shellPermissionState(res, options, shellInput),
|
|
38
|
+
product: objectWithFallback(shellInput?.product, options.product || {}),
|
|
39
|
+
renderMode: objectWithFallback(shellInput?.renderMode, locals.renderMode),
|
|
40
|
+
requirePermission: objectWithFallback(shellInput?.requirePermission, locals.requirePermission),
|
|
41
|
+
security: shellSecurity(locals, shellInput, nonce),
|
|
42
|
+
seo: objectWithFallback(shellInput?.seo, locals.seo),
|
|
43
|
+
theme: typeof shellInput?.theme === "string" ? shellInput.theme : toText(locals.theme),
|
|
44
|
+
ui: objectWithFallback(shellInput?.ui, locals.ui || readDefaultUi(options)),
|
|
45
|
+
viewer: shellInput?.viewer || serverObject(locals.viewer) || null,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export { buildReactRenderShell, objectWithFallback, readDefaultUi };
|
|
49
|
+
//# sourceMappingURL=shell.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell.js","sourceRoot":"","sources":["../../../../src/server/react/shell.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EACL,sBAAsB,GACvB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,YAAY,GAEb,MAAM,eAAe,CAAC;AAMvB,SAAS,kBAAkB,CAAC,KAAc,EAAE,QAAiB;IAC3D,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;IACnC,OAAO,MAAM,CAAC,IAAI,C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