@cossackframework/cms 0.0.0 → 0.9.2

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 (427) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +145 -2
  3. package/agent-docs.json +259 -0
  4. package/app/README.md +78 -0
  5. package/app/cossack-recipe.json +43 -0
  6. package/app/src/auth-bot-check.ts +32 -0
  7. package/app/src/auth-bot-token.ts +11 -0
  8. package/app/src/auth-input.ts +35 -0
  9. package/app/src/auth-options.ts +21 -0
  10. package/app/src/auth-providers.ts +16 -0
  11. package/app/src/auth.ts +1082 -0
  12. package/app/src/brand.ts +68 -0
  13. package/app/src/cms/ai.ts +54 -0
  14. package/app/src/cms/analytics.ts +33 -0
  15. package/app/src/cms/block-errors.ts +55 -0
  16. package/app/src/cms/block-inserter.ts +111 -0
  17. package/app/src/cms/block-panel.ts +68 -0
  18. package/app/src/cms/block-rows.ts +44 -0
  19. package/app/src/cms/block-tree.ts +585 -0
  20. package/app/src/cms/blocks.css +709 -0
  21. package/app/src/cms/builder.ts +126 -0
  22. package/app/src/cms/cache.ts +44 -0
  23. package/app/src/cms/carousel.client.ts +52 -0
  24. package/app/src/cms/collab/presence.ts +69 -0
  25. package/app/src/cms/collab/rich-text-collab.client.ts +197 -0
  26. package/app/src/cms/collab/rich-text-notes.client.ts +138 -0
  27. package/app/src/cms/collab/room.ts +881 -0
  28. package/app/src/cms/compare.client.ts +47 -0
  29. package/app/src/cms/condition-control.ts +109 -0
  30. package/app/src/cms/content-api.ts +143 -0
  31. package/app/src/cms/content.ts +524 -0
  32. package/app/src/cms/countdown.client.ts +37 -0
  33. package/app/src/cms/editor-layout-editor.ts +260 -0
  34. package/app/src/cms/editor-layout-view.ts +37 -0
  35. package/app/src/cms/editor.ts +381 -0
  36. package/app/src/cms/entry.ts +26 -0
  37. package/app/src/cms/feeds.ts +145 -0
  38. package/app/src/cms/field-controls.ts +222 -0
  39. package/app/src/cms/field-group-editor.ts +105 -0
  40. package/app/src/cms/field-group-view.ts +211 -0
  41. package/app/src/cms/form-view.ts +203 -0
  42. package/app/src/cms/form.client.ts +203 -0
  43. package/app/src/cms/guards.ts +27 -0
  44. package/app/src/cms/handoff.ts +202 -0
  45. package/app/src/cms/headings.ts +51 -0
  46. package/app/src/cms/icons.ts +80 -0
  47. package/app/src/cms/import.client.ts +16 -0
  48. package/app/src/cms/index.ts +191 -0
  49. package/app/src/cms/lightbox.client.ts +114 -0
  50. package/app/src/cms/machine.ts +118 -0
  51. package/app/src/cms/maintenance.ts +97 -0
  52. package/app/src/cms/manage.ts +1236 -0
  53. package/app/src/cms/mcp-tools.ts +388 -0
  54. package/app/src/cms/mcp.ts +242 -0
  55. package/app/src/cms/media-chooser.ts +123 -0
  56. package/app/src/cms/media-usage.ts +57 -0
  57. package/app/src/cms/middleware.ts +199 -0
  58. package/app/src/cms/middlewares.ts +13 -0
  59. package/app/src/cms/network-ui.ts +36 -0
  60. package/app/src/cms/network-view.ts +38 -0
  61. package/app/src/cms/notes-announce.ts +65 -0
  62. package/app/src/cms/notes-rail.ts +207 -0
  63. package/app/src/cms/notification-rules.ts +66 -0
  64. package/app/src/cms/recovery.ts +82 -0
  65. package/app/src/cms/replace.ts +63 -0
  66. package/app/src/cms/reserved-paths.ts +19 -0
  67. package/app/src/cms/rich-text-field.ts +325 -0
  68. package/app/src/cms/rich-text-schema.ts +91 -0
  69. package/app/src/cms/rich-text.client.ts +255 -0
  70. package/app/src/cms/search.client.ts +116 -0
  71. package/app/src/cms/seo-head.ts +78 -0
  72. package/app/src/cms/seo.ts +241 -0
  73. package/app/src/cms/settings-draft.ts +218 -0
  74. package/app/src/cms/settings-file.ts +127 -0
  75. package/app/src/cms/settings-form.ts +180 -0
  76. package/app/src/cms/settings-languages.ts +125 -0
  77. package/app/src/cms/settings-nav.ts +102 -0
  78. package/app/src/cms/settings-network.ts +151 -0
  79. package/app/src/cms/settings-permalinks.ts +114 -0
  80. package/app/src/cms/settings-scroll.ts +10 -0
  81. package/app/src/cms/settings-search.ts +77 -0
  82. package/app/src/cms/settings-section.ts +38 -0
  83. package/app/src/cms/share.client.ts +27 -0
  84. package/app/src/cms/site-editing.ts +219 -0
  85. package/app/src/cms/site-editor.client.ts +1008 -0
  86. package/app/src/cms/site-editor.ts +99 -0
  87. package/app/src/cms/site-export.ts +60 -0
  88. package/app/src/cms/site-forms.ts +143 -0
  89. package/app/src/cms/site-import.ts +28 -0
  90. package/app/src/cms/site-session.ts +36 -0
  91. package/app/src/cms/site-taskbar.ts +77 -0
  92. package/app/src/cms/site-view.ts +1014 -0
  93. package/app/src/cms/site.ts +1322 -0
  94. package/app/src/cms/sitemaps.ts +131 -0
  95. package/app/src/cms/stat.client.ts +56 -0
  96. package/app/src/cms/style-controls.ts +252 -0
  97. package/app/src/cms/tabs.client.ts +36 -0
  98. package/app/src/cms/taskbar.ts +134 -0
  99. package/app/src/cms/term-icons.ts +10 -0
  100. package/app/src/cms/traffic.ts +26 -0
  101. package/app/src/cms/ui.ts +170 -0
  102. package/app/src/cms/updates.ts +124 -0
  103. package/app/src/cms/uploads.ts +26 -0
  104. package/app/src/cms/worker.ts +13 -0
  105. package/app/src/config/auth.ts +30 -0
  106. package/app/src/config/cms.ts +18 -0
  107. package/app/src/dashboard/access.ts +344 -0
  108. package/app/src/dashboard/agent-icons.ts +44 -0
  109. package/app/src/dashboard/app-passwords.ts +62 -0
  110. package/app/src/dashboard/avatar-field.ts +58 -0
  111. package/app/src/dashboard/bulk.ts +22 -0
  112. package/app/src/dashboard/head.ts +29 -0
  113. package/app/src/dashboard/icons.ts +15 -0
  114. package/app/src/dashboard/list-table.ts +28 -0
  115. package/app/src/dashboard/modules/roles.ts +15 -0
  116. package/app/src/dashboard/modules/sessions.ts +15 -0
  117. package/app/src/dashboard/modules/settings.ts +15 -0
  118. package/app/src/dashboard/modules/users.ts +18 -0
  119. package/app/src/dashboard/page.ts +67 -0
  120. package/app/src/dashboard/registry.ts +18 -0
  121. package/app/src/dashboard/session-list.ts +98 -0
  122. package/app/src/dashboard/tabs.ts +2 -0
  123. package/app/src/dashboard/time-ago.ts +16 -0
  124. package/app/src/dashboard/types.ts +43 -0
  125. package/app/src/dashboard/user-sections.ts +172 -0
  126. package/app/src/lib/permissions.ts +84 -0
  127. package/app/src/middlewares/auth.ts +117 -0
  128. package/app/src/pages/(site)/[...path]/index.ts +609 -0
  129. package/app/src/pages/(site)/feed/[...rest]/index.ts +13 -0
  130. package/app/src/pages/(site)/feed/index.ts +12 -0
  131. package/app/src/pages/(site)/index.ts +11 -0
  132. package/app/src/pages/(site)/indexnow/[file]/index.ts +18 -0
  133. package/app/src/pages/(site)/layout.ts +219 -0
  134. package/app/src/pages/(site)/llms.txt/index.ts +23 -0
  135. package/app/src/pages/(site)/manifest.webmanifest/index.ts +29 -0
  136. package/app/src/pages/(site)/media/[id]/[name]/index.ts +59 -0
  137. package/app/src/pages/(site)/preview/[collection]/[id]/index.ts +115 -0
  138. package/app/src/pages/(site)/robots.txt/index.ts +29 -0
  139. package/app/src/pages/(site)/search/index.ts +36 -0
  140. package/app/src/pages/(site)/sitemap.xml/index.ts +26 -0
  141. package/app/src/pages/(site)/sitemaps/[file]/index.ts +33 -0
  142. package/app/src/pages/api/auth/session.ts +48 -0
  143. package/app/src/pages/api/cms/appearance/areas/[name].ts +12 -0
  144. package/app/src/pages/api/cms/appearance/areas/index.ts +6 -0
  145. package/app/src/pages/api/cms/appearance/locations/[location].ts +6 -0
  146. package/app/src/pages/api/cms/appearance/locations/index.ts +6 -0
  147. package/app/src/pages/api/cms/appearance/menus/[id].ts +12 -0
  148. package/app/src/pages/api/cms/appearance/menus/index.ts +13 -0
  149. package/app/src/pages/api/cms/appearance/themes/[name]/activate.ts +6 -0
  150. package/app/src/pages/api/cms/appearance/themes/index.ts +6 -0
  151. package/app/src/pages/api/cms/cache/purge.ts +6 -0
  152. package/app/src/pages/api/cms/collections/index.ts +6 -0
  153. package/app/src/pages/api/cms/commands/[plugin]/[command].ts +26 -0
  154. package/app/src/pages/api/cms/comments/[id].ts +9 -0
  155. package/app/src/pages/api/cms/comments/index.ts +126 -0
  156. package/app/src/pages/api/cms/comments/queue.ts +6 -0
  157. package/app/src/pages/api/cms/content/[collection]/[entry]/autosave.ts +27 -0
  158. package/app/src/pages/api/cms/content/[collection]/[entry]/blocks/[block].ts +16 -0
  159. package/app/src/pages/api/cms/content/[collection]/[entry]/notes.ts +18 -0
  160. package/app/src/pages/api/cms/content/[collection]/[entry]/publish.ts +11 -0
  161. package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/[revision]/index.ts +6 -0
  162. package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/[revision]/restore.ts +6 -0
  163. package/app/src/pages/api/cms/content/[collection]/[entry]/revisions/index.ts +6 -0
  164. package/app/src/pages/api/cms/content/[collection]/[entry]/unpublish.ts +6 -0
  165. package/app/src/pages/api/cms/content/[collection]/[entry].ts +42 -0
  166. package/app/src/pages/api/cms/content/[collection]/index.ts +24 -0
  167. package/app/src/pages/api/cms/export/[collection].ts +37 -0
  168. package/app/src/pages/api/cms/forms/[slug]/index.ts +173 -0
  169. package/app/src/pages/api/cms/forms/[slug]/submissions/[submission]/files/[file].ts +25 -0
  170. package/app/src/pages/api/cms/forms/[slug]/submissions/export.ts +34 -0
  171. package/app/src/pages/api/cms/forms/[slug]/submissions/index.ts +24 -0
  172. package/app/src/pages/api/cms/import/[collection].ts +23 -0
  173. package/app/src/pages/api/cms/mcp.ts +29 -0
  174. package/app/src/pages/api/cms/me/index.ts +6 -0
  175. package/app/src/pages/api/cms/me/recent-blocks.ts +37 -0
  176. package/app/src/pages/api/cms/me/tokens/[id].ts +6 -0
  177. package/app/src/pages/api/cms/me/tokens/index.ts +13 -0
  178. package/app/src/pages/api/cms/media/[id].ts +6 -0
  179. package/app/src/pages/api/cms/media.ts +26 -0
  180. package/app/src/pages/api/cms/menus/[location].ts +14 -0
  181. package/app/src/pages/api/cms/network/sites/[id]/export.ts +15 -0
  182. package/app/src/pages/api/cms/network/sites/[id]/index.ts +9 -0
  183. package/app/src/pages/api/cms/network/sites/index.ts +14 -0
  184. package/app/src/pages/api/cms/notes/[id].ts +13 -0
  185. package/app/src/pages/api/cms/notes/index.ts +6 -0
  186. package/app/src/pages/api/cms/payments/webhook.ts +28 -0
  187. package/app/src/pages/api/cms/plugins/[name]/grant.ts +6 -0
  188. package/app/src/pages/api/cms/plugins/[name]/revoke.ts +6 -0
  189. package/app/src/pages/api/cms/plugins/index.ts +6 -0
  190. package/app/src/pages/api/cms/recovery.ts +29 -0
  191. package/app/src/pages/api/cms/redirects/index.ts +9 -0
  192. package/app/src/pages/api/cms/roles/index.ts +6 -0
  193. package/app/src/pages/api/cms/schema/[collection].ts +13 -0
  194. package/app/src/pages/api/cms/search.ts +16 -0
  195. package/app/src/pages/api/cms/settings/[group].ts +9 -0
  196. package/app/src/pages/api/cms/settings/index.ts +9 -0
  197. package/app/src/pages/api/cms/site-export.ts +34 -0
  198. package/app/src/pages/api/cms/taxonomies/index.ts +6 -0
  199. package/app/src/pages/api/cms/terms/[taxonomy]/[id].ts +12 -0
  200. package/app/src/pages/api/cms/terms/[taxonomy]/index.ts +9 -0
  201. package/app/src/pages/api/cms/uploads/[id]/complete.ts +15 -0
  202. package/app/src/pages/api/cms/uploads/[id]/index.ts +15 -0
  203. package/app/src/pages/api/cms/uploads/index.ts +26 -0
  204. package/app/src/pages/api/cms/users/[id]/index.ts +12 -0
  205. package/app/src/pages/api/cms/users/[id]/meta.ts +40 -0
  206. package/app/src/pages/api/cms/users/index.ts +12 -0
  207. package/app/src/pages/api/cms/webhooks/[id].ts +6 -0
  208. package/app/src/pages/api/cms/webhooks/index.ts +9 -0
  209. package/app/src/pages/auth/[provider]/callback.ts +11 -0
  210. package/app/src/pages/auth/[provider]/redirect.ts +9 -0
  211. package/app/src/pages/auth/forgot-password/index.ts +82 -0
  212. package/app/src/pages/auth/layout.ts +32 -0
  213. package/app/src/pages/auth/login/index.ts +205 -0
  214. package/app/src/pages/auth/magic/index.ts +68 -0
  215. package/app/src/pages/auth/register/index.ts +124 -0
  216. package/app/src/pages/auth/reset-password/index.ts +74 -0
  217. package/app/src/pages/auth/setup/index.ts +194 -0
  218. package/app/src/pages/auth/two-factor/index.ts +69 -0
  219. package/app/src/pages/auth/verify/index.ts +62 -0
  220. package/app/src/pages/dashboard/(cms)/appearance/customize/index.ts +263 -0
  221. package/app/src/pages/dashboard/(cms)/appearance/dashboard-menu/index.ts +241 -0
  222. package/app/src/pages/dashboard/(cms)/appearance/index.ts +89 -0
  223. package/app/src/pages/dashboard/(cms)/appearance/menus/[id]/index.ts +697 -0
  224. package/app/src/pages/dashboard/(cms)/appearance/menus/index.ts +145 -0
  225. package/app/src/pages/dashboard/(cms)/appearance/widgets/index.ts +279 -0
  226. package/app/src/pages/dashboard/(cms)/blocks/index.ts +84 -0
  227. package/app/src/pages/dashboard/(cms)/calendar/index.ts +92 -0
  228. package/app/src/pages/dashboard/(cms)/collections/[name]/index.ts +525 -0
  229. package/app/src/pages/dashboard/(cms)/collections/index.ts +72 -0
  230. package/app/src/pages/dashboard/(cms)/collections/new/index.ts +66 -0
  231. package/app/src/pages/dashboard/(cms)/comments/index.ts +237 -0
  232. package/app/src/pages/dashboard/(cms)/content/[collection]/[id]/index.ts +2382 -0
  233. package/app/src/pages/dashboard/(cms)/content/[collection]/[id]/revisions/index.ts +126 -0
  234. package/app/src/pages/dashboard/(cms)/content/[collection]/index.ts +693 -0
  235. package/app/src/pages/dashboard/(cms)/field-groups/[id]/index.ts +193 -0
  236. package/app/src/pages/dashboard/(cms)/field-groups/index.ts +65 -0
  237. package/app/src/pages/dashboard/(cms)/forms/[id]/submissions/[submission]/index.ts +279 -0
  238. package/app/src/pages/dashboard/(cms)/forms/[id]/submissions/index.ts +170 -0
  239. package/app/src/pages/dashboard/(cms)/forms/index.ts +171 -0
  240. package/app/src/pages/dashboard/(cms)/media/[id]/index.ts +317 -0
  241. package/app/src/pages/dashboard/(cms)/media/index.ts +156 -0
  242. package/app/src/pages/dashboard/(cms)/media/new/index.ts +9 -0
  243. package/app/src/pages/dashboard/(cms)/media/summary/index.ts +74 -0
  244. package/app/src/pages/dashboard/(cms)/my-sites/index.ts +63 -0
  245. package/app/src/pages/dashboard/(cms)/network/index.ts +53 -0
  246. package/app/src/pages/dashboard/(cms)/network/plugins/index.ts +110 -0
  247. package/app/src/pages/dashboard/(cms)/network/sites/[id]/index.ts +243 -0
  248. package/app/src/pages/dashboard/(cms)/network/sites/index.ts +186 -0
  249. package/app/src/pages/dashboard/(cms)/network/sites/new/index.ts +77 -0
  250. package/app/src/pages/dashboard/(cms)/network/themes/index.ts +82 -0
  251. package/app/src/pages/dashboard/(cms)/network/updates/index.ts +48 -0
  252. package/app/src/pages/dashboard/(cms)/network/users/[id]/index.ts +176 -0
  253. package/app/src/pages/dashboard/(cms)/network/users/index.ts +174 -0
  254. package/app/src/pages/dashboard/(cms)/network/users/new/index.ts +66 -0
  255. package/app/src/pages/dashboard/(cms)/plugins/index.ts +172 -0
  256. package/app/src/pages/dashboard/(cms)/profile/public/index.ts +105 -0
  257. package/app/src/pages/dashboard/(cms)/registrations/index.ts +70 -0
  258. package/app/src/pages/dashboard/(cms)/settings/index.ts +359 -0
  259. package/app/src/pages/dashboard/(cms)/settings/json/index.ts +202 -0
  260. package/app/src/pages/dashboard/(cms)/settings/layout.ts +67 -0
  261. package/app/src/pages/dashboard/(cms)/taxonomies/[name]/index.ts +85 -0
  262. package/app/src/pages/dashboard/(cms)/taxonomies/index.ts +98 -0
  263. package/app/src/pages/dashboard/(cms)/terms/[taxonomy]/[id]/index.ts +244 -0
  264. package/app/src/pages/dashboard/(cms)/terms/[taxonomy]/index.ts +148 -0
  265. package/app/src/pages/dashboard/(cms)/tools/activity/index.ts +94 -0
  266. package/app/src/pages/dashboard/(cms)/tools/automations/index.ts +131 -0
  267. package/app/src/pages/dashboard/(cms)/tools/cache/index.ts +92 -0
  268. package/app/src/pages/dashboard/(cms)/tools/export/index.ts +99 -0
  269. package/app/src/pages/dashboard/(cms)/tools/health/index.ts +189 -0
  270. package/app/src/pages/dashboard/(cms)/tools/jobs/index.ts +93 -0
  271. package/app/src/pages/dashboard/(cms)/tools/links/index.ts +115 -0
  272. package/app/src/pages/dashboard/(cms)/tools/redirects/index.ts +161 -0
  273. package/app/src/pages/dashboard/(cms)/tools/replace/index.ts +124 -0
  274. package/app/src/pages/dashboard/(cms)/tools/schema/index.ts +54 -0
  275. package/app/src/pages/dashboard/(cms)/tools/seo/index.ts +156 -0
  276. package/app/src/pages/dashboard/(cms)/tools/updates/index.ts +114 -0
  277. package/app/src/pages/dashboard/(cms)/tools/webhooks/index.ts +183 -0
  278. package/app/src/pages/dashboard/index.ts +214 -0
  279. package/app/src/pages/dashboard/layout.ts +227 -0
  280. package/app/src/pages/dashboard/profile/index.ts +211 -0
  281. package/app/src/pages/dashboard/profile/security/index.ts +249 -0
  282. package/app/src/pages/dashboard/roles/[id]/index.ts +116 -0
  283. package/app/src/pages/dashboard/roles/index.ts +134 -0
  284. package/app/src/pages/dashboard/roles/new/index.ts +95 -0
  285. package/app/src/pages/dashboard/sessions/index.ts +105 -0
  286. package/app/src/pages/dashboard/users/[id]/index.ts +472 -0
  287. package/app/src/pages/dashboard/users/index.ts +299 -0
  288. package/app/src/pages/dashboard/users/new/index.ts +123 -0
  289. package/app/src/passkeys.client.ts +18 -0
  290. package/app/src/plugins/default-theme/assets/cover.svg +31 -0
  291. package/app/src/plugins/default-theme/assets/logo.svg +8 -0
  292. package/app/src/plugins/default-theme/parts/comments.ts +66 -0
  293. package/app/src/plugins/default-theme/parts/list.ts +38 -0
  294. package/app/src/plugins/default-theme/parts/media.ts +15 -0
  295. package/app/src/plugins/default-theme/parts/options.ts +45 -0
  296. package/app/src/plugins/default-theme/plugin.json +275 -0
  297. package/app/src/plugins/default-theme/templates/archive.ts +14 -0
  298. package/app/src/plugins/default-theme/templates/entry-blank.ts +13 -0
  299. package/app/src/plugins/default-theme/templates/entry.ts +27 -0
  300. package/app/src/plugins/default-theme/templates/home.ts +8 -0
  301. package/app/src/plugins/default-theme/templates/layout.ts +40 -0
  302. package/app/src/plugins/default-theme/templates/not-found.ts +10 -0
  303. package/app/src/plugins/default-theme/templates/search.ts +32 -0
  304. package/app/src/services/rbac.ts +65 -0
  305. package/app/src/services/roles.ts +89 -0
  306. package/app/src/services/users.ts +173 -0
  307. package/package.json +114 -2
  308. package/src/automations.ts +95 -0
  309. package/src/bindings.ts +138 -0
  310. package/src/block-references.ts +239 -0
  311. package/src/block-shape.ts +155 -0
  312. package/src/blocks.ts +1157 -0
  313. package/src/cache.ts +54 -0
  314. package/src/checks.ts +198 -0
  315. package/src/cloudflare-workers.d.ts +13 -0
  316. package/src/cloudflare.ts +61 -0
  317. package/src/collab.ts +372 -0
  318. package/src/collections.ts +421 -0
  319. package/src/comments.ts +46 -0
  320. package/src/cron.ts +95 -0
  321. package/src/dashboard-menu.ts +105 -0
  322. package/src/diff.ts +113 -0
  323. package/src/editor-layout.ts +316 -0
  324. package/src/errors.ts +50 -0
  325. package/src/field-groups.ts +498 -0
  326. package/src/fields.ts +411 -0
  327. package/src/form-builder.ts +1053 -0
  328. package/src/forms.ts +109 -0
  329. package/src/highlight.ts +134 -0
  330. package/src/hooks.ts +510 -0
  331. package/src/icon-catalog.ts +55 -0
  332. package/src/icons.ts +128 -0
  333. package/src/images.ts +149 -0
  334. package/src/index.ts +100 -0
  335. package/src/isolate-core.ts +245 -0
  336. package/src/isolate.ts +19 -0
  337. package/src/isolation.ts +69 -0
  338. package/src/mail.ts +182 -0
  339. package/src/manifest.ts +476 -0
  340. package/src/media.ts +193 -0
  341. package/src/menus.ts +287 -0
  342. package/src/module.ts +32 -0
  343. package/src/modules/content.ts +64 -0
  344. package/src/modules/forms.ts +35 -0
  345. package/src/node.ts +66 -0
  346. package/src/notes.ts +237 -0
  347. package/src/permissions.ts +139 -0
  348. package/src/plugin-settings.ts +114 -0
  349. package/src/records.ts +56 -0
  350. package/src/redirects.ts +59 -0
  351. package/src/resource.ts +245 -0
  352. package/src/richtext.ts +402 -0
  353. package/src/schema-json.ts +112 -0
  354. package/src/search.ts +89 -0
  355. package/src/seo.ts +477 -0
  356. package/src/server/accounts.ts +418 -0
  357. package/src/server/ai.ts +33 -0
  358. package/src/server/api-tokens.ts +91 -0
  359. package/src/server/areas.ts +116 -0
  360. package/src/server/audit.ts +94 -0
  361. package/src/server/auth.ts +89 -0
  362. package/src/server/automations.ts +190 -0
  363. package/src/server/autosaves.ts +69 -0
  364. package/src/server/brand-icons.ts +50 -0
  365. package/src/server/brands.ts +86 -0
  366. package/src/server/budget.ts +97 -0
  367. package/src/server/cache.ts +104 -0
  368. package/src/server/capabilities.ts +333 -0
  369. package/src/server/cloudflare.ts +92 -0
  370. package/src/server/comments.ts +237 -0
  371. package/src/server/drafts.ts +176 -0
  372. package/src/server/field-groups.ts +88 -0
  373. package/src/server/files.ts +780 -0
  374. package/src/server/forms.ts +726 -0
  375. package/src/server/handoffs.ts +107 -0
  376. package/src/server/host-schema.ts +312 -0
  377. package/src/server/host.ts +2892 -0
  378. package/src/server/images.ts +34 -0
  379. package/src/server/index.ts +59 -0
  380. package/src/server/indexnow.ts +91 -0
  381. package/src/server/isolation.ts +183 -0
  382. package/src/server/locked.ts +45 -0
  383. package/src/server/mail.ts +93 -0
  384. package/src/server/markdown.ts +24 -0
  385. package/src/server/menus.ts +286 -0
  386. package/src/server/network-policy.ts +60 -0
  387. package/src/server/network.ts +665 -0
  388. package/src/server/notes.ts +275 -0
  389. package/src/server/outbox.ts +213 -0
  390. package/src/server/path-moves.ts +33 -0
  391. package/src/server/payments.ts +59 -0
  392. package/src/server/previews.ts +62 -0
  393. package/src/server/purge.ts +140 -0
  394. package/src/server/reconcile.ts +38 -0
  395. package/src/server/redirects.ts +183 -0
  396. package/src/server/repository.ts +1107 -0
  397. package/src/server/schedules.ts +105 -0
  398. package/src/server/schema.ts +562 -0
  399. package/src/server/security.ts +391 -0
  400. package/src/server/seed.ts +52 -0
  401. package/src/server/shared-fields.ts +34 -0
  402. package/src/server/site-export.ts +151 -0
  403. package/src/server/site-import.ts +482 -0
  404. package/src/server/site-search.ts +289 -0
  405. package/src/server/site-settings.ts +286 -0
  406. package/src/server/sites.ts +243 -0
  407. package/src/server/stores.ts +314 -0
  408. package/src/server/stripe.ts +173 -0
  409. package/src/server/taxonomies.ts +415 -0
  410. package/src/server/tokens.ts +25 -0
  411. package/src/server/traffic.ts +118 -0
  412. package/src/server/users.ts +653 -0
  413. package/src/server/webhooks.ts +245 -0
  414. package/src/settings-controls.ts +54 -0
  415. package/src/settings-document.ts +111 -0
  416. package/src/settings.ts +426 -0
  417. package/src/storage/cloudflare.ts +94 -0
  418. package/src/storage/index.ts +30 -0
  419. package/src/storage/node.ts +114 -0
  420. package/src/taxonomy.ts +51 -0
  421. package/src/theme.ts +1135 -0
  422. package/src/to-markdown.ts +179 -0
  423. package/src/updates.ts +126 -0
  424. package/src/version.ts +2 -0
  425. package/src/vite.d.ts +25 -0
  426. package/src/vite.js +199 -0
  427. package/src/webhooks.ts +107 -0
