@plitzi/sdk-server 0.32.25 → 0.33.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 (514) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +326 -162
  3. package/dist/adapters/authAdapters.d.ts +21 -0
  4. package/dist/adapters/authAdapters.js +12 -0
  5. package/dist/adapters/jsonAdapters.d.ts +15 -0
  6. package/dist/adapters/jsonAdapters.js +9 -4
  7. package/dist/core/auth/api.d.ts +148 -0
  8. package/dist/core/auth/api.js +286 -0
  9. package/dist/core/auth/authorize.d.ts +96 -0
  10. package/dist/core/auth/authorize.js +92 -0
  11. package/dist/core/auth/createAuth.d.ts +165 -0
  12. package/dist/core/auth/createAuth.js +105 -0
  13. package/dist/core/auth/credentials.d.ts +29 -0
  14. package/dist/core/auth/credentials.js +48 -0
  15. package/dist/core/auth/domains.d.ts +41 -0
  16. package/dist/core/auth/domains.js +78 -0
  17. package/dist/core/auth/identity.d.ts +108 -0
  18. package/dist/core/auth/identity.js +164 -0
  19. package/dist/core/auth/oauth/client.d.ts +5 -0
  20. package/dist/core/auth/oauth/client.js +47 -0
  21. package/dist/core/auth/oauth/index.d.ts +78 -0
  22. package/dist/core/auth/oauth/index.js +113 -0
  23. package/dist/core/auth/oauth/providers/github.d.ts +2 -0
  24. package/dist/core/auth/oauth/providers/github.js +48 -0
  25. package/dist/core/auth/oauth/providers/google.d.ts +2 -0
  26. package/dist/core/auth/oauth/providers/google.js +30 -0
  27. package/dist/core/auth/oauth/state.d.ts +23 -0
  28. package/dist/core/auth/oauth/state.js +55 -0
  29. package/dist/core/auth/oauth/types.d.ts +51 -0
  30. package/dist/core/auth/oauth/types.js +13 -0
  31. package/dist/core/auth/routes.d.ts +50 -0
  32. package/dist/core/auth/routes.js +129 -0
  33. package/dist/core/auth/session.d.ts +128 -0
  34. package/dist/core/auth/session.js +165 -0
  35. package/dist/core/auth/spaceTokens.d.ts +137 -0
  36. package/dist/core/auth/spaceTokens.js +212 -0
  37. package/dist/core/auth/tokens.d.ts +151 -0
  38. package/dist/core/auth/tokens.js +221 -0
  39. package/dist/core/createServer.d.ts +29 -0
  40. package/dist/core/createServer.js +28 -14
  41. package/dist/core/handlers/authMiddleware.d.ts +27 -0
  42. package/dist/core/handlers/authMiddleware.js +38 -0
  43. package/dist/core/handlers/authRouteHandlers.d.ts +46 -0
  44. package/dist/core/handlers/authRouteHandlers.js +75 -0
  45. package/dist/core/handlers/types.d.ts +37 -0
  46. package/dist/{src/core → core}/http/dispatcher.d.ts +2 -2
  47. package/dist/core/http/dispatcher.js +8 -6
  48. package/dist/core/http/navigation.d.ts +11 -0
  49. package/dist/core/http/navigation.js +16 -0
  50. package/dist/core/http/securityHeaders.js +6 -4
  51. package/dist/core/http/stages/authApi.d.ts +17 -0
  52. package/dist/core/http/stages/authApi.js +66 -0
  53. package/dist/core/http/stages/authRoutes.js +40 -11
  54. package/dist/core/http/stages/exchangeRoute.d.ts +15 -0
  55. package/dist/core/http/stages/exchangeRoute.js +67 -0
  56. package/dist/core/http/stages/health.d.ts +11 -0
  57. package/dist/core/http/stages/health.js +25 -3
  58. package/dist/core/http/stages/middlewares.d.ts +2 -0
  59. package/dist/core/http/stages/static.d.ts +13 -0
  60. package/dist/core/http/stages/static.js +21 -6
  61. package/dist/core/http/types.d.ts +35 -0
  62. package/dist/{modules/mcp/constants.js → core/previewToken.js} +1 -1
  63. package/dist/core/sdkAssets.d.ts +16 -0
  64. package/dist/core/sdkAssets.js +46 -0
  65. package/dist/core/server/baseServer.js +40 -5
  66. package/dist/core/server/pageServer.d.ts +7 -0
  67. package/dist/core/server/pageServer.js +13 -17
  68. package/dist/core/services/action.d.ts +9 -0
  69. package/dist/core/services/action.js +21 -0
  70. package/dist/core/services/registry.d.ts +3 -0
  71. package/dist/core/services/registry.js +9 -19
  72. package/dist/{src/core → core}/services/resolve.d.ts +1 -0
  73. package/dist/core/services/resolve.js +6 -4
  74. package/dist/core/services/rsc.js +3 -2
  75. package/dist/core/staticFiles.js +1 -1
  76. package/dist/{src/core → core}/transports.d.ts +3 -0
  77. package/dist/core/transports.js +7 -6
  78. package/dist/handlers.d.ts +58 -0
  79. package/dist/handlers.js +3 -0
  80. package/dist/{src/helpers → helpers}/buildResponseHelpers.d.ts +2 -1
  81. package/dist/helpers/buildResponseHelpers.js +13 -4
  82. package/dist/helpers/buildServerInfo.d.ts +3 -0
  83. package/dist/helpers/buildServerInfo.js +25 -3
  84. package/dist/{src/helpers → helpers}/cache/keys.d.ts +5 -1
  85. package/dist/helpers/cache/keys.js +1 -1
  86. package/dist/helpers/compress.d.ts +18 -0
  87. package/dist/helpers/compress.js +47 -11
  88. package/dist/helpers/offlineDataLoader.d.ts +11 -0
  89. package/dist/helpers/offlineDataLoader.js +15 -0
  90. package/dist/helpers/resolveDebugMode.d.ts +10 -0
  91. package/dist/helpers/resolveDebugMode.js +13 -0
  92. package/dist/index.d.ts +16 -2
  93. package/dist/index.js +9 -20
  94. package/dist/kernel.d.ts +41 -0
  95. package/dist/kernel.js +22 -0
  96. package/dist/middlewares/spaceDeployment.d.ts +2 -0
  97. package/dist/middlewares/spaceDeployment.js +2 -1
  98. package/dist/modules/actions/handler.d.ts +11 -0
  99. package/dist/modules/actions/handler.js +77 -0
  100. package/dist/modules/connectors/engine.d.ts +42 -0
  101. package/dist/modules/connectors/engine.js +221 -0
  102. package/dist/modules/connectors/getByPath.d.ts +8 -0
  103. package/dist/modules/connectors/getByPath.js +21 -0
  104. package/dist/modules/connectors/index.d.ts +7 -0
  105. package/dist/modules/connectors/projection.d.ts +18 -0
  106. package/dist/modules/connectors/projection.js +108 -0
  107. package/dist/modules/connectors/resolver.d.ts +18 -0
  108. package/dist/modules/connectors/resolver.js +68 -0
  109. package/dist/modules/connectors/types.d.ts +19 -0
  110. package/dist/{src/modules → modules}/rsc/handler.d.ts +2 -2
  111. package/dist/modules/rsc/handler.js +54 -2
  112. package/dist/modules/rsc/resolveRscData.d.ts +35 -0
  113. package/dist/modules/rsc/resolveRscData.js +74 -0
  114. package/dist/{src/modules → modules}/ssr/Component.d.ts +4 -1
  115. package/dist/modules/ssr/Component.js +10 -3
  116. package/dist/modules/ssr/buildBody.d.ts +9 -0
  117. package/dist/modules/ssr/handler.d.ts +4 -0
  118. package/dist/modules/ssr/handler.js +18 -1
  119. package/dist/{src/modules → modules}/ssr/loadPluginComponents.d.ts +5 -2
  120. package/dist/modules/ssr/loadPluginComponents.js +20 -2
  121. package/dist/{src/modules → modules}/ssr/prepareRender.d.ts +2 -2
  122. package/dist/modules/ssr/prepareRender.js +24 -7
  123. package/dist/modules/ssr/preview.d.ts +10 -0
  124. package/dist/modules/ssr/preview.js +5 -78
  125. package/dist/modules/ssr/registerExternalPlugins.js +1 -1
  126. package/dist/modules/ssr/streamBody.d.ts +5 -0
  127. package/dist/modules/ssr/streamBody.js +1 -1
  128. package/dist/modules/ssr/template.d.ts +2 -0
  129. package/dist/modules/ssr/template.js +1 -1
  130. package/dist/plugins/compile.js +1 -1
  131. package/dist/plugins/manager.js +12 -8
  132. package/dist/ssr.d.ts +15 -0
  133. package/dist/ssr.js +4 -0
  134. package/package.json +29 -25
  135. package/dist/.gitkeep +0 -0
  136. package/dist/core/server/mcpServer.js +0 -29
  137. package/dist/core/services/mcp.js +0 -27
  138. package/dist/core/services/oauth.js +0 -116
  139. package/dist/core/services/preview.js +0 -37
  140. package/dist/core/services/proxy.js +0 -12
  141. package/dist/mcp.d.ts +0 -2
  142. package/dist/mcp.js +0 -7
  143. package/dist/modules/ai/AIEngine.js +0 -120
  144. package/dist/modules/ai/toolkit.js +0 -59
  145. package/dist/modules/mcp/apps/example/view/index.tsx +0 -70
  146. package/dist/modules/mcp/apps/index.js +0 -16
  147. package/dist/modules/mcp/apps/render/index.js +0 -17
  148. package/dist/modules/mcp/apps/render/styles.js +0 -54
  149. package/dist/modules/mcp/apps/render/view/heldBatch.ts +0 -107
  150. package/dist/modules/mcp/apps/render/view/index.tsx +0 -314
  151. package/dist/modules/mcp/apps/render/view/streamProgress.ts +0 -137
  152. package/dist/modules/mcp/apps/shared/assets.js +0 -10
  153. package/dist/modules/mcp/apps/shared/bundle.js +0 -23
  154. package/dist/modules/mcp/apps/shared/page.js +0 -34
  155. package/dist/modules/mcp/apps/shared/registerApp.js +0 -43
  156. package/dist/modules/mcp/apps/shared/resolve.js +0 -5
  157. package/dist/modules/mcp/apps/shared/shell.ejs +0 -59
  158. package/dist/modules/mcp/apps/shared/zodEnglishOnly.js +0 -23
  159. package/dist/modules/mcp/catalogs/builtinCallbacks.js +0 -204
  160. package/dist/modules/mcp/catalogs/builtinComponents.js +0 -170
  161. package/dist/modules/mcp/catalogs/builtinElementCallbacks.js +0 -50
  162. package/dist/modules/mcp/catalogs/builtinTransformers.js +0 -148
  163. package/dist/modules/mcp/catalogs/builtinUtilities.js +0 -90
  164. package/dist/modules/mcp/catalogs/cssCatalog/border.js +0 -30
  165. package/dist/modules/mcp/catalogs/cssCatalog/box.js +0 -31
  166. package/dist/modules/mcp/catalogs/cssCatalog/helpers.js +0 -185
  167. package/dist/modules/mcp/catalogs/cssCatalog/index.js +0 -131
  168. package/dist/modules/mcp/catalogs/cssCatalog/layout.js +0 -98
  169. package/dist/modules/mcp/catalogs/cssCatalog/visual.js +0 -144
  170. package/dist/modules/mcp/catalogs/observed.js +0 -90
  171. package/dist/modules/mcp/catalogs/paramSpec.js +0 -69
  172. package/dist/modules/mcp/catalogs/registry.js +0 -89
  173. package/dist/modules/mcp/handler.js +0 -83
  174. package/dist/modules/mcp/helpers/agentPrompt.js +0 -104
  175. package/dist/modules/mcp/helpers/computeVersion.js +0 -16
  176. package/dist/modules/mcp/helpers/guide.js +0 -467
  177. package/dist/modules/mcp/helpers/interactions.js +0 -123
  178. package/dist/modules/mcp/helpers/log.js +0 -64
  179. package/dist/modules/mcp/helpers/opResult.js +0 -18
  180. package/dist/modules/mcp/helpers/space.js +0 -300
  181. package/dist/modules/mcp/helpers/uris.js +0 -44
  182. package/dist/modules/mcp/previewClient.js +0 -31
  183. package/dist/modules/mcp/proxy/config.js +0 -63
  184. package/dist/modules/mcp/proxy/fetch.js +0 -91
  185. package/dist/modules/mcp/proxy/grant.js +0 -67
  186. package/dist/modules/mcp/proxy/guard.js +0 -38
  187. package/dist/modules/mcp/proxy/handler.js +0 -99
  188. package/dist/modules/mcp/proxy/payload.js +0 -29
  189. package/dist/modules/mcp/proxy/rewrite.js +0 -138
  190. package/dist/modules/mcp/proxy/sign.js +0 -15
  191. package/dist/modules/mcp/proxy/types.js +0 -9
  192. package/dist/modules/mcp/resources/canonical.js +0 -30
  193. package/dist/modules/mcp/resources/core.js +0 -18
  194. package/dist/modules/mcp/resources/envelope.js +0 -14
  195. package/dist/modules/mcp/resources/primer.js +0 -31
  196. package/dist/modules/mcp/resources/register.js +0 -190
  197. package/dist/modules/mcp/resources/renderGuide.js +0 -451
  198. package/dist/modules/mcp/resources/router.js +0 -37
  199. package/dist/modules/mcp/resources/schema.js +0 -43
  200. package/dist/modules/mcp/resources/style.js +0 -34
  201. package/dist/modules/mcp/screenshotClient.js +0 -47
  202. package/dist/modules/mcp/server.js +0 -113
  203. package/dist/modules/mcp/tools/apply/dispatch.js +0 -105
  204. package/dist/modules/mcp/tools/apply/index.js +0 -150
  205. package/dist/modules/mcp/tools/apply/writeResult.js +0 -37
  206. package/dist/modules/mcp/tools/index.js +0 -24
  207. package/dist/modules/mcp/tools/operations/index.js +0 -45
  208. package/dist/modules/mcp/tools/operations/schema/bindings/deleteBinding.js +0 -32
  209. package/dist/modules/mcp/tools/operations/schema/bindings/patchBinding.js +0 -36
  210. package/dist/modules/mcp/tools/operations/schema/bindings/upsertBinding.js +0 -47
  211. package/dist/modules/mcp/tools/operations/schema/elements/deleteElement.js +0 -29
  212. package/dist/modules/mcp/tools/operations/schema/elements/moveElement.js +0 -41
  213. package/dist/modules/mcp/tools/operations/schema/elements/patchElement.js +0 -58
  214. package/dist/modules/mcp/tools/operations/schema/elements/repeatElement.js +0 -148
  215. package/dist/modules/mcp/tools/operations/schema/elements/upsertElement.js +0 -65
  216. package/dist/modules/mcp/tools/operations/schema/folders/deleteFolder.js +0 -30
  217. package/dist/modules/mcp/tools/operations/schema/folders/upsertFolder.js +0 -49
  218. package/dist/modules/mcp/tools/operations/schema/interactions/deleteInteraction.js +0 -52
  219. package/dist/modules/mcp/tools/operations/schema/interactions/patchInteractionNode.js +0 -47
  220. package/dist/modules/mcp/tools/operations/schema/interactions/upsertInteractionFlow.js +0 -44
  221. package/dist/modules/mcp/tools/operations/schema/operations.js +0 -41
  222. package/dist/modules/mcp/tools/operations/schema/pages/deletePage.js +0 -25
  223. package/dist/modules/mcp/tools/operations/schema/pages/upsertPage.js +0 -75
  224. package/dist/modules/mcp/tools/operations/schema/settings/patchSettings.js +0 -45
  225. package/dist/modules/mcp/tools/operations/schema/shared.js +0 -122
  226. package/dist/modules/mcp/tools/operations/schema/translator.js +0 -215
  227. package/dist/modules/mcp/tools/operations/schema/variables/deleteVariable.js +0 -18
  228. package/dist/modules/mcp/tools/operations/schema/variables/upsertVariable.js +0 -42
  229. package/dist/modules/mcp/tools/operations/schema/write.js +0 -109
  230. package/dist/modules/mcp/tools/operations/schemaIds.js +0 -54
  231. package/dist/modules/mcp/tools/operations/style/definitions/deleteDefinition.js +0 -21
  232. package/dist/modules/mcp/tools/operations/style/definitions/patchDefinition.js +0 -28
  233. package/dist/modules/mcp/tools/operations/style/definitions/upsertDefinition.js +0 -24
  234. package/dist/modules/mcp/tools/operations/style/definitions/upsertDefinitions.js +0 -40
  235. package/dist/modules/mcp/tools/operations/style/globalStyles/deleteGlobalStyle.js +0 -21
  236. package/dist/modules/mcp/tools/operations/style/globalStyles/patchGlobalStyle.js +0 -28
  237. package/dist/modules/mcp/tools/operations/style/globalStyles/upsertGlobalStyle.js +0 -24
  238. package/dist/modules/mcp/tools/operations/style/idStyles/deleteIdStyle.js +0 -21
  239. package/dist/modules/mcp/tools/operations/style/idStyles/patchIdStyle.js +0 -28
  240. package/dist/modules/mcp/tools/operations/style/idStyles/upsertIdStyle.js +0 -24
  241. package/dist/modules/mcp/tools/operations/style/operations.js +0 -29
  242. package/dist/modules/mcp/tools/operations/style/shared.js +0 -59
  243. package/dist/modules/mcp/tools/operations/style/translator.js +0 -101
  244. package/dist/modules/mcp/tools/operations/style/variables/deleteStyleVariable.js +0 -21
  245. package/dist/modules/mcp/tools/operations/style/variables/upsertStyleVariable.js +0 -22
  246. package/dist/modules/mcp/tools/operations/style/write.js +0 -108
  247. package/dist/modules/mcp/tools/preview.js +0 -37
  248. package/dist/modules/mcp/tools/read.js +0 -51
  249. package/dist/modules/mcp/tools/render.js +0 -184
  250. package/dist/modules/mcp/tools/screenshot.js +0 -83
  251. package/dist/modules/mcp/tools/search.js +0 -115
  252. package/dist/modules/mcp/tools/shared/expandOperations.js +0 -44
  253. package/dist/modules/mcp/tools/shared/tool.js +0 -33
  254. package/dist/modules/mcp/tools/shared/validator/audit.js +0 -124
  255. package/dist/modules/mcp/tools/shared/validator/batch.js +0 -39
  256. package/dist/modules/mcp/tools/shared/validator/bindings.js +0 -70
  257. package/dist/modules/mcp/tools/shared/validator/context.js +0 -35
  258. package/dist/modules/mcp/tools/shared/validator/css.js +0 -39
  259. package/dist/modules/mcp/tools/shared/validator/elements.js +0 -68
  260. package/dist/modules/mcp/tools/shared/validator/index.js +0 -246
  261. package/dist/modules/mcp/tools/shared/validator/interactions.js +0 -103
  262. package/dist/modules/mcp/tools/shared/validator/refs.js +0 -28
  263. package/dist/modules/mcp/tools/validate.js +0 -47
  264. package/dist/modules/oauth/authorize.js +0 -177
  265. package/dist/modules/oauth/challenge.js +0 -33
  266. package/dist/modules/oauth/consentPage.js +0 -118
  267. package/dist/modules/oauth/metadata.js +0 -69
  268. package/dist/modules/oauth/params.js +0 -5
  269. package/dist/modules/oauth/pkce.js +0 -15
  270. package/dist/modules/oauth/records.js +0 -46
  271. package/dist/modules/oauth/register.js +0 -55
  272. package/dist/modules/oauth/respond.js +0 -44
  273. package/dist/modules/oauth/token.js +0 -100
  274. package/dist/public/.gitkeep +0 -0
  275. package/dist/src/adapters/jsonAdapters.d.ts +0 -7
  276. package/dist/src/core/createServer.d.ts +0 -14
  277. package/dist/src/core/http/stages/health.d.ts +0 -2
  278. package/dist/src/core/http/stages/middlewares.d.ts +0 -2
  279. package/dist/src/core/http/stages/static.d.ts +0 -5
  280. package/dist/src/core/http/types.d.ts +0 -22
  281. package/dist/src/core/server/mcpServer.d.ts +0 -2
  282. package/dist/src/core/server/pageServer.d.ts +0 -10
  283. package/dist/src/core/services/mcp.d.ts +0 -3
  284. package/dist/src/core/services/oauth.d.ts +0 -18
  285. package/dist/src/core/services/preview.d.ts +0 -2
  286. package/dist/src/core/services/proxy.d.ts +0 -2
  287. package/dist/src/core/services/registry.d.ts +0 -4
  288. package/dist/src/helpers/buildServerInfo.d.ts +0 -2
  289. package/dist/src/helpers/compress.d.ts +0 -3
  290. package/dist/src/index.d.ts +0 -15
  291. package/dist/src/mcp.d.ts +0 -14
  292. package/dist/src/middlewares/spaceDeployment.d.ts +0 -2
  293. package/dist/src/modules/ai/AIEngine.d.ts +0 -20
  294. package/dist/src/modules/ai/index.d.ts +0 -4
  295. package/dist/src/modules/ai/toolkit.d.ts +0 -17
  296. package/dist/src/modules/mcp/apps/example/index.d.ts +0 -8
  297. package/dist/src/modules/mcp/apps/index.d.ts +0 -11
  298. package/dist/src/modules/mcp/apps/render/index.d.ts +0 -4
  299. package/dist/src/modules/mcp/apps/render/styles.d.ts +0 -10
  300. package/dist/src/modules/mcp/apps/shared/assets.d.ts +0 -10
  301. package/dist/src/modules/mcp/apps/shared/bundle.d.ts +0 -4
  302. package/dist/src/modules/mcp/apps/shared/index.d.ts +0 -3
  303. package/dist/src/modules/mcp/apps/shared/page.d.ts +0 -2
  304. package/dist/src/modules/mcp/apps/shared/registerApp.d.ts +0 -5
  305. package/dist/src/modules/mcp/apps/shared/resolve.d.ts +0 -1
  306. package/dist/src/modules/mcp/apps/shared/zodEnglishOnly.d.ts +0 -4
  307. package/dist/src/modules/mcp/catalogs/builtinCallbacks.d.ts +0 -23
  308. package/dist/src/modules/mcp/catalogs/builtinComponents.d.ts +0 -4
  309. package/dist/src/modules/mcp/catalogs/builtinElementCallbacks.d.ts +0 -20
  310. package/dist/src/modules/mcp/catalogs/builtinTransformers.d.ts +0 -28
  311. package/dist/src/modules/mcp/catalogs/builtinUtilities.d.ts +0 -18
  312. package/dist/src/modules/mcp/catalogs/cssCatalog/border.d.ts +0 -4
  313. package/dist/src/modules/mcp/catalogs/cssCatalog/box.d.ts +0 -4
  314. package/dist/src/modules/mcp/catalogs/cssCatalog/helpers.d.ts +0 -34
  315. package/dist/src/modules/mcp/catalogs/cssCatalog/index.d.ts +0 -19
  316. package/dist/src/modules/mcp/catalogs/cssCatalog/layout.d.ts +0 -9
  317. package/dist/src/modules/mcp/catalogs/cssCatalog/visual.d.ts +0 -8
  318. package/dist/src/modules/mcp/catalogs/index.d.ts +0 -9
  319. package/dist/src/modules/mcp/catalogs/observed.d.ts +0 -48
  320. package/dist/src/modules/mcp/catalogs/paramSpec.d.ts +0 -42
  321. package/dist/src/modules/mcp/catalogs/registry.d.ts +0 -35
  322. package/dist/src/modules/mcp/e2e/index.d.ts +0 -6
  323. package/dist/src/modules/mcp/e2e/mcpEndpoint.d.ts +0 -27
  324. package/dist/src/modules/mcp/e2e/postMessageChannel.d.ts +0 -22
  325. package/dist/src/modules/mcp/e2e/renderingHost.d.ts +0 -34
  326. package/dist/src/modules/mcp/handler.d.ts +0 -22
  327. package/dist/src/modules/mcp/helpers/agentPrompt.d.ts +0 -4
  328. package/dist/src/modules/mcp/helpers/computeVersion.d.ts +0 -1
  329. package/dist/src/modules/mcp/helpers/guide.d.ts +0 -4
  330. package/dist/src/modules/mcp/helpers/index.d.ts +0 -8
  331. package/dist/src/modules/mcp/helpers/interactions.d.ts +0 -30
  332. package/dist/src/modules/mcp/helpers/log.d.ts +0 -8
  333. package/dist/src/modules/mcp/helpers/opResult.d.ts +0 -13
  334. package/dist/src/modules/mcp/helpers/space.d.ts +0 -115
  335. package/dist/src/modules/mcp/helpers/uris.d.ts +0 -28
  336. package/dist/src/modules/mcp/index.d.ts +0 -13
  337. package/dist/src/modules/mcp/previewClient.d.ts +0 -13
  338. package/dist/src/modules/mcp/proxy/config.d.ts +0 -19
  339. package/dist/src/modules/mcp/proxy/fetch.d.ts +0 -18
  340. package/dist/src/modules/mcp/proxy/grant.d.ts +0 -25
  341. package/dist/src/modules/mcp/proxy/guard.d.ts +0 -6
  342. package/dist/src/modules/mcp/proxy/handler.d.ts +0 -8
  343. package/dist/src/modules/mcp/proxy/index.d.ts +0 -8
  344. package/dist/src/modules/mcp/proxy/payload.d.ts +0 -8
  345. package/dist/src/modules/mcp/proxy/rewrite.d.ts +0 -18
  346. package/dist/src/modules/mcp/proxy/sign.d.ts +0 -6
  347. package/dist/src/modules/mcp/proxy/types.d.ts +0 -45
  348. package/dist/src/modules/mcp/resources/canonical.d.ts +0 -6
  349. package/dist/src/modules/mcp/resources/core.d.ts +0 -5
  350. package/dist/src/modules/mcp/resources/envelope.d.ts +0 -10
  351. package/dist/src/modules/mcp/resources/index.d.ts +0 -8
  352. package/dist/src/modules/mcp/resources/primer.d.ts +0 -7
  353. package/dist/src/modules/mcp/resources/register.d.ts +0 -10
  354. package/dist/src/modules/mcp/resources/renderGuide.d.ts +0 -10
  355. package/dist/src/modules/mcp/resources/router.d.ts +0 -10
  356. package/dist/src/modules/mcp/resources/schema.d.ts +0 -5
  357. package/dist/src/modules/mcp/resources/style.d.ts +0 -5
  358. package/dist/src/modules/mcp/screenshotClient.d.ts +0 -13
  359. package/dist/src/modules/mcp/server.d.ts +0 -31
  360. package/dist/src/modules/mcp/tests/helpers.d.ts +0 -13
  361. package/dist/src/modules/mcp/tools/apply/dispatch.d.ts +0 -6
  362. package/dist/src/modules/mcp/tools/apply/index.d.ts +0 -470
  363. package/dist/src/modules/mcp/tools/apply/writeResult.d.ts +0 -8
  364. package/dist/src/modules/mcp/tools/index.d.ts +0 -18
  365. package/dist/src/modules/mcp/tools/operations/index.d.ts +0 -928
  366. package/dist/src/modules/mcp/tools/operations/schema/bindings/deleteBinding.d.ts +0 -17
  367. package/dist/src/modules/mcp/tools/operations/schema/bindings/patchBinding.d.ts +0 -25
  368. package/dist/src/modules/mcp/tools/operations/schema/bindings/upsertBinding.d.ts +0 -27
  369. package/dist/src/modules/mcp/tools/operations/schema/elements/deleteElement.d.ts +0 -10
  370. package/dist/src/modules/mcp/tools/operations/schema/elements/moveElement.d.ts +0 -16
  371. package/dist/src/modules/mcp/tools/operations/schema/elements/patchElement.d.ts +0 -22
  372. package/dist/src/modules/mcp/tools/operations/schema/elements/repeatElement.d.ts +0 -55
  373. package/dist/src/modules/mcp/tools/operations/schema/elements/upsertElement.d.ts +0 -16
  374. package/dist/src/modules/mcp/tools/operations/schema/folders/deleteFolder.d.ts +0 -9
  375. package/dist/src/modules/mcp/tools/operations/schema/folders/upsertFolder.d.ts +0 -12
  376. package/dist/src/modules/mcp/tools/operations/schema/index.d.ts +0 -21
  377. package/dist/src/modules/mcp/tools/operations/schema/interactions/deleteInteraction.d.ts +0 -12
  378. package/dist/src/modules/mcp/tools/operations/schema/interactions/patchInteractionNode.d.ts +0 -18
  379. package/dist/src/modules/mcp/tools/operations/schema/interactions/upsertInteractionFlow.d.ts +0 -27
  380. package/dist/src/modules/mcp/tools/operations/schema/operations.d.ts +0 -229
  381. package/dist/src/modules/mcp/tools/operations/schema/pages/deletePage.d.ts +0 -9
  382. package/dist/src/modules/mcp/tools/operations/schema/pages/upsertPage.d.ts +0 -14
  383. package/dist/src/modules/mcp/tools/operations/schema/settings/patchSettings.d.ts +0 -34
  384. package/dist/src/modules/mcp/tools/operations/schema/shared.d.ts +0 -92
  385. package/dist/src/modules/mcp/tools/operations/schema/translator.d.ts +0 -12
  386. package/dist/src/modules/mcp/tools/operations/schema/variables/deleteVariable.d.ts +0 -9
  387. package/dist/src/modules/mcp/tools/operations/schema/variables/upsertVariable.d.ts +0 -16
  388. package/dist/src/modules/mcp/tools/operations/schema/write.d.ts +0 -42
  389. package/dist/src/modules/mcp/tools/operations/schemaIds.d.ts +0 -6
  390. package/dist/src/modules/mcp/tools/operations/style/definitions/deleteDefinition.d.ts +0 -9
  391. package/dist/src/modules/mcp/tools/operations/style/definitions/patchDefinition.d.ts +0 -37
  392. package/dist/src/modules/mcp/tools/operations/style/definitions/upsertDefinition.d.ts +0 -37
  393. package/dist/src/modules/mcp/tools/operations/style/definitions/upsertDefinitions.d.ts +0 -41
  394. package/dist/src/modules/mcp/tools/operations/style/globalStyles/deleteGlobalStyle.d.ts +0 -9
  395. package/dist/src/modules/mcp/tools/operations/style/globalStyles/patchGlobalStyle.d.ts +0 -37
  396. package/dist/src/modules/mcp/tools/operations/style/globalStyles/upsertGlobalStyle.d.ts +0 -37
  397. package/dist/src/modules/mcp/tools/operations/style/idStyles/deleteIdStyle.d.ts +0 -9
  398. package/dist/src/modules/mcp/tools/operations/style/idStyles/patchIdStyle.d.ts +0 -37
  399. package/dist/src/modules/mcp/tools/operations/style/idStyles/upsertIdStyle.d.ts +0 -37
  400. package/dist/src/modules/mcp/tools/operations/style/index.d.ts +0 -15
  401. package/dist/src/modules/mcp/tools/operations/style/operations.d.ts +0 -264
  402. package/dist/src/modules/mcp/tools/operations/style/shared.d.ts +0 -116
  403. package/dist/src/modules/mcp/tools/operations/style/translator.d.ts +0 -12
  404. package/dist/src/modules/mcp/tools/operations/style/variables/deleteStyleVariable.d.ts +0 -15
  405. package/dist/src/modules/mcp/tools/operations/style/variables/upsertStyleVariable.d.ts +0 -20
  406. package/dist/src/modules/mcp/tools/operations/style/write.d.ts +0 -12
  407. package/dist/src/modules/mcp/tools/preview.d.ts +0 -465
  408. package/dist/src/modules/mcp/tools/read.d.ts +0 -9
  409. package/dist/src/modules/mcp/tools/render.d.ts +0 -499
  410. package/dist/src/modules/mcp/tools/render.test.d.ts +0 -1
  411. package/dist/src/modules/mcp/tools/screenshot.d.ts +0 -470
  412. package/dist/src/modules/mcp/tools/search.d.ts +0 -15
  413. package/dist/src/modules/mcp/tools/shared/expandOperations.d.ts +0 -13
  414. package/dist/src/modules/mcp/tools/shared/tool.d.ts +0 -72
  415. package/dist/src/modules/mcp/tools/shared/validator/audit.d.ts +0 -4
  416. package/dist/src/modules/mcp/tools/shared/validator/batch.d.ts +0 -5
  417. package/dist/src/modules/mcp/tools/shared/validator/bindings.d.ts +0 -6
  418. package/dist/src/modules/mcp/tools/shared/validator/context.d.ts +0 -38
  419. package/dist/src/modules/mcp/tools/shared/validator/css.d.ts +0 -4
  420. package/dist/src/modules/mcp/tools/shared/validator/elements.d.ts +0 -7
  421. package/dist/src/modules/mcp/tools/shared/validator/index.d.ts +0 -8
  422. package/dist/src/modules/mcp/tools/shared/validator/interactions.d.ts +0 -3
  423. package/dist/src/modules/mcp/tools/shared/validator/refs.d.ts +0 -4
  424. package/dist/src/modules/mcp/tools/validate.d.ts +0 -467
  425. package/dist/src/modules/mcp/types/aiSchema.d.ts +0 -218
  426. package/dist/src/modules/mcp/types/appTypes.d.ts +0 -26
  427. package/dist/src/modules/mcp/types/index.d.ts +0 -5
  428. package/dist/src/modules/mcp/types/previewTypes.d.ts +0 -25
  429. package/dist/src/modules/mcp/types/screenshotTypes.d.ts +0 -29
  430. package/dist/src/modules/mcp/types/toolTypes.d.ts +0 -138
  431. package/dist/src/modules/oauth/authorize.d.ts +0 -7
  432. package/dist/src/modules/oauth/challenge.d.ts +0 -11
  433. package/dist/src/modules/oauth/consentPage.d.ts +0 -7
  434. package/dist/src/modules/oauth/metadata.d.ts +0 -40
  435. package/dist/src/modules/oauth/params.d.ts +0 -5
  436. package/dist/src/modules/oauth/pkce.d.ts +0 -6
  437. package/dist/src/modules/oauth/records.d.ts +0 -71
  438. package/dist/src/modules/oauth/register.d.ts +0 -5
  439. package/dist/src/modules/oauth/respond.d.ts +0 -13
  440. package/dist/src/modules/oauth/token.d.ts +0 -5
  441. package/dist/src/modules/ssr/buildBody.d.ts +0 -9
  442. package/dist/src/modules/ssr/handler.d.ts +0 -4
  443. package/dist/src/modules/ssr/preview.d.ts +0 -16
  444. package/dist/src/modules/ssr/streamBody.d.ts +0 -5
  445. package/dist/src/modules/ssr/template.d.ts +0 -6
  446. package/dist/src/standalone/alias-loader.d.mts +0 -2
  447. package/dist/src/standalone/plugins/ClientInfo.d.ts +0 -2
  448. package/dist/src/standalone/plugins/ServerInfo.d.ts +0 -2
  449. package/dist/src/standalone/plugins/SharedInfo.d.ts +0 -2
  450. package/dist/src/standalone/plugins/styles.d.ts +0 -5
  451. package/dist/src/standalone/register-alias.d.mts +0 -1
  452. package/dist/src/standalone/server.d.ts +0 -1
  453. package/dist/src/standalone/stubs/react-syntax-highlighter.d.mts +0 -31
  454. package/skills/plitzi-render/SKILL.md +0 -174
  455. /package/dist/{src/core/http/dispatcher.test.d.ts → core/auth/api.test.d.ts} +0 -0
  456. /package/dist/{src/core/server/mcpServer.test.d.ts → core/auth/authorize.test.d.ts} +0 -0
  457. /package/dist/{src/modules/ai/toolkit.test.d.ts → core/auth/createAuth.test.d.ts} +0 -0
  458. /package/dist/{src/modules/mcp/apps/apps.test.d.ts → core/auth/domains.test.d.ts} +0 -0
  459. /package/dist/{src/modules/mcp/apps/render/styles.test.d.ts → core/auth/identity.test.d.ts} +0 -0
  460. /package/dist/{src/modules → core/auth}/oauth/oauth.test.d.ts +0 -0
  461. /package/dist/{src/modules/mcp/catalogs/builtinTransformers.test.d.ts → core/auth/routes.test.d.ts} +0 -0
  462. /package/dist/{src/modules/mcp/catalogs/cssCatalog/cssCatalog.test.d.ts → core/auth/session.test.d.ts} +0 -0
  463. /package/dist/{src/modules/mcp/e2e/connector.test.d.ts → core/auth/spaceTokens.test.d.ts} +0 -0
  464. /package/dist/{src/modules/mcp/e2e/host.test.d.ts → core/auth/tokens.test.d.ts} +0 -0
  465. /package/dist/{src/modules/mcp/e2e/oauthConnector.test.d.ts → core/createServer.test.d.ts} +0 -0
  466. /package/dist/{src/modules/mcp/helpers/log.test.d.ts → core/handlers/handlers.test.d.ts} +0 -0
  467. /package/dist/{src/core → core}/health.d.ts +0 -0
  468. /package/dist/{src/modules/mcp/mcp.bench.d.ts → core/http/dispatcher.test.d.ts} +0 -0
  469. /package/dist/{src/core → core}/http/securityHeaders.d.ts +0 -0
  470. /package/dist/{src/core → core}/http/stages/authRoutes.d.ts +0 -0
  471. /package/dist/{src/core → core}/http/stages/pluginAssets.d.ts +0 -0
  472. /package/dist/{src/core → core}/mimeTypes.d.ts +0 -0
  473. /package/dist/{src/modules/mcp/constants.d.ts → core/previewToken.d.ts} +0 -0
  474. /package/dist/{src/core → core}/requestParser.d.ts +0 -0
  475. /package/dist/{src/core → core}/server/baseServer.d.ts +0 -0
  476. /package/dist/{src/modules/mcp/proxy/endpoint.test.d.ts → core/server/baseServer.test.d.ts} +0 -0
  477. /package/dist/{src/modules/mcp/proxy/proxy.test.d.ts → core/services/resolve.test.d.ts} +0 -0
  478. /package/dist/{src/core → core}/services/rsc.d.ts +0 -0
  479. /package/dist/{src/core → core}/services/ssr.d.ts +0 -0
  480. /package/dist/{src/core → core}/staticFiles.d.ts +0 -0
  481. /package/dist/{src/modules/mcp/proxy/wiring.test.d.ts → helpers/buildResponseHelpers.test.d.ts} +0 -0
  482. /package/dist/{src/helpers → helpers}/cache/TtlCache.d.ts +0 -0
  483. /package/dist/{src/helpers → helpers}/cache/cacheManager.d.ts +0 -0
  484. /package/dist/{src/helpers → helpers}/cache/defaults.d.ts +0 -0
  485. /package/dist/{src/helpers → helpers}/cache/index.d.ts +0 -0
  486. /package/dist/{src/modules/mcp/tests/apply.test.d.ts → helpers/cache/keys.test.d.ts} +0 -0
  487. /package/dist/{src/helpers → helpers}/cache/serverCaches.d.ts +0 -0
  488. /package/dist/{src/modules/mcp/tests/bindings.test.d.ts → helpers/compress.test.d.ts} +0 -0
  489. /package/dist/{src/helpers → helpers}/escapeJson.d.ts +0 -0
  490. /package/dist/{src/helpers → helpers}/metrics.d.ts +0 -0
  491. /package/dist/{src/helpers → helpers}/normalizePlugins.d.ts +0 -0
  492. /package/dist/{src/modules/mcp/tests/css.test.d.ts → helpers/offlineDataLoader.test.d.ts} +0 -0
  493. /package/dist/{src/helpers → helpers}/readCookie.d.ts +0 -0
  494. /package/dist/{src/modules/mcp/tests/interactions.test.d.ts → helpers/resolveDebugMode.test.d.ts} +0 -0
  495. /package/dist/{src/helpers → helpers}/runMiddlewares.d.ts +0 -0
  496. /package/dist/{src/helpers → helpers}/serverLog.d.ts +0 -0
  497. /package/dist/{src/middlewares → middlewares}/auth.d.ts +0 -0
  498. /package/dist/{src/middlewares → middlewares}/basicAuth.d.ts +0 -0
  499. /package/dist/{src/modules/mcp/tests/pages.test.d.ts → middlewares/spaceDeployment.test.d.ts} +0 -0
  500. /package/dist/{src/modules/mcp/tests/reads.test.d.ts → modules/actions/handler.test.d.ts} +0 -0
  501. /package/dist/{src/modules/mcp/tests/schemaIds.test.d.ts → modules/connectors/engine.test.d.ts} +0 -0
  502. /package/dist/{src/modules/mcp/tests/search.test.d.ts → modules/connectors/projection.test.d.ts} +0 -0
  503. /package/dist/{src/modules/mcp/tests/skill.test.d.ts → modules/connectors/resolver.test.d.ts} +0 -0
  504. /package/dist/{src/modules/mcp/tests/styles.test.d.ts → modules/rsc/resolveRscData.test.d.ts} +0 -0
  505. /package/dist/{src/modules → modules}/ssr/applySSRResult.d.ts +0 -0
  506. /package/dist/{src/modules/mcp/tests/tools.test.d.ts → modules/ssr/loadPluginComponents.test.d.ts} +0 -0
  507. /package/dist/{src/modules/mcp/tests/validation.test.d.ts → modules/ssr/metering.test.d.ts} +0 -0
  508. /package/dist/{src/modules → modules}/ssr/registerExternalPlugins.d.ts +0 -0
  509. /package/dist/{src/plugins → plugins}/compile.d.ts +0 -0
  510. /package/dist/{src/plugins → plugins}/copy.d.ts +0 -0
  511. /package/dist/{src/plugins → plugins}/detect.d.ts +0 -0
  512. /package/dist/{src/plugins → plugins}/manager.d.ts +0 -0
  513. /package/dist/{src/plugins → plugins}/validate.d.ts +0 -0
  514. /package/dist/{src/plugins → plugins}/validate.test.d.ts +0 -0
