inlaycms 0.0.0-stage → 0.1.0

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 (364) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +462 -2
  3. package/assets/admin/admin.css +2 -0
  4. package/assets/admin/admin.js +1 -0
  5. package/assets/admin/editor.js +125 -0
  6. package/dist/adapters/admin/activity.d.ts +17 -0
  7. package/dist/adapters/admin/activity.js +59 -0
  8. package/dist/adapters/admin/assets.d.ts +14 -0
  9. package/dist/adapters/admin/assets.js +64 -0
  10. package/dist/adapters/admin/attention.d.ts +15 -0
  11. package/dist/adapters/admin/attention.js +34 -0
  12. package/dist/adapters/admin/context.d.ts +40 -0
  13. package/dist/adapters/admin/context.js +142 -0
  14. package/dist/adapters/admin/form/walk.d.ts +61 -0
  15. package/dist/adapters/admin/form/walk.js +565 -0
  16. package/dist/adapters/admin/pages.d.ts +38 -0
  17. package/dist/adapters/admin/pages.js +66 -0
  18. package/dist/adapters/admin/publish.d.ts +12 -0
  19. package/dist/adapters/admin/publish.js +195 -0
  20. package/dist/adapters/admin/routes.d.ts +47 -0
  21. package/dist/adapters/admin/routes.js +255 -0
  22. package/dist/adapters/admin/screens/backups.d.ts +11 -0
  23. package/dist/adapters/admin/screens/backups.js +223 -0
  24. package/dist/adapters/admin/screens/dashboard.d.ts +4 -0
  25. package/dist/adapters/admin/screens/dashboard.js +160 -0
  26. package/dist/adapters/admin/screens/editor.d.ts +67 -0
  27. package/dist/adapters/admin/screens/editor.js +416 -0
  28. package/dist/adapters/admin/screens/history.d.ts +4 -0
  29. package/dist/adapters/admin/screens/history.js +105 -0
  30. package/dist/adapters/admin/screens/lists.d.ts +4 -0
  31. package/dist/adapters/admin/screens/lists.js +297 -0
  32. package/dist/adapters/admin/screens/media.d.ts +20 -0
  33. package/dist/adapters/admin/screens/media.js +186 -0
  34. package/dist/adapters/admin/screens/pickers.d.ts +29 -0
  35. package/dist/adapters/admin/screens/pickers.js +134 -0
  36. package/dist/adapters/admin/screens/preview-pane.d.ts +10 -0
  37. package/dist/adapters/admin/screens/preview-pane.js +74 -0
  38. package/dist/adapters/admin/screens/redirects.d.ts +4 -0
  39. package/dist/adapters/admin/screens/redirects.js +137 -0
  40. package/dist/adapters/admin/screens/releases.d.ts +7 -0
  41. package/dist/adapters/admin/screens/releases.js +287 -0
  42. package/dist/adapters/admin/screens/search.d.ts +22 -0
  43. package/dist/adapters/admin/screens/search.js +113 -0
  44. package/dist/adapters/admin/screens/security.d.ts +4 -0
  45. package/dist/adapters/admin/screens/security.js +85 -0
  46. package/dist/adapters/admin/screens/users.d.ts +4 -0
  47. package/dist/adapters/admin/screens/users.js +330 -0
  48. package/dist/adapters/admin/theme.d.ts +1 -0
  49. package/dist/adapters/admin/theme.js +1 -0
  50. package/dist/adapters/admin/translations.d.ts +16 -0
  51. package/dist/adapters/admin/translations.js +23 -0
  52. package/dist/adapters/admin/upload.d.ts +8 -0
  53. package/dist/adapters/admin/upload.js +116 -0
  54. package/dist/adapters/admin/views/data-table.d.ts +82 -0
  55. package/dist/adapters/admin/views/data-table.js +117 -0
  56. package/dist/adapters/admin/views/icons.d.ts +48 -0
  57. package/dist/adapters/admin/views/icons.js +47 -0
  58. package/dist/adapters/admin/views/layout.d.ts +51 -0
  59. package/dist/adapters/admin/views/layout.js +145 -0
  60. package/dist/adapters/admin/views/sheet.d.ts +15 -0
  61. package/dist/adapters/admin/views/sheet.js +6 -0
  62. package/dist/adapters/admin/views/status.d.ts +32 -0
  63. package/dist/adapters/admin/views/status.js +74 -0
  64. package/dist/adapters/auth/handler.d.ts +10 -0
  65. package/dist/adapters/auth/handler.js +63 -0
  66. package/dist/adapters/auth/request.d.ts +8 -0
  67. package/dist/adapters/auth/request.js +14 -0
  68. package/dist/adapters/cli/bin.d.ts +2 -0
  69. package/dist/adapters/cli/bin.js +42 -0
  70. package/dist/adapters/cli/main.d.ts +7 -0
  71. package/dist/adapters/cli/main.js +982 -0
  72. package/dist/adapters/cli/remote.d.ts +52 -0
  73. package/dist/adapters/cli/remote.js +161 -0
  74. package/dist/adapters/mcp/agent-refs.d.ts +9 -0
  75. package/dist/adapters/mcp/agent-refs.js +25 -0
  76. package/dist/adapters/mcp/documents.d.ts +15 -0
  77. package/dist/adapters/mcp/documents.js +26 -0
  78. package/dist/adapters/mcp/fetch-url.d.ts +19 -0
  79. package/dist/adapters/mcp/fetch-url.js +244 -0
  80. package/dist/adapters/mcp/request-state.d.ts +15 -0
  81. package/dist/adapters/mcp/request-state.js +38 -0
  82. package/dist/adapters/mcp/results.d.ts +20 -0
  83. package/dist/adapters/mcp/results.js +61 -0
  84. package/dist/adapters/mcp/route.d.ts +34 -0
  85. package/dist/adapters/mcp/route.js +52 -0
  86. package/dist/adapters/mcp/server.d.ts +44 -0
  87. package/dist/adapters/mcp/server.js +49 -0
  88. package/dist/adapters/mcp/tools/history.d.ts +5 -0
  89. package/dist/adapters/mcp/tools/history.js +84 -0
  90. package/dist/adapters/mcp/tools/media.d.ts +5 -0
  91. package/dist/adapters/mcp/tools/media.js +102 -0
  92. package/dist/adapters/mcp/tools/publish.d.ts +5 -0
  93. package/dist/adapters/mcp/tools/publish.js +157 -0
  94. package/dist/adapters/mcp/tools/read.d.ts +5 -0
  95. package/dist/adapters/mcp/tools/read.js +279 -0
  96. package/dist/adapters/mcp/tools/redirects.d.ts +5 -0
  97. package/dist/adapters/mcp/tools/redirects.js +74 -0
  98. package/dist/adapters/mcp/tools/write.d.ts +5 -0
  99. package/dist/adapters/mcp/tools/write.js +304 -0
  100. package/dist/adapters/site/backup-schedule.d.ts +8 -0
  101. package/dist/adapters/site/backup-schedule.js +31 -0
  102. package/dist/adapters/site/cache.d.ts +29 -0
  103. package/dist/adapters/site/cache.js +63 -0
  104. package/dist/adapters/site/context.d.ts +29 -0
  105. package/dist/adapters/site/context.js +278 -0
  106. package/dist/adapters/site/head.d.ts +23 -0
  107. package/dist/adapters/site/head.js +44 -0
  108. package/dist/adapters/site/limiter.d.ts +17 -0
  109. package/dist/adapters/site/limiter.js +39 -0
  110. package/dist/adapters/site/lock.d.ts +30 -0
  111. package/dist/adapters/site/lock.js +143 -0
  112. package/dist/adapters/site/media-routes.d.ts +4 -0
  113. package/dist/adapters/site/media-routes.js +55 -0
  114. package/dist/adapters/site/plugin.d.ts +122 -0
  115. package/dist/adapters/site/plugin.js +436 -0
  116. package/dist/adapters/site/preview.d.ts +36 -0
  117. package/dist/adapters/site/preview.js +82 -0
  118. package/dist/adapters/site/public.d.ts +6 -0
  119. package/dist/adapters/site/public.js +87 -0
  120. package/dist/adapters/site/render.d.ts +45 -0
  121. package/dist/adapters/site/render.js +191 -0
  122. package/dist/adapters/site/routes.d.ts +17 -0
  123. package/dist/adapters/site/routes.js +125 -0
  124. package/dist/adapters/site/sitemap.d.ts +10 -0
  125. package/dist/adapters/site/sitemap.js +10 -0
  126. package/dist/adapters/web.d.ts +22 -0
  127. package/dist/adapters/web.js +75 -0
  128. package/dist/config.d.ts +21 -0
  129. package/dist/config.js +58 -0
  130. package/dist/core/agent/format.d.ts +62 -0
  131. package/dist/core/agent/format.js +211 -0
  132. package/dist/core/agent/schema.d.ts +6 -0
  133. package/dist/core/agent/schema.js +86 -0
  134. package/dist/core/archive.d.ts +12 -0
  135. package/dist/core/archive.js +72 -0
  136. package/dist/core/auth/auth.d.ts +4911 -0
  137. package/dist/core/auth/auth.js +61 -0
  138. package/dist/core/auth/roles.d.ts +10 -0
  139. package/dist/core/auth/roles.js +38 -0
  140. package/dist/core/auth/service.d.ts +118 -0
  141. package/dist/core/auth/service.js +424 -0
  142. package/dist/core/auth/upload-token.d.ts +8 -0
  143. package/dist/core/auth/upload-token.js +27 -0
  144. package/dist/core/backup/backup.d.ts +28 -0
  145. package/dist/core/backup/backup.js +126 -0
  146. package/dist/core/backup/restore.d.ts +41 -0
  147. package/dist/core/backup/restore.js +264 -0
  148. package/dist/core/backup/schedule.d.ts +12 -0
  149. package/dist/core/backup/schedule.js +29 -0
  150. package/dist/core/boot.d.ts +63 -0
  151. package/dist/core/boot.js +141 -0
  152. package/dist/core/check.d.ts +32 -0
  153. package/dist/core/check.js +111 -0
  154. package/dist/core/content/activity.d.ts +8 -0
  155. package/dist/core/content/activity.js +101 -0
  156. package/dist/core/content/delete.d.ts +5 -0
  157. package/dist/core/content/delete.js +100 -0
  158. package/dist/core/content/diff.d.ts +6 -0
  159. package/dist/core/content/diff.js +129 -0
  160. package/dist/core/content/dry-run.d.ts +24 -0
  161. package/dist/core/content/dry-run.js +69 -0
  162. package/dist/core/content/gaps.d.ts +25 -0
  163. package/dist/core/content/gaps.js +50 -0
  164. package/dist/core/content/hidden.d.ts +33 -0
  165. package/dist/core/content/hidden.js +103 -0
  166. package/dist/core/content/history.d.ts +15 -0
  167. package/dist/core/content/history.js +62 -0
  168. package/dist/core/content/patch.d.ts +40 -0
  169. package/dist/core/content/patch.js +287 -0
  170. package/dist/core/content/path.d.ts +6 -0
  171. package/dist/core/content/path.js +38 -0
  172. package/dist/core/content/publish.d.ts +26 -0
  173. package/dist/core/content/publish.js +211 -0
  174. package/dist/core/content/read.d.ts +99 -0
  175. package/dist/core/content/read.js +141 -0
  176. package/dist/core/content/reader.d.ts +37 -0
  177. package/dist/core/content/reader.js +195 -0
  178. package/dist/core/content/refs.d.ts +44 -0
  179. package/dist/core/content/refs.js +161 -0
  180. package/dist/core/content/release-migrations.d.ts +12 -0
  181. package/dist/core/content/release-migrations.js +154 -0
  182. package/dist/core/content/save.d.ts +25 -0
  183. package/dist/core/content/save.js +87 -0
  184. package/dist/core/content/schema.d.ts +22 -0
  185. package/dist/core/content/schema.js +127 -0
  186. package/dist/core/content/search.d.ts +8 -0
  187. package/dist/core/content/search.js +89 -0
  188. package/dist/core/content/shipped-input.d.ts +39 -0
  189. package/dist/core/content/shipped-input.js +221 -0
  190. package/dist/core/content/shipped.d.ts +112 -0
  191. package/dist/core/content/shipped.js +437 -0
  192. package/dist/core/content/slug.d.ts +23 -0
  193. package/dist/core/content/slug.js +182 -0
  194. package/dist/core/content/stats.d.ts +11 -0
  195. package/dist/core/content/stats.js +30 -0
  196. package/dist/core/content/translate.d.ts +3 -0
  197. package/dist/core/content/translate.js +68 -0
  198. package/dist/core/content/usages.d.ts +13 -0
  199. package/dist/core/content/usages.js +70 -0
  200. package/dist/core/content/validate.d.ts +21 -0
  201. package/dist/core/content/validate.js +124 -0
  202. package/dist/core/content/write.d.ts +10 -0
  203. package/dist/core/content/write.js +93 -0
  204. package/dist/core/core.d.ts +227 -0
  205. package/dist/core/core.js +251 -0
  206. package/dist/core/db/connection.d.ts +6 -0
  207. package/dist/core/db/connection.js +12 -0
  208. package/dist/core/db/migrate.d.ts +9 -0
  209. package/dist/core/db/migrate.js +42 -0
  210. package/dist/core/db/migrations/0001_content.d.ts +2 -0
  211. package/dist/core/db/migrations/0001_content.js +69 -0
  212. package/dist/core/db/migrations/0002_media.d.ts +2 -0
  213. package/dist/core/db/migrations/0002_media.js +26 -0
  214. package/dist/core/db/migrations/0003_redirects.d.ts +2 -0
  215. package/dist/core/db/migrations/0003_redirects.js +19 -0
  216. package/dist/core/db/migrations/0004_token_cutoffs.d.ts +3 -0
  217. package/dist/core/db/migrations/0004_token_cutoffs.js +8 -0
  218. package/dist/core/db/migrations/0005_site_lock.d.ts +3 -0
  219. package/dist/core/db/migrations/0005_site_lock.js +10 -0
  220. package/dist/core/db/migrations/0006_releases.d.ts +3 -0
  221. package/dist/core/db/migrations/0006_releases.js +34 -0
  222. package/dist/core/db/schema.d.ts +155 -0
  223. package/dist/core/db/schema.js +1 -0
  224. package/dist/core/errors.d.ts +27 -0
  225. package/dist/core/errors.js +15 -0
  226. package/dist/core/export/export.d.ts +17 -0
  227. package/dist/core/export/export.js +185 -0
  228. package/dist/core/export/format.d.ts +241 -0
  229. package/dist/core/export/format.js +106 -0
  230. package/dist/core/export/import.d.ts +54 -0
  231. package/dist/core/export/import.js +180 -0
  232. package/dist/core/export/read.d.ts +16 -0
  233. package/dist/core/export/read.js +234 -0
  234. package/dist/core/export/replace.d.ts +17 -0
  235. package/dist/core/export/replace.js +36 -0
  236. package/dist/core/export/report.d.ts +55 -0
  237. package/dist/core/export/report.js +50 -0
  238. package/dist/core/export/schema.d.ts +8 -0
  239. package/dist/core/export/schema.js +47 -0
  240. package/dist/core/export/stage.d.ts +25 -0
  241. package/dist/core/export/stage.js +192 -0
  242. package/dist/core/fields/builtins.d.ts +70 -0
  243. package/dist/core/fields/builtins.js +335 -0
  244. package/dist/core/fields/define.d.ts +86 -0
  245. package/dist/core/fields/define.js +34 -0
  246. package/dist/core/fields/walk.d.ts +49 -0
  247. package/dist/core/fields/walk.js +270 -0
  248. package/dist/core/fields/widgets.d.ts +27 -0
  249. package/dist/core/fields/widgets.js +330 -0
  250. package/dist/core/fields/zod-internals.d.ts +29 -0
  251. package/dist/core/fields/zod-internals.js +28 -0
  252. package/dist/core/media/detect.d.ts +5 -0
  253. package/dist/core/media/detect.js +66 -0
  254. package/dist/core/media/labels.d.ts +6 -0
  255. package/dist/core/media/labels.js +17 -0
  256. package/dist/core/media/library.d.ts +45 -0
  257. package/dist/core/media/library.js +239 -0
  258. package/dist/core/media/store.d.ts +11 -0
  259. package/dist/core/media/store.js +49 -0
  260. package/dist/core/media/variants.d.ts +10 -0
  261. package/dist/core/media/variants.js +59 -0
  262. package/dist/core/messages/en.d.ts +1278 -0
  263. package/dist/core/messages/en.js +1287 -0
  264. package/dist/core/messages/index.d.ts +7 -0
  265. package/dist/core/messages/index.js +14 -0
  266. package/dist/core/preview.d.ts +16 -0
  267. package/dist/core/preview.js +42 -0
  268. package/dist/core/redirects/collapse.d.ts +68 -0
  269. package/dist/core/redirects/collapse.js +153 -0
  270. package/dist/core/redirects/csv.d.ts +15 -0
  271. package/dist/core/redirects/csv.js +68 -0
  272. package/dist/core/redirects/redirects.d.ts +58 -0
  273. package/dist/core/redirects/redirects.js +545 -0
  274. package/dist/core/registry/content.d.ts +26 -0
  275. package/dist/core/registry/content.js +9 -0
  276. package/dist/core/registry/define.d.ts +145 -0
  277. package/dist/core/registry/define.js +41 -0
  278. package/dist/core/registry/migration.d.ts +44 -0
  279. package/dist/core/registry/migration.js +4 -0
  280. package/dist/core/registry/registry.d.ts +18 -0
  281. package/dist/core/registry/registry.js +255 -0
  282. package/dist/core/registry/render.d.ts +98 -0
  283. package/dist/core/registry/render.js +1 -0
  284. package/dist/core/registry/route.d.ts +42 -0
  285. package/dist/core/registry/route.js +3 -0
  286. package/dist/core/release/bundle.d.ts +21 -0
  287. package/dist/core/release/bundle.js +252 -0
  288. package/dist/core/release/keys.d.ts +11 -0
  289. package/dist/core/release/keys.js +60 -0
  290. package/dist/core/release/manifest.d.ts +103 -0
  291. package/dist/core/release/manifest.js +138 -0
  292. package/dist/core/release/pack.d.ts +20 -0
  293. package/dist/core/release/pack.js +97 -0
  294. package/dist/core/release/pointer.d.ts +19 -0
  295. package/dist/core/release/pointer.js +53 -0
  296. package/dist/core/release/read.d.ts +59 -0
  297. package/dist/core/release/read.js +256 -0
  298. package/dist/core/report.d.ts +31 -0
  299. package/dist/core/report.js +37 -0
  300. package/dist/core/richtext/html.d.ts +15 -0
  301. package/dist/core/richtext/html.js +81 -0
  302. package/dist/core/richtext/markdown.d.ts +19 -0
  303. package/dist/core/richtext/markdown.js +951 -0
  304. package/dist/core/richtext/schema.d.ts +98 -0
  305. package/dist/core/richtext/schema.js +275 -0
  306. package/dist/core/site/live.d.ts +56 -0
  307. package/dist/core/site/live.js +145 -0
  308. package/dist/core/site/paths.d.ts +15 -0
  309. package/dist/core/site/paths.js +64 -0
  310. package/dist/core/site/resolve.d.ts +9 -0
  311. package/dist/core/site/resolve.js +202 -0
  312. package/dist/core/site/sitemap.d.ts +11 -0
  313. package/dist/core/site/sitemap.js +24 -0
  314. package/dist/core/site-lock/site-lock.d.ts +21 -0
  315. package/dist/core/site-lock/site-lock.js +65 -0
  316. package/dist/core/site-lock/token.d.ts +7 -0
  317. package/dist/core/site-lock/token.js +24 -0
  318. package/dist/core/theme.d.ts +22 -0
  319. package/dist/core/theme.js +133 -0
  320. package/dist/core/types.d.ts +253 -0
  321. package/dist/core/types.js +1 -0
  322. package/dist/core/version.d.ts +1 -0
  323. package/dist/core/version.js +5 -0
  324. package/dist/host/activate.d.ts +53 -0
  325. package/dist/host/activate.js +162 -0
  326. package/dist/host/app.d.ts +46 -0
  327. package/dist/host/app.js +129 -0
  328. package/dist/host/bin.d.ts +5 -0
  329. package/dist/host/bin.js +8 -0
  330. package/dist/host/config.d.ts +36 -0
  331. package/dist/host/config.js +152 -0
  332. package/dist/host/dev.d.ts +10 -0
  333. package/dist/host/dev.js +293 -0
  334. package/dist/host/diff.d.ts +78 -0
  335. package/dist/host/diff.js +346 -0
  336. package/dist/host/hooks.d.ts +41 -0
  337. package/dist/host/hooks.js +49 -0
  338. package/dist/host/ipc.d.ts +123 -0
  339. package/dist/host/ipc.js +61 -0
  340. package/dist/host/preview-proxy.d.ts +24 -0
  341. package/dist/host/preview-proxy.js +154 -0
  342. package/dist/host/preview-worker.d.ts +42 -0
  343. package/dist/host/preview-worker.js +242 -0
  344. package/dist/host/primary.d.ts +38 -0
  345. package/dist/host/primary.js +357 -0
  346. package/dist/host/push.d.ts +125 -0
  347. package/dist/host/push.js +420 -0
  348. package/dist/host/serve.d.ts +16 -0
  349. package/dist/host/serve.js +150 -0
  350. package/dist/host/store.d.ts +48 -0
  351. package/dist/host/store.js +109 -0
  352. package/dist/host/worker.d.ts +67 -0
  353. package/dist/host/worker.js +310 -0
  354. package/dist/index.d.ts +47 -0
  355. package/dist/index.js +32 -0
  356. package/dist/jsx/html.d.ts +16 -0
  357. package/dist/jsx/html.js +65 -0
  358. package/dist/jsx/jsx-dev-runtime.d.ts +4 -0
  359. package/dist/jsx/jsx-dev-runtime.js +5 -0
  360. package/dist/jsx/jsx-runtime.d.ts +17 -0
  361. package/dist/jsx/jsx-runtime.js +41 -0
  362. package/dist/site.d.ts +17 -0
  363. package/dist/site.js +14 -0
  364. package/package.json +111 -3
