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,7 @@
1
+ import { en } from './en.js';
2
+ export type MessageId = keyof typeof en;
3
+ /**
4
+ * The message `id` with `{name}` replaced by `params.name`. `{name|one|other}` gives `one` when the param is 1
5
+ * and `other` otherwise, for words that follow a count ("{count} {count|item|items}").
6
+ */
7
+ export declare function t(id: MessageId, params?: Record<string, string | number>): string;
@@ -0,0 +1,14 @@
1
+ import { en } from './en.js';
2
+ /**
3
+ * The message `id` with `{name}` replaced by `params.name`. `{name|one|other}` gives `one` when the param is 1
4
+ * and `other` otherwise, for words that follow a count ("{count} {count|item|items}").
5
+ */
6
+ export function t(id, params = {}) {
7
+ return en[id].replace(/\{(\w+)(?:\|([^|{}]*)\|([^|{}]*))?\}/g, (_, name, one, other) => {
8
+ if (!(name in params))
9
+ throw new Error(`Message "${id}" is missing param "${name}"`);
10
+ if (one !== undefined && other !== undefined)
11
+ return Number(params[name]) === 1 ? one : other;
12
+ return String(params[name]);
13
+ });
14
+ }
@@ -0,0 +1,16 @@
1
+ export declare const PREVIEW_TTL_MS: number;
2
+ /**
3
+ * A preview token valid for `PREVIEW_TTL_MS` from `now`: `v2.<expiry ms base36>.<release id or ->.<HMAC-SHA256
4
+ * base64url>`. With `release`, it previews that staged release; without, the live site's drafts.
5
+ */
6
+ export declare function createPreviewToken(secret: string, now: Date, opts?: {
7
+ release?: string;
8
+ }): string;
9
+ /**
10
+ * The token's expiry and the release it previews (null for the live site's drafts, and for a `v1` token), or `null`
11
+ * if it's malformed, wasn't signed with `secret`, or has expired.
12
+ */
13
+ export declare function verifyPreviewToken(secret: string, token: string, now: Date): {
14
+ expiresAt: Date;
15
+ release: string | null;
16
+ } | null;
@@ -0,0 +1,42 @@
1
+ import { createHmac, timingSafeEqual } from 'node:crypto';
2
+ import { InlayError } from './errors.js';
3
+ export const PREVIEW_TTL_MS = 24 * 60 * 60 * 1000;
4
+ const V1 = /^v1\.([0-9a-z]{1,11})\.([A-Za-z0-9_-]{43})$/;
5
+ const V2 = /^v2\.([0-9a-z]{1,11})\.(-|[A-Za-z0-9_][A-Za-z0-9_-]{0,63})\.([A-Za-z0-9_-]{43})$/;
6
+ const RELEASE_ID = /^[A-Za-z0-9_][A-Za-z0-9_-]{0,63}$/;
7
+ const sign = (secret, payload) => createHmac('sha256', secret).update(payload).digest('base64url');
8
+ /**
9
+ * A preview token valid for `PREVIEW_TTL_MS` from `now`: `v2.<expiry ms base36>.<release id or ->.<HMAC-SHA256
10
+ * base64url>`. With `release`, it previews that staged release; without, the live site's drafts.
11
+ */
12
+ export function createPreviewToken(secret, now, opts = {}) {
13
+ const { release } = opts;
14
+ if (release !== undefined && !RELEASE_ID.test(release))
15
+ throw new InlayError('not_found', 'error.releaseUnknown', { id: release });
16
+ const payload = `v2.${(now.getTime() + PREVIEW_TTL_MS).toString(36)}.${release ?? '-'}`;
17
+ return `${payload}.${sign(secret, payload)}`;
18
+ }
19
+ /**
20
+ * The token's expiry and the release it previews (null for the live site's drafts, and for a `v1` token), or `null`
21
+ * if it's malformed, wasn't signed with `secret`, or has expired.
22
+ */
23
+ export function verifyPreviewToken(secret, token, now) {
24
+ const v2 = V2.exec(token);
25
+ const v1 = v2 ? null : V1.exec(token);
26
+ const parts = v2
27
+ ? { payload: `v2.${v2[1]}.${v2[2]}`, expiry: v2[1], release: v2[2] === '-' ? null : v2[2], signature: v2[3] }
28
+ : v1
29
+ ? { payload: `v1.${v1[1]}`, expiry: v1[1], release: null, signature: v1[2] }
30
+ : null;
31
+ if (parts === null)
32
+ return null;
33
+ const { payload, expiry, release, signature } = parts;
34
+ const given = Buffer.from(signature);
35
+ const expected = Buffer.from(sign(secret, payload));
36
+ if (given.length !== expected.length || !timingSafeEqual(given, expected))
37
+ return null;
38
+ const expiresAt = parseInt(expiry, 36);
39
+ if (!Number.isSafeInteger(expiresAt) || expiresAt <= now.getTime())
40
+ return null;
41
+ return { expiresAt: new Date(expiresAt), release };
42
+ }
@@ -0,0 +1,68 @@
1
+ import type { Registry } from '../registry/registry.js';
2
+ export type RuleTarget = {
3
+ path: string;
4
+ } | {
5
+ document: string;
6
+ };
7
+ /** The `:name` params of a path, in order. A param is a whole segment. */
8
+ export declare function paramNames(path: string): string[];
9
+ export declare function isPattern(path: string): boolean;
10
+ /** A regexp matching a pattern `from` against a decoded path; its groups are the params, in order. */
11
+ export declare function patternRegExp(from: string): RegExp;
12
+ /** A path target with the params a rule matched filled in. */
13
+ export declare function fillParams(to: string, params: Record<string, string>): string;
14
+ export interface RuleCandidate<R> {
15
+ rule: R;
16
+ params: Record<string, string>;
17
+ /** Matched the unprefixed rest of a path outside the default locale, so its target gets the locale prefix. */
18
+ viaRest: boolean;
19
+ }
20
+ /** A pattern rule ready for matching; `rank` is its place in the order pattern rules are tried. */
21
+ interface PatternEntry<R> {
22
+ rule: R;
23
+ names: string[];
24
+ re: RegExp;
25
+ rank: number;
26
+ }
27
+ /**
28
+ * Rules ready for matching: exact rules by `from`, and pattern rules bucketed by segment count and
29
+ * their first literal segment (`n` alone when every segment is a param), each bucket in the order
30
+ * they are tried.
31
+ */
32
+ export interface RuleIndex<R> {
33
+ exact: ReadonlyMap<string, R>;
34
+ patterns: ReadonlyMap<string, ReadonlyArray<PatternEntry<R>>>;
35
+ }
36
+ /** Indexes `rules`, given in id order: pattern rules are tried fewest params first, then by id. */
37
+ export declare function ruleIndex<R extends {
38
+ from: string;
39
+ }>(rules: Iterable<R>): RuleIndex<R>;
40
+ /**
41
+ * The rules that could answer a request for `path`, in the order they are tried: an exact rule on
42
+ * `path`, then (outside the default locale) an exact rule on its unprefixed rest, then pattern rules
43
+ * on `path` and then the rest.
44
+ */
45
+ export declare function ruleCandidates<R>(registry: Registry, index: RuleIndex<R>, path: string): Generator<RuleCandidate<R>>;
46
+ /** Whether a path's first segment is a site locale code, so it already names its locale. */
47
+ export declare function hasLocalePrefix(registry: Registry, path: string): boolean;
48
+ /** `path` in `locale`, unless it already names a locale. */
49
+ export declare function localize(registry: Registry, locale: string, path: string): string;
50
+ /**
51
+ * Where a rule's path target sends a request in `locale`, given the candidate it matched as. A
52
+ * target that already names a locale is never given another prefix.
53
+ */
54
+ export declare function pathTarget(registry: Registry, locale: string, to: string, candidate: RuleCandidate<unknown>): string;
55
+ /**
56
+ * Where each of `rules` is stored: an exact path target is followed through exact rules, taking a
57
+ * hop `T → U` of a rule from `F` only when `canFollow(T, U, F)`. It stops at a document, a pattern
58
+ * path, a path with no exact rule, or before coming back to a path already passed (loops are left
59
+ * for the caller to find). Chains shared between rules whose `from` has the same `scope` are
60
+ * followed once, so `canFollow` may depend on `F` only through its scope.
61
+ */
62
+ export declare function collapseTargets(exact: ReadonlyMap<string, {
63
+ to: RuleTarget;
64
+ }>, rules: ReadonlyArray<{
65
+ from: string;
66
+ to: RuleTarget;
67
+ }>, canFollow: (path: string, next: RuleTarget, from: string) => boolean | Promise<boolean>, scope?: (from: string) => string): Promise<RuleTarget[]>;
68
+ export {};
@@ -0,0 +1,153 @@
1
+ import { splitLocale, withLocale } from '../site/paths.js';
2
+ const PARAM = /^:([A-Za-z_][A-Za-z0-9_]*)$/;
3
+ /** The `:name` params of a path, in order. A param is a whole segment. */
4
+ export function paramNames(path) {
5
+ return path.split('/').flatMap((s) => {
6
+ const name = PARAM.exec(s)?.[1];
7
+ return name === undefined ? [] : [name];
8
+ });
9
+ }
10
+ export function isPattern(path) {
11
+ return paramNames(path).length > 0;
12
+ }
13
+ /** A regexp matching a pattern `from` against a decoded path; its groups are the params, in order. */
14
+ export function patternRegExp(from) {
15
+ const parts = from.split('/').map((s) => PARAM.test(s) ? '([^/]+)' : s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
16
+ return new RegExp(`^${parts.join('/')}$`);
17
+ }
18
+ /** A path target with the params a rule matched filled in. */
19
+ export function fillParams(to, params) {
20
+ return to
21
+ .split('/')
22
+ .map((s) => (s.startsWith(':') ? (params[s.slice(1)] ?? s) : s))
23
+ .join('/');
24
+ }
25
+ /** The bucket a pattern `from` goes in: its segment count and first literal segment, with its place. */
26
+ function patternKey(from) {
27
+ const parts = from.split('/');
28
+ const at = parts.findIndex((s, i) => i > 0 && !PARAM.test(s));
29
+ return at === -1 ? `${parts.length}` : `${parts.length} ${at} ${parts[at]}`;
30
+ }
31
+ /** The buckets a path is looked up in: one per segment, and the all-param one. */
32
+ function pathKeys(path) {
33
+ const parts = path.split('/');
34
+ return [`${parts.length}`, ...parts.slice(1).map((s, i) => `${parts.length} ${i + 1} ${s}`)];
35
+ }
36
+ /** Indexes `rules`, given in id order: pattern rules are tried fewest params first, then by id. */
37
+ export function ruleIndex(rules) {
38
+ const exact = new Map();
39
+ const sorted = [];
40
+ for (const rule of rules) {
41
+ const names = paramNames(rule.from);
42
+ if (names.length === 0)
43
+ exact.set(rule.from, rule);
44
+ else
45
+ sorted.push({ rule, names, re: patternRegExp(rule.from) });
46
+ }
47
+ sorted.sort((a, b) => a.names.length - b.names.length);
48
+ const patterns = new Map();
49
+ sorted.forEach((p, rank) => {
50
+ const key = patternKey(p.rule.from);
51
+ const bucket = patterns.get(key) ?? [];
52
+ bucket.push({ ...p, rank });
53
+ patterns.set(key, bucket);
54
+ });
55
+ return { exact, patterns };
56
+ }
57
+ /** The pattern rules that could match `path`, in the order they are tried. */
58
+ function* patternsFor(index, path) {
59
+ const buckets = pathKeys(path).flatMap((k) => {
60
+ const b = index.patterns.get(k);
61
+ return b ? [b] : [];
62
+ });
63
+ if (buckets.length === 1) {
64
+ yield* buckets[0];
65
+ return;
66
+ }
67
+ const at = buckets.map(() => 0);
68
+ for (;;) {
69
+ let best = -1;
70
+ let rank = Infinity;
71
+ buckets.forEach((b, i) => {
72
+ const entry = b[at[i]];
73
+ if (entry && entry.rank < rank) {
74
+ best = i;
75
+ rank = entry.rank;
76
+ }
77
+ });
78
+ if (best === -1)
79
+ return;
80
+ yield buckets[best][at[best]++];
81
+ }
82
+ }
83
+ /**
84
+ * The rules that could answer a request for `path`, in the order they are tried: an exact rule on
85
+ * `path`, then (outside the default locale) an exact rule on its unprefixed rest, then pattern rules
86
+ * on `path` and then the rest.
87
+ */
88
+ export function* ruleCandidates(registry, index, path) {
89
+ const { locale, rest } = splitLocale(registry, path);
90
+ const tries = locale === registry.defaultLocale ? [[path, false]] : [[path, false], [rest, true]];
91
+ for (const [p, viaRest] of tries) {
92
+ const rule = index.exact.get(p);
93
+ if (rule)
94
+ yield { rule, params: {}, viaRest };
95
+ }
96
+ for (const [p, viaRest] of tries) {
97
+ for (const { rule, names, re } of patternsFor(index, p)) {
98
+ const m = re.exec(p);
99
+ if (m)
100
+ yield { rule, params: Object.fromEntries(names.map((n, i) => [n, m[i + 1] ?? ''])), viaRest };
101
+ }
102
+ }
103
+ }
104
+ /** Whether a path's first segment is a site locale code, so it already names its locale. */
105
+ export function hasLocalePrefix(registry, path) {
106
+ return registry.locales.includes(path.split('/')[1] ?? '');
107
+ }
108
+ /** `path` in `locale`, unless it already names a locale. */
109
+ export function localize(registry, locale, path) {
110
+ return hasLocalePrefix(registry, path) ? path : withLocale(registry, locale, path);
111
+ }
112
+ /**
113
+ * Where a rule's path target sends a request in `locale`, given the candidate it matched as. A
114
+ * target that already names a locale is never given another prefix.
115
+ */
116
+ export function pathTarget(registry, locale, to, candidate) {
117
+ const target = fillParams(to, candidate.params);
118
+ return candidate.viaRest ? localize(registry, locale, target) : target;
119
+ }
120
+ /**
121
+ * Where each of `rules` is stored: an exact path target is followed through exact rules, taking a
122
+ * hop `T → U` of a rule from `F` only when `canFollow(T, U, F)`. It stops at a document, a pattern
123
+ * path, a path with no exact rule, or before coming back to a path already passed (loops are left
124
+ * for the caller to find). Chains shared between rules whose `from` has the same `scope` are
125
+ * followed once, so `canFollow` may depend on `F` only through its scope.
126
+ */
127
+ export async function collapseTargets(exact, rules, canFollow, scope = () => '') {
128
+ const ends = new Map();
129
+ const out = [];
130
+ for (const rule of rules) {
131
+ const key = (path) => `${scope(rule.from)}\u0000${path}`;
132
+ const seen = new Set([rule.from]);
133
+ const passed = [];
134
+ let end = rule.to;
135
+ while ('path' in end && !isPattern(end.path)) {
136
+ const known = ends.get(key(end.path));
137
+ if (known) {
138
+ end = known;
139
+ break;
140
+ }
141
+ const next = exact.get(end.path)?.to;
142
+ if (!next || ('path' in next && seen.has(next.path)) || !(await canFollow(end.path, next, rule.from)))
143
+ break;
144
+ seen.add(end.path);
145
+ passed.push(end.path);
146
+ end = next;
147
+ }
148
+ for (const p of passed)
149
+ ends.set(key(p), end);
150
+ out.push(end);
151
+ }
152
+ return out;
153
+ }
@@ -0,0 +1,15 @@
1
+ export interface CsvResult {
2
+ rows: Array<{
3
+ line: number;
4
+ cells: string[];
5
+ }>;
6
+ problems: Array<{
7
+ line: number;
8
+ message: string;
9
+ }>;
10
+ }
11
+ /**
12
+ * Parses RFC 4180 CSV: quoted cells, doubled quotes, CRLF or LF line endings.
13
+ * Strips a BOM and skips blank lines. Each row carries the line it starts on.
14
+ */
15
+ export declare function parseCsv(text: string): CsvResult;
@@ -0,0 +1,68 @@
1
+ import { t } from '../messages/index.js';
2
+ /**
3
+ * Parses RFC 4180 CSV: quoted cells, doubled quotes, CRLF or LF line endings.
4
+ * Strips a BOM and skips blank lines. Each row carries the line it starts on.
5
+ */
6
+ export function parseCsv(text) {
7
+ const src = text.startsWith('') ? text.slice(1) : text;
8
+ const rows = [];
9
+ const problems = [];
10
+ let line = 1;
11
+ let i = 0;
12
+ while (i < src.length) {
13
+ const start = line;
14
+ const cells = [];
15
+ let cell = '';
16
+ let fresh = true;
17
+ let quoted = false;
18
+ while (i < src.length) {
19
+ const c = src[i];
20
+ if (quoted) {
21
+ if (c === '"' && src[i + 1] === '"') {
22
+ cell += '"';
23
+ i += 2;
24
+ }
25
+ else if (c === '"') {
26
+ quoted = false;
27
+ i++;
28
+ }
29
+ else {
30
+ if (c === '\n')
31
+ line++;
32
+ cell += c;
33
+ i++;
34
+ }
35
+ continue;
36
+ }
37
+ if (c === '"' && fresh) {
38
+ quoted = true;
39
+ fresh = false;
40
+ i++;
41
+ }
42
+ else if (c === ',') {
43
+ cells.push(cell);
44
+ cell = '';
45
+ fresh = true;
46
+ i++;
47
+ }
48
+ else if (c === '\n' || c === '\r') {
49
+ i += c === '\r' && src[i + 1] === '\n' ? 2 : 1;
50
+ line++;
51
+ break;
52
+ }
53
+ else {
54
+ cell += c;
55
+ fresh = false;
56
+ i++;
57
+ }
58
+ }
59
+ if (quoted) {
60
+ problems.push({ line: start, message: t('csv.unterminatedQuote', { line: start }) });
61
+ break;
62
+ }
63
+ cells.push(cell);
64
+ if (cells.length > 1 || cells[0].trim() !== '')
65
+ rows.push({ line: start, cells });
66
+ }
67
+ return { rows, problems };
68
+ }
@@ -0,0 +1,58 @@
1
+ import type { Selectable } from 'kysely';
2
+ import type { DocumentsTable, RedirectsTable } from '../db/schema.js';
3
+ import type { Registry } from '../registry/registry.js';
4
+ import type { ContentIssue, CoreDeps, Ctx, LiveState, Redirect, RedirectInput, RouteMatch } from '../types.js';
5
+ import { type RuleTarget } from './collapse.js';
6
+ type Row = Selectable<RedirectsTable>;
7
+ export declare function rowTarget(row: Pick<Row, 'to_path' | 'to_group_id'>): RuleTarget;
8
+ export declare function listRedirects(deps: CoreDeps): Promise<Redirect[]>;
9
+ /** A clean decoded site path without a query or fragment, or `null`. */
10
+ export declare function cleanPath(raw: string): string | null;
11
+ /**
12
+ * The stored form of a redirect's `from` (a full http(s) URL loses its origin), or `null` if it can't be
13
+ * used. A default-locale prefix can't be used: such a request is sent to the unprefixed path first.
14
+ */
15
+ export declare function redirectFrom(registry: Registry, raw: string): string | null;
16
+ /**
17
+ * What a path resolves to without redirect rules, memoized for the duration of one write. A path is
18
+ * a stop when this isn't `not_found`: a redirect rule never fires there.
19
+ */
20
+ export type Lookup = (path: string, state?: LiveState) => Promise<RouteMatch['kind']>;
21
+ export interface CheckedRule {
22
+ from: string;
23
+ to: RuleTarget;
24
+ status: 301 | 302;
25
+ note: string | null;
26
+ }
27
+ /**
28
+ * Checks a rule on its own (not against other rules): the shape of `from`
29
+ * and `to` (neither may start with the default locale, which a request is
30
+ * sent away from first), the status, and that an exact `from` isn't a
31
+ * published page.
32
+ */
33
+ export declare function checkRedirect(deps: CoreDeps, input: RedirectInput, look?: Lookup): Promise<{
34
+ rule: CheckedRule | null;
35
+ issues: ContentIssue[];
36
+ }>;
37
+ export declare function createRedirect(deps: CoreDeps, input: RedirectInput, ctx: Ctx): Promise<Redirect>;
38
+ export declare function deleteRedirect(deps: CoreDeps, id: number, ctx: Ctx): Promise<void>;
39
+ /**
40
+ * Called by `publish` inside its transaction, before a document's published
41
+ * slug and path move to its head. When its live URL changes, the old URL
42
+ * gets an automatic 301 to the document, rules that pointed at the old URL
43
+ * follow it to the new one, and an automatic rule from the new URL is dropped.
44
+ * A rule that fires in the document's locale follows the document itself;
45
+ * one that fires elsewhere keeps a path target, so its visitors stay on the
46
+ * same translation rather than switching to the request's locale.
47
+ */
48
+ export declare function autoRedirect(deps: CoreDeps, ctx: Ctx, doc: Pick<Selectable<DocumentsTable>, 'group_id' | 'type' | 'locale' | 'published_rev' | 'published_slug' | 'published_path' | 'head_slug' | 'head_path'>): Promise<void>;
49
+ /**
50
+ * Imports `from,to[,status][,note]` rows (with an optional header row). All or
51
+ * nothing: any problem throws `error.redirectImportFailed` with every problem
52
+ * by line. A `from` that already has a rule updates that rule.
53
+ */
54
+ export declare function importRedirects(deps: CoreDeps, csv: string, ctx: Ctx): Promise<{
55
+ created: number;
56
+ updated: number;
57
+ }>;
58
+ export {};