inlaycms 0.0.0-stage → 0.2.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 +469 -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,223 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "inlaycms/jsx-runtime";
2
+ import { randomUUID } from 'node:crypto';
3
+ import { createReadStream, createWriteStream } from 'node:fs';
4
+ import { lstat, mkdtemp, readdir, rm, stat } from 'node:fs/promises';
5
+ import { tmpdir } from 'node:os';
6
+ import { basename, join } from 'node:path';
7
+ import { pipeline } from 'node:stream/promises';
8
+ import { InlayError } from '../../../core/errors.js';
9
+ import { exportFileName } from '../../../core/export/format.js';
10
+ import { siteLockLines } from '../../../core/export/report.js';
11
+ import { formatSize } from '../../../core/media/labels.js';
12
+ import { t } from '../../../core/messages/index.js';
13
+ import { adminActor, forbidden, HTML, noticeOf, notFound } from '../context.js';
14
+ import { DataTable } from '../views/data-table.js';
15
+ import { Icon } from '../views/icons.js';
16
+ import { Alert, adminPage, Time } from '../views/layout.js';
17
+ /** The largest export the upload form takes. */
18
+ export const IMPORT_MAX_BYTES = 1024 ** 3;
19
+ /** How long an uploaded export waits for its confirmation before the next upload deletes it. */
20
+ const STAGED_MAX_AGE_MS = 60 * 60 * 1000;
21
+ const TOKEN = /^[0-9a-f-]{36}$/;
22
+ let staging;
23
+ /**
24
+ * This process's folder for uploaded exports: made once with a random name and mode 0700, so no other user can
25
+ * read, plant or swap files in it. Made again if it is gone or is no longer a private directory.
26
+ */
27
+ export async function stagingDir() {
28
+ const current = (staging ??= mkdtemp(join(tmpdir(), 'inlay-imports-')));
29
+ const dir = await current.catch(() => null);
30
+ const info = dir === null ? null : await lstat(dir).catch(() => null);
31
+ const own = process.getuid === undefined || info?.uid === process.getuid();
32
+ if (dir !== null && info?.isDirectory() && own && (info.mode & 0o077) === 0)
33
+ return dir;
34
+ if (staging === current)
35
+ staging = undefined;
36
+ return (staging ??= mkdtemp(join(tmpdir(), 'inlay-imports-')));
37
+ }
38
+ /** Deletes the staged uploads nobody confirmed within the hour. */
39
+ async function sweepStaged() {
40
+ const dir = await stagingDir();
41
+ const names = await readdir(dir).catch(() => []);
42
+ for (const name of names) {
43
+ const path = join(dir, name);
44
+ const info = await stat(path).catch(() => null);
45
+ if (info !== null && Date.now() - info.mtimeMs > STAGED_MAX_AGE_MS)
46
+ await rm(path, { force: true });
47
+ }
48
+ }
49
+ function Problems({ problems }) {
50
+ if (problems.length === 0)
51
+ return null;
52
+ return (_jsx("ul", { class: "list-disc pl-6 text-sm", children: problems.map((p) => (_jsxs("li", { children: [p.message, (p.issues ?? []).length > 0 && (_jsx("ul", { class: "list-disc pl-6", children: (p.issues ?? []).map((i) => (_jsx("li", { children: i.message }))) }))] }))) }));
53
+ }
54
+ /** The owner's Backups screen: the list, a "Back up now" button and the downloads. */
55
+ export function registerBackups(scope, ctx) {
56
+ const { core } = ctx;
57
+ scope.addHook('onClose', async () => {
58
+ const dir = await staging?.catch(() => null);
59
+ staging = undefined;
60
+ if (dir)
61
+ await rm(dir, { recursive: true, force: true }).catch(() => { });
62
+ });
63
+ const asCtx = (request) => ({ actor: adminActor(request), source: 'admin' });
64
+ async function backupsPage(request, reply, status = 200, error) {
65
+ const actor = adminActor(request);
66
+ const backups = await core.listBackups(asCtx(request));
67
+ const notice = noticeOf(request.query);
68
+ const body = (_jsxs("div", { class: "flex flex-col gap-8", children: [error !== undefined && (_jsx(Alert, { kind: "error", id: "import-error", children: error })), _jsx("p", { children: t('admin.backups.intro') }), _jsx(DataTable, { id: "backups", caption: t('admin.backups.table'), base: "/admin/backups", rows: backups, rowKey: (b) => b.path, rowLabel: (b) => b.createdAt, empty: t('admin.backups.empty'), columns: [
69
+ { key: 'made', label: t('admin.backups.made'), cell: (b) => _jsx(Time, { iso: b.createdAt, relative: true }) },
70
+ { key: 'kind', label: t('admin.backups.kind'), cell: (b) => t(`admin.backups.reason.${b.reason}`) },
71
+ { key: 'size', label: t('admin.backups.size'), align: 'end', class: 'tabular-nums', cell: (b) => formatSize(b.size) },
72
+ {
73
+ key: 'download',
74
+ label: t('admin.backups.download'),
75
+ hideLabel: true,
76
+ align: 'end',
77
+ cell: (b) => (_jsxs("a", { href: `/admin/backups/${encodeURIComponent(basename(b.path))}`, class: "btn btn-ghost btn-xs", children: [_jsx(Icon, { name: "download" }), t('admin.backups.download')] })),
78
+ },
79
+ ] }), _jsxs("p", { class: "flex items-center gap-2 text-sm text-base-content/60", children: [_jsx(Icon, { name: "info" }), t('admin.backups.restoreHint')] }), _jsxs("div", { class: "grid gap-6 lg:grid-cols-2", children: [_jsx("section", { class: "card card-border bg-base-100", "aria-labelledby": "export-heading", children: _jsxs("div", { class: "card-body gap-4", children: [_jsx("h2", { id: "export-heading", class: "card-title text-lg", children: t('admin.export.title') }), _jsx("p", { children: t('admin.export.intro') }), _jsx("div", { children: _jsx("a", { href: "/admin/backups/export", class: "btn", children: t('admin.export.download') }) })] }) }), _jsx("section", { class: "card card-border bg-base-100", "aria-labelledby": "import-heading", children: _jsxs("div", { class: "card-body gap-4", children: [_jsx("h2", { id: "import-heading", class: "card-title text-lg", children: t('admin.import.title') }), _jsx("p", { id: "import-hint", children: t('admin.import.intro') }), _jsxs("form", { method: "post", action: "/admin/backups/import", enctype: "multipart/form-data", class: "flex flex-col gap-4", children: [_jsxs("div", { class: "flex flex-col gap-1", children: [_jsx("label", { for: "import-archive", class: "text-sm font-medium", children: t('admin.import.file') }), _jsx("input", { id: "import-archive", name: "archive", type: "file", accept: ".tar.gz,application/gzip", class: "file-input w-full", "aria-describedby": "import-hint" })] }), _jsx("div", { children: _jsx("button", { type: "submit", class: "btn btn-primary", children: t('admin.import.check') }) })] })] }) })] })] }));
80
+ const page = await adminPage(ctx, {
81
+ title: t('admin.backups.title'),
82
+ actor,
83
+ section: 'backups',
84
+ status,
85
+ actions: (_jsx("form", { method: "post", action: "/admin/backups", children: _jsx("button", { type: "submit", class: "btn btn-primary btn-sm", children: t('admin.backups.make') }) })),
86
+ ...(notice !== undefined && { notice }),
87
+ }, body);
88
+ return reply.code(status).type(HTML).send(page);
89
+ }
90
+ async function reportPage(request, reply, status, report, token) {
91
+ const actor = adminActor(request);
92
+ const hiddenLocales = report.locales.filter((l) => l.status !== 'compatible');
93
+ const body = (_jsxs("div", { class: "flex flex-col gap-8", children: [_jsxs("p", { children: [t('admin.import.exportedAt'), " ", _jsx(Time, { iso: report.exportedAt }), ". ", t('admin.import.version', { version: report.inlayVersion }), "."] }), _jsxs("section", { class: "flex flex-col gap-2", "aria-labelledby": "types-heading", children: [_jsx("h2", { id: "types-heading", class: "text-lg font-semibold", children: t('admin.import.types') }), _jsx(DataTable, { id: "import-report", caption: t('admin.import.types'), base: "/admin/backups", rows: report.types, rowKey: (row) => row.label, rowLabel: (row) => row.label, empty: t('admin.import.typesEmpty'), columns: [
94
+ {
95
+ key: 'type',
96
+ label: t('admin.import.type'),
97
+ cell: (row) => (_jsxs(_Fragment, { children: [row.label, row.gaps > 0 && _jsx("p", { class: "text-sm", children: t('admin.import.gaps', { count: row.gaps }) })] })),
98
+ },
99
+ { key: 'documents', label: t('admin.import.documents'), cell: (row) => row.documents },
100
+ { key: 'status', label: t('admin.import.status'), cell: (row) => t(`import.status.${row.status}`) },
101
+ ] })] }), hiddenLocales.length > 0 && (_jsxs("section", { class: "flex flex-col gap-2", "aria-labelledby": "locales-heading", children: [_jsx("h2", { id: "locales-heading", class: "text-lg font-semibold", children: t('admin.import.locales') }), _jsx("ul", { class: "flex flex-col gap-2", children: hiddenLocales.map((row) => (_jsx("li", { children: t('import.localeLine', { locale: row.locale, status: t(`import.status.${row.status}`), documents: row.documents }) }))) })] })), report.general.length > 0 && (_jsxs("section", { class: "flex flex-col gap-2", "aria-labelledby": "general-heading", children: [_jsx("h2", { id: "general-heading", class: "text-lg font-semibold", children: t('admin.import.general') }), _jsx(Problems, { problems: report.general })] })), report.media.damaged.length > 0 && (_jsxs("section", { class: "flex flex-col gap-2", "aria-labelledby": "damaged-heading", children: [_jsx("h2", { id: "damaged-heading", class: "text-lg font-semibold", children: t('admin.import.damaged') }), _jsx("p", { children: t('import.damagedMedia', { count: report.media.damaged.length, names: report.media.damaged.join(', ') }) })] })), report.shipped.length > 0 && (_jsxs("section", { class: "flex flex-col gap-2", "aria-labelledby": "shipped-heading", children: [_jsx("h2", { id: "shipped-heading", class: "text-lg font-semibold", children: t('admin.import.shippedTitle') }), _jsx("ul", { class: "list-disc pl-6", children: report.shipped.map((title) => (_jsx("li", { children: title }))) })] })), siteLockLines(report.siteLock).length > 0 && (_jsxs("section", { class: "flex flex-col gap-2", "aria-labelledby": "site-lock-heading", children: [_jsx("h2", { id: "site-lock-heading", class: "text-lg font-semibold", children: t('admin.import.siteLockTitle') }), _jsx("ul", { class: "list-disc pl-6", children: siteLockLines(report.siteLock).map((line) => (_jsx("li", { children: line }))) })] })), report.ok ? (_jsxs("form", { method: "post", action: `/admin/backups/import/${token}`, class: "flex flex-col gap-4", children: [_jsx(Alert, { kind: "warning", id: "replace-warning", children: t('admin.import.replaceWarning') }), _jsxs("div", { class: "flex gap-4", children: [_jsx("button", { type: "submit", class: "btn btn-primary", children: t('admin.import.restore') }), _jsx("a", { href: "/admin/backups", class: "btn", children: t('admin.import.back') })] })] })) : (_jsxs("div", { class: "flex flex-col gap-4", children: [_jsx(Alert, { kind: "error", id: "cannot-restore", children: t('admin.import.cannotRestore') }), _jsx("div", { children: _jsx("a", { href: "/admin/backups", class: "btn", children: t('admin.import.back') }) })] }))] }));
102
+ const page = await adminPage(ctx, {
103
+ title: t('admin.import.reportTitle'),
104
+ actor,
105
+ section: 'backups',
106
+ status,
107
+ breadcrumbs: [{ label: t('admin.backups.title'), href: '/admin/backups' }],
108
+ }, body);
109
+ return reply.code(status).type(HTML).send(page);
110
+ }
111
+ scope.get('/admin/backups', async (request, reply) => {
112
+ const actor = adminActor(request);
113
+ if (actor.role !== 'owner')
114
+ return forbidden(reply, ctx, actor);
115
+ return backupsPage(request, reply);
116
+ });
117
+ scope.get('/admin/backups/export', async (request, reply) => {
118
+ const actor = adminActor(request);
119
+ if (actor.role !== 'owner')
120
+ return forbidden(reply, ctx, actor);
121
+ const file = join(tmpdir(), `inlay-export-${randomUUID()}.tar.gz`);
122
+ try {
123
+ await core.exportContent(file, asCtx(request));
124
+ const { size } = await stat(file);
125
+ const stream = createReadStream(file);
126
+ stream.on('close', () => void rm(file, { force: true }));
127
+ return reply
128
+ .type('application/gzip')
129
+ .header('content-disposition', `attachment; filename="${exportFileName(new Date())}"`)
130
+ .header('content-length', size)
131
+ .send(stream);
132
+ }
133
+ catch (e) {
134
+ await rm(file, { force: true });
135
+ throw e;
136
+ }
137
+ });
138
+ scope.post('/admin/backups/import', async (request, reply) => {
139
+ const actor = adminActor(request);
140
+ if (actor.role !== 'owner')
141
+ return forbidden(reply, ctx, actor);
142
+ if (!request.isMultipart())
143
+ return backupsPage(request, reply, 400, t('admin.import.noFile'));
144
+ await sweepStaged();
145
+ const part = await request.file({ limits: { fileSize: IMPORT_MAX_BYTES, files: 1 }, throwFileSizeLimit: false });
146
+ if (!part)
147
+ return backupsPage(request, reply, 400, t('admin.import.noFile'));
148
+ const token = randomUUID();
149
+ const path = join(await stagingDir(), `${token}.tar.gz`);
150
+ try {
151
+ await pipeline(part.file, createWriteStream(path));
152
+ if (part.file.truncated) {
153
+ await rm(path, { force: true });
154
+ return backupsPage(request, reply, 400, t('admin.import.tooLarge', { max: formatSize(IMPORT_MAX_BYTES) }));
155
+ }
156
+ if ((await stat(path)).size === 0) {
157
+ await rm(path, { force: true });
158
+ return backupsPage(request, reply, 400, t('admin.import.noFile'));
159
+ }
160
+ const report = await core.importDryRun(path, asCtx(request));
161
+ return reportPage(request, reply, 200, report, token);
162
+ }
163
+ catch (e) {
164
+ await rm(path, { force: true });
165
+ if (e instanceof InlayError && e.code === 'validation')
166
+ return backupsPage(request, reply, 400, e.message);
167
+ throw e;
168
+ }
169
+ });
170
+ scope.post('/admin/backups/import/:token', async (request, reply) => {
171
+ const actor = adminActor(request);
172
+ if (actor.role !== 'owner')
173
+ return forbidden(reply, ctx, actor);
174
+ const { token } = request.params;
175
+ if (!TOKEN.test(token))
176
+ return notFound(reply, ctx, actor);
177
+ const path = join(await stagingDir(), `${token}.tar.gz`);
178
+ if (!(await stat(path).catch(() => null)))
179
+ return notFound(reply, ctx, actor);
180
+ try {
181
+ const result = await core.importContent(path, asCtx(request));
182
+ await rm(path, { force: true });
183
+ return reply.redirect(`/admin/backups?notice=contentImported&documents=${result.imported.documents}`, 303);
184
+ }
185
+ catch (e) {
186
+ if (e instanceof InlayError && e.code === 'check_failed' && e.details.importReport) {
187
+ return reportPage(request, reply, 409, e.details.importReport, token);
188
+ }
189
+ if (e instanceof InlayError && e.code === 'validation') {
190
+ await rm(path, { force: true });
191
+ return backupsPage(request, reply, 400, e.message);
192
+ }
193
+ throw e;
194
+ }
195
+ });
196
+ scope.post('/admin/backups', async (request, reply) => {
197
+ const actor = adminActor(request);
198
+ if (actor.role !== 'owner')
199
+ return forbidden(reply, ctx, actor);
200
+ await core.backup(asCtx(request));
201
+ return reply.redirect('/admin/backups?notice=backedUp', 303);
202
+ });
203
+ scope.get('/admin/backups/:name', async (request, reply) => {
204
+ const actor = adminActor(request);
205
+ if (actor.role !== 'owner')
206
+ return forbidden(reply, ctx, actor);
207
+ const { name } = request.params;
208
+ try {
209
+ const backup = await core.backupFile(name, asCtx(request));
210
+ const file = basename(backup.path);
211
+ return reply
212
+ .type('application/gzip')
213
+ .header('content-disposition', `attachment; filename="${file}"`)
214
+ .header('content-length', backup.size)
215
+ .send(createReadStream(backup.path));
216
+ }
217
+ catch (e) {
218
+ if (e instanceof InlayError && e.code === 'not_found')
219
+ return notFound(reply, ctx, actor);
220
+ throw e;
221
+ }
222
+ });
223
+ }
@@ -0,0 +1,4 @@
1
+ import type { FastifyInstance } from 'fastify';
2
+ import { type AdminContext } from '../context.js';
3
+ /** `GET /admin`: counts at a glance, what is waiting to be published, what needs attention, and what changed lately. */
4
+ export declare function registerDashboard(scope: FastifyInstance, ctx: AdminContext): void;
@@ -0,0 +1,160 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "inlaycms/jsx-runtime";
2
+ import { InlayError } from '../../../core/errors.js';
3
+ import { formatSize } from '../../../core/media/labels.js';
4
+ import { t } from '../../../core/messages/index.js';
5
+ import { groupActivity } from '../activity.js';
6
+ import { needsAttention } from '../attention.js';
7
+ import { adminActor, HTML, noticeOf } from '../context.js';
8
+ import { missingTranslations, translationRows } from '../translations.js';
9
+ import { Icon } from '../views/icons.js';
10
+ import { adminPage, initials, Time } from '../views/layout.js';
11
+ import { sourceLabel, StatusBadge } from '../views/status.js';
12
+ const DAY_MS = 24 * 60 * 60 * 1000;
13
+ const TILE_COLLECTIONS = 2;
14
+ const ACTIVITY_LIMIT = 30;
15
+ const editorLink = (doc) => `/admin/documents/${encodeURIComponent(doc.id)}`;
16
+ function typeLabel(ctx, type) {
17
+ return ctx.core.registry.types.get(type)?.label ?? type;
18
+ }
19
+ function AddNew({ ctx }) {
20
+ return (_jsxs("details", { class: "dropdown dropdown-end", children: [_jsxs("summary", { class: "btn btn-sm", children: [_jsx(Icon, { name: "plus" }), t('admin.dashboard.addNew'), _jsx(Icon, { name: "chevron-down", class: "opacity-60" })] }), _jsxs("ul", { class: "dropdown-content menu menu-sm z-20 mt-1 w-48 rounded-box border border-base-300 bg-base-100 p-1 shadow-lg", children: [ctx.core.registry.site.collections.map((c) => (_jsx("li", { children: _jsx("a", { href: `/admin/collections/${encodeURIComponent(c.name)}/new`, children: c.label }) }))), _jsx("li", { children: _jsx("a", { href: "/admin/media?sheet=upload", children: t('admin.dashboard.upload') }) })] })] }));
21
+ }
22
+ function Tile({ href, label, icon, iconClass, value, note }) {
23
+ return (_jsxs("a", { href: href, class: "rounded-box border border-base-300 bg-base-100 p-4 hover:border-base-content/20", children: [_jsxs("div", { class: "flex items-center justify-between gap-2 text-sm text-base-content/70", children: [label, _jsx(Icon, { name: icon, ...(iconClass !== undefined && { class: iconClass }) })] }), _jsx("div", { class: "mt-1 truncate text-2xl font-semibold tabular-nums", children: value }), note !== undefined && _jsx("div", { class: "text-xs text-base-content/60", children: note })] }));
24
+ }
25
+ /** The newest backup, `null` when there is none, or `undefined` when the tile is left out (editors, or no backups folder). */
26
+ async function lastBackup(ctx, actor) {
27
+ if (actor.role !== 'owner')
28
+ return undefined;
29
+ const asCtx = { actor, source: 'admin' };
30
+ try {
31
+ return (await ctx.core.listBackups(asCtx))[0] ?? null;
32
+ }
33
+ catch (e) {
34
+ if (e instanceof InlayError && e.messageId === 'config.backupsMissing')
35
+ return undefined;
36
+ throw e;
37
+ }
38
+ }
39
+ function BackupTile({ backup, now }) {
40
+ const label = t('admin.dashboard.tile.lastBackup');
41
+ if (backup === null) {
42
+ return _jsx(Tile, { href: "/admin/backups", label: label, icon: "alert", iconClass: "text-error", value: t('admin.dashboard.tile.noBackup') });
43
+ }
44
+ const old = now.getTime() - Date.parse(backup.createdAt) > 2 * DAY_MS;
45
+ const kind = t(`admin.backups.reason.${backup.reason}`);
46
+ return (_jsx(Tile, { href: "/admin/backups", label: label, icon: old ? 'alert' : 'check-circle', ...(old && { iconClass: 'text-error' }), value: _jsx(Time, { iso: backup.createdAt, relative: true }), note: old ? `${kind} · ${t('admin.dashboard.tile.backupOld')}` : kind }));
47
+ }
48
+ function PendingRow({ ctx, item }) {
49
+ const { document, isNew, lines } = item;
50
+ const id = `pending-${document.id}`;
51
+ const first = isNew ? t('admin.dashboard.pending.new') : lines[0];
52
+ const meta = [typeLabel(ctx, document.type), document.locale, ...(first !== undefined ? [first] : [])].join(' · ');
53
+ const more = isNew ? 0 : lines.length - 1;
54
+ return (_jsxs("li", { class: "flex items-center gap-3 px-4 py-2.5", children: [_jsx("input", { type: "checkbox", name: "ids", value: document.id, id: id, checked: true, class: "checkbox checkbox-sm" }), _jsx("label", { for: id, class: "sr-only", children: t('admin.dashboard.pending.select', { title: document.title, locale: document.locale }) }), _jsxs("div", { class: "min-w-0 flex-1", children: [_jsx("a", { href: editorLink(document), class: "font-medium hover:underline", children: document.title }), _jsx("div", { class: "truncate text-xs text-base-content/60", children: meta }), more > 0 && _jsx("div", { class: "text-xs text-base-content/60", children: t('admin.dashboard.pending.more', { count: more }) })] }), _jsx(StatusBadge, { doc: document }), _jsx("span", { class: "hidden w-28 shrink-0 text-right text-xs text-base-content/60 sm:block", children: _jsx(Time, { iso: document.updatedAt, relative: true }) })] }));
55
+ }
56
+ function PendingCard({ ctx, pending, wide }) {
57
+ const span = wide ? 'rounded-box border border-base-300 bg-base-100 lg:col-span-3' : 'rounded-box border border-base-300 bg-base-100 lg:col-span-2';
58
+ const heading = (_jsxs("div", { children: [_jsx("h2", { id: "pending-heading", class: "font-semibold", children: t('admin.dashboard.pending.title') }), pending.length > 0 && _jsx("p", { class: "text-xs text-base-content/60", children: t('admin.dashboard.pending.intro') })] }));
59
+ if (pending.length === 0) {
60
+ return (_jsxs("section", { "aria-labelledby": "pending-heading", class: span, children: [_jsx("div", { class: "border-b border-base-300 px-4 py-3", children: heading }), _jsx("p", { class: "px-4 py-3 text-sm", children: t('admin.dashboard.pending.empty') })] }));
61
+ }
62
+ return (_jsx("section", { "aria-labelledby": "pending-heading", class: span, children: _jsxs("form", { method: "get", action: "/admin/publish", children: [_jsx("input", { type: "hidden", name: "ids", value: "" }), _jsxs("div", { class: "flex items-center justify-between gap-4 border-b border-base-300 px-4 py-3", children: [heading, _jsx("button", { type: "submit", "data-publish-dialog": true, class: "btn btn-primary btn-sm", children: t('admin.dashboard.pending.submit') })] }), _jsx("ul", { class: "divide-y divide-base-300", children: pending.map((item) => (_jsx(PendingRow, { ctx: ctx, item: item }))) })] }) }));
63
+ }
64
+ function AttentionCard({ items }) {
65
+ return (_jsxs("section", { "aria-labelledby": "attention-heading", class: "rounded-box border border-base-300 bg-base-100", children: [_jsx("div", { class: "border-b border-base-300 px-4 py-3", children: _jsx("h2", { id: "attention-heading", class: "font-semibold", children: t('admin.attention.title') }) }), _jsx("ul", { class: "divide-y divide-base-300 text-sm", children: items.map((item) => (_jsxs("li", { class: "flex items-start gap-3 px-4 py-3", children: [_jsx(Icon, { name: item.icon, class: "mt-0.5 text-base-content/60" }), _jsx("a", { href: item.href, class: "hover:underline", children: item.text })] }))) })] }));
66
+ }
67
+ /**
68
+ * Where a type's gapped documents are listed: its collection (in their language, when they are all in one), or the
69
+ * pages or site-wide content list.
70
+ */
71
+ function gapsHref(ctx, gap) {
72
+ const kind = ctx.core.registry.types.get(gap.type)?.kind;
73
+ if (kind === 'singleton')
74
+ return '/admin/pages';
75
+ if (kind === 'global')
76
+ return '/admin/globals';
77
+ const href = `/admin/collections/${encodeURIComponent(gap.type)}`;
78
+ const locales = Object.keys(gap.locales);
79
+ const only = locales.length === 1 ? locales[0] : undefined;
80
+ return only === undefined || only === ctx.core.registry.defaultLocale ? href : `${href}?locale=${encodeURIComponent(only)}`;
81
+ }
82
+ function GapsCard({ ctx, gaps }) {
83
+ return (_jsxs("section", { "aria-labelledby": "gaps-heading", class: "rounded-box border border-base-300 bg-base-100", children: [_jsxs("div", { class: "border-b border-base-300 px-4 py-3", children: [_jsx("h2", { id: "gaps-heading", class: "font-semibold", children: t('admin.gaps.title') }), _jsx("p", { class: "text-xs text-base-content/60", children: t('admin.gaps.intro') })] }), _jsx("ul", { class: "divide-y divide-base-300 text-sm", children: gaps.map((gap) => (_jsxs("li", { class: "flex items-start gap-3 px-4 py-3", children: [_jsx(Icon, { name: "alert", class: "mt-0.5 text-base-content/60" }), _jsx("a", { href: gapsHref(ctx, gap), class: "hover:underline", children: t('admin.gaps.summary', { label: gap.label, count: gap.documents }) })] }))) })] }));
84
+ }
85
+ function via(source) {
86
+ if (source === 'mcp')
87
+ return t('admin.activity.viaAssistant');
88
+ if (source === 'admin')
89
+ return '';
90
+ return t('admin.activity.viaSource', { source: sourceLabel(source) });
91
+ }
92
+ const joined = (...parts) => parts.filter((part) => part !== '').join(' ');
93
+ function LineText({ ctx, line }) {
94
+ switch (line.kind) {
95
+ case 'edit': {
96
+ const type = ctx.core.registry.types.get(line.document.type);
97
+ const tail = joined(via(line.source), line.count > 1 ? t('admin.activity.edits', { count: line.count }) : '');
98
+ return (_jsxs(_Fragment, { children: [_jsx("a", { href: editorLink(line.document), class: "hover:underline", children: t('admin.activity.changed', { name: line.authorName, title: line.document.title }) }), type?.kind === 'collection' && _jsxs("span", { class: "text-base-content/60", children: [" ", t('admin.activity.in', { type: type.label })] }), tail !== '' && ` ${tail}`] }));
99
+ }
100
+ case 'edits': {
101
+ const params = { name: line.authorName, count: line.documents.length };
102
+ if (line.source === 'release')
103
+ return _jsx(_Fragment, { children: t('admin.activity.shipped', { count: params.count }) });
104
+ return _jsx(_Fragment, { children: joined(t('admin.activity.changedMany', params), via(line.source)) });
105
+ }
106
+ case 'publish':
107
+ case 'unpublish': {
108
+ const main = t(line.kind === 'publish' ? 'admin.activity.published' : 'admin.activity.unpublished', {
109
+ name: line.authorName,
110
+ titles: line.documents.map((d) => d.title).join(', '),
111
+ });
112
+ return _jsx(_Fragment, { children: joined(main, via(line.source)) });
113
+ }
114
+ }
115
+ }
116
+ function ActivityCard({ ctx, activity, now }) {
117
+ const days = groupActivity(activity, now);
118
+ return (_jsxs("section", { "aria-labelledby": "activity-heading", class: "rounded-box border border-base-300 bg-base-100 lg:col-span-3", children: [_jsx("div", { class: "border-b border-base-300 px-4 py-3", children: _jsx("h2", { id: "activity-heading", class: "font-semibold", children: t('admin.dashboard.activity.title') }) }), days.length === 0 ? (_jsx("p", { class: "px-4 py-3 text-sm", children: t('admin.dashboard.activity.empty') })) : (days.map(({ day, lines }) => (_jsxs("div", { children: [_jsx("h3", { class: "border-b border-base-300 bg-base-200/50 px-4 py-1.5 text-xs font-medium text-base-content/60", children: day }), _jsx("ul", { class: "divide-y divide-base-300", children: lines.map((line) => (_jsxs("li", { class: "flex items-center gap-3 px-4 py-2", children: [_jsx("span", { "aria-hidden": "true", class: "grid size-7 shrink-0 place-items-center rounded-full bg-neutral text-xs text-neutral-content", children: initials(line.authorName) }), _jsx("div", { class: "min-w-0 flex-1 text-sm", children: _jsx(LineText, { ctx: ctx, line: line }) }), _jsx("span", { class: "shrink-0 text-xs text-base-content/60", children: _jsx(Time, { iso: line.at }) })] }))) })] }))))] }));
119
+ }
120
+ /** `GET /admin`: counts at a glance, what is waiting to be published, what needs attention, and what changed lately. */
121
+ export function registerDashboard(scope, ctx) {
122
+ const { core } = ctx;
123
+ const { registry } = core;
124
+ scope.get('/admin', async (request, reply) => {
125
+ const actor = adminActor(request);
126
+ const now = ctx.now();
127
+ const multilingual = registry.locales.length > 1;
128
+ const pageRows = multilingual ? await translationRows(ctx, registry.site.singletons) : [];
129
+ const [waiting, activity, counts, media, attention, backup, gaps] = await Promise.all([
130
+ core.listPendingChanges(),
131
+ core.recentActivity({ limit: ACTIVITY_LIMIT }),
132
+ core.countEntries({ changedSince: new Date(now.getTime() - 7 * DAY_MS).toISOString() }),
133
+ core.mediaStats(),
134
+ needsAttention(ctx, { singletons: pageRows }),
135
+ lastBackup(ctx, actor),
136
+ core.gapSummary(),
137
+ ]);
138
+ const pending = waiting.length > 0 ? await core.describeChanges(waiting.map((d) => d.id)) : [];
139
+ const untranslated = new Set(missingTranslations(pageRows).map((m) => m.def.name)).size;
140
+ const pagesNote = !multilingual
141
+ ? undefined
142
+ : untranslated > 0
143
+ ? t('admin.dashboard.tile.untranslated', { count: untranslated })
144
+ : t('admin.dashboard.tile.allTranslated');
145
+ const body = (_jsxs("div", { class: "flex flex-col gap-6", children: [_jsxs("div", { class: "grid grid-cols-2 gap-3 lg:grid-cols-4", children: [registry.site.collections.slice(0, TILE_COLLECTIONS).map((c) => {
146
+ const count = counts[c.name] ?? { total: 0, changed: 0 };
147
+ return (_jsx(Tile, { href: `/admin/collections/${encodeURIComponent(c.name)}`, label: c.label, icon: "collection", value: count.total, note: t('admin.dashboard.tile.changed', { count: count.changed }) }));
148
+ }), _jsx(Tile, { href: "/admin/pages", label: t('admin.nav.pages'), icon: "file", value: registry.site.singletons.length, note: pagesNote }), _jsx(Tile, { href: "/admin/media", label: t('admin.nav.media'), icon: "image", value: media.count, note: t('admin.dashboard.tile.mediaSize', { size: formatSize(media.totalBytes) }) }), backup !== undefined && _jsx(BackupTile, { backup: backup, now: now })] }), _jsxs("div", { class: "grid gap-6 lg:grid-cols-3", children: [_jsx(PendingCard, { ctx: ctx, pending: pending, wide: attention.length === 0 && gaps.length === 0 }), (attention.length > 0 || gaps.length > 0) && (_jsxs("div", { class: "flex flex-col gap-6 lg:col-span-1", children: [gaps.length > 0 && _jsx(GapsCard, { ctx: ctx, gaps: gaps }), attention.length > 0 && _jsx(AttentionCard, { items: attention })] })), _jsx(ActivityCard, { ctx: ctx, activity: activity, now: now })] })] }));
149
+ const notice = noticeOf(request.query);
150
+ const page = await adminPage(ctx, {
151
+ title: t('admin.nav.dashboard'),
152
+ actor,
153
+ section: 'dashboard',
154
+ description: t('admin.signedInAs', { name: actor.name, role: t(actor.role === 'owner' ? 'role.owner' : 'role.editor') }),
155
+ actions: _jsx(AddNew, { ctx: ctx }),
156
+ ...(notice !== undefined && { notice }),
157
+ }, body);
158
+ return reply.code(200).type(HTML).send(page);
159
+ });
160
+ }
@@ -0,0 +1,67 @@
1
+ import type { FastifyInstance } from 'fastify';
2
+ import type { Actor, ContentIssue, DocumentData, DocumentSummary, DocumentView } from '../../../core/types.js';
3
+ import type { Renderable } from '../../../jsx/html.js';
4
+ import { type AdminContext, type Section } from '../context.js';
5
+ /** The address of a document's editor. */
6
+ export declare const editorLink: (id: string) => string;
7
+ /** A locale's name in English ("Spanish"), or the code itself when it has none. */
8
+ export declare function localeName(locale: string): string;
9
+ /** Where a document sits in the navigation: its section and the breadcrumb back to its list. */
10
+ export declare function placement(ctx: AdminContext, doc: DocumentSummary): {
11
+ section: Section;
12
+ breadcrumbs: Array<{
13
+ label: string;
14
+ href: string;
15
+ }>;
16
+ };
17
+ /** One language of a document: the document in that locale, or `null` when it isn't translated yet. */
18
+ export interface Translation {
19
+ locale: string;
20
+ document: DocumentSummary | null;
21
+ }
22
+ /** Every locale of the site with its version of `doc`'s group. */
23
+ export declare function translationsOf(ctx: AdminContext, doc: DocumentSummary): Promise<Translation[]>;
24
+ /**
25
+ * Links to each language of the document as a compact button group, the current one marked. A locale without a document shows `missing`
26
+ * when given (the "Add <language>" button), otherwise a note that it isn't translated yet.
27
+ */
28
+ export declare function LocaleSwitcher({ doc, translations, missing }: {
29
+ doc: DocumentSummary;
30
+ translations: Translation[];
31
+ missing?: (locale: string) => Renderable;
32
+ }): import("../../../jsx/html.js").Html | null;
33
+ /** A button that creates the `locale` translation of the document group `id` belongs to. */
34
+ export declare function TranslateButton({ id, locale }: {
35
+ id: string;
36
+ locale: string;
37
+ }): import("../../../jsx/html.js").Html;
38
+ /** What the editor page shows besides the document itself. */
39
+ export interface EditorState {
40
+ /** The data in the form: the stored head, or what was submitted. */
41
+ data: DocumentData;
42
+ /** The `base` the form carries: the head it was opened from. */
43
+ base: string;
44
+ status?: number;
45
+ notice?: string;
46
+ /** Inside the form, so htmx swaps carry it: "not saved yet" after a list button. */
47
+ unsaved?: boolean;
48
+ /** A message about the whole form, shown as an error above the fields. */
49
+ error?: string;
50
+ problems?: Map<string, string[]>;
51
+ unplaced?: ContentIssue[];
52
+ /** A stale save: who saved since, and the head to save over. */
53
+ conflict?: {
54
+ head: number;
55
+ name: string;
56
+ source: DocumentView['revision']['source'];
57
+ };
58
+ /** After a list button: the list items and cards to show open and closed, as the editor had them. */
59
+ open?: Set<string>;
60
+ closed?: Set<string>;
61
+ /** After Save and publish: the review the publish dialog opens with as the page loads. */
62
+ review?: string;
63
+ }
64
+ /** The editor page of `doc` (the current head, for the header) showing `state`. */
65
+ export declare function editorPage(ctx: AdminContext, actor: Actor, doc: DocumentView, state: EditorState): Promise<string>;
66
+ /** The editor: `GET` shows a document's form, `POST` saves it (or applies a list button without saving). */
67
+ export declare function registerEditor(scope: FastifyInstance, ctx: AdminContext): void;