@michaelthielemann/kestrel 1.2.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 (395) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +12 -0
  3. package/README.md +234 -0
  4. package/kestrel.config.ts +28 -0
  5. package/layers/access/nuxt.config.ts +5 -0
  6. package/layers/access/server/middleware/00.ip-allowlist.ts +67 -0
  7. package/layers/access/server/middleware/access-guard.ts +30 -0
  8. package/layers/access/server/types.d.ts +8 -0
  9. package/layers/access/server/utils/csrf.ts +39 -0
  10. package/layers/access/server/utils/grant-registry.ts +36 -0
  11. package/layers/access/server/utils/guard.ts +44 -0
  12. package/layers/access/server/utils/ip-allowlist.ts +76 -0
  13. package/layers/access/server/utils/policy.ts +98 -0
  14. package/layers/access/server/utils/public-resources.ts +11 -0
  15. package/layers/access/server/utils/render-context.ts +41 -0
  16. package/layers/access/server/utils/require-admin.ts +15 -0
  17. package/layers/admin/app/components/AdminAccount.vue +212 -0
  18. package/layers/admin/app/components/AdminNav.vue +44 -0
  19. package/layers/admin/app/components/BlockFields.vue +68 -0
  20. package/layers/admin/app/components/BlockPreview.vue +401 -0
  21. package/layers/admin/app/components/BlockTree.vue +433 -0
  22. package/layers/admin/app/components/BlocksBody.vue +162 -0
  23. package/layers/admin/app/components/CollectionDeleteDialog.vue +38 -0
  24. package/layers/admin/app/components/CollectionEditor.vue +203 -0
  25. package/layers/admin/app/components/CollectionList.vue +1091 -0
  26. package/layers/admin/app/components/EditorStatus.vue +199 -0
  27. package/layers/admin/app/components/EditorUnsupported.vue +28 -0
  28. package/layers/admin/app/components/FieldsBody.vue +23 -0
  29. package/layers/admin/app/components/LocaleBar.vue +105 -0
  30. package/layers/admin/app/components/PageFields.vue +101 -0
  31. package/layers/admin/app/components/PageFieldsPane.vue +39 -0
  32. package/layers/admin/app/components/SeoFields.vue +169 -0
  33. package/layers/admin/app/components/SingletonEditor.vue +92 -0
  34. package/layers/admin/app/composables/useAuth.ts +68 -0
  35. package/layers/admin/app/composables/useBlockTree.ts +95 -0
  36. package/layers/admin/app/composables/useBlocks.ts +7 -0
  37. package/layers/admin/app/composables/useCachedResource.ts +35 -0
  38. package/layers/admin/app/composables/useCollectionOps.ts +53 -0
  39. package/layers/admin/app/composables/useCollections.ts +7 -0
  40. package/layers/admin/app/composables/useContentLocales.ts +23 -0
  41. package/layers/admin/app/composables/useEditForm.ts +370 -0
  42. package/layers/admin/app/composables/useLinkResolver.ts +40 -0
  43. package/layers/admin/app/composables/useListColumns.ts +53 -0
  44. package/layers/admin/app/composables/useListUrlState.ts +53 -0
  45. package/layers/admin/app/composables/usePendingPublishPoll.ts +15 -0
  46. package/layers/admin/app/composables/usePreviewViewport.ts +30 -0
  47. package/layers/admin/app/composables/usePublishStatus.ts +98 -0
  48. package/layers/admin/app/composables/useRailCollapsed.ts +14 -0
  49. package/layers/admin/app/composables/useTheme.ts +36 -0
  50. package/layers/admin/app/composables/useUnsavedGuard.ts +22 -0
  51. package/layers/admin/app/layouts/admin.vue +267 -0
  52. package/layers/admin/app/middleware/admin-auth.ts +4 -0
  53. package/layers/admin/app/pages/admin/[collection]/[id].vue +202 -0
  54. package/layers/admin/app/pages/admin/[collection]/index.vue +62 -0
  55. package/layers/admin/app/pages/admin/index.vue +118 -0
  56. package/layers/admin/app/pages/admin/login.vue +68 -0
  57. package/layers/admin/app/pages/admin/media.vue +28 -0
  58. package/layers/admin/app/pages/admin/references.vue +146 -0
  59. package/layers/admin/app/plugins/admin-style-guard.client.ts +76 -0
  60. package/layers/admin/app/plugins/reauth.client.ts +20 -0
  61. package/layers/admin/app/utils/admin-style-guard.ts +20 -0
  62. package/layers/admin/app/utils/block-tree.ts +214 -0
  63. package/layers/admin/app/utils/collection-ops.ts +44 -0
  64. package/layers/admin/app/utils/dead-refs.ts +30 -0
  65. package/layers/admin/app/utils/edit-form.ts +223 -0
  66. package/layers/admin/app/utils/editor-expose.ts +26 -0
  67. package/layers/admin/app/utils/editor-form-context.ts +83 -0
  68. package/layers/admin/app/utils/editor-registry.ts +20 -0
  69. package/layers/admin/app/utils/field-keys.ts +11 -0
  70. package/layers/admin/app/utils/list-columns.ts +141 -0
  71. package/layers/admin/app/utils/list-query.ts +96 -0
  72. package/layers/admin/app/utils/nav-active.ts +9 -0
  73. package/layers/admin/app/utils/populate-blocks.ts +288 -0
  74. package/layers/admin/app/utils/preview-channel.ts +62 -0
  75. package/layers/admin/app/utils/preview-viewport.ts +80 -0
  76. package/layers/admin/app/utils/reauth.ts +68 -0
  77. package/layers/admin/app/utils/record-title.ts +15 -0
  78. package/layers/admin/app/utils/register-builtin-editors.ts +9 -0
  79. package/layers/admin/app/utils/safe-redirect.ts +12 -0
  80. package/layers/admin/nuxt.config.ts +17 -0
  81. package/layers/auth/nuxt.config.ts +1 -0
  82. package/layers/auth/server/api/auth/login.post.ts +38 -0
  83. package/layers/auth/server/api/auth/logout.post.ts +9 -0
  84. package/layers/auth/server/api/auth/session.get.ts +1 -0
  85. package/layers/auth/server/utils/admin-credential.ts +42 -0
  86. package/layers/auth/server/utils/client-ip.ts +88 -0
  87. package/layers/auth/server/utils/login-throttle.ts +126 -0
  88. package/layers/auth/server/utils/password.ts +52 -0
  89. package/layers/auth/server/utils/session-cookie.ts +44 -0
  90. package/layers/auth/server/utils/session-epoch.ts +96 -0
  91. package/layers/auth/server/utils/session.ts +85 -0
  92. package/layers/collections/nuxt.config.ts +1 -0
  93. package/layers/collections/server/collections/pages.ts +19 -0
  94. package/layers/collections/server/plugins/01.register.ts +32 -0
  95. package/layers/collections/server/plugins/02.register-relation-populate.ts +17 -0
  96. package/layers/collections/server/utils/populate-relations.ts +66 -0
  97. package/layers/core/app/utils/bulk-actions.ts +9 -0
  98. package/layers/core/app/utils/filter-ops.ts +98 -0
  99. package/layers/core/app/utils/list-limits.ts +27 -0
  100. package/layers/core/app/utils/locale-path.ts +12 -0
  101. package/layers/core/app/utils/slugify.ts +16 -0
  102. package/layers/core/modules/auto-discovery/extract-block.ts +176 -0
  103. package/layers/core/modules/auto-discovery/index.ts +44 -0
  104. package/layers/core/modules/auto-discovery/scan.ts +78 -0
  105. package/layers/core/modules/auto-discovery/virtual.d.ts +12 -0
  106. package/layers/core/modules/kestrel/index.ts +86 -0
  107. package/layers/core/nuxt.config.ts +8 -0
  108. package/layers/core/server/api/[collection]/[id]/dead-refs.get.ts +8 -0
  109. package/layers/core/server/api/[collection]/[id]/translations.get.ts +4 -0
  110. package/layers/core/server/api/[collection]/[id].delete.ts +5 -0
  111. package/layers/core/server/api/[collection]/[id].get.ts +8 -0
  112. package/layers/core/server/api/[collection]/[id].patch.ts +8 -0
  113. package/layers/core/server/api/[collection]/bulk.post.ts +37 -0
  114. package/layers/core/server/api/[collection]/index.get.ts +19 -0
  115. package/layers/core/server/api/[collection]/index.post.ts +8 -0
  116. package/layers/core/server/api/[collection]/index.put.ts +7 -0
  117. package/layers/core/server/api/[collection]/options.get.ts +18 -0
  118. package/layers/core/server/api/[collection]/translations.get.ts +25 -0
  119. package/layers/core/server/api/collections/[name].get.ts +4 -0
  120. package/layers/core/server/api/collections/index.get.ts +3 -0
  121. package/layers/core/server/api/references/broken.get.ts +3 -0
  122. package/layers/core/server/api/references/referrers.get.ts +24 -0
  123. package/layers/core/server/database/record-refs.ts +20 -0
  124. package/layers/core/server/plugins/00.migrate.ts +11 -0
  125. package/layers/core/server/plugins/02.schema-sync.ts +63 -0
  126. package/layers/core/server/plugins/03.record-refs.ts +12 -0
  127. package/layers/core/server/schema/bootstrap.ts +41 -0
  128. package/layers/core/server/schema/desired.ts +99 -0
  129. package/layers/core/server/schema/dev-sync.ts +23 -0
  130. package/layers/core/server/schema/dialect.ts +59 -0
  131. package/layers/core/server/schema/diff.ts +110 -0
  132. package/layers/core/server/schema/introspect.ts +67 -0
  133. package/layers/core/server/schema/model.ts +61 -0
  134. package/layers/core/server/schema/render-sqlite.ts +89 -0
  135. package/layers/core/server/schema/sync.ts +201 -0
  136. package/layers/core/server/tasks/db/migrate.ts +54 -0
  137. package/layers/core/server/utils/blocks.ts +6 -0
  138. package/layers/core/server/utils/collection-types.ts +27 -0
  139. package/layers/core/server/utils/crud.ts +577 -0
  140. package/layers/core/server/utils/db.ts +26 -0
  141. package/layers/core/server/utils/defineCollection.ts +207 -0
  142. package/layers/core/server/utils/duplicate.ts +162 -0
  143. package/layers/core/server/utils/field-layout.ts +125 -0
  144. package/layers/core/server/utils/filter-predicate.ts +101 -0
  145. package/layers/core/server/utils/http.ts +50 -0
  146. package/layers/core/server/utils/if-unmodified.ts +13 -0
  147. package/layers/core/server/utils/kestrel-config.ts +410 -0
  148. package/layers/core/server/utils/key-lock.ts +33 -0
  149. package/layers/core/server/utils/locale.ts +53 -0
  150. package/layers/core/server/utils/page-route.ts +58 -0
  151. package/layers/core/server/utils/page-slug.ts +127 -0
  152. package/layers/core/server/utils/picker.ts +82 -0
  153. package/layers/core/server/utils/populate.ts +48 -0
  154. package/layers/core/server/utils/prerender-memo.ts +23 -0
  155. package/layers/core/server/utils/read-capture.ts +37 -0
  156. package/layers/core/server/utils/record-ref-index.ts +200 -0
  157. package/layers/core/server/utils/registry.ts +24 -0
  158. package/layers/core/server/utils/resolve-scope.ts +79 -0
  159. package/layers/core/server/utils/seo.ts +24 -0
  160. package/layers/core/server/utils/serialize-collection.ts +149 -0
  161. package/layers/core/server/utils/server-config.ts +18 -0
  162. package/layers/core/server/utils/sql.ts +2 -0
  163. package/layers/core/server/utils/storage.local.ts +117 -0
  164. package/layers/core/server/utils/storage.s3.ts +197 -0
  165. package/layers/core/server/utils/storage.ts +90 -0
  166. package/layers/core/server/utils/write-events.ts +31 -0
  167. package/layers/fields/app/utils/condition.ts +71 -0
  168. package/layers/fields/app/utils/define-block.ts +13 -0
  169. package/layers/fields/app/utils/field-constraints.ts +17 -0
  170. package/layers/fields/app/utils/field-factories.ts +129 -0
  171. package/layers/fields/app/utils/field-meta.ts +33 -0
  172. package/layers/fields/app/utils/field-validate.ts +75 -0
  173. package/layers/fields/app/utils/field-value.ts +7 -0
  174. package/layers/fields/app/utils/richtext-links.ts +48 -0
  175. package/layers/fields/nuxt.config.ts +1 -0
  176. package/layers/fields/server/api/blocks/index.get.ts +9 -0
  177. package/layers/fields/server/field-registry/index.ts +248 -0
  178. package/layers/fields/server/field-registry/naming.ts +10 -0
  179. package/layers/fields/server/field-registry/sanitize.ts +40 -0
  180. package/layers/fields/server/field-registry/types.ts +19 -0
  181. package/layers/fields/server/plugins/01.register-field-populate.ts +11 -0
  182. package/layers/fields/server/utils/block-ids.ts +43 -0
  183. package/layers/fields/server/utils/block-populate.ts +41 -0
  184. package/layers/fields/server/utils/buildCollection.ts +88 -0
  185. package/layers/fields/server/utils/buildFieldSchema.ts +22 -0
  186. package/layers/fields/server/utils/buildTable.ts +107 -0
  187. package/layers/fields/server/utils/conditional-required.ts +25 -0
  188. package/layers/fields/server/utils/defineBlock.ts +86 -0
  189. package/layers/fields/server/utils/defineFieldType.ts +33 -0
  190. package/layers/fields/server/utils/extract-refs.ts +152 -0
  191. package/layers/fields/server/utils/field-populate.ts +68 -0
  192. package/layers/media/app/components/KestrelImg.vue +65 -0
  193. package/layers/media/app/components/MediaConflictDialog.vue +35 -0
  194. package/layers/media/app/components/MediaDeleteDialog.vue +52 -0
  195. package/layers/media/app/components/MediaGrid.vue +113 -0
  196. package/layers/media/app/components/MediaImage.vue +70 -0
  197. package/layers/media/app/components/MediaLibrary.vue +451 -0
  198. package/layers/media/app/components/MediaNewFolderDialog.vue +32 -0
  199. package/layers/media/app/components/MediaPathBar.vue +163 -0
  200. package/layers/media/app/components/MediaPicker.vue +19 -0
  201. package/layers/media/app/components/MediaRenameDialog.vue +32 -0
  202. package/layers/media/app/components/MediaTable.vue +75 -0
  203. package/layers/media/app/components/MediaThumb.vue +25 -0
  204. package/layers/media/app/components/MediaToolbar.vue +90 -0
  205. package/layers/media/app/components/MediaUploadDialog.vue +87 -0
  206. package/layers/media/app/components/MediaViewer.vue +88 -0
  207. package/layers/media/app/components/field/Media.vue +261 -0
  208. package/layers/media/app/composables/useBlurUp.ts +55 -0
  209. package/layers/media/app/composables/useMediaClipboard.ts +14 -0
  210. package/layers/media/app/composables/useMediaContextMenu.ts +56 -0
  211. package/layers/media/app/composables/useMediaDnd.ts +56 -0
  212. package/layers/media/app/composables/useMediaLibrary.ts +151 -0
  213. package/layers/media/app/composables/useMediaOps.ts +50 -0
  214. package/layers/media/app/composables/useMediaRelocate.ts +39 -0
  215. package/layers/media/app/composables/useMediaResolver.ts +50 -0
  216. package/layers/media/app/composables/useMediaUpload.ts +93 -0
  217. package/layers/media/app/composables/useMediaVariant.ts +34 -0
  218. package/layers/media/app/plugins/field-media.client.ts +6 -0
  219. package/layers/media/app/utils/dnd.ts +69 -0
  220. package/layers/media/app/utils/library.ts +79 -0
  221. package/layers/media/app/utils/ops.ts +62 -0
  222. package/layers/media/app/utils/picture-model.ts +125 -0
  223. package/layers/media/app/utils/thumbhash.ts +19 -0
  224. package/layers/media/app/utils/variant-name.ts +20 -0
  225. package/layers/media/nuxt.config.ts +3 -0
  226. package/layers/media/server/api/media/[id]/usages.get.ts +8 -0
  227. package/layers/media/server/api/media/[id].delete.ts +18 -0
  228. package/layers/media/server/api/media/[id].get.ts +10 -0
  229. package/layers/media/server/api/media/[id].patch.ts +41 -0
  230. package/layers/media/server/api/media/backfill.post.ts +18 -0
  231. package/layers/media/server/api/media/copy.post.ts +7 -0
  232. package/layers/media/server/api/media/delete.post.ts +13 -0
  233. package/layers/media/server/api/media/folders.post.ts +18 -0
  234. package/layers/media/server/api/media/index.get.ts +15 -0
  235. package/layers/media/server/api/media/index.post.ts +157 -0
  236. package/layers/media/server/api/media/library.get.ts +17 -0
  237. package/layers/media/server/api/media/move.post.ts +7 -0
  238. package/layers/media/server/api/media/rename.post.ts +7 -0
  239. package/layers/media/server/api/media/resolve.get.ts +13 -0
  240. package/layers/media/server/collections/media-settings.ts +25 -0
  241. package/layers/media/server/collections/media.ts +29 -0
  242. package/layers/media/server/database/folders.ts +10 -0
  243. package/layers/media/server/middleware/ondemand-variants.ts +37 -0
  244. package/layers/media/server/plugins/02.register-media.ts +19 -0
  245. package/layers/media/server/plugins/03.media-cleanup.ts +20 -0
  246. package/layers/media/server/plugins/04.variant-capture.ts +23 -0
  247. package/layers/media/server/schema-tables/folders.ts +4 -0
  248. package/layers/media/server/tasks/media/backfill.ts +18 -0
  249. package/layers/media/server/utils/backfill.ts +132 -0
  250. package/layers/media/server/utils/derive.ts +59 -0
  251. package/layers/media/server/utils/folder-paths.ts +42 -0
  252. package/layers/media/server/utils/folders.ts +12 -0
  253. package/layers/media/server/utils/library.ts +90 -0
  254. package/layers/media/server/utils/media-cleanup.ts +27 -0
  255. package/layers/media/server/utils/media-enabled.ts +23 -0
  256. package/layers/media/server/utils/media-ops.ts +118 -0
  257. package/layers/media/server/utils/media-write.ts +13 -0
  258. package/layers/media/server/utils/naming.ts +52 -0
  259. package/layers/media/server/utils/ondemand.ts +69 -0
  260. package/layers/media/server/utils/persist-upload.ts +62 -0
  261. package/layers/media/server/utils/populate.ts +47 -0
  262. package/layers/media/server/utils/record.ts +63 -0
  263. package/layers/media/server/utils/relocate-ops.ts +341 -0
  264. package/layers/media/server/utils/relocate-plan.ts +63 -0
  265. package/layers/media/server/utils/resolve.ts +86 -0
  266. package/layers/media/server/utils/sanitize-svg.ts +12 -0
  267. package/layers/media/server/utils/sniff.ts +68 -0
  268. package/layers/media/server/utils/storage-relocate.ts +139 -0
  269. package/layers/media/server/utils/translations.ts +19 -0
  270. package/layers/media/server/utils/usages.ts +66 -0
  271. package/layers/media/server/utils/variant-capture.ts +70 -0
  272. package/layers/media/server/utils/variants.ts +108 -0
  273. package/layers/public/app/app.vue +5 -0
  274. package/layers/public/app/components/BlockRenderer.vue +56 -0
  275. package/layers/public/app/components/KestrelLink.vue +26 -0
  276. package/layers/public/app/components/KestrelPreviewBridge.vue +133 -0
  277. package/layers/public/app/composables/public-page.ts +24 -0
  278. package/layers/public/app/error.vue +12 -0
  279. package/layers/public/app/layouts/default.vue +5 -0
  280. package/layers/public/app/pages/[...slug].vue +157 -0
  281. package/layers/public/app/pages/__kestrel/preview.vue +34 -0
  282. package/layers/public/app/utils/block-edit-context.ts +16 -0
  283. package/layers/public/app/utils/link-href.ts +46 -0
  284. package/layers/public/app/utils/page-head.ts +84 -0
  285. package/layers/public/app/utils/preview-protocol.ts +81 -0
  286. package/layers/public/app/utils/public-route.ts +46 -0
  287. package/layers/public/modules/deploy-output/deploy-output.ts +370 -0
  288. package/layers/public/modules/deploy-output/index.ts +82 -0
  289. package/layers/public/modules/prerender-routes/discover.ts +37 -0
  290. package/layers/public/modules/prerender-routes/index.ts +85 -0
  291. package/layers/public/modules/prerender-routes/routes.ts +16 -0
  292. package/layers/public/modules/prune-media/index.ts +48 -0
  293. package/layers/public/modules/prune-media/prune-media.ts +81 -0
  294. package/layers/public/nuxt.config.ts +11 -0
  295. package/layers/public/server/api/links/resolve.get.ts +19 -0
  296. package/layers/public/server/api/publish-status.get.ts +44 -0
  297. package/layers/public/server/api/route.get.ts +18 -0
  298. package/layers/public/server/database/publish-deps.ts +12 -0
  299. package/layers/public/server/database/publish-status.ts +19 -0
  300. package/layers/public/server/plugins/02.register-links.ts +17 -0
  301. package/layers/public/server/plugins/zz.publish.ts +63 -0
  302. package/layers/public/server/routes/llms.txt.get.ts +72 -0
  303. package/layers/public/server/routes/robots.txt.get.ts +8 -0
  304. package/layers/public/server/routes/sitemap.xml.get.ts +66 -0
  305. package/layers/public/server/schema-tables/publish-deps.ts +4 -0
  306. package/layers/public/server/schema-tables/publish-status.ts +4 -0
  307. package/layers/public/server/tasks/publish/run.ts +26 -0
  308. package/layers/public/server/utils/link-resolve.ts +35 -0
  309. package/layers/public/server/utils/llms.ts +39 -0
  310. package/layers/public/server/utils/page-resolve.ts +86 -0
  311. package/layers/public/server/utils/populate-links.ts +66 -0
  312. package/layers/public/server/utils/publish/coalesce.ts +22 -0
  313. package/layers/public/server/utils/publish/deps-persistence.ts +43 -0
  314. package/layers/public/server/utils/publish/deps.ts +87 -0
  315. package/layers/public/server/utils/publish/invalidation.ts +141 -0
  316. package/layers/public/server/utils/publish/publish-status.ts +54 -0
  317. package/layers/public/server/utils/publish/publisher.ts +291 -0
  318. package/layers/public/server/utils/publish/queue.ts +67 -0
  319. package/layers/public/server/utils/publish/route-for-record.ts +16 -0
  320. package/layers/public/server/utils/publish/route-keys.ts +13 -0
  321. package/layers/public/server/utils/site-url.ts +32 -0
  322. package/layers/public/server/utils/sitemap.ts +97 -0
  323. package/layers/ui/app/assets/scss/_base.scss +16 -0
  324. package/layers/ui/app/assets/scss/_datepicker.scss +82 -0
  325. package/layers/ui/app/assets/scss/_mixins.scss +50 -0
  326. package/layers/ui/app/assets/scss/_reset.scss +65 -0
  327. package/layers/ui/app/assets/scss/_tokens.scss +183 -0
  328. package/layers/ui/app/assets/scss/main.scss +4 -0
  329. package/layers/ui/app/components/field/Boolean.vue +30 -0
  330. package/layers/ui/app/components/field/Choice.vue +68 -0
  331. package/layers/ui/app/components/field/Datetime.vue +96 -0
  332. package/layers/ui/app/components/field/DeadRefNote.vue +28 -0
  333. package/layers/ui/app/components/field/Json.vue +63 -0
  334. package/layers/ui/app/components/field/Layout.vue +140 -0
  335. package/layers/ui/app/components/field/Link.vue +112 -0
  336. package/layers/ui/app/components/field/LinkInternalPicker.vue +95 -0
  337. package/layers/ui/app/components/field/Number.vue +30 -0
  338. package/layers/ui/app/components/field/Relation.vue +49 -0
  339. package/layers/ui/app/components/field/Renderer.vue +30 -0
  340. package/layers/ui/app/components/field/Repeater.vue +460 -0
  341. package/layers/ui/app/components/field/Richtext.vue +26 -0
  342. package/layers/ui/app/components/field/Slug.vue +66 -0
  343. package/layers/ui/app/components/field/Text.vue +35 -0
  344. package/layers/ui/app/components/field/Unsupported.vue +34 -0
  345. package/layers/ui/app/components/ui/Alert.vue +50 -0
  346. package/layers/ui/app/components/ui/Brand.vue +22 -0
  347. package/layers/ui/app/components/ui/Button.vue +116 -0
  348. package/layers/ui/app/components/ui/ButtonGroup.vue +96 -0
  349. package/layers/ui/app/components/ui/Checkbox.vue +52 -0
  350. package/layers/ui/app/components/ui/CheckboxGroup.vue +50 -0
  351. package/layers/ui/app/components/ui/Combobox.vue +343 -0
  352. package/layers/ui/app/components/ui/DatePicker.vue +92 -0
  353. package/layers/ui/app/components/ui/DateRangePicker.vue +100 -0
  354. package/layers/ui/app/components/ui/Dialog.vue +107 -0
  355. package/layers/ui/app/components/ui/EmptyState.vue +46 -0
  356. package/layers/ui/app/components/ui/Field.vue +57 -0
  357. package/layers/ui/app/components/ui/Fieldset.vue +64 -0
  358. package/layers/ui/app/components/ui/Icon.vue +44 -0
  359. package/layers/ui/app/components/ui/Menu.vue +54 -0
  360. package/layers/ui/app/components/ui/NumberInput.vue +173 -0
  361. package/layers/ui/app/components/ui/Richtext.vue +119 -0
  362. package/layers/ui/app/components/ui/RichtextToolbar.vue +253 -0
  363. package/layers/ui/app/components/ui/Select.vue +51 -0
  364. package/layers/ui/app/components/ui/TextInput.vue +110 -0
  365. package/layers/ui/app/components/ui/Textarea.vue +38 -0
  366. package/layers/ui/app/components/ui/TimeInput.vue +17 -0
  367. package/layers/ui/app/components/ui/Toasts.vue +103 -0
  368. package/layers/ui/app/components/ui/Tooltip.vue +45 -0
  369. package/layers/ui/app/composables/useAdminLang.ts +8 -0
  370. package/layers/ui/app/composables/useDragReorder.ts +41 -0
  371. package/layers/ui/app/composables/useEchoGuard.ts +28 -0
  372. package/layers/ui/app/composables/useLinkField.ts +70 -0
  373. package/layers/ui/app/composables/useRecordOptions.ts +84 -0
  374. package/layers/ui/app/composables/useRepeater.ts +99 -0
  375. package/layers/ui/app/composables/useT.ts +32 -0
  376. package/layers/ui/app/composables/useToast.ts +46 -0
  377. package/layers/ui/app/i18n/de.ts +406 -0
  378. package/layers/ui/app/i18n/en.ts +440 -0
  379. package/layers/ui/app/utils/boolean-field.ts +10 -0
  380. package/layers/ui/app/utils/field-component.ts +22 -0
  381. package/layers/ui/app/utils/field-empty.ts +21 -0
  382. package/layers/ui/app/utils/field-registry.ts +36 -0
  383. package/layers/ui/app/utils/humanize.ts +14 -0
  384. package/layers/ui/app/utils/icons.ts +147 -0
  385. package/layers/ui/app/utils/iso-date.ts +18 -0
  386. package/layers/ui/app/utils/localized.ts +13 -0
  387. package/layers/ui/app/utils/record-context.ts +15 -0
  388. package/layers/ui/app/utils/reorder.ts +8 -0
  389. package/layers/ui/app/utils/richtext-preserve-class.ts +31 -0
  390. package/layers/ui/app/utils/useFieldA11y.ts +40 -0
  391. package/layers/ui/nuxt.config.ts +5 -0
  392. package/nuxt.config.ts +105 -0
  393. package/package.json +122 -0
  394. package/scripts/hash-password.mjs +26 -0
  395. package/scripts/typecheck.mjs +51 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,12 @@