@@ -0,0 +1,27 @@
1
+ import { AuthedRequest, JsonResponse } from './types';
2
+ import { AuthPolicy } from '../auth/authorize';
3
+ import { Identity } from '../auth/identity';
4
+ export interface AuthMiddlewareOptions {
5
+ /**
6
+ * Which key carries the human-readable refusal. `error` by convention; `message` for an API whose clients already
7
+ * read that. Only the wording moves — `reason` is always beside it, because that is the half a client acts on.
8
+ */
9
+ errorKey?: 'error' | 'message';
10
+ }
11
+ /**
12
+ * The authorizer, as middleware: `(req, res, next)`.
13
+ *
14
+ * The decision itself is `createAuthorizer` and is the same on every transport — that is why it lives a level down,
15
+ * and why a host that has no middleware chain should call that instead. What is here is the binding: put what was
16
+ * resolved onto the request so everything behind it can read `req.user` and `req.grant`, and answer a refusal in a
17
+ * shape a client can act on.
18
+ *
19
+ * Both halves of that answer matter. The message is for a person reading a log; `reason` is for the browser, and it
20
+ * is what separates "renew me" from "you are gone" — without it a client either signs people out on a hiccup or
21
+ * retries a dead session forever.
22
+ *
23
+ * ```ts
24
+ * app.use(createAuthMiddleware(auth.identity, policy));
25
+ * ```
26
+ */
27
+ export declare const createAuthMiddleware: (identity: Identity, policy: AuthPolicy, options?: AuthMiddlewareOptions) => (req: AuthedRequest, res: JsonResponse, next: () => void) => Promise<void>;
@@ -0,0 +1,38 @@
1
+ import { authFailureMessage } from "../auth/tokens.js";
2
+ import { createAuthorizer } from "../auth/authorize.js";
3
+ //#region src/core/handlers/authMiddleware.ts
4
+ /**
5
+ * The authorizer, as middleware: `(req, res, next)`.
6
+ *
7
+ * The decision itself is `createAuthorizer` and is the same on every transport — that is why it lives a level down,
8
+ * and why a host that has no middleware chain should call that instead. What is here is the binding: put what was
9
+ * resolved onto the request so everything behind it can read `req.user` and `req.grant`, and answer a refusal in a
10
+ * shape a client can act on.
11
+ *
12
+ * Both halves of that answer matter. The message is for a person reading a log; `reason` is for the browser, and it
13
+ * is what separates "renew me" from "you are gone" — without it a client either signs people out on a hiccup or
14
+ * retries a dead session forever.
15
+ *
16
+ * ```ts
17
+ * app.use(createAuthMiddleware(auth.identity, policy));
18
+ * ```
19
+ */
20
+ var createAuthMiddleware = (identity, policy, options = {}) => {
21
+ const { errorKey = "error" } = options;
22
+ const authorize = createAuthorizer(identity, policy);
23
+ return async (req, res, next) => {
24
+ const result = await authorize(req, req.path);
25
+ if (!result.ok) {
26
+ res.status(result.status).json({
27
+ [errorKey]: authFailureMessage[result.reason],
28
+ reason: result.reason
29
+ });
30
+ return;
31
+ }
32
+ if (result.actor) req.user = result.actor;
33
+ if (result.grant) req.grant = result.grant;
34
+ next();
35
+ };
36
+ };
37
+ //#endregion
38
+ export { createAuthMiddleware };
@@ -0,0 +1,46 @@
1
+ import { HttpRoute, RouterLike } from './types';
2
+ import { AuthApi } from '../auth/api';
3
+ import { SessionCookies } from '../auth/session';
4
+ export interface AuthRouteHandlersOptions {
5
+ api: AuthApi;
6
+ cookies: SessionCookies;
7
+ /** Reports a flow that threw. Without it the failure goes to `console.error`; the caller still gets a 500. */
8
+ onError?: (error: unknown, context: {
9
+ method: string;
10
+ path: string;
11
+ }) => void;
12
+ }
13
+ /**
14
+ * The whole `/auth` surface as request handlers: signing in and out, renewing, who-am-I, revoking every session,
15
+ * and whichever of signup and password reset the deployment's adapters offer.
16
+ *
17
+ * The kernel answers these as *outcomes* — a body, a status, what should happen to the session — because it has no
18
+ * idea what any deployment runs behind. Turning an outcome into an HTTP answer is the same everywhere, and every
19
+ * deployment wrote the same loop for it. Doing what the outcome says about the cookies is the part worth not
20
+ * rewriting: writing the session but not its readable hint is the failure that looks like a session which exists
21
+ * and then does not.
22
+ *
23
+ * A list, so nothing has to be a router. On a bare `node:http` server, dispatch it yourself:
24
+ *
25
+ * ```ts
26
+ * const routes = createAuthRouteHandlers({ api: auth.api, cookies: auth.cookies });
27
+ * const route = routes.find(r => r.method === req.method && `/auth${r.path}` === url.pathname);
28
+ * await route?.handle(request, response);
29
+ * ```
30
+ *
31
+ * With a router, {@link mountAuthRoutes} is that same loop already written.
32
+ *
33
+ * Which flows actually answer is decided by the adapters, not here — no `createAccount`, no signup, and the route
34
+ * reports 404 rather than failing at runtime. Mounting all of them is correct for a deployment that offers three.
35
+ */
36
+ export declare const createAuthRouteHandlers: ({ api, cookies, onError }: AuthRouteHandlersOptions) => HttpRoute[];
37
+ /**
38
+ * {@link createAuthRouteHandlers}, hung on anything with `get` and `post`.
39
+ *
40
+ * ```ts
41
+ * const router = Router();
42
+ * mountAuthRoutes(router, { api: auth.api, cookies: auth.cookies });
43
+ * app.use('/auth', router);
44
+ * ```
45
+ */
46
+ export declare const mountAuthRoutes: (router: RouterLike, options: AuthRouteHandlersOptions) => void;
@@ -0,0 +1,75 @@
1
+ import { applySessionOutcome, authRoutes } from "../auth/routes.js";
2
+ //#region src/core/handlers/authRouteHandlers.ts
3
+ /**
4
+ * Built field by field rather than spread: on several frameworks `hostname` is a getter on the request prototype,
5
+ * and a spread copies own properties only — it would arrive undefined, and every cookie would then be named for
6
+ * nowhere. The kind of thing that is obvious once and costs an afternoon otherwise, which is why it is stated here
7
+ * rather than left for each deployment to rediscover.
8
+ */
9
+ var carrier = (req) => ({
10
+ headers: req.headers,
11
+ hostname: req.hostname,
12
+ cookies: req.cookies,
13
+ query: req.query,
14
+ body: req.body,
15
+ actor: req.user
16
+ });
17
+ /**
18
+ * The whole `/auth` surface as request handlers: signing in and out, renewing, who-am-I, revoking every session,
19
+ * and whichever of signup and password reset the deployment's adapters offer.
20
+ *
21
+ * The kernel answers these as *outcomes* — a body, a status, what should happen to the session — because it has no
22
+ * idea what any deployment runs behind. Turning an outcome into an HTTP answer is the same everywhere, and every
23
+ * deployment wrote the same loop for it. Doing what the outcome says about the cookies is the part worth not
24
+ * rewriting: writing the session but not its readable hint is the failure that looks like a session which exists
25
+ * and then does not.
26
+ *
27
+ * A list, so nothing has to be a router. On a bare `node:http` server, dispatch it yourself:
28
+ *
29
+ * ```ts
30
+ * const routes = createAuthRouteHandlers({ api: auth.api, cookies: auth.cookies });
31
+ * const route = routes.find(r => r.method === req.method && `/auth${r.path}` === url.pathname);
32
+ * await route?.handle(request, response);
33
+ * ```
34
+ *
35
+ * With a router, {@link mountAuthRoutes} is that same loop already written.
36
+ *
37
+ * Which flows actually answer is decided by the adapters, not here — no `createAccount`, no signup, and the route
38
+ * reports 404 rather than failing at runtime. Mounting all of them is correct for a deployment that offers three.
39
+ */
40
+ var createAuthRouteHandlers = ({ api, cookies, onError }) => authRoutes({
41
+ api,
42
+ cookies
43
+ }).map(({ method, path, handler }) => ({
44
+ method,
45
+ path,
46
+ handle: async (req, res) => {
47
+ try {
48
+ const outcome = await handler(carrier(req));
49
+ applySessionOutcome(req, res, outcome, cookies);
50
+ res.status(outcome.ok ? outcome.status ?? 200 : outcome.status).json(outcome.body);
51
+ } catch (error) {
52
+ if (onError) onError(error, {
53
+ method,
54
+ path
55
+ });
56
+ else console.error(`[auth] ${method} ${path} failed:`, error);
57
+ res.status(500).json({ error: "Internal server error" });
58
+ }
59
+ }
60
+ }));
61
+ /**
62
+ * {@link createAuthRouteHandlers}, hung on anything with `get` and `post`.
63
+ *
64
+ * ```ts
65
+ * const router = Router();
66
+ * mountAuthRoutes(router, { api: auth.api, cookies: auth.cookies });
67
+ * app.use('/auth', router);
68
+ * ```
69
+ */
70
+ var mountAuthRoutes = (router, options) => {
71
+ for (const { method, path, handle } of createAuthRouteHandlers(options)) if (method === "GET") router.get(path, handle);
72
+ else router.post(path, handle);
73
+ };
74
+ //#endregion
75
+ export { createAuthRouteHandlers, mountAuthRoutes };
@@ -0,0 +1,37 @@
1
+ import { CredentialCarrier } from '../auth/credentials';
2
+ import { Actor, Grant } from '../auth/identity';
3
+ import { CookieSink } from '../auth/session';
4
+ /**
5
+ * A request and a response, described by what these handlers actually touch and nothing more.
6
+ *
7
+ * No framework is imported and none is assumed. A bare `node:http` request satisfies `AuthedRequest` once `path`
8
+ * is filled in (`parseRequest` from the kernel does that); an Express, Connect or Koa request satisfies it as it
9
+ * stands. The response needs three things — a status, a JSON body, and a header for the cookies.
10
+ */
11
+ export interface AuthedRequest extends CredentialCarrier {
12
+ /** The path alone, without the query string — what the policy matches on. */
13
+ path: string;
14
+ /** The parsed body, when there is one. The flows read fields off it; how it got parsed is the host's business. */
15
+ body?: unknown;
16
+ /** The account this request proved, once the auth middleware has run. */
17
+ user?: Actor;
18
+ /** The space this request is addressed to, and what its bearer may do with it. */
19
+ grant?: Grant;
20
+ }
21
+ export interface JsonResponse extends CookieSink {
22
+ status: (code: number) => JsonResponse;
23
+ json: (body: unknown) => unknown;
24
+ }
25
+ export type RouteHandler = (req: AuthedRequest, res: JsonResponse) => Promise<void>;
26
+ /** One flow, ready to serve: where it answers, and what to call when it does. */
27
+ export interface HttpRoute {
28
+ method: 'GET' | 'POST';
29
+ /** Relative to wherever the host mounts the set — `/auth`, conventionally. */
30
+ path: string;
31
+ handle: RouteHandler;
32
+ }
33
+ /** Anything routes can be hung on: a router, an app, or a stand-in in a test — `get` and `post`, nothing else. */
34
+ export interface RouterLike {
35
+ get: (path: string, handler: RouteHandler) => unknown;
36
+ post: (path: string, handler: RouteHandler) => unknown;
37
+ }
@@ -1,7 +1,7 @@
1
1
  import { BaseContext, Stage } from './types';
