@_tc/template-core 0.4.0 → 0.4.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.
Files changed (297) hide show
  1. package/.skills/tc-component-usage-skills/reference/component-api.md +27 -0
  2. package/.skills/tc-generator/SKILL.md +1 -1
  3. package/.skills/tc-generator/reference/project-template/ssr/apps/hello/hello.entry.tsx +6 -1
  4. package/.skills/tc-generator/reference/runtime-extensions.md +10 -0
  5. package/AGENT_README.md +8 -2
  6. package/CHANGE.md +27 -0
  7. package/README.md +157 -8
  8. package/cjs/app/ai/agent/agent-scanner.service.js +1 -1
  9. package/cjs/app/ai/agent/agent.module.js +1 -1
  10. package/cjs/app/ai/ai-config.module.js +1 -1
  11. package/cjs/app/ai/ai-config.service.js +1 -1
  12. package/cjs/app/ai/ai.controller.js +1 -1
  13. package/cjs/app/ai/ai.module.js +1 -1
  14. package/cjs/app/ai/guardrail/guardrail.module.js +1 -1
  15. package/cjs/app/ai/guardrail/guardrail.service.js +1 -1
  16. package/cjs/app/ai/index.js +1 -0
  17. package/cjs/app/ai/mcp/internal/read-sse-response.js +2 -0
  18. package/cjs/app/ai/mcp/internal/stdio-process.js +1 -0
  19. package/cjs/app/ai/mcp/mcp-registry.service.js +2 -2
  20. package/cjs/app/ai/mcp/mcp.client.js +2 -3
  21. package/cjs/app/ai/mcp/mcp.loader.js +1 -1
  22. package/cjs/app/ai/mcp/mcp.module.js +1 -1
  23. package/cjs/app/ai/memory/checkpoint.service.js +1 -1
  24. package/cjs/app/ai/memory/memory.module.js +1 -1
  25. package/cjs/app/ai/memory/thread.service.js +1 -1
  26. package/cjs/app/ai/models/chat-sse.js +4 -0
  27. package/cjs/app/ai/models/chat.js +1 -0
  28. package/cjs/app/ai/models/http.js +1 -0
  29. package/cjs/app/ai/models/image.js +1 -0
  30. package/cjs/app/ai/models/video.js +1 -0
  31. package/cjs/app/ai/nest-service-provider.js +1 -0
  32. package/cjs/app/ai/rag/rag.module.js +1 -1
  33. package/cjs/app/ai/rag/retriever.service.js +1 -1
  34. package/cjs/app/ai/retention/conversation-retention.service.js +1 -1
  35. package/cjs/app/ai/runtime/ai-runtime-startup.validator.js +1 -1
  36. package/cjs/app/ai/runtime/ai-runtime.js +1 -0
  37. package/cjs/app/ai/runtime/internal/context-compaction.service.js +3 -3
  38. package/cjs/app/ai/runtime/internal/declaration-snapshot.js +1 -0
  39. package/cjs/app/ai/runtime/internal/owned-runtime-resources.js +1 -0
  40. package/cjs/app/ai/runtime/langchain/langchain-planner.service.js +1 -1
  41. package/cjs/app/ai/runtime/langgraph/langgraph-orchestrator.service.js +1 -1
  42. package/cjs/app/ai/runtime/runtime.module.js +1 -1
  43. package/cjs/app/ai/skill/skill-scanner.service.js +1 -1
  44. package/cjs/app/ai/skill/skill.module.js +1 -1
  45. package/cjs/app/ai/snapshot-data.js +1 -0
  46. package/cjs/app/ai/store/internal/create-vector-store.js +1 -0
  47. package/cjs/app/ai/store/store.module.js +1 -1
  48. package/cjs/app/ai/tool/builtin/index.js +1 -1
  49. package/cjs/app/ai/tool/builtin/invoke-agent.tool.js +1 -1
  50. package/cjs/app/ai/tool/builtin/retrieve.tool.js +1 -1
  51. package/cjs/app/ai/tool/executor.service.js +1 -1
  52. package/cjs/app/ai/tool/tool-registry.service.js +1 -1
  53. package/cjs/app/ai/tool/tool.module.js +1 -1
  54. package/cjs/app/ai/trace/trace.service.js +1 -1
  55. package/cjs/app/csr/controller.js +1 -1
  56. package/cjs/app/csr/types.js +0 -0
  57. package/cjs/app/html/browser-options.js +1 -1
  58. package/cjs/app/html/shell.js +31 -16
  59. package/cjs/app/http/api-signing.js +1 -0
  60. package/cjs/app/http/body-parser.middleware.js +1 -1
  61. package/cjs/app/http/csp-nonce.js +1 -0
  62. package/cjs/app/http/error-response.js +1 -1
  63. package/cjs/app/http/exception-filter.js +1 -1
  64. package/cjs/app/http/request-body-parser-policy.js +1 -0
  65. package/cjs/app/http/security.guard.js +1 -1
  66. package/cjs/app/project/controller.js +1 -1
  67. package/cjs/app/project/service.js +1 -1
  68. package/cjs/app/providers/foundation.js +1 -1
  69. package/cjs/app/ssr/artifacts.js +1 -1
  70. package/cjs/app/ssr/controller.js +1 -1
  71. package/cjs/app/ssr/html.js +17 -17
  72. package/cjs/app/ssr/stream.js +1 -1
  73. package/cjs/app/static-assets.middleware.js +1 -1
  74. package/cjs/app/template-core.module.js +1 -1
  75. package/cjs/app/view/entry.tpl +2 -2
  76. package/cjs/bundler/buildSSR.js +1 -1
  77. package/cjs/bundler/entryCollect.js +1 -1
  78. package/cjs/bundler/feSharedConfig.js +1 -1
  79. package/cjs/bundler/utils.js +3 -3
  80. package/cjs/config/config.default.js +1 -1
  81. package/cjs/packages/common/index.js +1 -1
  82. package/cjs/packages/core/bootstrap.js +1 -1
  83. package/cjs/packages/core/startup.js +1 -1
  84. package/esm/app/ai/agent/agent-scanner.service.js +33 -36
  85. package/esm/app/ai/agent/agent.module.js +9 -7
  86. package/esm/app/ai/ai-config.module.js +14 -7
  87. package/esm/app/ai/ai-config.service.js +24 -20
  88. package/esm/app/ai/ai.controller.js +41 -41
  89. package/esm/app/ai/ai.module.js +15 -15
  90. package/esm/app/ai/guardrail/guardrail.module.js +11 -9
  91. package/esm/app/ai/guardrail/guardrail.service.js +5 -10
  92. package/esm/app/ai/index.js +2 -0
  93. package/esm/app/ai/mcp/internal/read-sse-response.js +35 -0
  94. package/esm/app/ai/mcp/internal/stdio-process.js +59 -0
  95. package/esm/app/ai/mcp/mcp-registry.service.js +10 -15
  96. package/esm/app/ai/mcp/mcp.client.js +77 -78
  97. package/esm/app/ai/mcp/mcp.loader.js +64 -42
  98. package/esm/app/ai/mcp/mcp.module.js +62 -22
  99. package/esm/app/ai/memory/checkpoint.service.js +18 -28
  100. package/esm/app/ai/memory/memory.module.js +15 -12
  101. package/esm/app/ai/memory/thread.service.js +21 -26
  102. package/esm/app/ai/models/chat-sse.js +44 -0
  103. package/esm/app/ai/models/chat.js +60 -0
  104. package/esm/app/ai/models/http.js +52 -0
  105. package/esm/app/ai/models/image.js +37 -0
  106. package/esm/app/ai/models/video.js +32 -0
  107. package/esm/app/ai/nest-service-provider.js +10 -0
  108. package/esm/app/ai/rag/rag.module.js +24 -15
  109. package/esm/app/ai/rag/retriever.service.js +37 -54
  110. package/esm/app/ai/retention/conversation-retention.service.js +16 -34
  111. package/esm/app/ai/runtime/ai-runtime-startup.validator.js +2 -19
  112. package/esm/app/ai/runtime/ai-runtime.js +104 -0
  113. package/esm/app/ai/runtime/internal/context-compaction.service.js +139 -145
  114. package/esm/app/ai/runtime/internal/declaration-snapshot.js +32 -0
  115. package/esm/app/ai/runtime/internal/owned-runtime-resources.js +21 -0
  116. package/esm/app/ai/runtime/langchain/langchain-planner.service.js +43 -49
  117. package/esm/app/ai/runtime/langgraph/langgraph-orchestrator.service.js +273 -225
  118. package/esm/app/ai/runtime/runtime.module.js +56 -35
  119. package/esm/app/ai/skill/skill-scanner.service.js +11 -16
  120. package/esm/app/ai/skill/skill.module.js +11 -9
  121. package/esm/app/ai/snapshot-data.js +24 -0
  122. package/esm/app/ai/store/internal/create-vector-store.js +10 -0
  123. package/esm/app/ai/store/store.module.js +9 -13
  124. package/esm/app/ai/tool/builtin/index.js +16 -4
  125. package/esm/app/ai/tool/builtin/invoke-agent.tool.js +30 -34
  126. package/esm/app/ai/tool/builtin/retrieve.tool.js +9 -13
  127. package/esm/app/ai/tool/executor.service.js +22 -29
  128. package/esm/app/ai/tool/tool-registry.service.js +6 -16
  129. package/esm/app/ai/tool/tool.module.js +26 -12
  130. package/esm/app/ai/trace/trace.service.js +15 -28
  131. package/esm/app/csr/controller.js +114 -63
  132. package/esm/app/csr/types.js +0 -0
  133. package/esm/app/html/browser-options.js +2 -2
  134. package/esm/app/html/shell.js +173 -32
  135. package/esm/app/http/api-signing.js +13 -0
  136. package/esm/app/http/body-parser.middleware.js +47 -27
  137. package/esm/app/http/csp-nonce.js +13 -0
  138. package/esm/app/http/error-response.js +8 -5
  139. package/esm/app/http/exception-filter.js +4 -4
  140. package/esm/app/http/request-body-parser-policy.js +46 -0
  141. package/esm/app/http/security.guard.js +23 -21
  142. package/esm/app/project/controller.js +15 -15
  143. package/esm/app/project/service.js +3 -3
  144. package/esm/app/providers/foundation.js +5 -5
  145. package/esm/app/ssr/artifacts.js +25 -21
  146. package/esm/app/ssr/controller.js +148 -75
  147. package/esm/app/ssr/html.js +49 -44
  148. package/esm/app/ssr/stream.js +25 -24
  149. package/esm/app/static-assets.middleware.js +4 -4
  150. package/esm/app/template-core.module.js +57 -52
  151. package/esm/app/view/entry.tpl +2 -2
  152. package/esm/bundler/buildSSR.js +1 -1
  153. package/esm/bundler/entryCollect.js +9 -9
  154. package/esm/bundler/feSharedConfig.js +42 -42
  155. package/esm/bundler/utils.js +78 -90
  156. package/esm/config/config.default.js +4 -3
  157. package/esm/packages/common/index.js +6 -6
  158. package/esm/packages/core/bootstrap.js +5 -5
  159. package/esm/packages/core/startup.js +69 -46
  160. package/fe/frontend/src/common/request.js +5 -2
  161. package/fe/frontend/src/hooks/useRouterParams.d.ts +4 -2
  162. package/fe/packages/common/ssr/hydration.d.ts +9 -0
  163. package/fe/packages/react/core/Label/Label.d.ts +1 -0
  164. package/fe/packages/react/core/Label/Label.js +3 -1
  165. package/fe/packages/react/core/internal/i18n/default.d.ts +13 -0
  166. package/fe/packages/react/core/internal/i18n/default.js +16 -1
  167. package/fe/packages/react/core/internal/i18n/en-US.d.ts +13 -0
  168. package/fe/packages/react/core/internal/i18n/en-US.js +16 -1
  169. package/fe/packages/react/forms/DataTable/index.d.ts +2 -0
  170. package/fe/packages/react/forms/DataTable/index.js +43 -29
  171. package/fe/packages/react/forms/Form/FormItem.js +39 -12
  172. package/fe/packages/react/forms/MultiSelect/MultiSelect.d.ts +26 -0
  173. package/fe/packages/react/forms/MultiSelect/MultiSelect.js +218 -0
  174. package/fe/packages/react/forms/MultiSelect/index.d.ts +1 -0
  175. package/fe/packages/react/forms/MultiSelect/index.js +2 -0
  176. package/fe/packages/react/forms/Pagination/Pagination.d.ts +6 -1
  177. package/fe/packages/react/forms/Pagination/Pagination.js +13 -4
  178. package/fe/packages/react/forms/Select/Select.d.ts +11 -0
  179. package/fe/packages/react/forms/Select/Select.js +20 -7
  180. package/fe/packages/react/forms/index.d.ts +1 -0
  181. package/fe/packages/react/forms/index.js +3 -1
  182. package/fe/packages/react/i18n/getUiReactLocale.d.ts +26 -0
  183. package/fe/packages/react/index.js +2 -1
  184. package/fe/packages/react/overlays/Drawer/Drawer.d.ts +3 -2
  185. package/fe/packages/react/overlays/Drawer/Drawer.js +16 -2
  186. package/fe/packages/react/overlays/Dropdown/Dropdown.d.ts +12 -2
  187. package/fe/packages/react/overlays/Dropdown/Dropdown.js +27 -14
  188. package/fe/packages/react/overlays/Modal/Modal.d.ts +11 -3
  189. package/fe/packages/react/overlays/Modal/Modal.js +26 -2
  190. package/fe/packages/react/overlays/Modal/ModalManager.d.ts +13 -12
  191. package/fe/packages/react/overlays/Modal/ModalManager.js +15 -5
  192. package/fe/packages/react/overlays/Modal/index.d.ts +1 -0
  193. package/fe/packages/react/overlays/Overlay/Overlay.d.ts +6 -2
  194. package/fe/packages/react/overlays/Overlay/Overlay.js +31 -14
  195. package/fe/packages/react/overlays/Overlay/focusTypes.d.ts +8 -0
  196. package/fe/packages/react/overlays/Overlay/focusTypes.js +0 -0
  197. package/fe/packages/react/overlays/Overlay/index.d.ts +1 -0
  198. package/fe/packages/react/overlays/Overlay/overlayStack.d.ts +16 -0
  199. package/fe/packages/react/overlays/Overlay/overlayStack.js +290 -0
  200. package/fe/packages/react/overlays/Popup/Popup.d.ts +5 -4
  201. package/fe/packages/react/overlays/Popup/Popup.js +28 -11
  202. package/fe/packages/react/ui/components/index.js +2 -1
  203. package/fe/packages/react/ui/index.js +2 -1
  204. package/fe/ssr/components/StreamingRender/StreamingCache.d.ts +1 -0
  205. package/fe/ssr/components/StreamingRender/StreamingCache.js +5 -1
  206. package/fe/ssr/components/StreamingRender/StreamingRender.js +1 -1
  207. package/fe/ssr/components/StreamingRender/StreamingScript.d.ts +1 -0
  208. package/fe/ssr/components/StreamingRender/StreamingScript.js +9 -1
  209. package/fe/ssr/createSSREntry.d.ts +9 -3
  210. package/fe/ssr/createSSREntry.js +43 -19
  211. package/fe/ssr/index.d.ts +4 -1
  212. package/fe/ssr/index.js +2 -1
  213. package/fe/ssr/router.d.ts +76 -0
  214. package/fe/ssr/router.js +349 -0
  215. package/fe/ssr/types.d.ts +1 -1
  216. package/models/packages/common/ssr/hydration.d.ts +9 -0
  217. package/models/packages/react/core/Label/Label.d.ts +1 -0
  218. package/models/packages/react/core/internal/i18n/default.d.ts +13 -0
  219. package/models/packages/react/core/internal/i18n/en-US.d.ts +13 -0
  220. package/models/packages/react/forms/DataTable/index.d.ts +2 -0
  221. package/models/packages/react/forms/MultiSelect/MultiSelect.d.ts +26 -0
  222. package/models/packages/react/forms/MultiSelect/index.d.ts +1 -0
  223. package/models/packages/react/forms/Pagination/Pagination.d.ts +6 -1
  224. package/models/packages/react/forms/Select/Select.d.ts +11 -0
  225. package/models/packages/react/forms/index.d.ts +1 -0
  226. package/models/packages/react/i18n/getUiReactLocale.d.ts +26 -0
  227. package/models/packages/react/overlays/Drawer/Drawer.d.ts +3 -2
  228. package/models/packages/react/overlays/Dropdown/Dropdown.d.ts +12 -2
  229. package/models/packages/react/overlays/Modal/Modal.d.ts +11 -3
  230. package/models/packages/react/overlays/Modal/ModalManager.d.ts +13 -12
  231. package/models/packages/react/overlays/Modal/index.d.ts +1 -0
  232. package/models/packages/react/overlays/Overlay/Overlay.d.ts +6 -2
  233. package/models/packages/react/overlays/Overlay/focusTypes.d.ts +8 -0
  234. package/models/packages/react/overlays/Overlay/index.d.ts +1 -0
  235. package/models/packages/react/overlays/Overlay/overlayStack.d.ts +16 -0
  236. package/models/packages/react/overlays/Popup/Popup.d.ts +5 -4
  237. package/package.json +26 -1
  238. package/types/app/ai/agent/agent-scanner.service.d.ts +4 -4
  239. package/types/app/ai/ai-config.service.d.ts +7 -3
  240. package/types/app/ai/guardrail/guardrail.service.d.ts +2 -2
  241. package/types/app/ai/index.d.ts +9 -0
  242. package/types/app/ai/mcp/internal/load-mcp-config.d.ts +2 -2
  243. package/types/app/ai/mcp/internal/read-sse-response.d.ts +2 -0
  244. package/types/app/ai/mcp/internal/stdio-process.d.ts +5 -0
  245. package/types/app/ai/mcp/mcp-registry.service.d.ts +5 -3
  246. package/types/app/ai/mcp/mcp.client.d.ts +7 -4
  247. package/types/app/ai/mcp/mcp.loader.d.ts +11 -11
  248. package/types/app/ai/mcp/mcp.module.d.ts +5 -5
  249. package/types/app/ai/memory/thread.service.d.ts +3 -3
  250. package/types/app/ai/models/chat-sse.d.ts +5 -0
  251. package/types/app/ai/models/chat.d.ts +22 -0
  252. package/types/app/ai/models/http.d.ts +20 -0
  253. package/types/app/ai/models/image.d.ts +69 -0
  254. package/types/app/ai/models/video.d.ts +99 -0
  255. package/types/app/ai/nest-service-provider.d.ts +6 -0
  256. package/types/app/ai/retention/conversation-retention.service.d.ts +3 -4
  257. package/types/app/ai/runtime/ai-runtime-startup.validator.d.ts +2 -3
  258. package/types/app/ai/runtime/ai-runtime.d.ts +46 -0
  259. package/types/app/ai/runtime/internal/agent-run-context.d.ts +4 -0
  260. package/types/app/ai/runtime/internal/context-compaction.service.d.ts +2 -2
  261. package/types/app/ai/runtime/internal/declaration-snapshot.d.ts +8 -0
  262. package/types/app/ai/runtime/internal/owned-runtime-resources.d.ts +5 -0
  263. package/types/app/ai/runtime/langchain/langchain-planner.service.d.ts +1 -1
  264. package/types/app/ai/runtime/langgraph/langgraph-orchestrator.service.d.ts +33 -16
  265. package/types/app/ai/skill/skill-scanner.service.d.ts +3 -4
  266. package/types/app/ai/snapshot-data.d.ts +1 -0
  267. package/types/app/ai/store/internal/create-vector-store.d.ts +4 -0
  268. package/types/app/ai/tool/builtin/index.d.ts +1 -1
  269. package/types/app/ai/tool/builtin/invoke-agent.tool.d.ts +10 -3
  270. package/types/app/ai/tool/builtin/retrieve.tool.d.ts +4 -3
  271. package/types/app/ai/tool/executor.service.d.ts +3 -3
  272. package/types/app/ai/tool/tool-registry.service.d.ts +2 -7
  273. package/types/app/ai/tool/tool.interface.d.ts +1 -1
  274. package/types/app/ai/tool/tool.module.d.ts +8 -1
  275. package/types/app/ai/trace/trace.service.d.ts +4 -5
  276. package/types/app/csr/types.d.ts +10 -0
  277. package/types/app/html/browser-options.d.ts +1 -1
  278. package/types/app/html/shell.d.ts +37 -10
  279. package/types/app/http/api-signing.d.ts +16 -0
  280. package/types/app/http/body-parser.middleware.d.ts +6 -2
  281. package/types/app/http/csp-nonce.d.ts +3 -0
  282. package/types/app/http/error-response.d.ts +1 -0
  283. package/types/app/http/request-body-parser-policy.d.ts +8 -0
  284. package/types/app/http/security.guard.d.ts +1 -0
  285. package/types/app/ssr/artifacts.d.ts +6 -3
  286. package/types/app/ssr/html.d.ts +7 -0
  287. package/types/app/ssr/stream.d.ts +1 -1
  288. package/types/app/ssr/types.d.ts +56 -0
  289. package/types/bundler/buildSSR.d.ts +2 -1
  290. package/types/bundler/index.d.ts +1 -1
  291. package/types/bundler/state.d.ts +13 -0
  292. package/types/bundler/utils.d.ts +3 -14
  293. package/types/config/config.default.d.ts +9 -3
  294. package/types/index.d.ts +4 -1
  295. package/types/packages/common/ssr/hydration.d.ts +13 -0
  296. package/types/packages/core/index.d.ts +1 -1
  297. package/types/packages/core/startup.d.ts +41 -0