1
+ Kestrel
2
+ Copyright 2026 Michael Thielemann
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
5
+ this software except in compliance with the License. You may obtain a copy of
6
+ the License in the LICENSE file distributed with this software, or at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ This product is provided free of charge and is developed and made available
11
+ outside of any commercial activity. It comes with NO WARRANTY and no commercial
12
+ support; see sections 7 and 8 of the License.
package/README.md ADDED
@@ -0,0 +1,234 @@
1
+ # Kestrel
2
+
3
+ A slim, **static-site-generator CMS**: a generic collection-driven CRUD core with a schema-driven admin
4
+ editor. You declare collections and fields in TypeScript; Kestrel derives the database, a typed CRUD API,
5
+ and a full admin UI from those definitions, and renders published content to static HTML via
6
+ `nuxt generate` — there is **no live public SSR**.
7
+
8
+ Built on **Nuxt 4 layers + Drizzle/SQLite + Zod**. The whole CMS is a stack of swappable Nuxt layers, so
9
+ a consumer extends it (`extends: ['@michaelthielemann/kestrel']`) and drops in their own collection/field/block definitions.
10
+
11
+ ## What Kestrel is — and isn't
12
+
13
+ Kestrel is a **CMS engine**, not a finished website. It ships the admin UI, the schema/CRUD/render
14
+ engines, and two toggleable built-in collections (`pages` + the `media` library); **you** define your
15
+ content model and bring the public components and layout that render it.
16
+
17
+ It is for a private editing origin that publishes **static HTML** (a local dir or S3), served by any
18
+ static host. It is deliberately **not**:
19
+
20
+ - **No live public SSR** — published pages are static (`nuxt generate` or the runtime incremental
21
+ publisher); there is no per-request rendering of the public site.
22
+ - **Single-user** — one admin (session + CSRF). No roles, capabilities, or multi-user.
23
+ - **SQLite only** — one database, single instance. (A Postgres `Dialect` seam exists; no impl is active.)
24
+ - **No public data API** — only published *page-like* records have a read surface (mirroring the static
25
+ output); everything else stays behind the admin guard. No per-request rate limiting / live API.
26
+ - **No runtime redirect engine** — handle redirects at the edge (NGINX / CDN).
27
+ - **No per-file access control on uploads.** The admin guard protects the media *library* — listing,
28
+ editing, deleting — but not the bytes. With `media.driver: 'local'` the files are served from the app
29
+ origin by Nitro's static handler, which runs ahead of every middleware, so anyone who knows a URL can
30
+ fetch it; the optional IP allow-list does not cover them either (see
31
+ [configuration.md](./docs/configuration.md#ip-allow-list--optional)). That is the intended model — the
32
+ editing origin is meant to be non-public, and published media is public by definition. If you deploy
33
+ Kestrel as a general-purpose CMS whose uploads must stay private, restrict them at the reverse proxy or
34
+ serve media from a private S3 bucket; the app will not do it for you.
35
+
36
+ ## Features
37
+
38
+ - **Collection-driven** — declare collections + fields in TypeScript; Kestrel derives the SQLite tables, a
39
+ typed CRUD REST API, and the full admin UI. The schema **migrates itself** (additive in dev; explicit
40
+ `db:migrate` in prod).
41
+ - **Field types** — text, textarea, rich-text, number, boolean, choice (select / buttons / checkboxes),
42
+ date / time, media, relation (single / many), link (internal / external / email / tel), repeater
43
+ (nestable), JSON — plus per-field `condition` visibility rules.
44
+ - **Page-like collections** — give a collection a `path`, SEO meta, and block or flat content; published
45
+ records render to static HTML and join the sitemap. **Singletons** for settings / navigation.
46
+ - **Block page-builder** — a 3-pane editor (tree · live preview · fields) with nestable block slots; each
47
+ block is a single `app/blocks/*.vue` SFC (schema via field-factory `defineProps` + the display template).
48
+ - **Media library** — upload (magic-byte sniff + SVG sanitize), local or S3 storage, responsive WebP
49
+ derivatives + thumbhash, folders, and a full-screen asset viewer.
50
+ - **Multilingual content** — optional per-record translations, an editor locale flow, locale-prefixed
51
+ routing, hreflang alternates in the sitemap.
52
+ - **Static output** — `nuxt generate` (full rebuild) or a runtime **incremental publisher** (re-renders
53
+ only the pages a write affects), to a local dir or S3; emits `sitemap.xml`, `robots.txt`, and
54
+ **`llms.txt`** (an [llmstxt.org](https://llmstxt.org) site map so AI agents grasp the site). A live
55
+ in-dashboard preview renders straight from the origin.
56
+ - **Reference integrity** — writes invalidate exactly the affected static pages; dead-reference warnings;
57
+ required + globally-unique page slugs per locale.
58
+
59
+ ## Quickstart (consumer)
60
+
61
+ ```bash
62
+ pnpm add @michaelthielemann/kestrel
63
+ ```
64
+
65
+ ```ts
66
+ // nuxt.config.ts
67
+ export default defineNuxtConfig({
68
+ extends: ['@michaelthielemann/kestrel'],
69
+ kestrel: {
70
+ db: '.data/site.sqlite',
71
+ siteUrl: 'https://example.com',
72
+ siteName: 'Example', // used in the generated llms.txt
73
+ locales: ['en', 'de'],
74
+ media: { uploadDir: '.data/uploads' },
75
+ // collections: { pages: false }, // drop a built-in to define your own with that name
76
+ },
77
+ })
78
+ ```
79
+
80
+ ```ts
81
+ // server/collections/products.ts — auto-discovered; the table is created on next boot
82
+ export default defineCollection({
83
+ name: 'products',
84
+ mode: 'multi',
85
+ fields: { title: { type: 'text', required: true }, price: { type: 'number' }, image: { type: 'media' } },
86
+ })
87
+ ```
88
+
89
+ Set the auth env (`KESTREL_SESSION_SECRET`, `KESTREL_ADMIN_PASSWORD_HASH`), start the app, and manage
90
+ content at `/admin`. You bring your own **public layout** and **block SFCs**
91
+ (`app/blocks/Hero.vue` — one file for schema + display — is the `hero` block). Full guide:
92
+ **[consuming-kestrel.md](docs/consuming-kestrel.md)**.
93
+
94
+ ## Documentation
95
+
96
+ Start with the **[architecture guide](docs/architecture.md)** — a per-layer map (what each layer owns,
97
+ where to start reading, the cross-layer seams, the gotchas). Then the per-topic docs:
98
+
99
+ | Doc | Covers |
100
+ |-----|--------|
101
+ | [architecture.md](docs/architecture.md) | **Start here** — the layer model, boot order, cross-cutting seams, per-layer guide |
102
+ | [consuming-kestrel.md](docs/consuming-kestrel.md) | Using Kestrel in your own app: defining collections/fields/blocks, auto-discovery, the schema lifecycle |
103
+ | [configuration.md](docs/configuration.md) | The single config source (`kestrel.config.ts`), every `KESTREL_*` env var, the auth/session env split |
104
+ | [block-editing.md](docs/block-editing.md) | The block content model + the 3-pane block editor (tree · preview · fields) |
105
+ | [media-uploads.md](docs/media-uploads.md) | Ingest security, storage drivers (local/S3), responsive-image derivation |
106
+ | [multilingual.md](docs/multilingual.md) | Content locales, the editor locale flow, locale-prefixed routing |
107
+ | [static-output.md](docs/static-output.md) | `nuxt generate` + the runtime incremental publisher, the live editor preview, `sitemap.xml` / `robots.txt` / `llms.txt`, the optional S3 deploy |
108
+ | [reference-integrity.md](docs/reference-integrity.md) | How writes invalidate the static site precisely, dead-reference warnings (a dead link renders `#`, and the editor is warned), and required/unique page slugs |
109
+ | [architecture-decisions.md](docs/architecture-decisions.md) | ADRs (the collection-derived schema engine, reference integrity, the auth/password choice) |
110
+
111
+ ## Layout
112
+
113
+ The CMS is split into Nuxt layers under `layers/`:
114
+
115
+ - **`core`** — the collection/field model, the generic CRUD engine + REST API, def→JSON serialization,
116
+ the runtime schema-migration engine, config resolution, and the populate registry.
117
+ - **`fields`** — turns a definition into Drizzle tables + Zod schemas (the field-type registry).
118
+ - **`ui`** — the admin design system: schema-driven field widgets, generic primitives, tokens, i18n.
119
+ - **`auth`** — single-user authentication (session cookie, scrypt password, login, CSRF).
120
+ - **`access`** — authorization: a default-deny guard over the entire `/api/` surface + policy/grant registry.
121
+ - **`collections`** — the toggleable built-in `pages` collection + the plugin that registers every
122
+ discovered collection/block. (Demo content — `posts`/`settings`, the `hero`/`prose` blocks, and a layout —
123
+ lives in the repo root, dev-only, and is **not** shipped in the package.)
124
+ - **`media`** — uploads, pluggable storage, image derivation, the media library + asset viewer.
125
+ - **`admin`** — the editor SPA: collection list, record editor, the 3-pane block editor.
126
+ - **`public`** — the SSG render path: the catch-all page, `BlockRenderer`, sitemap / robots / llms.txt, deploy.
127
+
128
+ `playground/` is a small consuming example.
129
+
130
+ ## Development
131
+
132
+ Requires Node + [pnpm](https://pnpm.io).
133
+
134
+ ```bash
135
+ pnpm install
136
+ pnpm dev # dev server (admin at /admin)
137
+ pnpm build # production build
138
+ pnpm generate # render the static public site to .output/public
139
+
140
+ pnpm test # node + happy-dom unit tests
141
+ pnpm test:nuxt # Nuxt-environment component tests
142
+ pnpm test:e2e # end-to-end tests (real dev server)
143
+
144
+ pnpm db:generate # drizzle-kit: generate a migration
145
+ pnpm db:migrate # drizzle-kit: apply migrations
146
+ pnpm hash-password # produce a KESTREL_ADMIN_PASSWORD_HASH
147
+ ```
148
+
149
+ In dev, the schema auto-syncs from the collection definitions (additive changes only); production applies
150
+ schema changes explicitly via the `db:migrate` task. See
151
+ [architecture-decisions.md](docs/architecture-decisions.md) for the rationale.
152
+
153
+ ### Publishing the static site
154
+
155
+ Two ways to produce the static output:
156
+
157
+ - **One-shot:** `pnpm generate` → `.output/public` (the classic full rebuild).
158
+ - **Runtime publisher (default):** a **production** run (`pnpm build && pnpm preview`, or
159
+ `node .output/server/index.mjs`) publishes on boot and incrementally re-publishes the affected pages on
160
+ every content write, into `output.dir` (default `.data/published`). Serve that dir with any static
161
+ server, e.g. `npx serve .data/published`.
162
+
163
+ The runtime publisher is **intentionally disabled in `pnpm dev`** (a dev render would write un-hashed Vite
164
+ HTML), so the static files only appear on a production run. In dev you instead get the **live preview**:
165
+ public pages render straight from the running server, and an authenticated admin can open an unpublished
166
+ page at its real URL (the "open in new tab" button in the editor). See
167
+ [static-output.md](docs/static-output.md) for the full picture.
168
+
169
+ ### Simulate a production deploy locally
170
+
171
+ A real deployment is **two processes**: the private CMS server that *renders* the static files, and a
172
+ public static host that *serves* them. Rehearse that split on one machine:
173
+
174
+ ```bash
175
+ # 1. Auth secrets live in .env (pnpm preview loads it). At minimum:
176
+ # KESTREL_SESSION_SECRET=<≥32 bytes, e.g. `openssl rand -hex 32`>
177
+ # KESTREL_ADMIN_PASSWORD_HASH=<from `pnpm hash-password <your-password>`>
178
+ # Leave KESTREL_SECURE_COOKIES at its default — see the note below.
179
+
180
+ pnpm build
181
+ pnpm preview # built Nitro server, NODE_ENV=production → admin at http://localhost:3000/admin
182
+ # boot-publish writes .data/published; editing in /admin re-publishes affected pages
183
+
184
+ # in a SECOND terminal — serve the generated site like a CDN would:
185
+ npx serve .data/published # the public static site, exactly as it ships
186
+ ```
187
+
188
+ `pnpm preview` runs the build under `NODE_ENV=production` and **loads `.env`** (running
189
+ `node .output/server/index.mjs` directly does **not** — export the vars yourself if you go that route).
190
+ Note the split: the **auth** vars below are read per request, so exporting them works either way, but the
191
+ non-auth `KESTREL_*` settings are baked in during `pnpm build` — in front of an already-built server they
192
+ are ignored, and you override them with Nuxt's runtime names instead (`NUXT_KESTREL_DB_PATH`,
193
+ `NUXT_KESTREL_SITE_URL`, …; see [configuration.md](docs/configuration.md)).
194
+ Production mode makes the auth guards strict, so for a working local login:
195
+
196
+ - `KESTREL_SESSION_SECRET` is **required and ≥32 bytes** (dev uses a random per-process secret); the
197
+ check runs per-request, not at boot, so a deploy that forgets it still starts and binds the port —
198
+ every `/api/*` request then answers **500** until the secret is set.
199
+ - `KESTREL_ADMIN_PASSWORD_HASH` must be set, or `POST /api/auth/login` answers **503** (“admin login is
200
+ not configured”) rather than a wrong-password 401.
201
+ - **Keep `KESTREL_SECURE_COOKIES` at its default (`true`).** `=false` is *refused* in production
202
+ (`KESTREL_SECURE_COOKIES=false is not allowed in production`); you don't need it — the session cookie is
203
+ `Secure`/`__Host-`, and browsers accept those over plain `http://localhost`, so login works without HTTPS.
204
+
205
+ Watch the CMS terminal: boot prints `[kestrel] boot publish: N route(s) written, …`, and each save logs
206
+ the routes it re-rendered. Env reference → [configuration.md](docs/configuration.md); publishing internals
207
+ → [static-output.md](docs/static-output.md).
208
+
209
+ ## Configuration
210
+
211
+ Non-auth settings live in `kestrel.config.ts` (`satisfies KestrelConfig`); each setting follows
212
+ `KESTREL_* env → config → default`, resolved at build/dev start and frozen into `runtimeConfig` (a prebuilt
213
+ server is retuned with the `NUXT_*` runtimeConfig names, not `KESTREL_*`). Auth/session secrets are
214
+ **env-only** and read per request (`KESTREL_SESSION_SECRET`, `KESTREL_ADMIN_PASSWORD_HASH`, …). Full reference:
215
+ [configuration.md](docs/configuration.md).
216
+
217
+ ## Security
218
+
219
+ Report vulnerabilities privately — see [SECURITY.md](SECURITY.md), which also lists the documented design
220
+ decisions that are explicitly out of scope (uploads are not access-controlled; the editing origin is
221
+ assumed to be non-public).
222
+
223
+ ## Licence
224
+
225
+ Apache License 2.0 — see [LICENSE](LICENSE) and [NOTICE](NOTICE). You may use, modify and distribute
226
+ Kestrel, including commercially and in closed-source work, as long as you keep the copyright notice and
227
+ the licence, state significant changes you make to the files, and pass the NOTICE along. The licence
228
+ grants patent rights but **no trademark rights**: the name "Kestrel" and the project's branding are not
229
+ covered, so a fork needs its own name.
230
+
231
+ Kestrel is provided free of charge, developed and published outside any commercial activity, **with no
232
+ warranty and no commercial support** (see sections 7 and 8 of the licence). If you need guarantees for a
233
+ production deployment, the honest answer is to read the code, run the test suite, and decide for yourself
234
+ — that is what the licence terms mean in practice.
@@ -0,0 +1,28 @@
1
+ import type { KestrelConfig } from './layers/core/server/utils/kestrel-config'
2
+
3
+ /**
4
+ * Central Kestrel configuration (everything except auth/session, which stays env-only because secrets
5
+ * don't belong in committed config). This one file is the single source: it flows into `nuxt.config`'s
6
+ * `kestrel: { … }`, into `drizzle.config` (so `drizzle-kit` uses the same DB), and into the server at
7
+ * runtime. Precedence per setting: the matching `KESTREL_*` env var → a value here → a built-in default.
8
+ *
9
+ * This instance's non-auth config lives here (not in `.env`) so `nuxt.config`, `drizzle-kit` and the
10
+ * runtime server all derive the SAME values from one place — in particular the same SQLite file, so
11
+ * `pnpm dev`, `pnpm build` and a migration never drift onto different DBs (they set no `KESTREL_*`, so
12
+ * this file wins). `.env` keeps only the auth/session secrets. An explicit `KESTREL_*` env var OVERRIDES
13
+ * this file — the escape-hatch for a per-environment value or an isolated test (the e2e suite sets
14
+ * `KESTREL_DB` / `KESTREL_MEDIA_LOCAL_DIR` / `KESTREL_SITE_URL` per run). The static-publish `output`
15
+ * target is left to its defaults (local `.data/published`, auto-publish on).
16
+ */
17
+ export default {
18
+ db: '.data/dev.sqlite',
19
+ siteUrl: 'http://localhost:3000',
20
+ locales: ['en', 'de'],
21
+ primaryLocale: 'en',
22
+ media: {
23
+ driver: 'local',
24
+ uploadDir: '.data/uploads',
25
+ baseUrl: '/uploads',
26
+ maxBytes: 26214400, // 25 MiB
27
+ },
28
+ } satisfies KestrelConfig
@@ -0,0 +1,5 @@
1
+ // Authorization (authz) layer — the access guard, policy, CSRF + (later) the grant registry. Split out of
2
+ // `auth` (which keeps authentication: session/password/login). Composes AFTER `auth`: the guard verifies the
3
+ // session (via auth's `verifySession`/`sessionSettings`) to derive the request principal, then evaluates the
4
+ // policy. Keeping authz separate is the seam a future User&Roles extension plugs into.
5
+ export default defineNuxtConfig({})
@@ -0,0 +1,67 @@
1
+ // Stage-level IP gate: the ENFORCEMENT of an allow-list Kestrel provides; the list itself is consumer
2
+ // config (env `KESTREL_IP_ALLOWLIST`, typically only on non-public DEV/EDIT stages). Runs before the API
3
+ // access-guard (00. sort prefix) and covers every route this app defines — the admin UI, public preview,
4
+ // and API. It does NOT cover assets Nitro serves itself ahead of this stack (`/_nuxt/**`, and `/uploads`
5
+ // when `media.driver: 'local'`) — the `00.` prefix only orders files within this layer, while Nitro's own
6
+ // static handler is unconditionally unshifted to the front of the whole handler list. `off` when no list
7
+ // is set → zero cost on PROD/local.
8
+ function loadConfig() {
9
+ const listRaw = process.env.KESTREL_IP_ALLOWLIST
10
+ const mode = allowlistMode(process.env.KESTREL_IP_ALLOWLIST_MODE, listRaw)
11
+ // Named per-token, not just a "0 valid CIDRs" count — a mixed list (one good entry, one IPv6 CIDR this
12
+ // IPv4-only parser can never match) would otherwise silently under-enforce with no diagnostic at all.
13
+ const cidrs = parseAllowlist(listRaw, (token) => {
14
+ console.warn(`[ip-allowlist] dropping unparseable/unsupported allow-list entry "${token}" (IPv4/CIDR only)`)
15
+ })
16
+ if (mode !== 'off' && cidrs.length === 0) {
17
+ console.warn('[ip-allowlist] KESTREL_IP_ALLOWLIST is set but parsed to 0 valid CIDRs — enforce mode will block ALL traffic')
18
+ }
19
+ return { mode, cidrs }
20
+ }
21
+
22
+ // Env is fixed for the process lifetime → parse the (up to a few hundred) CIDRs once, not per request.
23
+ let configured: ReturnType<typeof loadConfig> | undefined
24
+
25
+ // A listener that never shows the gate a usable client address blocks everything, which looks like an
26
+ // outage rather than a misconfiguration unless we say once what to set.
27
+ let warnedUnresolvable = false
28
+
29
+ export default defineEventHandler((event) => {
30
+ configured ??= loadConfig()
31
+ const { mode, cidrs } = configured
32
+ if (mode === 'off') return
33
+
34
+ // The runtime publisher renders the public site via a nested in-process $fetch (renderer principal), and
35
+ // build-time prerender the same. Neither is an external client — exempt them or publishing 403s itself.
36
+ if (import.meta.prerender === true || isRendererContext()) return
37
+
38
+ // Nitro's other in-process sub-requests (the SSR page's own `$fetch`, the preview) run through this
39
+ // stack on a mocked socket with no peer, so they could never match a CIDR — gating them would 403 the
40
+ // very pages the gate protects. They are recognised by the async context of the request that spawned
41
+ // them: a missing peer alone is NOT a pass, or a listener that reports none for anybody (a unix domain
42
+ // socket) would turn the gate into a silent no-op.
43
+ if (isStageGatePassedContext() && !event.node?.req?.socket?.remoteAddress) return
44
+
45
+ const ip = clientIp(event)
46
+ if (ipAllowed(ip, cidrs)) {
47
+ // The in-process sub-requests this one spawns inherit the decision (see above).
48
+ markStageGatePassed()
49
+ return
50
+ }
51
+
52
+ if (ipv4ToInt(ip) === null && !warnedUnresolvable) {
53
+ warnedUnresolvable = true
54
+ console.warn(`[ip-allowlist] cannot resolve an IPv4 client address (got "${ip}") — such requests are blocked in enforce mode; set KESTREL_TRUST_PROXY when a reverse proxy fronts this listener`)
55
+ }
56
+
57
+ if (mode === 'log') {
58
+ // Calibration mode: never block, just surface what the gate WOULD reject so the operator can confirm
59
+ // the resolved client IP + KESTREL_TRUST_PROXY depth before switching to enforce.
60
+ console.warn(`[ip-allowlist] would block ${ip} — ${event.method} ${event.path} (xff=${getRequestHeader(event, 'x-forwarded-for') ?? '-'})`)
61
+ // Nothing is blocked in this mode, so the report is about the external request, not the in-process
62
+ // renders it goes on to spawn.
63
+ markStageGatePassed()
64
+ return
65
+ }
66
+ throw createError({ statusCode: 403, statusMessage: 'Forbidden' })
67
+ })
@@ -0,0 +1,30 @@
1
+ export default defineEventHandler((event) => {
2
+ if (!event.path.startsWith('/api/')) return // default-deny applies to the API only
3
+ const settings = sessionSettings()
4
+ const decision = evaluateAccess({
5
+ method: getMethod(event),
6
+ path: event.path,
7
+ csrf: {
8
+ secFetchSite: getRequestHeader(event, 'sec-fetch-site'),
9
+ origin: getRequestHeader(event, 'origin'),
10
+ referer: getRequestHeader(event, 'referer'),
11
+ host: getRequestHeader(event, 'host'),
12
+ },
13
+ cookie: getCookie(event, settings.cookieName),
14
+ secret: settings.secret,
15
+ nowMs: Date.now(),
16
+ // The renderer principal is granted to build-time prerender AND to the runtime publisher's render
17
+ // (an in-process ALS context, not a forgeable header) — both render the public site via /api/route.
18
+ isPrerender: import.meta.prerender === true || isRendererContext(),
19
+ // Registry-contributed grants (opt-in layers, e.g. a public proofing back-channel) consulted on top of
20
+ // the hardcoded policy. Empty by default → guard behaviour unchanged.
21
+ }, publicReadableResources(), registeredGrants())
22
+ if (!decision.allow) {
23
+ throw createError({ statusCode: decision.status, statusMessage: decision.message })
24
+ }
25
+ event.context.principal = decision.principal
26
+ event.context.readScope = decision.readScope
27
+ // Sliding-expiry: any authenticated API activity refreshes the session so it stays alive while in use and
28
+ // auto-expires after `maxAge` of inactivity (idle logout). No-op for anonymous/public requests.
29
+ refreshAuthSession(event)
30
+ })
@@ -0,0 +1,8 @@
1
+ import type { Principal } from './utils/policy'
2
+
3
+ declare module 'h3' {
4
+ interface H3EventContext {
5
+ principal?: Principal
6
+ readScope?: 'published' | 'all'
7
+ }
8
+ }
@@ -0,0 +1,39 @@
1
+ export interface CsrfHeaders {
2
+ secFetchSite?: string | null
3
+ origin?: string | null
4
+ referer?: string | null
5
+ host?: string | null
6
+ }
7
+
8
+ function hostOf(url: string | null | undefined): string | null {
9
+ if (!url) return null
10
+ try {
11
+ return new URL(url).host
12
+ } catch {
13
+ return null
14
+ }
15
+ }
16
+
17
+ export function isCrossSiteWrite(h: CsrfHeaders): boolean {
18
+ if (h.secFetchSite) {
19
+ return !(h.secFetchSite === 'same-origin' || h.secFetchSite === 'none')
20
+ }
21
+ // hostOf() lowercases per the URL spec; the raw Host header does not, so normalize both
22
+ // sides — host comparison is case-insensitive (RFC 3986).
23
+ const host = (h.host ?? '').toLowerCase()
24
+ // The literal opaque origin `null` (a browser signal from a sandboxed iframe, a data: URL, or some
25
+ // redirect chains) is unparseable by new URL, so it must NOT fall through to the all-absent "allow"
26
+ // path — per spec it is cross-origin. Treat it as cross-site.
27
+ if (h.origin === 'null') return true
28
+ const originHost = hostOf(h.origin)
29
+ if (originHost !== null) return originHost !== host
30
+ const refererHost = hostOf(h.referer)
31
+ if (refererHost !== null) return refererHost !== host
32
+ // A write carrying NONE of Sec-Fetch-Site / Origin / Referer is treated as same-site (allowed). A
33
+ // browser ALWAYS attaches Origin and/or Sec-Fetch-Site to a cross-origin state-changing request, so
34
+ // the all-absent case can only come from a NON-browser client (the test harness, a server-to-server
35
+ // import, automation) — which carries no ambient cookies and therefore cannot mount CSRF. The real
36
+ // defenses are SameSite=Strict on the session cookie + the Origin/Referer checks above; failing closed
37
+ // here adds no protection and breaks legitimate authenticated API clients.
38
+ return false
39
+ }