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,36 @@
1
+ import type { UploadLimits } from '../core/types.js';
2
+ export interface HostConfig {
3
+ dataDir: string;
4
+ paths: {
5
+ db: string;
6
+ media: string;
7
+ backups: string;
8
+ releases: string;
9
+ };
10
+ baseUrl: string;
11
+ secret: string;
12
+ trustedKeys: string[];
13
+ port: number;
14
+ host: string;
15
+ rateLimit: boolean;
16
+ uploads?: UploadLimits;
17
+ backupKeep: number;
18
+ publicMaxAge: number;
19
+ cdn: {
20
+ maxAge: number;
21
+ staleIfError: number;
22
+ };
23
+ /** The reverse proxies whose X-Forwarded-For is believed, for Fastify's `trustProxy`; false trusts none. */
24
+ trustProxy: false | string[];
25
+ secrets: (names: readonly string[]) => Record<string, string>;
26
+ }
27
+ /** Where a host keeps its files, all in its data folder. */
28
+ export declare function hostPaths(dataDir: string): HostConfig['paths'];
29
+ /** INLAY_DATA_DIR, which must be set. */
30
+ export declare function readDataDir(env: NodeJS.ProcessEnv): string;
31
+ /** The public keys in INLAY_TRUSTED_KEYS and the file INLAY_TRUSTED_KEYS_FILE names; none when neither is set. */
32
+ export declare function readTrustedKeys(env: NodeJS.ProcessEnv): string[];
33
+ export declare function readHostConfig(env: NodeJS.ProcessEnv, opts?: {
34
+ needKeys?: boolean;
35
+ }): HostConfig;
36
+ export declare function ensureDataDir(config: HostConfig): Promise<void>;
@@ -0,0 +1,152 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { mkdir } from 'node:fs/promises';
3
+ import { isIP } from 'node:net';
4
+ import { join } from 'node:path';
5
+ import { InlayError } from '../core/errors.js';
6
+ import { parsePublicKeys } from '../core/release/keys.js';
7
+ function checkBaseUrl(value) {
8
+ const fail = () => new InlayError('config', 'config.host.baseUrl', { value });
9
+ let url;
10
+ try {
11
+ url = new URL(value);
12
+ }
13
+ catch {
14
+ throw fail();
15
+ }
16
+ const bare = url.pathname === '/' && url.search === '' && url.hash === '' && url.username === '' && url.password === '';
17
+ if ((url.protocol !== 'https:' && url.protocol !== 'http:') || !bare || !/^https?:\/\/[^/?#]+\/?$/i.test(value)) {
18
+ throw fail();
19
+ }
20
+ return url.origin;
21
+ }
22
+ function readNumber(env, name, fallback) {
23
+ const raw = env[name];
24
+ if (raw === undefined || raw.trim() === '')
25
+ return fallback;
26
+ if (!/^\d+$/.test(raw.trim()))
27
+ throw new InlayError('config', 'config.host.number', { name, value: raw });
28
+ return Number(raw.trim());
29
+ }
30
+ /** Address ranges `trustProxy` knows by name (proxy-addr's). */
31
+ const PROXY_RANGES = new Set(['loopback', 'linklocal', 'uniquelocal']);
32
+ /** Whether `entry` is an IP address, an address range such as 10.0.0.0/8, or a named range. */
33
+ function isProxyAddress(entry) {
34
+ if (PROXY_RANGES.has(entry))
35
+ return true;
36
+ const [address = '', bits, ...rest] = entry.split('/');
37
+ const version = isIP(address);
38
+ if (version === 0 || rest.length > 0)
39
+ return false;
40
+ return bits === undefined || (/^\d{1,3}$/.test(bits) && Number(bits) <= (version === 4 ? 32 : 128));
41
+ }
42
+ /**
43
+ * INLAY_TRUST_PROXY: off (the default), or the reverse proxies' addresses separated by commas. There's no way to
44
+ * trust every address: then any visitor could fake theirs in X-Forwarded-For and get around the login limits.
45
+ */
46
+ function readTrustProxy(env) {
47
+ const raw = env.INLAY_TRUST_PROXY;
48
+ if (raw === undefined || raw.trim() === '' || raw.trim().toLowerCase() === 'off')
49
+ return false;
50
+ const entries = raw.split(',').map((entry) => entry.trim());
51
+ if (!entries.every(isProxyAddress))
52
+ throw new InlayError('config', 'config.host.trustProxy', { value: raw });
53
+ return entries;
54
+ }
55
+ function readFlag(env, name, fallback) {
56
+ const raw = env[name];
57
+ if (raw === undefined || raw.trim() === '')
58
+ return fallback;
59
+ const value = raw.trim().toLowerCase();
60
+ if (value === 'on')
61
+ return true;
62
+ if (value === 'off')
63
+ return false;
64
+ throw new InlayError('config', 'config.host.flag', { name, value: raw });
65
+ }
66
+ /** Where a host keeps its files, all in its data folder. */
67
+ export function hostPaths(dataDir) {
68
+ return {
69
+ db: join(dataDir, 'inlay.db'),
70
+ media: join(dataDir, 'media'),
71
+ backups: join(dataDir, 'backups'),
72
+ releases: join(dataDir, 'releases'),
73
+ };
74
+ }
75
+ /** INLAY_DATA_DIR, which must be set. */
76
+ export function readDataDir(env) {
77
+ const dataDir = env.INLAY_DATA_DIR;
78
+ if (!dataDir)
79
+ throw new InlayError('config', 'config.host.dataDir', { value: dataDir ?? '' });
80
+ return dataDir;
81
+ }
82
+ /** The public keys in INLAY_TRUSTED_KEYS and the file INLAY_TRUSTED_KEYS_FILE names; none when neither is set. */
83
+ export function readTrustedKeys(env) {
84
+ const keys = new Set();
85
+ if (env.INLAY_TRUSTED_KEYS)
86
+ for (const key of parsePublicKeys(env.INLAY_TRUSTED_KEYS))
87
+ keys.add(key);
88
+ const keysFile = env.INLAY_TRUSTED_KEYS_FILE;
89
+ if (keysFile) {
90
+ let text;
91
+ try {
92
+ text = readFileSync(keysFile, 'utf8');
93
+ }
94
+ catch {
95
+ throw new InlayError('config', 'config.host.trustedKeysFile', { value: keysFile });
96
+ }
97
+ for (const key of parsePublicKeys(text))
98
+ keys.add(key);
99
+ }
100
+ return [...keys];
101
+ }
102
+ export function readHostConfig(env, opts = {}) {
103
+ const dataDir = readDataDir(env);
104
+ const baseUrlRaw = env.INLAY_BASE_URL;
105
+ if (!baseUrlRaw)
106
+ throw new InlayError('config', 'config.host.baseUrl', { value: baseUrlRaw ?? '' });
107
+ const baseUrl = checkBaseUrl(baseUrlRaw);
108
+ const secret = env.INLAY_SECRET;
109
+ if (secret === undefined || secret.length < 32)
110
+ throw new InlayError('config', 'config.host.secret', { value: '' });
111
+ const keys = readTrustedKeys(env);
112
+ if (opts.needKeys && keys.length === 0)
113
+ throw new InlayError('config', 'config.host.trustedKeys', { value: '' });
114
+ const portRaw = env.INLAY_PORT;
115
+ const port = readNumber(env, 'INLAY_PORT', 3000);
116
+ if (port < 1 || port > 65535)
117
+ throw new InlayError('config', 'config.host.port', { value: portRaw ?? '' });
118
+ const maxBytes = readNumber(env, 'INLAY_UPLOAD_MAX_BYTES', undefined);
119
+ return {
120
+ dataDir,
121
+ paths: hostPaths(dataDir),
122
+ baseUrl,
123
+ secret,
124
+ trustedKeys: keys,
125
+ port,
126
+ host: env.INLAY_HOST || '0.0.0.0',
127
+ rateLimit: readFlag(env, 'INLAY_RATE_LIMIT', true),
128
+ ...(maxBytes !== undefined && { uploads: { maxBytes } }),
129
+ backupKeep: readNumber(env, 'INLAY_BACKUP_KEEP', 14),
130
+ publicMaxAge: readNumber(env, 'INLAY_PUBLIC_MAX_AGE', 3600),
131
+ cdn: {
132
+ maxAge: readNumber(env, 'INLAY_CDN_MAX_AGE', 15),
133
+ staleIfError: readNumber(env, 'INLAY_CDN_STALE_IF_ERROR', 86400),
134
+ },
135
+ trustProxy: readTrustProxy(env),
136
+ secrets: (names) => {
137
+ const out = {};
138
+ for (const name of names) {
139
+ const value = env[name];
140
+ if (value !== undefined)
141
+ out[name] = value;
142
+ }
143
+ return out;
144
+ },
145
+ };
146
+ }
147
+ export async function ensureDataDir(config) {
148
+ await mkdir(config.dataDir, { recursive: true });
149
+ for (const dir of [config.paths.media, config.paths.backups, config.paths.releases]) {
150
+ await mkdir(dir, { recursive: true });
151
+ }
152
+ }
@@ -0,0 +1,10 @@
1
+ export interface DevIo {
2
+ cwd: string;
3
+ out(line: string): void;
4
+ err(line: string): void;
5
+ }
6
+ /**
7
+ * `inlaycms dev`: runs the site from its source in a child process and restarts it whenever a file in the site folder
8
+ * changes, until SIGINT or SIGTERM. The child is this same command with INLAY_DEV_CONFIG set.
9
+ */
10
+ export declare function dev(argv: string[], io: DevIo): Promise<number>;
@@ -0,0 +1,293 @@
1
+ import { fork } from 'node:child_process';
2
+ import { existsSync, readdirSync, statSync, watch } from 'node:fs';
3
+ import { registerHooks } from 'node:module';
4
+ import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
5
+ import { pathToFileURL } from 'node:url';
6
+ import { parseArgs } from 'node:util';
7
+ import { loadConfig } from '../config.js';
8
+ import { InlayError } from '../core/errors.js';
9
+ import { t } from '../core/messages/index.js';
10
+ import { INLAY_ENTRIES } from '../core/release/read.js';
11
+ import { createSiteApp } from './app.js';
12
+ import { INLAY_BIN } from './bin.js';
13
+ import { ensureDataDir, readHostConfig } from './config.js';
14
+ /** Only for `inlaycms dev` on a developer's computer: the server's own secret when INLAY_SECRET isn't set. */
15
+ const DEV_SECRET = 'inlay-development-secret-not-for-production-0123456789';
16
+ const DEBOUNCE_MS = 200;
17
+ const STOP_TIMEOUT_MS = 10_000;
18
+ function usage(io) {
19
+ for (const line of t('cli.usage').split('\n'))
20
+ io.err(line);
21
+ return 2;
22
+ }
23
+ function findConfig(cwd, explicit) {
24
+ if (explicit)
25
+ return resolve(cwd, explicit);
26
+ for (const name of ['inlay.config.ts', 'inlay.config.js', 'inlay.config.mjs']) {
27
+ const candidate = join(cwd, name);
28
+ if (existsSync(candidate))
29
+ return candidate;
30
+ }
31
+ throw new InlayError('not_found', 'error.configMissing', { path: join(cwd, 'inlay.config.ts') });
32
+ }
33
+ /** The host settings for a site run from source: the environment, with development defaults for the rest. */
34
+ function devEnv(env, cwd, siteDir, port) {
35
+ return {
36
+ ...env,
37
+ INLAY_DATA_DIR: env.INLAY_DATA_DIR ? resolve(cwd, env.INLAY_DATA_DIR) : join(siteDir, 'data'),
38
+ INLAY_BASE_URL: env.INLAY_BASE_URL || `http://localhost:${port}`,
39
+ INLAY_SECRET: env.INLAY_SECRET ?? DEV_SECRET,
40
+ INLAY_PORT: String(port),
41
+ INLAY_HOST: env.INLAY_HOST || 'localhost',
42
+ };
43
+ }
44
+ /** Whether a change at `rel` (relative to the site folder) leaves the running site as it is. */
45
+ function ignored(rel, dataRel) {
46
+ const parts = rel.split(sep);
47
+ if (parts.some((p) => p === 'node_modules' || p.startsWith('.')))
48
+ return true;
49
+ const under = (dir) => rel === dir || rel.startsWith(dir + sep);
50
+ return under('data') || (dataRel !== null && under(dataRel)) || under(join('assets', 'admin'));
51
+ }
52
+ function isDirectory(path) {
53
+ try {
54
+ return statSync(path).isDirectory();
55
+ }
56
+ catch {
57
+ return false;
58
+ }
59
+ }
60
+ /**
61
+ * Watches the site folder for changes that matter, calling `onChange` with the path relative to it. The folder
62
+ * itself is watched for its own entries and each folder in it separately, so the watch never descends into
63
+ * `node_modules`, dotfiles or the data folder (a folder that holds the data folder is split up the same way).
64
+ */
65
+ function watchSite(siteDir, dataRel, onChange) {
66
+ const watchers = new Map();
67
+ /** Stops watching `rel` and every folder in it. */
68
+ const forget = (rel) => {
69
+ for (const key of [...watchers.keys()]) {
70
+ if (key !== rel && !(rel === '' || key.startsWith(rel + sep)))
71
+ continue;
72
+ watchers.get(key).close();
73
+ watchers.delete(key);
74
+ }
75
+ };
76
+ const add = (rel) => {
77
+ if (watchers.has(rel) || (rel !== '' && ignored(rel, dataRel)))
78
+ return;
79
+ const abs = rel === '' ? siteDir : join(siteDir, rel);
80
+ // Split up: the site folder, and any folder the data folder is in. The rest is watched whole.
81
+ const split = rel === '' || (dataRel !== null && dataRel.startsWith(rel + sep));
82
+ const watcher = watch(abs, { recursive: !split }, (_event, name) => {
83
+ if (name === null)
84
+ return;
85
+ const changed = rel === '' ? String(name) : join(rel, String(name));
86
+ if (ignored(changed, dataRel))
87
+ return;
88
+ if (split) {
89
+ // A folder made, removed or replaced here: watch what is there now.
90
+ forget(changed);
91
+ if (isDirectory(join(siteDir, changed)))
92
+ add(changed);
93
+ }
94
+ onChange(changed);
95
+ });
96
+ watcher.on('error', () => forget(rel));
97
+ watchers.set(rel, watcher);
98
+ if (split) {
99
+ for (const entry of readdirSync(abs, { withFileTypes: true })) {
100
+ if (entry.isDirectory())
101
+ add(rel === '' ? entry.name : join(rel, entry.name));
102
+ }
103
+ }
104
+ };
105
+ try {
106
+ add('');
107
+ }
108
+ catch (e) {
109
+ for (const rel of [...watchers.keys()])
110
+ forget(rel);
111
+ throw e;
112
+ }
113
+ return {
114
+ close() {
115
+ for (const rel of [...watchers.keys()])
116
+ forget(rel);
117
+ },
118
+ };
119
+ }
120
+ /**
121
+ * Makes the site's `import 'inlaycms'` load the running copy, as a release's `site.js` does, so a site folder
122
+ * without its own install (or with another copy) still shares the host's field definitions.
123
+ */
124
+ function useRunningInlay() {
125
+ const urls = new Map(Object.entries(INLAY_ENTRIES).map(([specifier, file]) => [specifier, pathToFileURL(file).href]));
126
+ registerHooks({
127
+ resolve(specifier, context, next) {
128
+ const url = urls.get(specifier);
129
+ return url === undefined ? next(specifier, context) : { url, shortCircuit: true };
130
+ },
131
+ });
132
+ }
133
+ /** The child: loads the site from source, applies its shipped content and serves it until told to stop. */
134
+ async function runSite(configFile, io) {
135
+ // The parent decides when the site stops; Ctrl-C reaches the whole process group.
136
+ process.on('SIGINT', () => { });
137
+ let app;
138
+ let closing = false;
139
+ const close = async () => {
140
+ if (closing)
141
+ return;
142
+ closing = true;
143
+ await app?.close();
144
+ process.exit(0);
145
+ };
146
+ process.on('SIGTERM', () => void close());
147
+ process.on('disconnect', () => void close());
148
+ try {
149
+ useRunningInlay();
150
+ const { config, dir } = await loadConfig(configFile);
151
+ const host = readHostConfig(process.env);
152
+ await ensureDataDir(host);
153
+ const publicDir = join(dir, 'public');
154
+ app = (await createSiteApp(host, { site: config.site, publicDir: existsSync(publicDir) ? publicDir : null }, {
155
+ content: 'apply',
156
+ logger: true,
157
+ })).app;
158
+ if (closing)
159
+ return 0;
160
+ await app.listen({ port: host.port, host: host.host });
161
+ }
162
+ catch (e) {
163
+ io.err(t('host.workerFailed', { problem: e instanceof Error ? e.message : String(e) }));
164
+ process.exit(1);
165
+ }
166
+ process.send?.({ type: 'ready' });
167
+ return 0;
168
+ }
169
+ /**
170
+ * `inlaycms dev`: runs the site from its source in a child process and restarts it whenever a file in the site folder
171
+ * changes, until SIGINT or SIGTERM. The child is this same command with INLAY_DEV_CONFIG set.
172
+ */
173
+ export async function dev(argv, io) {
174
+ const childConfig = process.env.INLAY_DEV_CONFIG;
175
+ if (childConfig && process.send)
176
+ return runSite(childConfig, io);
177
+ let values;
178
+ try {
179
+ ;
180
+ ({ values } = parseArgs({ args: argv, options: { config: { type: 'string' }, port: { type: 'string' } } }));
181
+ }
182
+ catch (e) {
183
+ io.err(e instanceof Error ? e.message : String(e));
184
+ return usage(io);
185
+ }
186
+ const portRaw = values.port ?? (process.env.INLAY_PORT || '3000');
187
+ const port = Number(portRaw);
188
+ if (!/^\d+$/.test(portRaw) || port < 1 || port > 65535) {
189
+ io.err(t('host.devPort', { value: portRaw }));
190
+ return 2;
191
+ }
192
+ let configFile;
193
+ let env;
194
+ let dataDir;
195
+ let baseUrl;
196
+ try {
197
+ configFile = findConfig(io.cwd, values.config);
198
+ if (!existsSync(configFile))
199
+ throw new InlayError('not_found', 'error.configMissing', { path: configFile });
200
+ env = devEnv(process.env, io.cwd, dirname(configFile), port);
201
+ ({ dataDir, baseUrl } = readHostConfig(env));
202
+ }
203
+ catch (e) {
204
+ io.err(e instanceof Error ? e.message : String(e));
205
+ return 2;
206
+ }
207
+ const siteDir = dirname(configFile);
208
+ const dataRel = relative(siteDir, dataDir);
209
+ const dataInside = dataRel !== '' && !dataRel.startsWith('..') && !isAbsolute(dataRel) ? dataRel : null;
210
+ return new Promise((done) => {
211
+ let child = null;
212
+ /** Children told to stop, whose exit isn't news. */
213
+ const told = new WeakSet();
214
+ let announced = false;
215
+ let stopping = false;
216
+ let timer;
217
+ let changed = null;
218
+ let restarting = Promise.resolve();
219
+ const start = () => {
220
+ const proc = fork(INLAY_BIN, ['dev'], {
221
+ env: { ...env, INLAY_DEV_CONFIG: configFile },
222
+ stdio: 'inherit',
223
+ });
224
+ child = proc;
225
+ proc.on('message', (m) => {
226
+ if (m?.type !== 'ready' || announced)
227
+ return;
228
+ announced = true;
229
+ io.out(t('host.devListening', { url: baseUrl }));
230
+ });
231
+ proc.on('exit', (code, signal) => {
232
+ if (child === proc)
233
+ child = null;
234
+ if (!stopping && !told.has(proc)) {
235
+ io.err(t('host.devStopped', { code: code ?? signal ?? '' }));
236
+ }
237
+ });
238
+ };
239
+ const stopChild = async () => {
240
+ const proc = child;
241
+ if (proc === null || proc.exitCode !== null || proc.signalCode !== null)
242
+ return;
243
+ told.add(proc);
244
+ const gone = new Promise((exited) => proc.once('exit', exited));
245
+ proc.kill('SIGTERM');
246
+ const force = setTimeout(() => proc.kill('SIGKILL'), STOP_TIMEOUT_MS);
247
+ await gone;
248
+ clearTimeout(force);
249
+ };
250
+ const restart = () => {
251
+ const file = changed;
252
+ changed = null;
253
+ if (file === null || stopping)
254
+ return;
255
+ restarting = restarting.then(async () => {
256
+ if (stopping)
257
+ return;
258
+ io.out(t('host.devRestart', { file }));
259
+ await stopChild();
260
+ if (!stopping)
261
+ start();
262
+ });
263
+ };
264
+ let watcher = null;
265
+ try {
266
+ watcher = watchSite(siteDir, dataInside, (rel) => {
267
+ changed = rel;
268
+ clearTimeout(timer);
269
+ timer = setTimeout(restart, DEBOUNCE_MS);
270
+ });
271
+ }
272
+ catch (e) {
273
+ io.err(e instanceof Error ? e.message : String(e));
274
+ done(2);
275
+ return;
276
+ }
277
+ const shutDown = async () => {
278
+ if (stopping)
279
+ return;
280
+ stopping = true;
281
+ process.off('SIGINT', shutDown);
282
+ process.off('SIGTERM', shutDown);
283
+ clearTimeout(timer);
284
+ watcher?.close();
285
+ await restarting;
286
+ await stopChild();
287
+ done(0);
288
+ };
289
+ process.on('SIGINT', shutDown);
290
+ process.on('SIGTERM', shutDown);
291
+ start();
292
+ });
293
+ }
@@ -0,0 +1,78 @@
1
+ import { type ReleaseManifest } from '../core/release/manifest.js';
2
+ import type { ReleaseDiff } from './push.js';
3
+ type Route = {
4
+ method: string;
5
+ path: string;
6
+ };
7
+ type FieldChange = 'added' | 'removed' | 'type' | 'required' | 'optional';
8
+ type Slot = {
9
+ type: string;
10
+ slot: string;
11
+ };
12
+ /** What a staged release changes, read from the manifests alone. */
13
+ export interface StructuralDiff {
14
+ /** `changed`: types both releases have whose kind (singleton, collection, global) differs. */
15
+ types: {
16
+ added: string[];
17
+ removed: string[];
18
+ changed: Array<{
19
+ type: string;
20
+ from: string;
21
+ to: string;
22
+ }>;
23
+ };
24
+ /**
25
+ * Slots added to or removed from a type both releases have, and slots both have that can now be switched off
26
+ * (`optional`) or are now always on (`required`).
27
+ */
28
+ slots: {
29
+ added: Slot[];
30
+ removed: Slot[];
31
+ optional: Slot[];
32
+ required: Slot[];
33
+ };
34
+ locales: {
35
+ added: string[];
36
+ removed: string[];
37
+ };
38
+ /**
39
+ * Fields of types (and slots) both releases have, by path: `fields.seo.title`, `slots.hero.headline`, with `[]`
40
+ * for a list's items (`fields.links[].url`).
41
+ */
42
+ fields: Array<{
43
+ type: string;
44
+ path: string;
45
+ change: FieldChange;
46
+ }>;
47
+ routes: {
48
+ added: Route[];
49
+ removed: Route[];
50
+ };
51
+ /** Every secret the staged release needs. */
52
+ secrets: string[];
53
+ /** Every migration function of the staged release, in order. */
54
+ migrations: string[];
55
+ shipped: {
56
+ /** Shipped documents and locales whose content changed while their edition stayed the same, so it won't be applied. */
57
+ stale: Array<{
58
+ type: string;
59
+ key: string;
60
+ locale: string;
61
+ edition: number;
62
+ }>;
63
+ };
64
+ }
65
+ /**
66
+ * What changes in structure when `staged` replaces `current` (null for the first release), from their manifests
67
+ * alone. Fields are compared by presence, required-ness and the shape of their schema; a renamed field is one
68
+ * removed and one added. Types and slots that are added or removed are reported as such, not field by field.
69
+ */
70
+ export declare function structuralDiff(current: ReleaseManifest | null, staged: ReleaseManifest): StructuralDiff;
71
+ /**
72
+ * The release diff as plain-language lines, one per item: what is removed (and the content that will be hidden),
73
+ * added and changed, the gaps and shipped documents the content half found, a warning per shipped document whose
74
+ * content changed without a new edition, then migrations, routes and the secrets the release needs. A release that
75
+ * changes nothing says so.
76
+ */
77
+ export declare function formatDiff(diff: ReleaseDiff): string[];
78
+ export {};