@@ -2,119 +2,192 @@ import { TC_LOGGER as e } from "../../packages/core/tokens.js";
2
2
  import { TemplateCoreRuntime as t } from "../../packages/core/startup.js";
3
3
  import "../../packages/core/index.js";
4
4
  import { FrontendDevelopment as n } from "../frontend-development.js";
5
- import { createTemplateCoreHttpContext as r } from "../http/context.js";
6
- import { ssrClientAssetUrl as i } from "../../ssrSharedData/outputPaths.js";
7
- import { SSRArtifacts as a } from "./artifacts.js";
8
- import { createHydrationData as o, serializeHydrationDataScriptContent as s } from "../../packages/common/ssr/hydration.js";
9
- import { createSSRDocument as c, renderSSRErrorHtml as l } from "./html.js";
10
- import { findSSRClientEntry as u, generateSSRPreloadLinks as d } from "./manifest.js";
11
- import { streamSSRDocument as f } from "./stream.js";
12
- import { SSRRenderInterruptedError as p, SSRRenderSessionRegistry as m } from "./session.js";
13
- import { Controller as h, Get as g, Inject as _, Req as v, Res as y } from "@nestjs/common";
14
- import b from "@oxc-project/runtime/helpers/decorateMetadata";
5
+ import { resolveCspNonce as r } from "../http/csp-nonce.js";
6
+ import { createTemplateCoreHttpContext as i } from "../http/context.js";
7
+ import { ssrClientAssetUrl as a } from "../../ssrSharedData/outputPaths.js";
8
+ import { SSRArtifacts as o } from "./artifacts.js";
9
+ import { createHydrationData as s, serializeHydrationDataScriptContent as c } from "../../packages/common/ssr/hydration.js";
10
+ import { createSSRDocument as l, renderSSRErrorHtml as u } from "./html.js";
11
+ import { findSSRClientEntry as d, generateSSRPreloadLinks as f } from "./manifest.js";
12
+ import { streamSSRDocument as p } from "./stream.js";
13
+ import { SSRRenderInterruptedError as m, SSRRenderSessionRegistry as h } from "./session.js";
14
+ import { Controller as g, Get as _, Inject as v, Req as y, Res as b } from "@nestjs/common";
15
15
  import x from "@oxc-project/runtime/helpers/decorate";