package/src/seo.ts ADDED
@@ -0,0 +1,477 @@
1
+ /**
2
+ * Search and answer-engine data, client-safe: the structured-data types a collection can map
3
+ * its fields to, title and description templates, robots directives, author profile fields
4
+ * and the JSON-LD graph of a site page. The app's `seo.ts` gathers the inputs on the server.
5
+ */
6
+ import { field, type FieldDeclaration } from './fields';
7
+
8
+ /** Structured-data types a collection's entries can be; `none` emits no JSON-LD for them. */
9
+ export const SCHEMA_TYPES = ['Article', 'BlogPosting', 'NewsArticle', 'WebPage', 'Product', 'Event', 'Recipe', 'Person', 'Organization', 'LocalBusiness', 'VideoObject', 'none'] as const;
10
+ export type SchemaType = (typeof SCHEMA_TYPES)[number];
11
+
12
+ /** Types whose entries are articles: they carry an author, a publisher and dates. */
13
+ export const ARTICLE_TYPES: ReadonlySet<SchemaType> = new Set<SchemaType>(['Article', 'BlogPosting', 'NewsArticle']);
14
+
15
+ export const SCHEMA_TYPE_LABELS: { readonly [type in SchemaType]: string } = {
16
+ Article: 'Article', BlogPosting: 'Blog post', NewsArticle: 'News article', WebPage: 'Web page', Product: 'Product', Event: 'Event', Recipe: 'Recipe',
17
+ Person: 'Person', Organization: 'Organization', LocalBusiness: 'Local business', VideoObject: 'Video', none: 'No structured data',
18
+ };
19
+
20
+ export interface SchemaProperty {
21
+ readonly name: string;
22
+ readonly label: string;
23
+ /** What the field should hold, shown as a hint. */
24
+ readonly hint: string;
25
+ }
26
+
27
+ /** Properties of each type an entry's fields can fill; the title, description, image, dates and author come from the core fields. */
28
+ export const SCHEMA_PROPERTIES: { readonly [type in SchemaType]: readonly SchemaProperty[] } = {
29
+ Article: [], BlogPosting: [], NewsArticle: [], WebPage: [], none: [],
30
+ Product: [
31
+ { name: 'price', label: 'Price', hint: 'A number.' }, { name: 'priceCurrency', label: 'Currency', hint: 'An ISO 4217 code such as USD.' },
32
+ { name: 'sku', label: 'SKU', hint: 'Text.' }, { name: 'gtin', label: 'GTIN', hint: 'A barcode number.' }, { name: 'brand', label: 'Brand', hint: 'Text.' },
33
+ { name: 'availability', label: 'Availability', hint: 'InStock, OutOfStock, PreOrder or a yes/no field (in stock).' },
34
+ ],
35
+ Event: [
36
+ { name: 'startDate', label: 'Starts', hint: 'A date field.' }, { name: 'endDate', label: 'Ends', hint: 'A date field.' },
37
+ { name: 'locationName', label: 'Venue', hint: 'Text.' }, { name: 'locationAddress', label: 'Address', hint: 'Text.' }, { name: 'organizer', label: 'Organizer', hint: 'Text.' },
38
+ { name: 'price', label: 'Ticket price', hint: 'A number.' }, { name: 'priceCurrency', label: 'Currency', hint: 'An ISO 4217 code such as USD.' },
39
+ ],
40
+ Recipe: [
41
+ { name: 'prepTime', label: 'Preparation time', hint: 'Minutes, as a number.' }, { name: 'cookTime', label: 'Cooking time', hint: 'Minutes, as a number.' },
42
+ { name: 'recipeYield', label: 'Yield', hint: 'Text such as 4 servings.' }, { name: 'recipeCategory', label: 'Category', hint: 'Text such as Dessert.' }, { name: 'recipeCuisine', label: 'Cuisine', hint: 'Text such as Italian.' },
43
+ { name: 'recipeIngredient', label: 'Ingredients', hint: 'A list, or text with one per line.' }, { name: 'recipeInstructions', label: 'Instructions', hint: 'A list, or text with one step per line.' },
44
+ { name: 'calories', label: 'Calories', hint: 'A number per serving.' },
45
+ ],
46
+ Person: [
47
+ { name: 'jobTitle', label: 'Job title', hint: 'Text.' }, { name: 'email', label: 'Email', hint: 'Text.' }, { name: 'telephone', label: 'Telephone', hint: 'Text.' },
48
+ { name: 'url', label: 'Website', hint: 'A URL.' }, { name: 'sameAs', label: 'Profiles', hint: 'A list of URLs, or text with one per line.' }, { name: 'worksFor', label: 'Works for', hint: 'An organization name.' },
49
+ ],
50
+ Organization: [
51
+ { name: 'url', label: 'Website', hint: 'A URL.' }, { name: 'email', label: 'Email', hint: 'Text.' }, { name: 'telephone', label: 'Telephone', hint: 'Text.' },
52
+ { name: 'address', label: 'Address', hint: 'Text.' }, { name: 'sameAs', label: 'Profiles', hint: 'A list of URLs, or text with one per line.' },
53
+ ],
54
+ LocalBusiness: [
55
+ { name: 'url', label: 'Website', hint: 'A URL.' }, { name: 'email', label: 'Email', hint: 'Text.' }, { name: 'telephone', label: 'Telephone', hint: 'Text.' },
56
+ { name: 'address', label: 'Address', hint: 'Text.' }, { name: 'openingHours', label: 'Opening hours', hint: 'Text such as Mo-Fr 09:00-17:00, or a list.' },
57
+ { name: 'priceRange', label: 'Price range', hint: 'Text such as $$.' }, { name: 'latitude', label: 'Latitude', hint: 'A number.' }, { name: 'longitude', label: 'Longitude', hint: 'A number.' },
58
+ ],
59
+ VideoObject: [
60
+ { name: 'contentUrl', label: 'Video file', hint: 'A media field or URL.' }, { name: 'embedUrl', label: 'Embed URL', hint: 'A URL.' },
61
+ { name: 'duration', label: 'Duration', hint: 'Seconds, as a number.' }, { name: 'uploadDate', label: 'Uploaded', hint: 'A date field; the publication date otherwise.' },
62
+ { name: 'thumbnailUrl', label: 'Thumbnail', hint: 'A media field; the featured image otherwise.' },
63
+ ],
64
+ };
65
+
66
+ /** How a collection's entries appear as structured data: the type and which fields fill its properties. */
67
+ export interface CollectionSchema {
68
+ readonly type: SchemaType;
69
+ /** Schema property → field name of the collection, for the type's `SCHEMA_PROPERTIES`. */
70
+ readonly map?: { readonly [property: string]: string };
71
+ }
72
+
73
+ /** Robots directives of a collection's entries and archive. */
74
+ export interface CollectionRobots {
75
+ /** Entries are kept out of search engines. */
76
+ readonly noindex?: boolean;
77
+ /** Links on entries are not followed. */
78
+ readonly nofollow?: boolean;
79
+ /** The archive is kept out of search engines. */
80
+ readonly archiveNoindex?: boolean;
81
+ }
82
+
83
+ /** Templates for a collection's titles and descriptions; see `renderSeoTemplate`. Empty uses Settings → SEO. */
84
+ export interface CollectionSeoTemplates {
85
+ readonly title?: string;
86
+ readonly description?: string;
87
+ readonly archiveTitle?: string;
88
+ }
89
+
90
+ /** Problems in a collection's `schema`, `robots` and `seoTemplates`; empty when valid. */
91
+ export function collectionSeoProblems(input: { schema?: unknown; robots?: unknown; seoTemplates?: unknown; fields?: readonly string[] }): string[] {
92
+ const problems: string[] = [];
93
+ const schema = input.schema as CollectionSchema | undefined;
94
+ if (schema !== undefined) {
95
+ if (!schema || typeof schema !== 'object' || Array.isArray(schema) || !(SCHEMA_TYPES as readonly string[]).includes(schema.type)) problems.push(`The structured data type is one of ${SCHEMA_TYPES.join(', ')}.`);
96
+ else if (schema.map !== undefined) {
97
+ const allowed = new Set(SCHEMA_PROPERTIES[schema.type].map(property => property.name));
98
+ if (!schema.map || typeof schema.map !== 'object' || Array.isArray(schema.map)) problems.push('The structured data map is an object of properties to field names.');
99
+ else for (const [property, name] of Object.entries(schema.map)) {
100
+ if (!allowed.has(property)) problems.push(`${schema.type} has no property ${property} to map.`);
101
+ else if (typeof name !== 'string' || !/^[a-z][A-Za-z0-9]{0,39}$/.test(name)) problems.push(`Property ${property} needs a field name.`);
102
+ else if (input.fields && !input.fields.includes(name)) problems.push(`Property ${property} maps to ${name}, which is not a field.`);
103
+ }
104
+ }
105
+ }
106
+ const robots = input.robots as CollectionRobots | undefined;
107
+ if (robots !== undefined && (!robots || typeof robots !== 'object' || Array.isArray(robots) || Object.entries(robots).some(([key, value]) => !['noindex', 'nofollow', 'archiveNoindex'].includes(key) || typeof value !== 'boolean'))) problems.push('Robots settings are noindex, nofollow and archiveNoindex, each on or off.');
108
+ const templates = input.seoTemplates as CollectionSeoTemplates | undefined;
109
+ if (templates !== undefined && (!templates || typeof templates !== 'object' || Array.isArray(templates) || Object.entries(templates).some(([key, value]) => !['title', 'description', 'archiveTitle'].includes(key) || typeof value !== 'string' || value.length > 300))) problems.push('SEO templates are title, description and archiveTitle, each at most 300 characters.');
110
+ return problems;
111
+ }
112
+
113
+ // --- Templates ----------------------------------------------------------------------------
114
+
115
+ /** Variables a title or description template can use, as `%name%`. */
116
+ export const SEO_TEMPLATE_VARIABLES = Object.freeze({
117
+ title: 'The entry, archive or term title', sep: 'The title separator', site: 'The site title', tagline: 'The tagline', excerpt: 'The entry\'s excerpt or summary',
118
+ term: 'The term, on its archive', taxonomy: 'The taxonomy, on a term archive', author: 'The author', collection: 'The collection\'s plural label', page: 'The page number, from the second page on', date: 'The publication date',
119
+ });
120
+ export type SeoTemplateVariable = keyof typeof SEO_TEMPLATE_VARIABLES;
121
+
122
+ /** Settings → SEO's default templates. */
123
+ export const SEO_TEMPLATE_DEFAULTS = Object.freeze({
124
+ home: '%site% %sep% %tagline%', entry: '%title% %sep% %site%', archive: '%title% %sep% %site%', term: '%term% %sep% %site%', author: '%author% %sep% %site%', search: 'Search results for “%title%” %sep% %site%',
125
+ description: '%excerpt%',
126
+ });
127
+
128
+ /**
129
+ * Render a template: `%var%` tokens are replaced, unknown ones removed, and separators left
130
+ * dangling by empty values are dropped, so `%title% %sep% %site%` with no site title reads
131
+ * as the title alone. A page number is appended when the template does not place it.
132
+ */
133
+ export function renderSeoTemplate(template: string, variables: Partial<Record<SeoTemplateVariable, string | number | null | undefined>>): string {
134
+ const sep = String(variables.sep ?? '–').trim() || '–';
135
+ const page = Number(variables.page ?? 1);
136
+ let text = template;
137
+ if (page > 1 && !/%page%/.test(text)) text = `${text} %sep% Page %page%`;
138
+ text = text.replace(/%([a-z]+)%/g, (_match, name: string) => {
139
+ if (name === 'sep') return `\u0000`;
140
+ if (name === 'page') return page > 1 ? String(page) : '';
141
+ const value = Object.hasOwn(variables, name) ? variables[name as SeoTemplateVariable] : undefined;
142
+ return value === undefined || value === null ? '' : String(value).trim();
143
+ });
144
+ // Collapse separators around empty values: at the ends, or two in a row.
145
+ const parts = text.split('\u0000').map(part => part.replace(/\s+/g, ' ').trim()).filter(Boolean);
146
+ return parts.join(` ${sep} `);
147
+ }
148
+
149
+ // --- Robots -------------------------------------------------------------------------------
150
+
151
+ export type ImagePreview = 'none' | 'standard' | 'large';
152
+
153
+ export interface RobotsOptions {
154
+ /** The whole site is hidden: `noindex, nofollow`. */
155
+ readonly hidden?: boolean;
156
+ readonly noindex?: boolean;
157
+ readonly nofollow?: boolean;
158
+ readonly nosnippet?: boolean;
159
+ /** Characters of the page engines may quote; null or a negative number for no limit. */
160
+ readonly maxSnippet?: number | null;
161
+ readonly maxImagePreview?: ImagePreview;
162
+ /** Bing: do not keep a cached copy, which also keeps the page out of Copilot's training. */
163
+ readonly noarchive?: boolean;
164
+ }
165
+
166
+ /** The `robots` meta content, or empty when every engine default applies. */
167
+ export function robotsDirectives(options: RobotsOptions): string {
168
+ if (options.hidden) return 'noindex, nofollow';
169
+ const parts: string[] = [];
170
+ if (options.noindex) parts.push('noindex');
171
+ if (options.nofollow) parts.push('nofollow');
172
+ if (options.nosnippet) parts.push('nosnippet');
173
+ else if (typeof options.maxSnippet === 'number' && options.maxSnippet >= 0 && Number.isFinite(options.maxSnippet)) parts.push(`max-snippet:${Math.floor(options.maxSnippet)}`);
174
+ if (options.noarchive) parts.push('noarchive');
175
+ if (options.maxImagePreview && options.maxImagePreview !== 'standard') parts.push(`max-image-preview:${options.maxImagePreview}`);
176
+ return parts.join(', ');
177
+ }
178
+
179
+ // --- Authors ------------------------------------------------------------------------------
180
+
181
+ /** A user's public profile, kept in `meta`: shown on author pages and as the `Person` of their entries. */
182
+ export const AUTHOR_FIELDS: { readonly [name: string]: FieldDeclaration } = Object.freeze({
183
+ bio: field.text({ max: 1000, label: 'Bio', description: 'A few sentences about you, shown on your author page.' }),
184
+ jobTitle: field.string({ max: 100, label: 'Job title' }),
185
+ website: field.string({ max: 2000, pattern: '(?:https?://[^\\s]+)?', label: 'Website' }),
186
+ profiles: field.text({ max: 2000, label: 'Profiles', description: 'Links to your profiles elsewhere, one per line: social accounts, Wikidata, an ORCID.' }),
187
+ });
188
+
189
+ /** `/author/<slug>`, with the language prefix. */
190
+ export function authorUrl(slug: string | null | undefined, prefix = ''): string | null {
191
+ return slug ? `${prefix}/author/${slug}` : null;
192
+ }
193
+
194
+ /** URLs out of a text with one per line, http(s) only. */
195
+ export function urlList(text: unknown): string[] {
196
+ if (Array.isArray(text)) return text.filter((entry): entry is string => typeof entry === 'string' && /^https?:\/\//.test(entry.trim())).map(entry => entry.trim());
197
+ if (typeof text !== 'string') return [];
198
+ return text.split(/\r?\n|,\s+/).map(line => line.trim()).filter(line => /^https?:\/\/[^\s]+$/.test(line));
199
+ }
200
+
201
+ // --- Structured data graph ----------------------------------------------------------------
202
+
203
+ export interface SchemaImage {
204
+ /** Absolute URL. */
205
+ readonly url: string;
206
+ readonly width?: number | null;
207
+ readonly height?: number | null;
208
+ readonly alt?: string;
209
+ }
210
+
211
+ export interface SchemaSite {
212
+ /** `https://example.com`, no trailing slash. */
213
+ readonly origin: string;
214
+ readonly name: string;
215
+ readonly tagline: string;
216
+ readonly locale: string;
217
+ readonly representation: 'organization' | 'person';
218
+ /** The organization's or person's name; the site title when empty. */
219
+ readonly publisherName: string;
220
+ readonly logo: SchemaImage | null;
221
+ readonly sameAs: readonly string[];
222
+ }
223
+
224
+ export interface SchemaAuthor {
225
+ readonly name: string;
226
+ /** The author page, absolute; null when author pages are off. */
227
+ readonly url: string | null;
228
+ readonly image?: string | null;
229
+ readonly description?: string;
230
+ readonly jobTitle?: string;
231
+ readonly website?: string | null;
232
+ readonly sameAs?: readonly string[];
233
+ }
234
+
235
+ export interface SchemaBreadcrumb { readonly name: string; readonly url: string }
236
+
237
+ export interface SchemaPage {
238
+ readonly kind: 'entry' | 'home' | 'archive' | 'term' | 'search' | 'author';
239
+ /** Absolute. */
240
+ readonly url: string;
241
+ readonly title: string;
242
+ readonly description: string;
243
+ readonly locale: string;
244
+ readonly image?: SchemaImage | null;
245
+ /** ISO 8601. */
246
+ readonly published?: string;
247
+ readonly modified?: string;
248
+ /** Ancestors, top first, the current page left out. */
249
+ readonly breadcrumbs?: readonly SchemaBreadcrumb[];
250
+ /** Entries: the collection's type and its mapped properties, already schema-shaped. */
251
+ readonly type?: SchemaType;
252
+ readonly properties?: { readonly [property: string]: unknown };
253
+ /** Who wrote the entry, the main author first; each becomes a Person. */
254
+ readonly authors?: readonly SchemaAuthor[];
255
+ readonly keywords?: readonly string[];
256
+ readonly section?: string;
257
+ /** Things the page is about: terms with a `sameAs` URL. */
258
+ readonly about?: readonly { readonly name: string; readonly sameAs?: string }[];
259
+ /** Author pages: the person shown. */
260
+ readonly profile?: SchemaAuthor;
261
+ /** The entry's summary, as `abstract`. */
262
+ readonly abstract?: string;
263
+ /** Questions and answers blocks that asked for FAQPage markup. */
264
+ readonly faq?: readonly { readonly question: string; readonly answer: string }[];
265
+ }
266
+
267
+ type Node = { [key: string]: unknown };
268
+
269
+ const ref = (id: string) => ({ '@id': id });
270
+ const clean = (node: Node): Node => Object.fromEntries(Object.entries(node).filter(([, value]) => value !== undefined && value !== null && value !== '' && !(Array.isArray(value) && !value.length)));
271
+
272
+ function imageNode(id: string, image: SchemaImage): Node {
273
+ return clean({ '@type': 'ImageObject', '@id': id, url: image.url, contentUrl: image.url, width: image.width ?? undefined, height: image.height ?? undefined, caption: image.alt });
274
+ }
275
+
276
+ function personNode(id: string, author: SchemaAuthor): Node {
277
+ return clean({ '@type': 'Person', '@id': id, name: author.name, url: author.url ?? author.website ?? undefined, image: author.image ?? undefined, description: author.description, jobTitle: author.jobTitle, sameAs: [...(author.website && author.url ? [author.website] : []), ...(author.sameAs ?? [])] });
278
+ }
279
+
280
+ /**
281
+ * The JSON-LD of a site page as one `@graph`: the publisher (Organization or Person), the
282
+ * WebSite, the page (WebPage, CollectionPage, SearchResultsPage or ProfilePage) with its
283
+ * image and breadcrumbs, and for entries the typed node: an Article with its author, or a
284
+ * Product, Event, Recipe and the like with the collection's mapped properties.
285
+ */
286
+ export function schemaGraph(site: SchemaSite, page: SchemaPage): { '@context': 'https://schema.org'; '@graph': Node[] } {
287
+ const root = `${site.origin}/`;
288
+ const publisherId = `${root}#${site.representation === 'person' ? 'person' : 'organization'}`;
289
+ const websiteId = `${root}#website`;
290
+ const pageId = `${page.url}#webpage`;
291
+ const graph: Node[] = [];
292
+ const publisherName = site.publisherName || site.name;
293
+ graph.push(clean({
294
+ '@type': site.representation === 'person' ? 'Person' : 'Organization', '@id': publisherId, name: publisherName, url: root,
295
+ ...(site.logo ? { logo: ref(`${root}#logo`), image: ref(`${root}#logo`) } : {}), sameAs: site.sameAs,
296
+ }));
297
+ if (site.logo) graph.push(imageNode(`${root}#logo`, site.logo));
298
+ graph.push(clean({ '@type': 'WebSite', '@id': websiteId, name: site.name, description: site.tagline, url: root, publisher: ref(publisherId), inLanguage: site.locale }));
299
+
300
+ const type = page.kind === 'entry' ? page.type ?? 'WebPage' : undefined;
301
+ if (type === 'none') return { '@context': 'https://schema.org', '@graph': graph };
302
+ const pageType = page.kind === 'archive' || page.kind === 'term' ? 'CollectionPage' : page.kind === 'search' ? 'SearchResultsPage' : page.kind === 'author' || type === 'Person' ? 'ProfilePage' : 'WebPage';
303
+ const imageId = page.image ? `${page.url}#primaryimage` : undefined;
304
+ const breadcrumbId = page.breadcrumbs?.length ? `${page.url}#breadcrumb` : undefined;
305
+ const entityId = type && type !== 'WebPage' ? `${page.url}#${ARTICLE_TYPES.has(type) ? 'article' : type.toLowerCase()}` : page.kind === 'author' && page.profile ? `${page.url}#person` : undefined;
306
+ graph.push(clean({
307
+ '@type': pageType, '@id': pageId, url: page.url, name: page.title, description: page.description, isPartOf: ref(websiteId), inLanguage: page.locale,
308
+ datePublished: page.published, dateModified: page.modified, primaryImageOfPage: imageId ? ref(imageId) : undefined, image: imageId ? ref(imageId) : undefined,
309
+ breadcrumb: breadcrumbId ? ref(breadcrumbId) : undefined, about: page.kind === 'home' ? ref(publisherId) : undefined,
310
+ mainEntity: entityId && !ARTICLE_TYPES.has(type ?? 'none') ? ref(entityId) : undefined,
311
+ }));
312
+ if (imageId && page.image) graph.push(imageNode(imageId, page.image));
313
+ if (breadcrumbId && page.breadcrumbs) {
314
+ graph.push({ '@type': 'BreadcrumbList', '@id': breadcrumbId, itemListElement: [...page.breadcrumbs, { name: page.title, url: page.url }].map((crumb, index, all) => clean({ '@type': 'ListItem', position: index + 1, name: crumb.name, item: index === all.length - 1 ? undefined : crumb.url })) });
315
+ }
316
+ const authors = (page.authors ?? []).map((author, index) => ({ author, id: author.url ? `${author.url}#person` : `${page.url}#author${index ? `-${index + 1}` : ''}` }));
317
+ // One author is a reference, several a list of them.
318
+ const authorRef = authors.length > 1 ? authors.map(entry => ref(entry.id)) : authors.length ? ref(authors[0]!.id) : undefined;
319
+ const about = page.about?.map(thing => clean({ '@type': 'Thing', name: thing.name, sameAs: thing.sameAs }));
320
+ if (type && ARTICLE_TYPES.has(type)) {
321
+ graph.push(clean({
322
+ '@type': type, '@id': entityId, headline: page.title, description: page.description, abstract: page.abstract, url: page.url, isPartOf: ref(pageId), mainEntityOfPage: ref(pageId), inLanguage: page.locale,
323
+ datePublished: page.published, dateModified: page.modified, image: imageId ? ref(imageId) : undefined, author: authorRef, publisher: ref(publisherId),
324
+ keywords: page.keywords, articleSection: page.section, about,
325
+ }));
326
+ for (const entry of authors) graph.push(personNode(entry.id, entry.author));
327
+ } else if (type && type !== 'WebPage' && entityId) {
328
+ const properties = page.properties ?? {};
329
+ graph.push(clean({
330
+ '@type': type, '@id': entityId, name: page.title, description: page.description, url: page.url, mainEntityOfPage: ref(pageId), image: imageId ? ref(imageId) : undefined,
331
+ ...(type === 'Recipe' || type === 'VideoObject' ? { datePublished: page.published, author: authorRef } : {}),
332
+ ...(type === 'VideoObject' ? { uploadDate: properties.uploadDate ?? page.published, thumbnailUrl: properties.thumbnailUrl ?? page.image?.url } : {}),
333
+ ...properties, about,
334
+ }));
335
+ if (type === 'Recipe' || type === 'VideoObject') for (const entry of authors) graph.push(personNode(entry.id, entry.author));
336
+ } else if (page.kind === 'author' && page.profile && entityId) {
337
+ graph.push(personNode(entityId, page.profile));
338
+ }
339
+ if (page.faq?.length) {
340
+ graph.push({ '@type': 'FAQPage', '@id': `${page.url}#faq`, isPartOf: ref(pageId), mainEntity: page.faq.map(item => ({ '@type': 'Question', name: item.question, acceptedAnswer: { '@type': 'Answer', text: item.answer } })) });
341
+ }
342
+ return { '@context': 'https://schema.org', '@graph': graph };
343
+ }
344
+
345
+ /**
346
+ * Values of a type's mapped properties, schema-shaped, from an entry's fields: dates become
347
+ * ISO strings, minutes durations, media URLs, line lists arrays, and prices an `Offer`.
348
+ */
349
+ export function schemaProperties(schema: CollectionSchema, record: { readonly [field: string]: unknown }, fields: { readonly [name: string]: FieldDeclaration }, resolve: { mediaUrl(id: string): string | null; now?: number }): { [property: string]: unknown } {
350
+ const map = schema.map ?? {};
351
+ const allowed = new Set(SCHEMA_PROPERTIES[schema.type].map(property => property.name));
352
+ const raw: { [property: string]: unknown } = {};
353
+ for (const [property, name] of Object.entries(map)) {
354
+ if (!allowed.has(property)) continue;
355
+ const declaration = fields[name];
356
+ const value = record[name];
357
+ if (!declaration || value === undefined || value === null || value === '') continue;
358
+ raw[property] = schemaValue(property, declaration, value, resolve);
359
+ }
360
+ const out: { [property: string]: unknown } = {};
361
+ const offer = clean({ '@type': 'Offer', price: raw.price, priceCurrency: raw.priceCurrency, availability: availabilityOf(raw.availability) });
362
+ for (const [property, value] of Object.entries(raw)) {
363
+ if (['price', 'priceCurrency', 'availability'].includes(property)) continue;
364
+ if (property === 'brand' || property === 'organizer' || property === 'worksFor') out[property] = { '@type': 'Organization', name: value };
365
+ else if (property === 'locationName' || property === 'locationAddress') {
366
+ out.location = { ...(out.location as Node | undefined), '@type': 'Place', ...(property === 'locationName' ? { name: value } : { address: value }) };
367
+ } else if (property === 'latitude' || property === 'longitude') out.geo = { ...(out.geo as Node | undefined), '@type': 'GeoCoordinates', [property]: value };
368
+ else if (property === 'calories') out.nutrition = { '@type': 'NutritionInformation', calories: `${value} calories` };
369
+ else if (property === 'recipeInstructions' && Array.isArray(value)) out.recipeInstructions = value.map(step => ({ '@type': 'HowToStep', text: step }));
370
+ else out[property] = value;
371
+ }
372
+ if (Object.keys(offer).length > 1 && (raw.price !== undefined || raw.availability !== undefined)) out.offers = offer;
373
+ return out;
374
+ }
375
+
376
+ const AVAILABILITY = new Set(['InStock', 'OutOfStock', 'PreOrder', 'BackOrder', 'Discontinued', 'SoldOut', 'LimitedAvailability', 'OnlineOnly', 'InStoreOnly', 'PreSale']);
377
+
378
+ function availabilityOf(value: unknown): string | undefined {
379
+ if (value === true) return 'https://schema.org/InStock';
380
+ if (value === false) return 'https://schema.org/OutOfStock';
381
+ if (typeof value !== 'string') return undefined;
382
+ const name = value.replace(/^https?:\/\/schema\.org\//, '').replace(/\s+/g, '');
383
+ const match = [...AVAILABILITY].find(entry => entry.toLowerCase() === name.toLowerCase());
384
+ return match ? `https://schema.org/${match}` : undefined;
385
+ }
386
+
387
+ const MINUTES = new Set(['prepTime', 'cookTime', 'totalTime']);
388
+ const LISTS = new Set(['recipeIngredient', 'recipeInstructions', 'sameAs', 'openingHours']);
389
+
390
+ function schemaValue(property: string, declaration: FieldDeclaration, value: unknown, resolve: { mediaUrl(id: string): string | null }): unknown {
391
+ if (declaration.media) {
392
+ const ids = Array.isArray(value) ? value : [value];
393
+ const urls = ids.map(id => resolve.mediaUrl(String(id))).filter((url): url is string => !!url);
394
+ return urls.length > 1 ? urls : urls[0];
395
+ }
396
+ if (declaration.kind === 'datetime') return typeof value === 'number' ? new Date(value).toISOString() : undefined;
397
+ if (MINUTES.has(property)) return typeof value === 'number' ? `PT${Math.round(value)}M` : typeof value === 'string' && /^PT/.test(value) ? value : undefined;
398
+ if (property === 'duration') return typeof value === 'number' ? `PT${Math.round(value)}S` : typeof value === 'string' && /^PT/.test(value) ? value : undefined;
399
+ if (LISTS.has(property)) {
400
+ const items = Array.isArray(value) ? value.map(String) : String(value).split(/\r?\n/);
401
+ return items.map(item => item.trim()).filter(Boolean);
402
+ }
403
+ if (declaration.kind === 'richtext' || declaration.kind === 'blocks' || declaration.kind === 'json') return undefined;
404
+ return Array.isArray(value) ? value.map(String) : value;
405
+ }
406
+
407
+ // --- Crawlers -----------------------------------------------------------------------------
408
+
409
+ export interface CrawlerGroup {
410
+ readonly id: 'search' | 'aiSearch' | 'aiTraining' | 'fetchers';
411
+ readonly label: string;
412
+ readonly description: string;
413
+ /** User-agent tokens, as robots.txt names them. */
414
+ readonly bots: readonly string[];
415
+ /** False for agents that fetch a page a person asked for: robots.txt does not stop them. */
416
+ readonly blockable: boolean;
417
+ }
418
+
419
+ /**
420
+ * Crawlers by what they do with the page, for Settings → Crawlers. The lists ship with the
421
+ * package and are revised with releases; a bot that is not listed is treated like a search
422
+ * engine. `Google-Extended` is training *and* grounding in Gemini, so it sits with training.
423
+ */
424
+ export const CRAWLER_GROUPS: readonly CrawlerGroup[] = Object.freeze([
425
+ { id: 'search', label: 'Search engines', description: 'Index pages for search results, and feed the answers built on those results (AI Overviews, AI Mode, Copilot).', bots: ['Googlebot', 'Bingbot', 'Applebot', 'DuckDuckBot', 'YandexBot', 'Baiduspider', 'Slurp'], blockable: true },
426
+ { id: 'aiSearch', label: 'AI search and answers', description: 'Index pages for AI assistants that cite sources: ChatGPT search, Claude, Perplexity.', bots: ['OAI-SearchBot', 'Claude-SearchBot', 'PerplexityBot', 'DuckAssistBot'], blockable: true },
427
+ { id: 'aiTraining', label: 'AI training', description: 'Collect pages to train models. Blocking them keeps the site out of future models; Google-Extended also stops grounding in Gemini.', bots: ['GPTBot', 'ClaudeBot', 'anthropic-ai', 'Google-Extended', 'CCBot', 'Applebot-Extended', 'Bytespider', 'meta-externalagent', 'Amazonbot', 'cohere-ai', 'Diffbot', 'omgili', 'PanguBot', 'Timpibot'], blockable: true },
428
+ { id: 'fetchers', label: 'User-initiated fetchers', description: 'Fetch one page because a person asked an assistant about it. robots.txt does not apply to them; they count as visitors.', bots: ['ChatGPT-User', 'Claude-User', 'Perplexity-User', 'Meta-ExternalFetcher', 'Google-CloudVertexBot'], blockable: false },
429
+ ]);
430
+
431
+ export interface CrawlerSettings {
432
+ readonly allowSearch: boolean;
433
+ readonly allowAiSearch: boolean;
434
+ readonly allowAiTraining: boolean;
435
+ /** Add Cloudflare's `Content-Signal` line stating the same preferences. */
436
+ readonly contentSignals: boolean;
437
+ }
438
+
439
+ /** The user-agent groups robots.txt blocks: a `User-agent` line per bot, then `Disallow: /`. */
440
+ export function blockedCrawlerGroups(settings: CrawlerSettings): CrawlerGroup[] {
441
+ return CRAWLER_GROUPS.filter(group => group.blockable && (group.id === 'search' ? !settings.allowSearch : group.id === 'aiSearch' ? !settings.allowAiSearch : group.id === 'aiTraining' ? !settings.allowAiTraining : false));
442
+ }
443
+
444
+ /**
445
+ * robots.txt of the site: the application's private paths kept out, blocked crawler groups,
446
+ * the optional Content-Signal preference, extra rules and the sitemap. Hidden sites get
447
+ * `Disallow: /` alone.
448
+ */
449
+ export function robotsTxtLines(input: { hidden: boolean; crawlers: CrawlerSettings; extra: string; sitemapUrl: string; disallow?: readonly string[] }): string[] {
450
+ if (input.hidden) return ['User-agent: *', 'Disallow: /'];
451
+ const lines = ['User-agent: *', ...(input.disallow ?? ['/dashboard/', '/api/', '/auth/', '/preview/', '/indexnow/']).map(path => `Disallow: ${path}`)];
452
+ if (input.crawlers.contentSignals) {
453
+ const yes = (value: boolean) => value ? 'yes' : 'no';
454
+ lines.push(`Content-Signal: search=${yes(input.crawlers.allowSearch)}, ai-input=${yes(input.crawlers.allowAiSearch)}, ai-train=${yes(input.crawlers.allowAiTraining)}`);
455
+ }
456
+ for (const group of blockedCrawlerGroups(input.crawlers)) {
457
+ lines.push('', `# ${group.label}`);
458
+ for (const bot of group.bots) lines.push(`User-agent: ${bot}`);
459
+ lines.push('Disallow: /');
460
+ }
461
+ const extra = input.extra.trim();
462
+ if (extra) lines.push('', extra);
463
+ lines.push('', `Sitemap: ${input.sitemapUrl}`);
464
+ return lines;
465
+ }
466
+
467
+ /** Search engine crawlers that are not in `CRAWLER_GROUPS` (never blocked), recognised for visit counts. */
468
+ const SEARCH_AGENTS = ['Googlebot', 'Bingbot', 'bingbot', 'Applebot', 'DuckDuckBot', 'YandexBot', 'Baiduspider', 'Slurp', 'Google-InspectionTool', 'Storebot-Google', 'GoogleOther', 'AdsBot-Google'];
469
+
470
+ /** The crawler a user agent string names, with its group, or null for browsers and unknown agents. */
471
+ export function crawlerOf(userAgent: string): { agent: string; group: CrawlerGroup['id'] | 'search' } | null {
472
+ if (!userAgent) return null;
473
+ const lower = userAgent.toLowerCase();
474
+ for (const group of CRAWLER_GROUPS) for (const bot of group.bots) if (lower.includes(bot.toLowerCase())) return { agent: bot, group: group.id };
475
+ for (const bot of SEARCH_AGENTS) if (lower.includes(bot.toLowerCase())) return { agent: bot.replace(/^bingbot$/, 'Bingbot'), group: 'search' };
476
+ return null;
477
+ }