2
2
  import { RawResponse } from '../../helpers/buildResponseHelpers';
3
3
  import { Handler } from '../transports';
4
- import { SSRRequest, SSRResponseHelpers } from '@plitzi/sdk-shared';
4
+ import { SSRRequest, SSRResponseHelpers, SSRServerConfig } from '@plitzi/sdk-shared';
5
5
  import { IncomingMessage } from 'node:http';
6
6
  export type BuildContext<C extends BaseContext> = (raw: IncomingMessage, rawRes: RawResponse, req: SSRRequest, res: SSRResponseHelpers) => C;
7
- export declare const makeHandler: <C extends BaseContext>(label: string, buildContext: BuildContext<C>, stages: Stage<C>[]) => Handler;
7
+ export declare const makeHandler: <C extends BaseContext>(label: string, buildContext: BuildContext<C>, stages: Stage<C>[], compressionConfig?: SSRServerConfig["compression"]) => Handler;
@@ -1,6 +1,7 @@
1
+ import { clientIp, parseRequest } from "../requestParser.js";
1
2
  import { applySecurityHeaders } from "./securityHeaders.js";
3
+ import { resolveCompression } from "../../helpers/compress.js";
2
4
  import { buildResponseHelpers } from "../../helpers/buildResponseHelpers.js";