@@ -0,0 +1,45 @@
1
+ import type { Core } from '../../core/core.js';
2
+ import { type MessageId } from '../../core/messages/index.js';
3
+ import type { TemplateDef } from '../../core/registry/define.js';
4
+ import type { ContentIssue, DocumentData, LiveDocument, LiveState } from '../../core/types.js';
5
+ import { type SafeHtml } from '../../jsx/html.js';
6
+ export declare const PREVIEW_EXIT_PATH = "/_inlay/preview/exit";
7
+ /** A page Inlay renders itself (in the catalog's language), with `body` (Inlay-built HTML) under its `title` heading. */
8
+ export declare function inlayPage(title: string, body: SafeHtml): string;
9
+ /** A page Inlay renders itself, in the catalog's language. */
10
+ export declare function catalogPage(titleId: MessageId, bodyId: MessageId): string;
11
+ /**
12
+ * Renders `doc` through its template, with its enabled slots rendered by their blocks. Render errors propagate.
13
+ * In preview the page gets the preview banner (naming `release`, the name of the staged release previewed, when
14
+ * given), and a draft that fails strict validation gets a list of its problems instead of its template.
15
+ */
16
+ export declare function renderPage(core: Core, doc: LiveDocument, opts: {
17
+ state: LiveState;
18
+ page: number;
19
+ baseUrl: string;
20
+ release?: string;
21
+ }): Promise<string>;
22
+ export type PaneResult = {
23
+ ok: true;
24
+ html: string;
25
+ } | {
26
+ ok: false;
27
+ issues: ContentIssue[];
28
+ };
29
+ export declare const SLOT_START: (key: string) => string;
30
+ export declare const SLOT_END: (key: string) => string;
31
+ /** `doc` rendered for the editor's live preview pane: strict-checked, no banner, slot markers, `<base href>` of the page path. Render errors propagate. */
32
+ export declare function renderPane(core: Core, doc: LiveDocument, opts: {
33
+ page: number;
34
+ baseUrl: string;
35
+ }): Promise<PaneResult>;
36
+ /**
37
+ * `template` rendered with `data` (already read with `fill`) as a published page at `path` that no document backs,
38
+ * such as one a route returns: no canonical link and no alternates. Its title is the `title` field when that is
39
+ * text, else the template's label or name. Render errors propagate.
40
+ */
41
+ export declare function renderTemplateData(core: Core, template: TemplateDef, data: DocumentData, opts: {
42
+ locale: string;
43
+ path: string;
44
+ baseUrl: string;
45
+ }): Promise<string>;
@@ -0,0 +1,191 @@
1
+ import { validateContent } from '../../core/content/validate.js';
2
+ import { InlayError } from '../../core/errors.js';
3
+ import { fieldMeta } from '../../core/fields/define.js';
4
+ import { t } from '../../core/messages/index.js';
5
+ import { escapeHtml, raw, renderToString, toHtml } from '../../jsx/html.js';
6
+ import { createRenderContext } from './context.js';
7
+ import { buildHead, injectHead } from './head.js';
8
+ const DOCTYPE = /^\s*<!doctype\s/i;
9
+ const BODY = /<body\b[^>]*>/i;
10
+ export const PREVIEW_EXIT_PATH = '/_inlay/preview/exit';
11
+ const PREVIEW_PUBLISH_PATH = '/admin/publish';
12
+ const STYLE = 'body{margin:0;font:16px/1.5 system-ui,sans-serif;color:#111827;background:#f9fafb}' +
13
+ 'main{max-width:32rem;margin:3rem auto;padding:0 1rem}h1{font-size:1.5rem}' +
14
+ 'label{display:block;margin-top:1rem;font-weight:600}' +
15
+ 'input:not([type=hidden]){display:block;box-sizing:border-box;width:100%;margin-top:.25rem;padding:.5rem;font:inherit}' +
16
+ 'button{margin-top:1.25rem;padding:.5rem 1rem;font:inherit;cursor:pointer}' +
17
+ '.inlay-error{color:#b91c1c}.inlay-hint{color:#4b5563;font-size:.875rem;margin:.25rem 0 0}';
18
+ /** A page Inlay renders itself (in the catalog's language), with `body` (Inlay-built HTML) under its `title` heading. */
19
+ export function inlayPage(title, body) {
20
+ const heading = escapeHtml(title);
21
+ return ('<!doctype html><html lang="en"><head><meta charset="utf-8">' +
22
+ '<meta name="viewport" content="width=device-width, initial-scale=1"><meta name="robots" content="noindex">' +
23
+ `<title>${heading}</title><style>${STYLE}</style></head><body><main><h1>${heading}</h1>${body.value}</main></body></html>`);
24
+ }
25
+ function catalogDocument(titleId, body) {
26
+ return inlayPage(t(titleId), body);
27
+ }
28
+ /** A page Inlay renders itself, in the catalog's language. */
29
+ export function catalogPage(titleId, bodyId) {
30
+ return catalogDocument(titleId, raw(`<p>${escapeHtml(t(bodyId))}</p>`));
31
+ }
32
+ /**
33
+ * `html` with the preview banner inserted after its opening `<body>` tag, or at the end when it has none. The banner
34
+ * of a staged release's preview names the release and has no link to publish.
35
+ */
36
+ function withPreviewBanner(html, release) {
37
+ const publish = ` <a href="${PREVIEW_PUBLISH_PATH}" style="color:#fff">${escapeHtml(t('preview.publish'))}</a>`;
38
+ const banner = '<div class="inlay-preview" role="status" style="position:sticky;top:0;z-index:2147483647;padding:8px 16px;' +
39
+ 'background:#1f2937;color:#fff;font:14px/1.4 system-ui,sans-serif">' +
40
+ (release === undefined ? `${escapeHtml(t('preview.banner'))}${publish}` : escapeHtml(t('preview.bannerRelease', { name: release }))) +
41
+ ` <a href="${PREVIEW_EXIT_PATH}" style="color:#fff">${escapeHtml(t('preview.exit'))}</a></div>`;
42
+ const body = BODY.exec(html);
43
+ if (!body)
44
+ return `${html}${banner}`;
45
+ const at = body.index + body[0].length;
46
+ return `${html.slice(0, at)}${banner}${html.slice(at)}`;
47
+ }
48
+ /**
49
+ * Renders `doc` through its template, with its enabled slots rendered by their blocks. Render errors propagate.
50
+ * In preview the page gets the preview banner (naming `release`, the name of the staged release previewed, when
51
+ * given), and a draft that fails strict validation gets a list of its problems instead of its template.
52
+ */
53
+ export async function renderPage(core, doc, opts) {
54
+ const { release, ...render } = opts;
55
+ if (render.state !== 'preview')
56
+ return renderTemplate(core, doc, render);
57
+ const checked = validateContent(core.registry, doc.type, doc.data, 'strict');
58
+ if (!checked.ok) {
59
+ const items = checked.issues.map((issue) => `<li>${escapeHtml(issue.message)}</li>`).join('');
60
+ const body = raw(`<p>${escapeHtml(t('preview.incomplete'))}</p><ul>${items}</ul>`);
61
+ return withPreviewBanner(catalogDocument('preview.incomplete.title', body), release);
62
+ }
63
+ return withPreviewBanner(await renderTemplate(core, doc, render), release);
64
+ }
65
+ export const SLOT_START = (key) => `<!--inlay:slot ${key}-->`;
66
+ export const SLOT_END = (key) => `<!--/inlay:slot ${key}-->`;
67
+ const HEAD_OPEN = /<head\b[^>]*>/i;
68
+ /** `doc` rendered for the editor's live preview pane: strict-checked, no banner, slot markers, `<base href>` of the page path. Render errors propagate. */
69
+ export async function renderPane(core, doc, opts) {
70
+ if (doc.path === null)
71
+ throw new InlayError('invalid_operation', 'error.paneNoPath', { title: doc.title });
72
+ const checked = validateContent(core.registry, doc.type, doc.data, 'strict');
73
+ if (!checked.ok)
74
+ return { ok: false, issues: checked.issues };
75
+ return { ok: true, html: await renderTemplate(core, doc, { ...opts, state: 'preview' }, { pane: true }) };
76
+ }
77
+ /** `template` rendered with `data` and its enabled slots rendered by their blocks: the page before its head is added. */
78
+ async function renderBody(template, data, page, ctx, internal) {
79
+ if (!template.render)
80
+ throw new InlayError('config', 'config.renderMissing', { name: template.name });
81
+ const slots = {};
82
+ const slotData = {};
83
+ for (const [key, slot] of Object.entries(template.slots)) {
84
+ const stored = data.slots[key];
85
+ if (!stored?.enabled) {
86
+ slots[key] = null;
87
+ slotData[key] = null;
88
+ continue;
89
+ }
90
+ slotData[key] = stored.data;
91
+ const rendered = slot.block.render ? await toHtml(slot.block.render(stored.data, ctx)) : raw('');
92
+ slots[key] = internal.pane ? raw(SLOT_START(key) + rendered.value + SLOT_END(key)) : rendered;
93
+ }
94
+ return renderToString(template.render({ fields: data.fields, slots, data: slotData, page }, ctx));
95
+ }
96
+ const withDoctype = (html) => (DOCTYPE.test(html) ? html : `<!doctype html>${html}`);
97
+ async function renderTemplate(core, doc, opts, internal = {}) {
98
+ const { template } = core.registry.getType(doc.type);
99
+ if (!template.render)
100
+ throw new InlayError('config', 'config.renderMissing', { name: template.name });
101
+ const alternates = await core.liveAlternates(doc.groupId, { state: opts.state });
102
+ const ctx = createRenderContext(core, {
103
+ locale: doc.locale,
104
+ state: opts.state,
105
+ page: opts.page,
106
+ baseUrl: opts.baseUrl,
107
+ alternates,
108
+ });
109
+ await ctx.preload([doc]);
110
+ const page = {
111
+ title: doc.title,
112
+ type: doc.type,
113
+ locale: doc.locale,
114
+ contentLocale: doc.contentLocale,
115
+ fallback: doc.fallback,
116
+ path: doc.path ?? '',
117
+ page: opts.page,
118
+ };
119
+ const html = await renderBody(template, doc.data, page, ctx, internal);
120
+ const seo = seoValue(template.fields, doc.data.fields);
121
+ const own = doc.path;
122
+ const base = doc.fallback ? (alternates.find((a) => a.locale === core.registry.defaultLocale)?.path ?? own) : own;
123
+ const head = buildHead({
124
+ title: doc.title,
125
+ seo,
126
+ canonical: own === null || base === null ? null : opts.page > 1 ? `${base}?page=${opts.page}` : base,
127
+ alternates: doc.fallback ? [] : alternates.filter((a) => !a.fallback),
128
+ defaultLocale: core.registry.defaultLocale,
129
+ image: ctx.image(seo?.image),
130
+ baseUrl: opts.baseUrl,
131
+ preview: opts.state === 'preview',
132
+ });
133
+ let out = injectHead(html, head);
134
+ if (internal.pane && doc.path !== null) {
135
+ const open = HEAD_OPEN.exec(out);
136
+ if (open) {
137
+ const at = open.index + open[0].length;
138
+ out = `${out.slice(0, at)}<base href="${escapeHtml(doc.path)}">${out.slice(at)}`;
139
+ }
140
+ }
141
+ return withDoctype(out);
142
+ }
143
+ /**
144
+ * `template` rendered with `data` (already read with `fill`) as a published page at `path` that no document backs,
145
+ * such as one a route returns: no canonical link and no alternates. Its title is the `title` field when that is
146
+ * text, else the template's label or name. Render errors propagate.
147
+ */
148
+ export async function renderTemplateData(core, template, data, opts) {
149
+ const ctx = createRenderContext(core, {
150
+ locale: opts.locale,
151
+ state: 'published',
152
+ page: 1,
153
+ baseUrl: opts.baseUrl,
154
+ alternates: [],
155
+ });
156
+ await ctx.preloadData(template, data);
157
+ const field = data.fields.title;
158
+ const title = typeof field === 'string' && field !== '' ? field : (template.label ?? template.name);
159
+ const page = {
160
+ title,
161
+ type: '',
162
+ locale: opts.locale,
163
+ contentLocale: opts.locale,
164
+ fallback: false,
165
+ path: opts.path,
166
+ page: 1,
167
+ };
168
+ const html = await renderBody(template, data, page, ctx, {});
169
+ const seo = seoValue(template.fields, data.fields);
170
+ const head = buildHead({
171
+ title,
172
+ seo,
173
+ canonical: null,
174
+ alternates: [],
175
+ defaultLocale: core.registry.defaultLocale,
176
+ image: ctx.image(seo?.image),
177
+ baseUrl: opts.baseUrl,
178
+ preview: false,
179
+ });
180
+ return withDoctype(injectHead(html, head));
181
+ }
182
+ /** The value of the first top-level field marked by `f.seo()`. */
183
+ function seoValue(fields, values) {
184
+ for (const [key, schema] of Object.entries(fields.shape)) {
185
+ if (!fieldMeta(schema)?.seo)
186
+ continue;
187
+ const v = values[key];
188
+ return v && typeof v === 'object' ? v : null;
189
+ }
190
+ return null;
191
+ }
@@ -0,0 +1,17 @@
1
+ import type { FastifyBaseLogger, FastifyInstance } from 'fastify';
2
+ import type { Core } from '../../core/core.js';
3
+ import type { Registry } from '../../core/registry/registry.js';
4
+ export interface ReleaseRouteOptions {
5
+ core: Core;
6
+ registry: Registry;
7
+ baseUrl: string;
8
+ /** Host-supplied secret values; a route sees only the ones its site declares. */
9
+ secrets: Readonly<Record<string, string>>;
10
+ log: FastifyBaseLogger;
11
+ }
12
+ /**
13
+ * Serves the site's routes in one encapsulated scope that reads only urlencoded forms and JSON (1 MB each). Any other
14
+ * body is a 415, a body Fastify can't read a 400 or 413, and a handler throw a logged 500, each as a plain Inlay page.
15
+ * The site lock still applies: its gate runs before these routes.
16
+ */
17
+ export declare function registerReleaseRoutes(app: FastifyInstance, opts: ReleaseRouteOptions): void;
@@ -0,0 +1,125 @@
1
+ import { normalizeContent } from '../../core/content/schema.js';
2
+ import { readData } from '../../core/content/reader.js';
3
+ import { t } from '../../core/messages/index.js';
4
+ import { queryApi } from './context.js';
5
+ import { catalogPage, renderTemplateData } from './render.js';
6
+ const BODY_LIMIT = 1024 * 1024;
7
+ const HTML = 'text/html; charset=utf-8';
8
+ /** Headers a route never sees: routes run anonymous. */
9
+ const HIDDEN_HEADERS = new Set(['cookie', 'authorization', 'proxy-authorization', 'x-api-key']);
10
+ const ERROR_PAGES = {
11
+ 400: ['site.badRequest.title', 'site.badRequest'],
12
+ 413: ['site.tooLarge.title', 'site.tooLarge'],
13
+ 415: ['site.unsupported.title', 'site.unsupported'],
14
+ 500: ['site.error.title', 'site.error'],
15
+ };
16
+ /** 413 and 415 as Fastify gave them, 400 for any other request it refused (`FST_*` with a 4xx status), else 500. */
17
+ function errorStatus(error) {
18
+ const { code, statusCode } = (typeof error === 'object' && error !== null ? error : {});
19
+ if (typeof code !== 'string' || !code.startsWith('FST_') || typeof statusCode !== 'number')
20
+ return 500;
21
+ if (statusCode === 413 || statusCode === 415)
22
+ return statusCode;
23
+ return statusCode >= 400 && statusCode < 500 ? 400 : 500;
24
+ }
25
+ function plainHeaders(raw) {
26
+ const out = {};
27
+ for (const [name, value] of Object.entries(raw)) {
28
+ const key = name.toLowerCase();
29
+ if (value === undefined || HIDDEN_HEADERS.has(key))
30
+ continue;
31
+ out[key] = Array.isArray(value) ? value.join(', ') : value;
32
+ }
33
+ return out;
34
+ }
35
+ function plainQuery(url) {
36
+ const q = url.indexOf('?');
37
+ return q === -1 ? {} : Object.fromEntries(new URLSearchParams(url.slice(q + 1)));
38
+ }
39
+ /** A registry whose every type is `template`, so content reading works for a template no type uses. */
40
+ function templateRegistry(registry, template) {
41
+ return { ...registry, getType: () => ({ kind: 'global', name: template.name, label: template.name, template }) };
42
+ }
43
+ function send(reply, res) {
44
+ const headers = res.headers ?? {};
45
+ const typed = Object.keys(headers).some((h) => h.toLowerCase() === 'content-type');
46
+ const json = res.json !== undefined;
47
+ const body = json ? JSON.stringify(res.json) : res.body;
48
+ reply.headers(headers).code(res.status ?? (body === undefined ? 204 : 200));
49
+ if (body === undefined)
50
+ return reply.send();
51
+ if (!typed)
52
+ reply.type(json ? 'application/json; charset=utf-8' : 'text/plain; charset=utf-8');
53
+ return reply.send(body);
54
+ }
55
+ /**
56
+ * Serves the site's routes in one encapsulated scope that reads only urlencoded forms and JSON (1 MB each). Any other
57
+ * body is a 415, a body Fastify can't read a 400 or 413, and a handler throw a logged 500, each as a plain Inlay page.
58
+ * The site lock still applies: its gate runs before these routes.
59
+ */
60
+ export function registerReleaseRoutes(app, opts) {
61
+ const { core, registry, baseUrl, log } = opts;
62
+ const routes = registry.site.routes;
63
+ if (routes.length === 0)
64
+ return;
65
+ const secrets = {};
66
+ for (const name of registry.site.secrets) {
67
+ const value = opts.secrets[name];
68
+ if (value !== undefined)
69
+ secrets[name] = value;
70
+ }
71
+ Object.freeze(secrets);
72
+ const localeOf = (value) => typeof value === 'string' && registry.locales.includes(value) ? value : undefined;
73
+ app.register(async (scope) => {
74
+ scope.removeAllContentTypeParsers();
75
+ scope.addContentTypeParser('application/json', { parseAs: 'string', bodyLimit: BODY_LIMIT }, scope.getDefaultJsonParser('error', 'error'));
76
+ scope.addContentTypeParser('application/x-www-form-urlencoded', { parseAs: 'string', bodyLimit: BODY_LIMIT }, (_request, body, done) => done(null, Object.fromEntries(new URLSearchParams(body))));
77
+ scope.setErrorHandler(async (error, request, reply) => {
78
+ const status = errorStatus(error);
79
+ const params = { method: request.method, path: request.url.split('?')[0] ?? request.url };
80
+ if (status === 500)
81
+ log.error({ err: error }, t('log.routeFailed', params));
82
+ const [title, body] = ERROR_PAGES[status];
83
+ return reply.code(status).type(HTML).send(catalogPage(title, body));
84
+ });
85
+ for (const route of routes)
86
+ register(scope, route);
87
+ });
88
+ function register(scope, route) {
89
+ scope.route({
90
+ method: route.method,
91
+ url: route.path,
92
+ handler: async (request, reply) => {
93
+ const query = plainQuery(request.url);
94
+ const type = request.headers['content-type'] ?? '';
95
+ const form = /^application\/x-www-form-urlencoded\b/i.test(type);
96
+ const body = route.method === 'POST' && request.body !== undefined ? request.body : null;
97
+ const fields = form && body !== null ? body : undefined;
98
+ const locale = localeOf(query.locale) ?? localeOf(fields?.locale) ?? registry.defaultLocale;
99
+ const req = {
100
+ method: route.method,
101
+ path: route.path,
102
+ query,
103
+ headers: plainHeaders(request.headers),
104
+ body,
105
+ locale,
106
+ };
107
+ const ctx = {
108
+ query: queryApi(core, { locale, baseUrl }),
109
+ async render(template, data = {}, o = {}) {
110
+ const read = templateRegistry(registry, template);
111
+ const doc = readData(read, template.name, normalizeContent(read, template.name, data), { fill: true }).data;
112
+ const html = await renderTemplateData(core, template, doc, { locale, path: route.path, baseUrl });
113
+ return { status: o.status ?? 200, headers: { 'content-type': HTML }, body: html };
114
+ },
115
+ fetch: (input, init) => globalThis.fetch(input, init),
116
+ secrets,
117
+ redirect: (location, status = 303) => ({ status, headers: { location } }),
118
+ baseUrl,
119
+ locale,
120
+ };
121
+ return send(reply, await route.handler(req, ctx));
122
+ },
123
+ });
124
+ }
125
+ }
@@ -0,0 +1,10 @@
1
+ interface Item {
2
+ path: string;
3
+ updatedAt: string;
4
+ alternates: Array<{
5
+ locale: string;
6
+ path: string;
7
+ }>;
8
+ }
9
+ export declare function renderSitemap(entries: readonly Item[], baseUrl: string): string;
10
+ export {};
@@ -0,0 +1,10 @@
1
+ import { escapeHtml } from '../../jsx/html.js';
2
+ import { encodePath } from '../../core/site/paths.js';
3
+ export function renderSitemap(entries, baseUrl) {
4
+ const url = (path) => escapeHtml(`${baseUrl}${path === '/' ? '/' : encodePath(path)}`);
5
+ const items = entries.map((e) => {
6
+ const links = e.alternates.map((a) => `<xhtml:link rel="alternate" hreflang="${escapeHtml(a.locale)}" href="${url(a.path)}"/>`);
7
+ return `<url><loc>${url(e.path)}</loc><lastmod>${escapeHtml(e.updatedAt.slice(0, 10))}</lastmod>${links.join('')}</url>`;
8
+ });
9
+ return `<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">${items.join('')}</urlset>\n`;
10
+ }
@@ -0,0 +1,22 @@
1
+ import type { FastifyReply, FastifyRequest } from 'fastify';
2
+ /** The only header better-auth reads the client's IP from; Inlay always sets it itself. */
3
+ export declare const CLIENT_IP_HEADER = "x-inlay-client-ip";
4
+ /** The request's headers as Web `Headers`, with `x-inlay-client-ip` set from Fastify's `request.ip`. */
5
+ export declare function webHeaders(request: FastifyRequest): Headers;
6
+ /**
7
+ * A Web `Request` for `request` at `baseUrl` (so better-auth sees the site's own origin), with its headers and the
8
+ * client IP. `path` (default: the request's URL) and `body` replace the request's own; `headers` are set last.
9
+ */
10
+ export declare function toWebRequest(request: FastifyRequest, baseUrl: string, opts?: {
11
+ path?: string;
12
+ body?: string | Buffer;
13
+ headers?: Record<string, string>;
14
+ }): Request;
15
+ /** Copies every `set-cookie` of `res` onto `reply`, each as its own header. */
16
+ export declare function copyCookies(reply: FastifyReply, res: Response): void;
17
+ /** Sends `res` through `reply`: status, headers (each `set-cookie` separately) and a streamed body. */
18
+ export declare function sendWebResponse(reply: FastifyReply, res: Response): Promise<FastifyReply>;
19
+ /** Whether the request's `Origin` header is exactly `baseUrl`. A missing `Origin` is not the same origin. */
20
+ export declare function sameOrigin(request: FastifyRequest, baseUrl: string): boolean;
21
+ /** `raw` as a clean site-relative path (with its query), or `fallback` when it isn't one. */
22
+ export declare function safeNext(raw: unknown, fallback?: string): string;
@@ -0,0 +1,75 @@
1
+ import { Readable } from 'node:stream';
2
+ /** The only header better-auth reads the client's IP from; Inlay always sets it itself. */
3
+ export const CLIENT_IP_HEADER = 'x-inlay-client-ip';
4
+ /** Request headers that describe the incoming connection or body, not the request, so they're never forwarded. */
5
+ const HOP = new Set(['connection', 'keep-alive', 'transfer-encoding', 'upgrade', 'expect', 'host', 'content-length']);
6
+ /** The request's headers as Web `Headers`, with `x-inlay-client-ip` set from Fastify's `request.ip`. */
7
+ export function webHeaders(request) {
8
+ const headers = new Headers();
9
+ for (const [name, value] of Object.entries(request.headers)) {
10
+ if (value === undefined || HOP.has(name) || name === CLIENT_IP_HEADER)
11
+ continue;
12
+ headers.set(name, Array.isArray(value) ? value.join(', ') : value);
13
+ }
14
+ headers.set(CLIENT_IP_HEADER, request.ip);
15
+ return headers;
16
+ }
17
+ /**
18
+ * A Web `Request` for `request` at `baseUrl` (so better-auth sees the site's own origin), with its headers and the
19
+ * client IP. `path` (default: the request's URL) and `body` replace the request's own; `headers` are set last.
20
+ */
21
+ export function toWebRequest(request, baseUrl, opts = {}) {
22
+ const headers = webHeaders(request);
23
+ for (const [name, value] of Object.entries(opts.headers ?? {})) {
24
+ if (name.toLowerCase() !== CLIENT_IP_HEADER)
25
+ headers.set(name, value);
26
+ }
27
+ const { method } = request;
28
+ const hasBody = opts.body !== undefined && method !== 'GET' && method !== 'HEAD';
29
+ return new Request(`${baseUrl}${opts.path ?? request.url}`, {
30
+ method,
31
+ headers,
32
+ ...(hasBody && { body: typeof opts.body === 'string' ? opts.body : new Uint8Array(opts.body) }),
33
+ });
34
+ }
35
+ /** Copies every `set-cookie` of `res` onto `reply`, each as its own header. */
36
+ export function copyCookies(reply, res) {
37
+ const cookies = res.headers.getSetCookie();
38
+ if (cookies.length > 0)
39
+ reply.header('set-cookie', cookies);
40
+ }
41
+ /** Sends `res` through `reply`: status, headers (each `set-cookie` separately) and a streamed body. */
42
+ export async function sendWebResponse(reply, res) {
43
+ reply.code(res.status);
44
+ res.headers.forEach((value, name) => {
45
+ if (name !== 'set-cookie' && name !== 'transfer-encoding' && name !== 'connection')
46
+ reply.header(name, value);
47
+ });
48
+ copyCookies(reply, res);
49
+ if (res.body === null)
50
+ return reply.send();
51
+ return reply.send(Readable.fromWeb(res.body));
52
+ }
53
+ /** Whether the request's `Origin` header is exactly `baseUrl`. A missing `Origin` is not the same origin. */
54
+ export function sameOrigin(request, baseUrl) {
55
+ return request.headers.origin === baseUrl;
56
+ }
57
+ const PROBE = 'http://inlay.invalid';
58
+ /** `raw` as a clean site-relative path (with its query), or `fallback` when it isn't one. */
59
+ export function safeNext(raw, fallback = '/admin') {
60
+ if (typeof raw !== 'string' || !raw.startsWith('/') || raw.startsWith('//'))
61
+ return fallback;
62
+ if (/[\\\u0000-\u001f\u007f]/.test(raw))
63
+ return fallback;
64
+ let url;
65
+ try {
66
+ url = new URL(raw, PROBE);
67
+ }
68
+ catch {
69
+ return fallback;
70
+ }
71
+ if (url.origin !== PROBE)
72
+ return fallback;
73
+ const next = `${url.pathname}${url.search}`;
74
+ return next.startsWith('/') && !next.startsWith('//') ? next : fallback;
75
+ }
@@ -0,0 +1,21 @@
1
+ import type { SiteDefinition } from './core/registry/define.js';
2
+ export interface InlayConfig {
3
+ site: SiteDefinition;
4
+ /** The database file. Only the commands that work on a database need it; `--db` can give it instead. */
5
+ db?: string;
6
+ backups?: string;
7
+ media?: string;
8
+ }
9
+ export declare function defineConfig(c: InlayConfig): InlayConfig;
10
+ /** A loaded config, with the absolute path of its file and that file's directory. */
11
+ export interface LoadedConfig {
12
+ config: InlayConfig;
13
+ file: string;
14
+ dir: string;
15
+ }
16
+ /**
17
+ * Loads a config file. Relative paths in it resolve against the file's
18
+ * directory; `backups` defaults to `<dir of db>/backups` and `media` to
19
+ * `<dir of db>/media` when there is a database.
20
+ */
21
+ export declare function loadConfig(file: string): Promise<LoadedConfig>;
package/dist/config.js ADDED
@@ -0,0 +1,58 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { mkdtemp, rm, writeFile } from 'node:fs/promises';
3
+ import { tmpdir } from 'node:os';
4
+ import { dirname, isAbsolute, join, resolve } from 'node:path';
5
+ import { pathToFileURL } from 'node:url';
6
+ import { InlayError } from './core/errors.js';
7
+ export function defineConfig(c) {
8
+ return c;
9
+ }
10
+ /**
11
+ * Imports the config module at `file` through a bundle of it and everything it imports, so TypeScript and JSX load
12
+ * without tsx, and the site's `inlaycms` is the running copy.
13
+ */
14
+ async function importConfig(file) {
15
+ // Imported here, not at the top: `inlaycms/site` re-exports `defineConfig` and shouldn't pull in esbuild.
16
+ const { bundleConfig } = await import('./core/release/bundle.js');
17
+ const dir = await mkdtemp(join(tmpdir(), 'inlay-config-'));
18
+ try {
19
+ const out = join(dir, 'config.js');
20
+ await writeFile(join(dir, 'package.json'), '{ "type": "module" }\n');
21
+ await bundleConfig(file, out);
22
+ return (await import(pathToFileURL(out).href));
23
+ }
24
+ finally {
25
+ await rm(dir, { recursive: true, force: true });
26
+ }
27
+ }
28
+ /**
29
+ * Loads a config file. Relative paths in it resolve against the file's
30
+ * directory; `backups` defaults to `<dir of db>/backups` and `media` to
31
+ * `<dir of db>/media` when there is a database.
32
+ */
33
+ export async function loadConfig(file) {
34
+ const abs = resolve(file);
35
+ if (!existsSync(abs))
36
+ throw new InlayError('not_found', 'error.configMissing', { path: abs });
37
+ const mod = await importConfig(abs);
38
+ const config = mod.default;
39
+ if (!config || typeof config !== 'object' || !config.site || (config.db !== undefined && typeof config.db !== 'string')) {
40
+ throw new InlayError('not_found', 'error.configMissing', { path: abs });
41
+ }
42
+ const dir = dirname(abs);
43
+ const fromBase = (p) => (isAbsolute(p) ? p : join(dir, p));
44
+ const db = config.db !== undefined ? fromBase(config.db) : undefined;
45
+ const near = (name) => (db !== undefined ? join(dirname(db), name) : undefined);
46
+ const backups = config.backups !== undefined ? fromBase(config.backups) : near('backups');
47
+ const media = config.media !== undefined ? fromBase(config.media) : near('media');
48
+ return {
49
+ config: {
50
+ site: config.site,
51
+ ...(db !== undefined && { db }),
52
+ ...(backups !== undefined && { backups }),
53
+ ...(media !== undefined && { media }),
54
+ },
55
+ file: abs,
56
+ dir,
57
+ };
58
+ }
@@ -0,0 +1,62 @@
1
+ import { type AgentRefs } from '../fields/define.js';
2
+ import type { Registry } from '../registry/registry.js';
3
+ import type { ContentInput, ContentIssue, DocumentData, PathSegment } from '../types.js';
4
+ export type { AgentCodec, AgentRefs } from '../fields/define.js';
5
+ /** A document as an assistant reads and writes it: the stored shape with agent-format values. */
6
+ export type AgentDocument = {
7
+ slug?: string;
8
+ path?: string;
9
+ fields: Record<string, unknown>;
10
+ slots: Record<string, {
11
+ enabled: boolean;
12
+ data: Record<string, unknown>;
13
+ }>;
14
+ };
15
+ export type AgentLink = {
16
+ uri: string;
17
+ title?: string;
18
+ url?: string | null;
19
+ filename?: string;
20
+ missing?: string;
21
+ };
22
+ export type AgentInput = Partial<Omit<AgentDocument, 'slots'>> & {
23
+ slots?: Record<string, {
24
+ enabled?: boolean;
25
+ data?: Record<string, unknown>;
26
+ }>;
27
+ };
28
+ /** Every document (`groupId`) and media id `toAgent` will look up through `AgentRefs`. */
29
+ export declare function agentRefsNeeded(registry: Registry, type: string, data: DocumentData): {
30
+ documents: string[];
31
+ media: string[];
32
+ };
33
+ /** The stored document as the assistant reads it. */
34
+ export declare function toAgent(registry: Registry, type: string, data: DocumentData, refs: AgentRefs): AgentDocument;
35
+ /** Every `inlay:` link and image target in the document's rich text, with what it points to. */
36
+ export declare function agentLinks(registry: Registry, type: string, data: DocumentData, refs: AgentRefs): AgentLink[];
37
+ /** A dotted field path; all-digit segments are list indexes. `null` if any segment is empty. */
38
+ export declare function parsePath(path: string): PathSegment[] | null;
39
+ export type FromAgentResult = {
40
+ ok: true;
41
+ value: unknown;
42
+ } | {
43
+ ok: false;
44
+ issues: ContentIssue[];
45
+ };
46
+ /**
47
+ * Turns a value the assistant wrote at `path` into the stored form. A path that
48
+ * isn't in the schema leaves `value` unchanged, so the patch reports it.
49
+ */
50
+ export declare function fromAgent(registry: Registry, type: string, path: PathSegment[], value: unknown): FromAgentResult;
51
+ /**
52
+ * Turns a document the assistant wrote into content for creating it. A slot `{ enabled: false }` becomes `false`.
53
+ * On failure `content` keeps each value that couldn't be converted as it was written.
54
+ */
55
+ export declare function contentFromAgent(registry: Registry, type: string, input: AgentInput): {
56
+ ok: true;
57
+ content: ContentInput;
58
+ } | {
59
+ ok: false;
60
+ issues: ContentIssue[];
61
+ content: ContentInput;
62
+ };