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,346 @@
1
+ import { t } from '../core/messages/index.js';
2
+ import { canonicalJson } from '../core/release/manifest.js';
3
+ const isJson = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
4
+ /** The properties and required names of an object schema, or null when it has no properties. */
5
+ function objectOf(schema) {
6
+ if (!isJson(schema) || !isJson(schema.properties))
7
+ return null;
8
+ const props = {};
9
+ for (const [key, value] of Object.entries(schema.properties))
10
+ if (isJson(value))
11
+ props[key] = value;
12
+ const required = Array.isArray(schema.required) ? schema.required.filter((r) => typeof r === 'string') : [];
13
+ return { props, required: new Set(required) };
14
+ }
15
+ /**
16
+ * Keywords that don't decide what can be stored: annotations and limits, and `x-setting` (only where the admin shows a
17
+ * field). Every other keyword counts, Inlay's own field kinds (such as `richText`) among them.
18
+ */
19
+ const IGNORED = new Set([
20
+ 'title',
21
+ 'description',
22
+ 'default',
23
+ 'examples',
24
+ '$schema',
25
+ '$id',
26
+ '$comment',
27
+ 'deprecated',
28
+ 'readOnly',
29
+ 'writeOnly',
30
+ 'minLength',
31
+ 'maxLength',
32
+ 'pattern',
33
+ 'minimum',
34
+ 'maximum',
35
+ 'exclusiveMinimum',
36
+ 'exclusiveMaximum',
37
+ 'multipleOf',
38
+ 'minItems',
39
+ 'maxItems',
40
+ 'uniqueItems',
41
+ 'minProperties',
42
+ 'maxProperties',
43
+ 'contentMediaType',
44
+ 'contentEncoding',
45
+ 'x-setting',
46
+ ]);
47
+ /** Keywords whose value is a schema, or a list of them, compared by shape in turn. */
48
+ const SCHEMA_LISTS = new Set(['anyOf', 'oneOf', 'allOf', 'prefixItems']);
49
+ const SCHEMAS = new Set([
50
+ 'items',
51
+ 'additionalProperties',
52
+ 'unevaluatedProperties',
53
+ 'unevaluatedItems',
54
+ 'not',
55
+ 'if',
56
+ 'then',
57
+ 'else',
58
+ 'contains',
59
+ 'propertyNames',
60
+ ]);
61
+ /** Keywords whose value maps names to schemas. */
62
+ const SCHEMA_MAPS = new Set(['patternProperties', 'dependentSchemas', '$defs', 'definitions']);
63
+ /** The parts of a property schema that decide what can be stored in it: no titles, help, defaults or limits. */
64
+ function shape(schema) {
65
+ if (!isJson(schema))
66
+ return schema;
67
+ const out = {};
68
+ for (const [key, value] of Object.entries(schema)) {
69
+ if (IGNORED.has(key) || key === 'properties' || key === 'required')
70
+ continue;
71
+ if (key === 'enum' && Array.isArray(value))
72
+ out.enum = [...value].sort();
73
+ else if (SCHEMA_LISTS.has(key) && Array.isArray(value))
74
+ out[key] = value.map(shape);
75
+ else if (SCHEMAS.has(key))
76
+ out[key] = shape(value);
77
+ else if (SCHEMA_MAPS.has(key) && isJson(value))
78
+ out[key] = Object.fromEntries(Object.entries(value).map(([k, v]) => [k, shape(v)]));
79
+ else
80
+ out[key] = value;
81
+ }
82
+ const object = objectOf(schema);
83
+ if (object) {
84
+ out.properties = Object.fromEntries(Object.entries(object.props).map(([k, v]) => [k, shape(v)]));
85
+ out.required = [...object.required].sort();
86
+ }
87
+ return out;
88
+ }
89
+ /** How the walk goes into a property: through an object's properties, through a list's item object, or not at all. */
90
+ function descent(schema, inList) {
91
+ if (objectOf(schema))
92
+ return 'object';
93
+ if (!inList && schema.type === 'array' && objectOf(schema.items))
94
+ return 'list';
95
+ return null;
96
+ }
97
+ /** Standard JSON Schema keywords about structure; any keyword in neither this nor `IGNORED` is one of Inlay's own. */
98
+ const STRUCTURAL = new Set([
99
+ 'type',
100
+ 'properties',
101
+ 'required',
102
+ 'additionalProperties',
103
+ 'patternProperties',
104
+ 'propertyNames',
105
+ 'unevaluatedProperties',
106
+ 'items',
107
+ 'prefixItems',
108
+ 'unevaluatedItems',
109
+ 'contains',
110
+ 'anyOf',
111
+ 'oneOf',
112
+ 'allOf',
113
+ 'not',
114
+ 'if',
115
+ 'then',
116
+ 'else',
117
+ 'enum',
118
+ 'const',
119
+ 'format',
120
+ '$ref',
121
+ 'dependentRequired',
122
+ 'dependentSchemas',
123
+ '$defs',
124
+ 'definitions',
125
+ ]);
126
+ /** Inlay's own keywords on a schema, such as `richText`: they name the kind of field. */
127
+ function kindOf(schema) {
128
+ if (!isJson(schema))
129
+ return {};
130
+ return Object.fromEntries(Object.entries(schema).filter(([key]) => !IGNORED.has(key) && !STRUCTURAL.has(key)));
131
+ }
132
+ /** What a property is compared by: the walk reports the inside of objects and list items field by field. */
133
+ function compared(schema, how) {
134
+ if (how === 'object')
135
+ return canonicalJson({ type: 'object', ...kindOf(schema) });
136
+ if (how === 'list')
137
+ return canonicalJson({ type: 'array', ...kindOf(schema), items: { type: 'object', ...kindOf(schema.items) } });
138
+ return canonicalJson(shape(schema));
139
+ }
140
+ function walkFields(type, prefix, current, staged, inList, out) {
141
+ const a = objectOf(current) ?? { props: {}, required: new Set() };
142
+ const b = objectOf(staged) ?? { props: {}, required: new Set() };
143
+ for (const [name, next] of Object.entries(b.props)) {
144
+ const path = `${prefix}.${name}`;
145
+ const prev = Object.hasOwn(a.props, name) ? a.props[name] : undefined;
146
+ if (prev === undefined) {
147
+ out.push({ type, path, change: 'added' });
148
+ continue;
149
+ }
150
+ const howPrev = descent(prev, inList);
151
+ const howNext = descent(next, inList);
152
+ if (compared(prev, howPrev) !== compared(next, howNext)) {
153
+ out.push({ type, path, change: 'type' });
154
+ continue;
155
+ }
156
+ if (a.required.has(name) !== b.required.has(name)) {
157
+ out.push({ type, path, change: b.required.has(name) ? 'required' : 'optional' });
158
+ }
159
+ if (howNext === 'object')
160
+ walkFields(type, path, prev, next, inList, out);
161
+ if (howNext === 'list')
162
+ walkFields(type, `${path}[]`, prev.items, next.items, true, out);
163
+ }
164
+ for (const name of Object.keys(a.props)) {
165
+ if (!Object.hasOwn(b.props, name))
166
+ out.push({ type, path: `${prefix}.${name}`, change: 'removed' });
167
+ }
168
+ }
169
+ /** The `fields` object schema of a stored-type schema. */
170
+ function fieldsOf(schema) {
171
+ return objectOf(schema)?.props.fields;
172
+ }
173
+ /** The schema of a slot of a stored-type schema. */
174
+ const slotOf = (schema, slot) => objectOf(objectOf(schema)?.props.slots)?.props[slot];
175
+ /** Whether a slot can be switched off: its schema is a choice of variants rather than the data directly. */
176
+ function isOptionalSlot(schema, slot) {
177
+ const slotSchema = slotOf(schema, slot);
178
+ return slotSchema !== undefined && objectOf(slotSchema)?.props.data === undefined && (Array.isArray(slotSchema.oneOf) || Array.isArray(slotSchema.anyOf));
179
+ }
180
+ /** The `data` object schema of a slot: directly on an always-on slot, on the switched-on variant of an optional one. */
181
+ function slotDataOf(schema, slot) {
182
+ const slotSchema = slotOf(schema, slot);
183
+ if (!slotSchema)
184
+ return undefined;
185
+ const direct = objectOf(slotSchema)?.props.data;
186
+ if (direct)
187
+ return direct;
188
+ const variants = Array.isArray(slotSchema.oneOf) ? slotSchema.oneOf : Array.isArray(slotSchema.anyOf) ? slotSchema.anyOf : [];
189
+ const on = variants.find((v) => objectOf(v)?.props.enabled?.const === true) ?? variants.find((v) => objectOf(v)?.props.data);
190
+ return objectOf(on)?.props.data;
191
+ }
192
+ function added(from, to, key = String) {
193
+ const known = new Set(from.map(key));
194
+ return to.filter((t) => !known.has(key(t)));
195
+ }
196
+ const routeKey = (r) => `${r.method} ${r.path}`;
197
+ /**
198
+ * What changes in structure when `staged` replaces `current` (null for the first release), from their manifests
199
+ * alone. Fields are compared by presence, required-ness and the shape of their schema; a renamed field is one
200
+ * removed and one added. Types and slots that are added or removed are reported as such, not field by field.
201
+ */
202
+ export function structuralDiff(current, staged) {
203
+ const curTypes = current?.types ?? {};
204
+ const curNames = Object.keys(curTypes);
205
+ const stagedNames = Object.keys(staged.types);
206
+ const slots = { added: [], removed: [], optional: [], required: [] };
207
+ const changed = [];
208
+ const fields = [];
209
+ for (const type of stagedNames) {
210
+ const prev = Object.hasOwn(curTypes, type) ? curTypes[type] : undefined;
211
+ const next = staged.types[type];
212
+ if (!prev || !next || !current)
213
+ continue;
214
+ if (prev.kind !== next.kind)
215
+ changed.push({ type, from: prev.kind, to: next.kind });
216
+ for (const slot of added(prev.slots, next.slots))
217
+ slots.added.push({ type, slot });
218
+ for (const slot of added(next.slots, prev.slots))
219
+ slots.removed.push({ type, slot });
220
+ const before = current.schema[type];
221
+ const after = staged.schema[type];
222
+ walkFields(type, 'fields', fieldsOf(before), fieldsOf(after), false, fields);
223
+ for (const slot of next.slots) {
224
+ if (!prev.slots.includes(slot))
225
+ continue;
226
+ const was = isOptionalSlot(before, slot);
227
+ const is = isOptionalSlot(after, slot);
228
+ if (was !== is)
229
+ (is ? slots.optional : slots.required).push({ type, slot });
230
+ walkFields(type, `slots.${slot}`, slotDataOf(before, slot), slotDataOf(after, slot), false, fields);
231
+ }
232
+ }
233
+ const shippedKey = (s) => `${s.type}\u0000${s.key}`;
234
+ const curShipped = new Map((current?.shipped ?? []).map((s) => [shippedKey(s), s]));
235
+ const stale = [];
236
+ for (const doc of staged.shipped) {
237
+ const prev = curShipped.get(shippedKey(doc));
238
+ if (!prev || prev.edition !== doc.edition)
239
+ continue;
240
+ const locales = [...Object.keys(doc.locales), ...added(Object.keys(doc.locales), Object.keys(prev.locales))];
241
+ for (const locale of locales) {
242
+ if (doc.locales[locale] !== prev.locales[locale]) {
243
+ stale.push({ type: doc.type, key: doc.key, locale, edition: doc.edition });
244
+ }
245
+ }
246
+ }
247
+ return {
248
+ types: { added: added(curNames, stagedNames), removed: added(stagedNames, curNames), changed },
249
+ slots,
250
+ locales: { added: added(current?.locales ?? [], staged.locales), removed: added(staged.locales, current?.locales ?? []) },
251
+ fields,
252
+ routes: {
253
+ added: added(current?.routes ?? [], staged.routes, routeKey),
254
+ removed: added(staged.routes, current?.routes ?? [], routeKey),
255
+ },
256
+ secrets: [...staged.secrets],
257
+ migrations: [...staged.migrations],
258
+ shipped: { stale },
259
+ };
260
+ }
261
+ /** How a line names a shipped document: a singleton by its type, an entry as `type/key`. */
262
+ const docName = (type, key) => (key === type ? type : `${type}/${key}`);
263
+ /** A field's path as a line shows it: `seo.title` for the type's own fields, `slots.hero.headline` for a slot's. */
264
+ const fieldName = (path) => path.replace(/^fields\./, '');
265
+ const FIELD_LINES = {
266
+ added: 'diff.release.fieldAdded',
267
+ removed: 'diff.release.fieldRemoved',
268
+ type: 'diff.release.fieldType',
269
+ required: 'diff.release.fieldRequired',
270
+ optional: 'diff.release.fieldOptional',
271
+ };
272
+ /**
273
+ * The release diff as plain-language lines, one per item: what is removed (and the content that will be hidden),
274
+ * added and changed, the gaps and shipped documents the content half found, a warning per shipped document whose
275
+ * content changed without a new edition, then migrations, routes and the secrets the release needs. A release that
276
+ * changes nothing says so.
277
+ */
278
+ export function formatDiff(diff) {
279
+ const { structural: s, content } = diff;
280
+ const lines = [];
281
+ const hiddenTypes = new Map((content?.hidden.types ?? []).map((h) => [h.type, h.documents]));
282
+ const hiddenLocales = new Map((content?.hidden.locales ?? []).map((h) => [h.locale, h.documents]));
283
+ for (const type of s.types.removed) {
284
+ const count = hiddenTypes.get(type) ?? 0;
285
+ lines.push(count > 0 ? t('diff.release.typeRemovedCount', { type, count }) : t('diff.release.typeRemoved', { type }));
286
+ }
287
+ for (const { type, slot } of s.slots.removed)
288
+ lines.push(t('diff.release.slotRemoved', { type, slot }));
289
+ for (const locale of s.locales.removed) {
290
+ const count = hiddenLocales.get(locale) ?? 0;
291
+ lines.push(count > 0 ? t('diff.release.localeRemovedCount', { locale, count }) : t('diff.release.localeRemoved', { locale }));
292
+ }
293
+ for (const type of s.types.added)
294
+ lines.push(t('diff.release.typeAdded', { type }));
295
+ for (const change of s.types.changed ?? [])
296
+ lines.push(t('diff.release.typeKind', change));
297
+ for (const { type, slot } of s.slots.added)
298
+ lines.push(t('diff.release.slotAdded', { type, slot }));
299
+ for (const { type, slot } of s.slots.optional ?? [])
300
+ lines.push(t('diff.release.slotOptional', { type, slot }));
301
+ for (const { type, slot } of s.slots.required ?? [])
302
+ lines.push(t('diff.release.slotRequired', { type, slot }));
303
+ for (const locale of s.locales.added)
304
+ lines.push(t('diff.release.localeAdded', { locale }));
305
+ for (const { type, path, change } of s.fields)
306
+ lines.push(t(FIELD_LINES[change], { type, field: fieldName(path) }));
307
+ if (content !== null) {
308
+ for (const gap of content.gaps)
309
+ lines.push(t('diff.release.gaps', { label: gap.label, count: gap.documents }));
310
+ const { shipped } = content;
311
+ for (const i of shipped.created)
312
+ lines.push(t('diff.release.shippedCreated', { doc: docName(i.type, i.key), locale: i.locale }));
313
+ for (const i of shipped.replaced) {
314
+ lines.push(t('diff.release.shippedReplaced', { doc: docName(i.type, i.key), locale: i.locale, edition: i.edition }));
315
+ }
316
+ for (const i of shipped.skipped)
317
+ lines.push(t('diff.release.shippedSkipped', { doc: docName(i.type, i.key), locale: i.locale }));
318
+ for (const { item, target, field } of shipped.deletedRefs) {
319
+ lines.push(t('diff.release.shippedDeletedRef', {
320
+ doc: docName(item.type, item.key),
321
+ locale: item.locale,
322
+ field,
323
+ target: docName(target.type, target.key),
324
+ }));
325
+ }
326
+ for (const w of shipped.warnings)
327
+ lines.push(t('diff.release.warning', { message: w.message }));
328
+ }
329
+ // One line per document, however many of its locales changed.
330
+ const stale = new Map();
331
+ for (const d of s.shipped.stale)
332
+ stale.set(`${d.type}\u0000${d.key}`, { doc: docName(d.type, d.key), edition: d.edition });
333
+ for (const d of stale.values())
334
+ lines.push(t('diff.release.stale', d));
335
+ for (const name of s.migrations)
336
+ lines.push(t('diff.release.migration', { name }));
337
+ for (const r of s.routes.added)
338
+ lines.push(t('diff.release.routeAdded', r));
339
+ for (const r of s.routes.removed)
340
+ lines.push(t('diff.release.routeRemoved', r));
341
+ if (lines.length === 0)
342
+ lines.push(t('diff.release.nothing'));
343
+ if (s.secrets.length > 0)
344
+ lines.push(t('diff.release.secrets', { count: s.secrets.length, names: s.secrets.join(', ') }));
345
+ return lines;
346
+ }
@@ -0,0 +1,41 @@
1
+ import type { HostApi } from '../adapters/site/plugin.js';
2
+ import type { ReleaseManifest } from '../core/release/manifest.js';
3
+ import type { ActivationSummary } from './ipc.js';
4
+ import { type ContentDiff, type PushOptions, type ReleaseDiff } from './push.js';
5
+ import { type ReleaseRow } from './store.js';
6
+ /** What a staged release finds against live content; `content` is null, with `warnings` saying why, when that couldn't be worked out. */
7
+ export interface ContentDiffResult {
8
+ content: ContentDiff | null;
9
+ warnings: string[];
10
+ }
11
+ /**
12
+ * What the admin's Releases screen can ask of the host it runs under. Without them (tests, `inlaycms dev`) the screen
13
+ * still lists, compares, deletes and uploads releases, but can't preview or activate one.
14
+ */
15
+ export interface AdminHostHooks {
16
+ /** Makes a stored release live; rejects with the activation's error, the previous release still live. */
17
+ requestActivation(id: string): Promise<ActivationSummary>;
18
+ /** What a staged release finds against live content, from its preview, within a short deadline. */
19
+ contentDiff(id: string): Promise<ContentDiffResult>;
20
+ /** Checks and stages a release file as a push does. */
21
+ pushFile(file: string, opts: {
22
+ pushedBy: string | null;
23
+ name?: string;
24
+ }): Promise<{
25
+ release: ReleaseRow;
26
+ diff: ReleaseDiff;
27
+ previewUrl: string;
28
+ }>;
29
+ /** The release's preview worker, if one runs, is no longer needed (the release was deleted). */
30
+ stopPreview?(id: string): Promise<void>;
31
+ /** The manifest of what the site runs now, as a push compares with; null when the host serves no site yet. */
32
+ liveManifest?(): Promise<ReleaseManifest | null>;
33
+ }
34
+ /**
35
+ * The admin's hooks for a site served by `inlaycms serve`: activation through `host`, the rest as the push API does it.
36
+ * A staged release's content diff is asked of its preview within `activateDiffTimeoutMs` (`ACTIVATE_DIFF_TIMEOUT_MS`
37
+ * by default) and kept, per release, while the same release stays live; a diff that couldn't be had is asked again.
38
+ */
39
+ export declare function adminHostHooks(opts: PushOptions & {
40
+ host: HostApi;
41
+ }): AdminHostHooks;
@@ -0,0 +1,49 @@
1
+ import { previewLink } from '../adapters/site/preview.js';
2
+ import { InlayError } from '../core/errors.js';
3
+ import { ACTIVATE_DIFF_TIMEOUT_MS, contentDiff, currentManifest, pushRelease, } from './push.js';
4
+ import { currentRelease } from './store.js';
5
+ /**
6
+ * The admin's hooks for a site served by `inlaycms serve`: activation through `host`, the rest as the push API does it.
7
+ * A staged release's content diff is asked of its preview within `activateDiffTimeoutMs` (`ACTIVATE_DIFF_TIMEOUT_MS`
8
+ * by default) and kept, per release, while the same release stays live; a diff that couldn't be had is asked again.
9
+ */
10
+ export function adminHostHooks(opts) {
11
+ const diffs = new Map();
12
+ const live = async () => (await currentRelease(opts.db))?.id ?? null;
13
+ return {
14
+ requestActivation: async (id) => {
15
+ try {
16
+ return await opts.host.requestActivation(id);
17
+ }
18
+ finally {
19
+ diffs.clear();
20
+ }
21
+ },
22
+ contentDiff: async (id) => {
23
+ const now = await live();
24
+ const kept = diffs.get(id);
25
+ if (kept !== undefined && kept.live === now)
26
+ return { content: kept.content, warnings: [] };
27
+ const found = await contentDiff(opts, id, { deadlineMs: opts.activateDiffTimeoutMs ?? ACTIVATE_DIFF_TIMEOUT_MS });
28
+ if (found.content !== null)
29
+ diffs.set(id, { live: now, content: found.content });
30
+ return found;
31
+ },
32
+ pushFile: async (file, push) => {
33
+ if (opts.config.trustedKeys.length === 0)
34
+ throw new InlayError('release', 'admin.releases.noKeys');
35
+ const { release, diff } = await pushRelease(opts, file, { ...push, dryRun: false });
36
+ if (release === null)
37
+ throw new InlayError('release', 'error.releaseInvalid');
38
+ if (diff.content !== null)
39
+ diffs.set(release.id, { live: await live(), content: diff.content });
40
+ const previewUrl = previewLink({ baseUrl: opts.config.baseUrl, secret: opts.config.secret, now: opts.now }, '/', { release: release.id });
41
+ return { release, diff, previewUrl };
42
+ },
43
+ stopPreview: async (id) => {
44
+ diffs.delete(id);
45
+ await opts.host.stopPreview?.(id);
46
+ },
47
+ liveManifest: () => currentManifest(opts),
48
+ };
49
+ }
@@ -0,0 +1,123 @@
1
+ import { InlayError } from '../core/errors.js';
2
+ /** What a failed activation reports: the error code, its plain-language message and, for an `InlayError`, its message ID. */
3
+ export interface IpcError {
4
+ code: string;
5
+ message: string;
6
+ messageId?: string;
7
+ params?: Record<string, string | number>;
8
+ }
9
+ /** What an activation did, as counts, so it can cross from the worker that did it to the one that asked. */
10
+ export interface ActivationSummary {
11
+ shipped: {
12
+ created: number;
13
+ replaced: number;
14
+ skipped: number;
15
+ };
16
+ /** The migration functions run, in order. */
17
+ migrations: string[];
18
+ /** The pre-activation backup, null when none was needed. */
19
+ backup: string | null;
20
+ /** True when the release was already current and nothing was done. */
21
+ noop: boolean;
22
+ /** How many shipped slugs or paths were already taken and resolved. */
23
+ warnings: number;
24
+ }
25
+ /**
26
+ * The Unix socket the preview of `releaseId` listens on: a short name under `<dataDir>/run`, as a socket path can't be
27
+ * much over 100 bytes.
28
+ */
29
+ export declare function previewSocket(dataDir: string, releaseId: string): string;
30
+ /** How long a worker waits for a preview worker to be ready. */
31
+ export declare const PREVIEW_START_TIMEOUT_MS = 60000;
32
+ /** A preview worker that no request used for this long is stopped. */
33
+ export declare const PREVIEW_IDLE_MS: number;
34
+ /** How long an activation may take: the primary stops its worker, and a worker that asked stops waiting, after it. */
35
+ export declare const ACTIVATION_TIMEOUT_MS: number;
36
+ /** Messages a worker sends to the primary. */
37
+ export type WorkerMessage =
38
+ /** Listening; `releaseId` is the release it serves, null for the "no site" page. An activation worker adds what it did. */
39
+ {
40
+ type: 'ready';
41
+ releaseId: string | null;
42
+ activation?: ActivationSummary;
43
+ }
44
+ /** Asks the primary to make a stored release live (push, the admin). Only the current worker may ask. */
45
+ | {
46
+ type: 'activate';
47
+ requestId: string;
48
+ releaseId: string;
49
+ }
50
+ /** An activation worker committed the activation: the release is current, whether or not it then starts serving. */
51
+ | {
52
+ type: 'activated';
53
+ activation: ActivationSummary;
54
+ }
55
+ /** An activation worker that couldn't start, activate or listen. */
56
+ | {
57
+ type: 'failed';
58
+ error: IpcError;
59
+ }
60
+ /**
61
+ * Asks the primary for the preview worker of a staged release, started if it isn't running. Only the current worker
62
+ * may ask. `dir`: a push's scratch folder (`<releases>/.push-*`) holding the release, for a dry run that keeps nothing.
63
+ */
64
+ | {
65
+ type: 'preview-start';
66
+ requestId: string;
67
+ releaseId: string;
68
+ dir?: string;
69
+ }
70
+ /** The release's preview worker is no longer needed. */
71
+ | {
72
+ type: 'preview-stop';
73
+ releaseId: string;
74
+ }
75
+ /** The release's preview is still in use (sent at most once a minute), so its worker isn't stopped as idle. */
76
+ | {
77
+ type: 'preview-touch';
78
+ releaseId: string;
79
+ }
80
+ /** A preview worker is listening on the Unix socket `socket`. A preview worker that can't start sends `failed`. */
81
+ | {
82
+ type: 'preview-ready';
83
+ releaseId: string;
84
+ socket: string;
85
+ };
86
+ /** Messages the primary sends to a worker. */
87
+ export type PrimaryMessage =
88
+ /** Stop accepting requests, finish the ones in flight and exit. */
89
+ {
90
+ type: 'shutdown';
91
+ }
92
+ /** The answer to a worker's `activate` request. */
93
+ | {
94
+ type: 'activation';
95
+ requestId: string;
96
+ ok: true;
97
+ activation: ActivationSummary;
98
+ } | {
99
+ type: 'activation';
100
+ requestId: string;
101
+ ok: false;
102
+ error: IpcError;
103
+ }
104
+ /** The answer to a worker's `preview-start` request: the socket the preview worker listens on. */
105
+ | {
106
+ type: 'preview';
107
+ requestId: string;
108
+ ok: true;
109
+ socket: string;
110
+ } | {
111
+ type: 'preview';
112
+ requestId: string;
113
+ ok: false;
114
+ error: IpcError;
115
+ };
116
+ export declare function isWorkerMessage(m: unknown): m is WorkerMessage;
117
+ export declare function isPrimaryMessage(m: unknown): m is PrimaryMessage;
118
+ /**
119
+ * The error an activation reported over IPC, as an `InlayError` with its code and its own message: an `InlayError`
120
+ * comes back as it was thrown, anything else as `error.releaseActivationFailed` with its message.
121
+ */
122
+ export declare function activationError(error: IpcError): InlayError;
123
+ export declare function toIpcError(e: unknown): IpcError;
@@ -0,0 +1,61 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { join } from 'node:path';
3
+ import { InlayError } from '../core/errors.js';
4
+ import { en } from '../core/messages/en.js';
5
+ /**
6
+ * The Unix socket the preview of `releaseId` listens on: a short name under `<dataDir>/run`, as a socket path can't be
7
+ * much over 100 bytes.
8
+ */
9
+ export function previewSocket(dataDir, releaseId) {
10
+ return join(dataDir, 'run', `p-${createHash('sha256').update(releaseId).digest('hex').slice(0, 12)}.sock`);
11
+ }
12
+ /** How long a worker waits for a preview worker to be ready. */
13
+ export const PREVIEW_START_TIMEOUT_MS = 60_000;
14
+ /** A preview worker that no request used for this long is stopped. */
15
+ export const PREVIEW_IDLE_MS = 10 * 60_000;
16
+ /** How long an activation may take: the primary stops its worker, and a worker that asked stops waiting, after it. */
17
+ export const ACTIVATION_TIMEOUT_MS = 10 * 60_000;
18
+ const isObject = (m) => typeof m === 'object' && m !== null && 'type' in m;
19
+ const WORKER_TYPES = new Set(['ready', 'activate', 'activated', 'failed', 'preview-start', 'preview-stop', 'preview-touch', 'preview-ready']);
20
+ const PRIMARY_TYPES = new Set(['shutdown', 'activation', 'preview']);
21
+ export function isWorkerMessage(m) {
22
+ return isObject(m) && WORKER_TYPES.has(m.type);
23
+ }
24
+ export function isPrimaryMessage(m) {
25
+ return isObject(m) && PRIMARY_TYPES.has(m.type);
26
+ }
27
+ const CODES = {
28
+ not_found: true,
29
+ forbidden: true,
30
+ conflict: true,
31
+ validation: true,
32
+ in_use: true,
33
+ invalid_operation: true,
34
+ definition: true,
35
+ shipped_content: true,
36
+ check_failed: true,
37
+ config: true,
38
+ release: true,
39
+ read_only: true,
40
+ };
41
+ /**
42
+ * The error an activation reported over IPC, as an `InlayError` with its code and its own message: an `InlayError`
43
+ * comes back as it was thrown, anything else as `error.releaseActivationFailed` with its message.
44
+ */
45
+ export function activationError(error) {
46
+ const code = Object.hasOwn(CODES, error.code) ? error.code : 'release';
47
+ if (error.messageId !== undefined && Object.hasOwn(en, error.messageId)) {
48
+ try {
49
+ return new InlayError(code, error.messageId, error.params ?? {});
50
+ }
51
+ catch {
52
+ // Params that don't fit the message: fall back to its text.
53
+ }
54
+ }
55
+ return new InlayError(code, 'error.releaseActivationFailed', { problem: error.message });
56
+ }
57
+ export function toIpcError(e) {
58
+ if (e instanceof InlayError)
59
+ return { code: e.code, message: e.message, messageId: e.messageId, params: e.params };
60
+ return { code: 'release', message: e instanceof Error ? e.message : String(e) };
61
+ }
@@ -0,0 +1,24 @@
1
+ import type { FastifyInstance } from 'fastify';
2
+ import type { HostApi } from '../adapters/site/plugin.js';
3
+ /** Names the release a request was forwarded for, so the preview can tell it was meant for it. */
4
+ export declare const PREVIEW_RELEASE_HEADER = "x-inlay-preview-release";
5
+ /** How often, at most, a preview in use is reported to the primary so it isn't stopped as idle. */
6
+ export declare const PREVIEW_TOUCH_MS = 60000;
7
+ export interface PreviewProxyOptions {
8
+ host: HostApi;
9
+ secret: string;
10
+ baseUrl: string;
11
+ now: () => Date;
12
+ /** Whether the release is still staged; one that isn't (deleted, or made live since) isn't previewed. */
13
+ isStaged: (releaseId: string) => Promise<boolean>;
14
+ }
15
+ /**
16
+ * Sends every request whose preview cookie names a staged release to that release's preview worker, over its Unix
17
+ * socket (spec §7, §8.4), from an `onRequest` hook of the current site: the request as it came (minus `Host`, plus
18
+ * `x-inlay-preview-release`), the answer as it comes back with `Cache-Control: no-store` and `Vary: Cookie` in place
19
+ * of the preview's caching headers. The host starts the preview on the first request and is
20
+ * told it is still in use at most once a minute. A cookie naming a release that isn't staged any more, or whose
21
+ * preview can't start, is cleared and the live site answers; a preview that doesn't answer gives a plain 502 page.
22
+ * `/_inlay`, the admin, `/api/auth`, `/mcp` and `/.well-known` are always answered here.
23
+ */
24
+ export declare function registerPreviewProxy(app: FastifyInstance, opts: PreviewProxyOptions): void;