16
- import S from "@oxc-project/runtime/helpers/decorateParam";
17
- import * as C from "react";
16
+ import S from "@oxc-project/runtime/helpers/decorateMetadata";
17
+ import C from "@oxc-project/runtime/helpers/decorateParam";
18
+ import * as w from "react";
18
19
  //#region app/ssr/controller.ts
19
- var w = /^[A-Za-z0-9_-]+$/;
20
- async function T(e, t, n) {
20
+ var T = /^[A-Za-z0-9_-]+$/, E = "x-tc-ssr-data";
21
+ function D(e) {
22
+ let t = e.headers[E];
23
+ return Array.isArray(t) ? t.some((e) => e === "1") : t === "1";
24
+ }
25
+ function O(e, t, n = 200) {
26
+ e.status(n).setHeader("Cache-Control", "private, no-store").type("json").json(t);
27
+ }
28
+ function k(e, t, n, r, i, a) {
29
+ let o = w.createElement(e, n);
30
+ return t ? w.createElement(t, {
31
+ children: o,
32
+ page: r,
33
+ path: i,
34
+ query: a
35
+ }) : o;
36
+ }
37
+ async function A(e, t, n) {
21
38
  let r = typeof e == "function" ? await e(t) : e;
22
39
  return r == null ? n : String(r);
23
40
  }
24
- function E(E) {
25
- var D, O, k, A;
26
- let j = class {
41
+ async function j(e, t) {
42
+ return (typeof e == "function" ? await e(t) : e) ?? void 0;
43
+ }
44
+ function M(e) {
45
+ if (!e || typeof e != "object" || !("redirect" in e) || e.type !== "redirect") return !1;
46
+ let t = e.redirect;
47
+ return Object.keys(e).length === 2 && !!t && typeof t == "object" && Object.keys(t).length === 2 && "location" in t && "status" in t;
48
+ }
49
+ function N(e) {
50
+ return !!e && typeof e == "object" && "status" in e && "props" in e && Object.keys(e).length === 3 && e.type === "status" && typeof e.status == "number" && !!e.props && typeof e.props == "object";
51
+ }
52
+ function P(E) {
53
+ var P, F, I, L;
54
+ let R = class {
27
55
  constructor(e, t, n, r, i) {
28
56
  this.runtime = e, this.artifacts = t, this.sessions = n, this.development = r, this.logger = i;
29
57
  }
30
58
  async render(e, t) {
31
- let n = String(e.params.page ?? ""), a = r(e, t), m = this.runtime.config.ssr, h = m && typeof m == "object" && "exposeErrorDetails" in m ? !!m.exposeErrorDetails : void 0, g = {
59
+ let n = String(e.params.page ?? ""), o = D(e), h = i(e, t), g = this.runtime.config.ssr, _ = g && typeof g == "object" && "exposeErrorDetails" in g ? !!g.exposeErrorDetails : void 0, v = {
32
60
  options: this.runtime.options,
33
61
  config: {
34
62
  signKey: this.runtime.config.signKey,
35
- ssr: { exposeErrorDetails: h }
63
+ apiSignVerify: this.runtime.config.apiSignVerify,
64
+ html: this.runtime.config.html,
65
+ ssr: { exposeErrorDetails: _ }
36
66
  },
37
67
  envs: { isLocal: () => this.runtime.environment === "local" }
38
- }, _ = {
68
+ }, y = {
39
69
  query: e.query,
40
- projectKey: a.projectKey
41
- }, v = this.sessions.create(t, m, (e) => this.logger.error(`[SSR] Failed to render ${n}`, e)), y = (e, r, i, a) => {
42
- t.destroyed || t.headersSent || t.writableEnded || t.status(e).type("html").send(l({
43
- app: g,
44
- ctx: _,
70
+ projectKey: h.projectKey,
71
+ language: h.language
72
+ }, b, x = this.sessions.create(t, g, (e) => this.logger.error(`[SSR] Failed to render ${n}`, e)), S = (e, r, i, a) => {
73
+ t.destroyed || t.headersSent || t.writableEnded || t.status(e).type("html").send(u({
74
+ app: v,
75
+ ctx: y,
45
76
  page: n,
46
77
  status: e,
47
78
  title: r,
48
79
  message: i,
49
- error: a
80
+ error: a,
81
+ nonce: b
50
82
  }));
51
83
  };
52
84
  try {
53
- await v.run(async () => {
54
- if (!w.test(n)) {
55
- y(404, "SSR page not found", "The requested SSR page is not registered.");
85
+ await x.run(async () => {
86
+ if (b = await r(e, t, this.runtime.config), x.assertActive(), !T.test(n)) {
87
+ S(404, "SSR page not found", "The requested SSR page is not registered.");
56
88
  return;
57
89
  }
58
- let r = await this.artifacts.loadPage(n);
59
- if (v.assertActive(), !r) {
60
- y(404, "SSR bundle not found", `No server bundle was found for "${n}".`);
90
+ let i = await this.artifacts.loadPage(n);
91
+ if (x.assertActive(), !i) {
92
+ S(404, "SSR bundle not found", `No server bundle was found for "${n}".`);
61
93
  return;
62
94
  }
63
- let l = {
95
+ let u = {
64
96
  params: Object.fromEntries(Object.entries(e.params).map(([e, t]) => [e, Array.isArray(t) ? t.join("/") : String(t)])),
65
97
  query: e.query,
66
98
  path: e.path,
67
99
  app: this.runtime.application,
68
- ctx: a
69
- }, p = await r.getServerProps?.(l) ?? {};
70
- v.assertActive();
71
- let m = {
72
- ...l,
73
- props: p
74
- }, h = await T(r.pageTitle, m, n);
75
- v.assertActive();
76
- let b = await T(r.pageDescription, m, "");
77
- v.assertActive();
78
- let x = o(p, {
79
- title: h,
80
- description: b,
81
- pathname: e.path
82
- }), S = this.development.session, E = S ? null : this.artifacts.readManifest(), D = u(E, n), O = c(C, {
83
- app: g,
84
- ctx: _,
100
+ ctx: h
101
+ }, m = await i.getServerProps?.(u) ?? {};
102
+ if (M(m)) {
103
+ let { location: e, status: r } = m.redirect;
104
+ if (typeof e != "string" || !Number.isInteger(r) || r < 300 || r > 399) throw Error("[SSR] Invalid redirect result");
105
+ if (o) {
106
+ O(t, {
107
+ type: "redirect",
108
+ page: n,
109
+ location: e,
110
+ status: r,
111
+ buildKey: this.artifacts.readBuildKey()
112
+ });
113
+ return;
114
+ }
115
+ t.redirect(r, e);
116
+ return;
117
+ }
118
+ let g = N(m) ? m.status : 200, _ = N(m) ? m.props : m;
119
+ if (!Number.isInteger(g) || g < 100 || g > 599) throw Error("[SSR] Invalid response status");
120
+ x.assertActive();
121
+ let C = {
122
+ ...u,
123
+ props: _
124
+ }, E = await A(i.pageTitle, C, n);
125
+ x.assertActive();
126
+ let D = await A(i.pageDescription, C, "");
127
+ x.assertActive();
128
+ let P = await j(i.pageHead, C);
129
+ x.assertActive();
130
+ let F = this.development.session, I = F ? null : this.artifacts.readManifest(), L = d(I, n), R = this.artifacts.readBuildKey(), z = L?.file ? a(L.file) : null;
131
+ if (o) {
132
+ O(t, {
133
+ type: N(m) ? "status" : "page",
134
+ page: n,
135
+ props: _,
136
+ title: E,
137
+ description: D,
138
+ head: P,
139
+ status: g,
140
+ buildKey: R,
141
+ entry: z
142
+ }, g);
143
+ return;
144
+ }
145
+ let B = s(_, {
146
+ title: E,
147
+ description: D,
148
+ pathname: e.path,
149
+ page: n,
150
+ buildKey: R,
151
+ entry: z,
152
+ head: P
153
+ }), V = l(w, {
154
+ app: v,
155
+ ctx: y,
85
156
  page: n,
86
- title: h,
87
- description: b,
88
- preloadLinks: S ? await S.renderSSRHead(n) : d(E, D),
89
- hydrationScriptContent: s(x),
90
- appNode: C.createElement(r.default, p)
91
- }), k = D?.file ? i(D.file) : void 0;
92
- S && t.setHeader("Cache-Control", "no-store"), await f(O, t, v, k);
157
+ title: E,
158
+ description: D,
159
+ head: P,
160
+ nonce: b,
161
+ preloadLinks: F ? await F.renderSSRHead(n) : f(I, L),
162
+ hydrationScriptContent: c(B),
163
+ appNode: k(i.default, i.layout, _, n, e.path, e.query)
164
+ }), H = z ?? void 0;
165
+ F && t.setHeader("Cache-Control", "no-store"), await p(V, t, x, H, g, b);
93
166
  });
94
167
  } catch (e) {
95
- if (e instanceof p || (v.report(e), t.writableFinished) || t.headersSent || t.destroyed || t.writableEnded) return;
96
- y(500, "SSR render error", "The SSR page failed while loading data or rendering.", e);
168
+ if (e instanceof m || (x.report(e), t.writableFinished) || t.headersSent || t.destroyed || t.writableEnded) return;
169
+ S(500, "SSR render error", "The SSR page failed while loading data or rendering.", e);
97
170
  }
98
171
  }
99
172
  };
100
173
  return x([
101
- g([":page", ":page/{*rest}"]),
102
- S(0, v()),
103
- S(1, y()),
104
- b("design:type", Function),
105
- b("design:paramtypes", [Object, Object]),
106
- b("design:returntype", Promise)
107
- ], j.prototype, "render", null), j = x([
108
- h(E),
109
- S(4, _(e)),
110
- b("design:paramtypes", [
111
- typeof (D = t !== void 0 && t) == "function" ? D : Object,
112
- typeof (O = a !== void 0 && a) == "function" ? O : Object,
113
- typeof (k = m !== void 0 && m) == "function" ? k : Object,
114
- typeof (A = n !== void 0 && n) == "function" ? A : Object,
174
+ _([":page", ":page/{*rest}"]),
175
+ C(0, y()),
176
+ C(1, b()),
177
+ S("design:type", Function),
178
+ S("design:paramtypes", [Object, Object]),
179
+ S("design:returntype", Promise)
180
+ ], R.prototype, "render", null), R = x([
181
+ g(E),
182
+ C(4, v(e)),
183
+ S("design:paramtypes", [
184
+ typeof (P = t !== void 0 && t) == "function" ? P : Object,
185
+ typeof (F = o !== void 0 && o) == "function" ? F : Object,
186
+ typeof (I = h !== void 0 && h) == "function" ? I : Object,
187
+ typeof (L = n !== void 0 && n) == "function" ? L : Object,
115
188
  Object
116
189
  ])
117
- ], j), j;
190
+ ], R), R;
118
191
  }
119
192
  //#endregion
120
- export { E as createSSRPageController };
193
+ export { P as createSSRPageController };
@@ -1,40 +1,42 @@
1
1
  import { normalizeRouteBasePath as e } from "../../packages/core/paths.js";
2
2
  import "../../packages/core/index.js";
3
3
  import { projectBrowserOptions as t } from "../html/browser-options.js";
4
- import { escapeHtml as n, escapeHtmlAttr as r, renderDocumentHeadHtml as i, renderRuntimeContextScriptsFromExpressions as a, serializeForHtmlScript as o } from "../html/shell.js";
4
+ import { resolveBrowserSignKey as n } from "../http/api-signing.js";
5
+ import { escapeHtml as r, escapeHtmlAttr as i, renderDocumentHeadHtml as a, renderHtmlBodyAttributes as o, renderHtmlDocumentStart as s, renderHtmlHeadContent as c, renderRuntimeContextScriptsFromExpressions as l, renderScriptNonceAttribute as u, renderThemeScriptContent as d, resolveHtmlShellOptions as f, serializeForHtmlScript as p } from "../html/shell.js";
5
6
  //#region app/ssr/html.ts
6
- function s(...e) {
7
+ function m(...e) {
7
8
  return `/${e.filter(Boolean).map((e) => e.replace(/^\/+|\/+$/g, "")).filter(Boolean).join("/")}`;
8
9
  }
9
- function c(e) {
10
+ function h(e) {
10
11
  if (e.projectKey !== void 0) return e.projectKey;
11
12
  let t = e.query.projk;
12
13
  return Array.isArray(t) ? t.join("") : String(t ?? "");
13
14
  }
14
- function l(n, r, i) {
15
- let a = e(n.options.pageBasePath) || "/", l = s(e(n.options.ssrPageBasePath, "/fessr") || "/fessr", i), u = c(r);
15
+ function g(r, i, a, o) {
16
+ let s = e(r.options.pageBasePath) || "/", c = m(e(r.options.ssrPageBasePath, "/fessr") || "/fessr", a), l = h(i);
16
17
  return {
17
- basePathExpression: o(l),
18
- feBasePageExpression: o(a),
19
- projKeyExpression: o(u),
20
- signKeyExpression: o(n.config.signKey),
21
- renderModeExpression: o("ssr"),
22
- optionsJsonHtml: o(t(n.options))
18
+ basePathExpression: p(c),
19
+ feBasePageExpression: p(s),
20
+ projKeyExpression: p(l),
21
+ signKeyExpression: p(n(r.config)),
22
+ renderModeExpression: p("ssr"),
23
+ optionsJsonHtml: p(t(r.options)),
24
+ nonceAttr: u(o)
23
25
  };
24
26
  }
25
- function u(e, t, n) {
26
- return a(l(e, t, n));
27
+ function _(e, t, n, r) {
28
+ return l(g(e, t, n, r));
27
29
  }
28
- function d(e) {
29
- let { app: t, ctx: n, page: r, hydrationScript: i = "", clientScript: a = "" } = e;
30
+ function v(e) {
31
+ let { app: t, ctx: n, page: r, hydrationScript: i = "", clientScript: a = "" } = e, c = f(t.options.html, t.config.html, n.language);
30
32
  return {
31
33
  beforeAppHtml: `<!DOCTYPE html>
32
- <html lang="en" class="dark" style="color-scheme: dark">
34
+ ${s(c)}
33
35
  <head>
34
- ${p(e)}
36
+ ${b(e, c)}
35
37
  </head>
36
- ${u(t, n, r)}
37
- <body>
38
+ ${_(t, n, r, e.nonce)}
39
+ <body${o(c.body)}>
38
40
  <div id="root">`,
39
41
  afterAppHtml: `</div>
40
42
  ${i}
@@ -43,57 +45,60 @@ ${u(t, n, r)}
43
45
  </html>`
44
46
  };
45
47
  }
46
- function f(e) {
47
- let { app: t, ctx: n, page: r, hydrationScript: i = "" } = e;
48
+ function y(e) {
49
+ let { app: t, ctx: n, page: r, hydrationScript: i = "" } = e, a = f(t.options.html, t.config.html, n.language);
48
50
  return {
49
51
  beforeAppHtml: `<!DOCTYPE html>
50
- <html lang="en" class="dark" style="color-scheme: dark">
52
+ ${s(a)}
51
53
  <head>
52
- ${p(e)}
54
+ ${b(e, a)}
53
55
  </head>
54
- <body>
55
- ${u(t, n, r)}
56
+ <body${o(a.body)}>
57
+ ${_(t, n, r, e.nonce)}
56
58
  ${i}`,
57
59
  afterAppHtml: "</body>\n</html>"
58
60
  };
59
61
  }
60
- function p(e) {
61
- let { title: t, description: a = "", preloadLinks: o = "" } = e;
62
- return i({
63
- titleHtml: n(t),
64
- descriptionAttr: r(a),
65
- preloadLinks: o
62
+ function b(e, t = f(e.app.options.html, e.app.config.html, e.ctx.language)) {
63
+ let { title: n, description: i = "", preloadLinks: o = "", head: s, nonce: l } = e;
64
+ return a({
65
+ titleHtml: r(n),
66
+ preloadLinks: o,
67
+ extraHeadHtml: c(t, s, i, l),
68
+ nonceAttr: u(l),
69
+ themeScriptContent: d(t)
66
70
  });
67
71
  }
68
- function m(e, t) {
72
+ function x(e, t) {
69
73
  let { appNode: n, hydrationScriptContent: r = "" } = t;
70
74
  return {
71
- ...f({
75
+ ...y({
72
76
  ...t,
73
- hydrationScript: r ? `<script>${r}<\/script>` : ""
77
+ hydrationScript: r ? `<script${u(t.nonce)}>${r}<\/script>` : ""
74
78
  }),
75
79
  element: e.createElement("div", { id: "root" }, n)
76
80
  };
77
81
  }
78
- function h(e) {
79
- let { appHtml: t, ...n } = e, { beforeAppHtml: r, afterAppHtml: i } = d(n);
82
+ function S(e) {
83
+ let { appHtml: t, ...n } = e, { beforeAppHtml: r, afterAppHtml: i } = v(n);
80
84
  return `${r}${t}${i}`;
81
85
  }
82
- function g(e) {
83
- let { app: t, ctx: r, page: i, status: a, title: o, message: s, error: c } = e, l = t.config.ssr?.exposeErrorDetails ?? t.envs.isLocal(), u = c instanceof Error ? c.stack || c.message : String(c ?? ""), d = l && u ? `<pre style="white-space:pre-wrap;margin-top:16px;padding:12px;border:1px solid #d8dee4;background:#f6f8fa;color:#24292f;overflow:auto">${n(u)}</pre>` : "";
84
- return h({
86
+ function C(e) {
87
+ let { app: t, ctx: n, page: i, status: a, title: o, message: s, error: c, nonce: l } = e, u = t.config.ssr?.exposeErrorDetails ?? t.envs.isLocal(), d = c instanceof Error ? c.stack || c.message : String(c ?? ""), f = u && d ? `<pre style="white-space:pre-wrap;margin-top:16px;padding:12px;border:1px solid #d8dee4;background:#f6f8fa;color:#24292f;overflow:auto">${r(d)}</pre>` : "";
88
+ return S({
85
89
  app: t,
86
- ctx: r,
90
+ ctx: n,
87
91
  page: i,
88
92
  title: o,
89
93
  description: s,
94
+ nonce: l,
90
95
  appHtml: `<main style="font-family:system-ui,-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;max-width:720px;margin:72px auto;padding:0 24px;line-height:1.5;color:#24292f">
91
96
  <p style="margin:0 0 8px;color:#57606a;font-size:14px">SSR ${a}</p>
92
- <h1 style="margin:0 0 12px;font-size:28px;line-height:1.2">${n(o)}</h1>
93
- <p style="margin:0;color:#57606a">${n(s)}</p>
94
- ${d}
97
+ <h1 style="margin:0 0 12px;font-size:28px;line-height:1.2">${r(o)}</h1>
98
+ <p style="margin:0;color:#57606a">${r(s)}</p>
99
+ ${f}
95
100
  </main>`
96
101
  });
97
102
  }
98
103
  //#endregion
99
- export { m as createSSRDocument, n as escapeHtml, r as escapeHtmlAttr, g as renderSSRErrorHtml, h as renderSSRHtmlShell, d as renderSSRHtmlShellParts, o as serializeForHtmlScript };
104
+ export { x as createSSRDocument, r as escapeHtml, i as escapeHtmlAttr, C as renderSSRErrorHtml, S as renderSSRHtmlShell, v as renderSSRHtmlShellParts, p as serializeForHtmlScript };
@@ -1,48 +1,49 @@
1
1
  import { PassThrough as e } from "node:stream";
2
2
  import { renderToPipeableStream as t } from "react-dom/server";
3
3
  //#region app/ssr/stream.ts
4
- function n(n, r, i, a) {
5
- return new Promise((o, s) => {
6
- let c = !1, l, u = !1, d, f = () => void 0, p = new e(), m = () => {
7
- r.removeListener("finish", g), r.removeListener("close", _), r.removeListener("error", v), p.removeListener("end", y), p.removeListener("error", v), p.unpipe(r), p.destroy(), f();
8
- }, h = (e) => {
9
- u || (u = !0, m(), e === void 0 ? o() : s(e));
10
- }, g = () => h(), _ = () => {
11
- r.writableFinished || h(/* @__PURE__ */ Error("SSR response closed before the stream finished"));
12
- }, v = (e) => {
13
- i.report(e), i.cancel(e, !0), h(e);
14
- }, y = () => {
4
+ function n(n, r, i, a, o = 200, s) {
5
+ return new Promise((c, l) => {
6
+ let u = !1, d, f = !1, p, m = () => void 0, h = new e(), g = () => {
7
+ r.removeListener("finish", v), r.removeListener("close", y), r.removeListener("error", b), h.removeListener("end", x), h.removeListener("error", b), h.unpipe(r), h.destroy(), m();
8
+ }, _ = (e) => {
9
+ f || (f = !0, g(), e === void 0 ? c() : l(e));
10
+ }, v = () => _(), y = () => {
11
+ r.writableFinished || _(/* @__PURE__ */ Error("SSR response closed before the stream finished"));
12
+ }, b = (e) => {
13
+ i.report(e), i.cancel(e, !0), _(e);
14
+ }, x = () => {
15
15
  r.destroyed || r.writableEnded || r.end(n.afterAppHtml);
16
16
  };
17
- if (r.once("finish", g), r.once("close", _), r.once("error", v), p.once("error", v), p.once("end", y), f = i.onAbort((e) => {
18
- h(e), d?.abort(e);
19
- }), !u) try {
20
- d = t(n.element, {
17
+ if (r.once("finish", v), r.once("close", y), r.once("error", b), h.once("error", b), h.once("end", x), m = i.onAbort((e) => {
18
+ _(e), p?.abort(e);
19
+ }), !f) try {
20
+ p = t(n.element, {
21
21
  bootstrapModules: a ? [a] : void 0,
22
+ nonce: s,
22
23
  onShellReady() {
23
- if (l) {
24
- d?.abort(l), h(l);
24
+ if (d) {
25
+ p?.abort(d), _(d);
25
26
  return;
26
27
  }
27
28
  try {
28
- i.markStreaming(), c = !0, r.status(200).type("html"), r.setHeader("Cache-Control", "no-transform"), r.flushHeaders(), r.write(n.beforeAppHtml), p.pipe(r, { end: !1 }), d?.pipe(p);
29
+ i.markStreaming(), u = !0, r.status(o).type("html"), r.setHeader("Cache-Control", "no-transform"), r.flushHeaders(), r.write(n.beforeAppHtml), h.pipe(r, { end: !1 }), p?.pipe(h);
29
30
  } catch (e) {
30
- i.cancel(e instanceof Error ? e : Error(String(e)), r.headersSent), h(e);
31
+ i.cancel(e instanceof Error ? e : Error(String(e)), r.headersSent), _(e);
31
32
  }
32
33
  },
33
34
  onShellError(e) {
34
- d?.abort(e), h(e);
35
+ p?.abort(e), _(e);
35
36
  },
36
37
  onError(e) {
37
- if (!c) {
38
- l = e;
38
+ if (!u) {
39
+ d = e;
39
40
  return;
40
41
  }
41
- i.report(e), i.cancel(e instanceof Error ? e : Error(String(e)), !0), h(e);
42
+ i.report(e), i.cancel(e instanceof Error ? e : Error(String(e)), !0), _(e);
42
43
  }
43
44
  });
44
45
  } catch (e) {
45
- h(e);
46
+ _(e);
46
47
  }
47
48
  });
48
49
  }
@@ -4,8 +4,8 @@ import { TemplateCoreRuntime as n } from "../packages/core/startup.js";
4
4
  import "../packages/core/index.js";
5
5
  import { SSR_SERVER_OUT_DIR as r } from "../ssrSharedData/outputPaths.js";
6
6
  import { Inject as i, Injectable as a } from "@nestjs/common";
7
- import o from "@oxc-project/runtime/helpers/decorateMetadata";
8
- import s from "@oxc-project/runtime/helpers/decorate";
7
+ import o from "@oxc-project/runtime/helpers/decorate";
8
+ import s from "@oxc-project/runtime/helpers/decorateMetadata";
9
9
  import c from "@oxc-project/runtime/helpers/decorateParam";
10
10
  import l from "express";
11
11
  //#region app/static-assets.middleware.ts
@@ -59,10 +59,10 @@ var h = class {
59
59
  a(0);
60
60
  }
61
61
  };
62
- h = s([
62
+ h = o([
63
63
  a(),
64
64
  c(1, i(t)),
65
- o("design:paramtypes", [typeof (u = n !== void 0 && n) == "function" ? u : Object, typeof (d = e !== void 0 && e) == "function" ? d : Object])
65
+ s("design:paramtypes", [typeof (u = n !== void 0 && n) == "function" ? u : Object, typeof (d = e !== void 0 && e) == "function" ? d : Object])
66
66
  ], h);
67
67
  //#endregion
68
68
  export { h as StaticAssetsMiddleware };