3
- import { clientIp, parseRequest } from "../requestParser.js";
4
5
  //#region src/core/http/dispatcher.ts
5
6
  var safePath = (url) => {
6
7
  const [path = "/", query] = url.split("?");
@@ -10,10 +11,10 @@ var safePath = (url) => {
10
11
  };
11
12
  var errorText = (error) => error instanceof Error ? error.message : String(error);
12
13
  var statusOf = (rawRes, res) => rawRes.headersSent ? rawRes.statusCode : res.status;
13
- var runPipeline = async (raw, rawRes, buildContext, stages, server) => {
14
+ var runPipeline = async (raw, rawRes, buildContext, stages, server, compression) => {
14
15
  const startedAt = Date.now();
15
16
  const req = parseRequest(raw);
16
- const res = buildResponseHelpers(rawRes, req.headers["accept-encoding"]);
17
+ const res = buildResponseHelpers(rawRes, req.headers["accept-encoding"], compression);
17
18
  const ctx = buildContext(raw, rawRes, req, res);
18
19
  const logger = ctx.config.logger;
19
20
  const ip = logger ? clientIp(raw, req) : "";
@@ -29,7 +30,7 @@ var runPipeline = async (raw, rawRes, buildContext, stages, server) => {
29
30
  ...ctx.operation === void 0 ? {} : { operation: ctx.operation },
30
31
  status,
31
32
  durationMs: Date.now() - startedAt,
32
- ok: !error && status < 400,
33
+ ok: !error && status < 500,
33
34
  ...error ? { error: errorText(error) } : {},
34
35
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
35
36
  });
@@ -52,9 +53,10 @@ var runPipeline = async (raw, rawRes, buildContext, stages, server) => {
52
53
  throw error;
53
54
  }
54
55
  };
55
- var makeHandler = (label, buildContext, stages) => {
56
+ var makeHandler = (label, buildContext, stages, compressionConfig) => {
57
+ const compression = resolveCompression(compressionConfig);
56
58
  return (raw, rawRes) => {
57
- runPipeline(raw, rawRes, buildContext, stages, label).catch((err) => {
59
+ runPipeline(raw, rawRes, buildContext, stages, label, compression).catch((err) => {
58
60
  console.error(`[${label}] Unhandled error:`, err);
59
61
  try {
60
62
  if (!rawRes.headersSent) rawRes.writeHead(500, { "Content-Type": "text/plain" });
@@ -0,0 +1,11 @@
1
+ import { SSRRequest } from '@plitzi/sdk-shared';
2
+ /**
3
+ * A full-page form submission, as opposed to a script's fetch.
4
+ *
5
+ * The difference decides how an auth flow answers: a browser navigating away from a page it has already left shows
6
+ * its own error page for a bodyless 401, and stays on the stale one for a 204. Either way the visitor sees the wrong
7
+ * thing, so a navigation is answered with a redirect and the view re-renders through a GET. A fetch wants the body.
8
+ */
9
+ export declare const isNavigation: (req: SSRRequest) => boolean;
10
+ /** Same-origin only: absolute URLs and protocol-relative `//host` are refused, to avoid an open redirect. */
11
+ export declare const safeRedirectTarget: (req: SSRRequest) => string;
@@ -0,0 +1,16 @@
1
+ //#region src/core/http/navigation.ts
2
+ /**
3
+ * A full-page form submission, as opposed to a script's fetch.
4
+ *
5
+ * The difference decides how an auth flow answers: a browser navigating away from a page it has already left shows
6
+ * its own error page for a bodyless 401, and stays on the stale one for a 204. Either way the visitor sees the wrong
7
+ * thing, so a navigation is answered with a redirect and the view re-renders through a GET. A fetch wants the body.
8
+ */
9
+ var isNavigation = (req) => req.headers["sec-fetch-mode"] === "navigate";
10
+ /** Same-origin only: absolute URLs and protocol-relative `//host` are refused, to avoid an open redirect. */
11
+ var safeRedirectTarget = (req) => {
12
+ const redirectParam = req.query["redirect"];
13
+ return redirectParam && redirectParam.startsWith("/") && !redirectParam.startsWith("//") ? redirectParam : "/";
14
+ };
15
+ //#endregion
16
+ export { isNavigation, safeRedirectTarget };
@@ -4,10 +4,12 @@ var applySecurityHeaders = (res, config, port) => {
4
4
  res.setHeader("Referrer-Policy", "strict-origin-when-cross-origin");
5
5
  res.setHeader("X-DNS-Prefetch-Control", "off");
6
6
  const frameOptions = config.frameOptions === void 0 ? "DENY" : config.frameOptions;
7
- if (frameOptions) if (Array.isArray(frameOptions)) res.setHeader("Content-Security-Policy", `frame-ancestors ${frameOptions.join(" ")}`);
8
- else {
9
- res.setHeader("X-Frame-Options", frameOptions);
10
- res.setHeader("Content-Security-Policy", `frame-ancestors '${frameOptions === "DENY" ? "none" : "self"}'`);
7
+ if (frameOptions) {
8
+ if (Array.isArray(frameOptions)) res.setHeader("Content-Security-Policy", `frame-ancestors ${frameOptions.join(" ")}`);
9
+ else {
10
+ res.setHeader("X-Frame-Options", frameOptions);
11
+ res.setHeader("Content-Security-Policy", `frame-ancestors '${frameOptions === "DENY" ? "none" : "self"}'`);
12
+ }
11
13
  }
12
14
  if ((config.httpVersion ?? 2) >= 3) res.setHeader("Alt-Svc", `h3=":${port}"; ma=86400`);
13
15
  };
@@ -0,0 +1,17 @@
1
+ import { Auth } from '../../auth/createAuth';
2
+ import { BaseContext, Stage } from '../types';
3
+ /**
4
+ * Serves the whole `/auth` surface: signing in and out, renewing before the credential lapses, answering who this
5
+ * is, revoking every session, and whichever of signup and password reset the deployment offers.
6
+ *
7
+ * A page server that stops at login and logout leaves a space unable to keep anybody signed in — the SDK renews
8
+ * against `refreshUrl`, and with nothing there a visitor is signed out the moment their access token ages out. So
9
+ * `createServer({ auth })` mounts these, and a deployment gets the whole cycle rather than the two ends of it.
10
+ *
11
+ * It owns login and logout too, rather than leaving them to the adapter-only stages that can also answer on those
12
+ * paths: those know how to establish a session and nothing about the account behind it, so they can only answer a
13
+ * bodyless 200 where this one returns the grant — the token, its expiry and who it belongs to. Whichever runs is
14
+ * what a caller gets, so having both live meant a signed-in client that could not tell it had signed in.
15
+ * `createServer` stands the adapter-only pair down when an auth kernel is present.
16
+ */
17
+ export declare const createAuthApiStage: (auth: Auth, basePath?: string) => Stage<BaseContext>;
@@ -0,0 +1,66 @@
1
+ import { readRawBody } from "../../requestParser.js";
2
+ import { isNavigation, safeRedirectTarget } from "../navigation.js";
3
+ //#region src/core/http/stages/authApi.ts
4
+ var parseBody = (raw, contentType) => {
5
+ if (!raw) return;
6
+ if (typeof contentType === "string" && contentType.includes("application/json")) try {
7
+ return JSON.parse(raw);
8
+ } catch {
9
+ return;
10
+ }
11
+ return Object.fromEntries(new URLSearchParams(raw));
12
+ };
13
+ /**
14
+ * Serves the whole `/auth` surface: signing in and out, renewing before the credential lapses, answering who this
15
+ * is, revoking every session, and whichever of signup and password reset the deployment offers.
16
+ *
17
+ * A page server that stops at login and logout leaves a space unable to keep anybody signed in — the SDK renews
18
+ * against `refreshUrl`, and with nothing there a visitor is signed out the moment their access token ages out. So
19
+ * `createServer({ auth })` mounts these, and a deployment gets the whole cycle rather than the two ends of it.
20
+ *
21
+ * It owns login and logout too, rather than leaving them to the adapter-only stages that can also answer on those
22
+ * paths: those know how to establish a session and nothing about the account behind it, so they can only answer a
23
+ * bodyless 200 where this one returns the grant — the token, its expiry and who it belongs to. Whichever runs is
24
+ * what a caller gets, so having both live meant a signed-in client that could not tell it had signed in.
25
+ * `createServer` stands the adapter-only pair down when an auth kernel is present.
26
+ */
27
+ var createAuthApiStage = (auth, basePath = auth.basePath) => {
28
+ const byPath = new Map(auth.routes.map((route) => [`${basePath}${route.path}`, route]));
29
+ return async (ctx) => {
30
+ const { req, res, raw } = ctx;
31
+ const route = byPath.get(req.path);
32
+ if (!route || route.method !== req.method) return false;
33
+ const decision = await auth.authorize(req, req.path);
34
+ if (!decision.ok) {
35
+ res.setStatus(decision.status);
36
+ res.setHeader("Content-Type", "application/json");
37
+ res.send(JSON.stringify({
38
+ error: "Access Not Authorized",
39
+ reason: decision.reason
40
+ }));
41
+ return true;
42
+ }
43
+ req.body = req.method === "POST" ? await readRawBody(raw) : void 0;
44
+ const authRequest = {
45
+ headers: req.headers,
46
+ hostname: req.hostname,
47
+ query: req.query,
48
+ body: parseBody(req.body, req.headers["content-type"]),
49
+ actor: decision.actor
50
+ };
51
+ const outcome = await route.handler(authRequest);
52
+ auth.applySession(req, res, outcome, auth.cookies);
53
+ if (isNavigation(req)) {
54
+ res.setStatus(303);
55
+ res.setHeader("Location", outcome.ok ? safeRedirectTarget(req) : req.path);
56
+ res.end();
57
+ return true;
58
+ }
59
+ res.setStatus(outcome.ok ? outcome.status ?? 200 : outcome.status);
60
+ res.setHeader("Content-Type", "application/json");
61
+ res.send(JSON.stringify(outcome.body));
62
+ return true;
63
+ };
64
+ };
65
+ //#endregion
66
+ export { createAuthApiStage };
@@ -1,23 +1,47 @@
1
1
  import { readRawBody } from "../../requestParser.js";
2
+ import { isNavigation, safeRedirectTarget } from "../navigation.js";
3
+ import { clearSessionCookies, writeSessionCookies } from "../../auth/session.js";
4
+ import { exchangeStage } from "./exchangeRoute.js";
2
5
  //#region src/core/http/stages/authRoutes.ts
3
- var safeRedirectTarget = (req) => {
4
- const redirectParam = req.query["redirect"];
5
- return redirectParam && redirectParam.startsWith("/") && !redirectParam.startsWith("//") ? redirectParam : "/";
6
+ /**
7
+ * Credentials as they arrive from a page: a posted form, or JSON from a script. Every field is handed to the
8
+ * adapter a deployment may sign people in with something other than a username and a password, and this layer
9
+ * has no opinion about which fields those are.
10
+ */
11
+ var parseCredentials = (req) => {
12
+ if (!req.body) return {};
13
+ const contentType = req.headers["content-type"];
14
+ if (typeof contentType === "string" && contentType.includes("application/json")) try {
15
+ const parsed = JSON.parse(req.body);
16
+ return Object.fromEntries(Object.entries(parsed).filter((entry) => typeof entry[1] === "string"));
17
+ } catch {
18
+ return {};
19
+ }
20
+ return Object.fromEntries(new URLSearchParams(req.body));
6
21
  };
7
22
  var loginStage = async (ctx) => {
8
23
  const { config, raw, req, res } = ctx;
9
24
  const loginPath = config.loginPath === false ? null : config.loginPath ?? "/auth/login";
10
25
  if (!loginPath || req.method !== "POST" || req.path !== loginPath) return false;
11
26
  req.body = await readRawBody(raw);
12
- const isLoggedIn = await config.adapters.onLogin?.(req, res);
13
- if (req.headers["sec-fetch-mode"] === "navigate") {
27
+ const session = await config.adapters.authenticate?.(parseCredentials(req), req);
28
+ if (session) writeSessionCookies(req, res, session, config.authCookie);
29
+ if (isNavigation(req)) {
14
30
  res.setStatus(303);
15
- res.setHeader("Location", isLoggedIn ? safeRedirectTarget(req) : loginPath);
31
+ res.setHeader("Location", session ? safeRedirectTarget(req) : loginPath);
16
32
  res.end();
17
33
  return true;
18
34
  }
19
- res.setStatus(isLoggedIn ? 200 : 401);
20
- res.end();
35
+ res.setStatus(session ? 200 : 401);
36
+ res.setHeader("Content-Type", "application/json");
37
+ res.send(JSON.stringify(session ? {
38
+ success: true,
39
+ access_token: session.token,
40
+ expire_at: session.expiresAt
41
+ } : {
42
+ error: "Invalid credentials",
43
+ reason: "invalid"
44
+ }));
21
45
  return true;
22
46
  };
23
47
  var logoutStage = async (ctx) => {
@@ -25,8 +49,9 @@ var logoutStage = async (ctx) => {
25
49
  const logoutPath = config.logoutPath === false ? null : config.logoutPath ?? "/auth/logout";
26
50
  if (!logoutPath || req.method !== "POST" || req.path !== logoutPath) return false;
27
51
  req.body = await readRawBody(raw);
28
- await config.adapters.onLogout?.(req, res);
29
- if (req.headers["sec-fetch-mode"] === "navigate") {
52
+ await config.adapters.endSession?.(req);
53
+ clearSessionCookies(req, res, config.authCookie);
54
+ if (isNavigation(req)) {
30
55
  res.setStatus(303);
31
56
  res.setHeader("Location", safeRedirectTarget(req));
32
57
  res.end();
@@ -36,6 +61,10 @@ var logoutStage = async (ctx) => {
36
61
  res.end();
37
62
  return true;
38
63
  };
39
- var authRoutesStages = [loginStage, logoutStage];
64
+ var authRoutesStages = [
65
+ loginStage,
66
+ logoutStage,
67
+ exchangeStage
68
+ ];
40
69
  //#endregion
41
70
  export { authRoutesStages, loginStage, logoutStage };
@@ -0,0 +1,15 @@
1
+ import { Stage } from '../types';
2
+ /**
3
+ * Turns a credential the browser obtained on its own into a session of this server's, through the
4
+ * `exchangeCredential` adapter. A deployment running the auth kernel gets `POST /auth/exchange` from the flows
5
+ * instead, and `createServer` stands this one down so the two never answer on the same path.
6
+ *
7
+ * It exists for identity providers that live in the front-end — Auth0 and the like — where this server never sees
8
+ * the sign-in and would go on rendering every page as a guest while the browser knows perfectly well who the
9
+ * visitor is. The page then changes under them as it hydrates. Handing the credential over closes that gap.
10
+ *
11
+ * Everything that decides whether the credential is any good is the adapter's: which providers this deployment
12
+ * trusts, whether the token was minted for *this* application, and who it belongs to. This layer contributes the
13
+ * part that is the same everywhere — reading the request, and writing the session it gets back.
14
+ */
15
+ export declare const exchangeStage: Stage;
@@ -0,0 +1,67 @@
1
+ import { readRawBody } from "../../requestParser.js";
2
+ import { writeSessionCookies } from "../../auth/session.js";
3
+ //#region src/core/http/stages/exchangeRoute.ts
4
+ var parseBody = (req) => {
5
+ if (!req.body) return {};
6
+ try {
7
+ const parsed = JSON.parse(req.body);
8
+ return {
9
+ provider: typeof parsed.provider === "string" ? parsed.provider : void 0,
10
+ token: typeof parsed.token === "string" ? parsed.token : void 0
11
+ };
12
+ } catch {
13
+ return {};
14
+ }
15
+ };
16
+ /**
17
+ * Turns a credential the browser obtained on its own into a session of this server's, through the
18
+ * `exchangeCredential` adapter. A deployment running the auth kernel gets `POST /auth/exchange` from the flows
19
+ * instead, and `createServer` stands this one down so the two never answer on the same path.
20
+ *
21
+ * It exists for identity providers that live in the front-end — Auth0 and the like — where this server never sees
22
+ * the sign-in and would go on rendering every page as a guest while the browser knows perfectly well who the
23
+ * visitor is. The page then changes under them as it hydrates. Handing the credential over closes that gap.
24
+ *
25
+ * Everything that decides whether the credential is any good is the adapter's: which providers this deployment
26
+ * trusts, whether the token was minted for *this* application, and who it belongs to. This layer contributes the
27
+ * part that is the same everywhere — reading the request, and writing the session it gets back.
28
+ */
29
+ var exchangeStage = async (ctx) => {
30
+ const { config, raw, req, res } = ctx;
31
+ const exchangePath = config.exchangePath === false ? null : config.exchangePath ?? "/auth/exchange";
32
+ if (!exchangePath || req.method !== "POST" || req.path !== exchangePath) return false;
33
+ if (!config.adapters.exchangeCredential) {
34
+ res.setStatus(404);
35
+ res.end();
36
+ return true;
37
+ }
38
+ req.body = await readRawBody(raw);
39
+ const { provider, token } = parseBody(req);
40
+ if (!provider || !token) {
41
+ res.setStatus(400);
42
+ res.setHeader("Content-Type", "application/json");
43
+ res.send(JSON.stringify({ error: "A provider and a token are required" }));
44
+ return true;
45
+ }
46
+ const result = await config.adapters.exchangeCredential(provider, token, req);
47
+ if (!result.ok) {
48
+ res.setStatus(result.status ?? 401);
49
+ res.setHeader("Content-Type", "application/json");
50
+ res.send(JSON.stringify({
51
+ error: result.error,
52
+ reason: result.reason ?? "revoked"
53
+ }));
54
+ return true;
55
+ }
56
+ writeSessionCookies(req, res, result.session, config.authCookie);
57
+ res.setStatus(200);
58
+ res.setHeader("Content-Type", "application/json");
59
+ res.send(JSON.stringify({
60
+ success: true,
61
+ details: result.user,
62
+ access_token: result.session.token
63
+ }));
64
+ return true;
65
+ };
66
+ //#endregion
67
+ export { exchangeStage };
@@ -0,0 +1,11 @@
1
+ import { Stage } from '../types';
2
+ /**
3
+ * Liveness/readiness endpoint for standalone servers (k8s probes). Always answers at /health so every server built
4
+ * on sdk-server has one without the consumer wiring it. The body is the generic identity payload (from
5
+ * `config.health.name/version/role`) unless `payload` overrides it entirely.
6
+ *
7
+ * `check` is what makes it a readiness probe: it reports live state — the stores this process depends on, most
8
+ * often — and `healthy: false` answers 503 so an orchestrator stops routing to a replica that cannot serve. A
9
+ * server that answered 200 while its database was gone is one an orchestrator keeps sending traffic to.
10
+ */
11
+ export declare const healthStage: Stage;
@@ -1,11 +1,33 @@
1
1
  import { buildHealthPayload } from "../../health.js";
2
2
  //#region src/core/http/stages/health.ts
3
- var healthStage = (ctx) => {
3
+ /**
4
+ * Liveness/readiness endpoint for standalone servers (k8s probes). Always answers at /health so every server built
5
+ * on sdk-server has one without the consumer wiring it. The body is the generic identity payload (from
6
+ * `config.health.name/version/role`) unless `payload` overrides it entirely.
7
+ *
8
+ * `check` is what makes it a readiness probe: it reports live state — the stores this process depends on, most
9
+ * often — and `healthy: false` answers 503 so an orchestrator stops routing to a replica that cannot serve. A
10
+ * server that answered 200 while its database was gone is one an orchestrator keeps sending traffic to.
11
+ */
12
+ var healthStage = async (ctx) => {
4
13
  const health = ctx.config.health;
5
14
  if (ctx.req.path !== (health?.path ?? "/health")) return false;
15
+ const payload = health?.payload ?? buildHealthPayload(health);
16
+ let live = {};
17
+ if (health?.check) try {
18
+ live = await health.check();
19
+ } catch (error) {
20
+ live = {
21
+ healthy: false,
22
+ reason: error instanceof Error ? error.message : String(error)
23
+ };
24
+ }
6
25
  ctx.res.setHeader("Content-Type", "application/json");
7
- ctx.res.setStatus(200);
8
- ctx.res.send(JSON.stringify(health?.payload ?? buildHealthPayload(health)));
26
+ ctx.res.setStatus(live.healthy === false ? 503 : 200);
27
+ ctx.res.send(JSON.stringify({
28
+ ...payload,
29
+ ...live
30
+ }));
9
31
  return true;
10
32
  };
11
33
  //#endregion
@@ -0,0 +1,2 @@
1
+ import { SSRContext, Stage } from '../types';
2
+ export declare const middlewaresStage: Stage<SSRContext>;
@@ -0,0 +1,13 @@
1
+ import { Stage } from '../types';
2
+ export declare const publicDirStage: Stage;
3
+ export declare const wellKnownStage: Stage;
4
+ export declare const configStaticStage: Stage;
5
+ /**
6
+ * The SDK bundle, served from this package's own copy.
7
+ *
8
+ * The rendered page is told to fetch `/sdk-assets/plitzi-sdk.js`, and it is this server that puts the URL there — so
9
+ * answering it is this server's job too, not a mount every deployment has to remember to declare. It runs after
10
+ * `configStaticStage`, so a deployment serving its own build (a pinned version, a CDN mirror) still wins by
11
+ * declaring `static: { '/sdk-assets': … }`.
12
+ */
13
+ export declare const sdkAssetsStage: Stage;