@conloca/content-api 0.1.16 → 0.2.1

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 (299) hide show
  1. package/dist/asset-constraints.d.ts +16 -0
  2. package/dist/asset-constraints.d.ts.map +1 -0
  3. package/dist/asset-constraints.js +29 -0
  4. package/dist/asset-constraints.js.map +1 -0
  5. package/dist/asset-metadata-store.d.ts +60 -0
  6. package/dist/asset-metadata-store.d.ts.map +1 -0
  7. package/dist/asset-metadata-store.js +335 -0
  8. package/dist/asset-metadata-store.js.map +1 -0
  9. package/dist/asset-operations.d.ts +21 -28
  10. package/dist/asset-operations.d.ts.map +1 -1
  11. package/dist/asset-operations.js +268 -305
  12. package/dist/asset-operations.js.map +1 -0
  13. package/dist/asset-types.d.ts +23 -7
  14. package/dist/asset-types.d.ts.map +1 -1
  15. package/dist/asset-types.js +8 -2
  16. package/dist/asset-types.js.map +1 -0
  17. package/dist/asset-usage.d.ts +11 -0
  18. package/dist/asset-usage.d.ts.map +1 -0
  19. package/dist/asset-usage.js +50 -0
  20. package/dist/asset-usage.js.map +1 -0
  21. package/dist/base-content-index.d.ts +8 -2
  22. package/dist/base-content-index.d.ts.map +1 -1
  23. package/dist/base-content-index.js +24 -3
  24. package/dist/base-content-index.js.map +1 -0
  25. package/dist/cf-access.js +1 -0
  26. package/dist/cf-access.js.map +1 -0
  27. package/dist/component-registry.d.ts +1 -1
  28. package/dist/component-registry.d.ts.map +1 -1
  29. package/dist/component-registry.js +2 -1
  30. package/dist/component-registry.js.map +1 -0
  31. package/dist/component-registry.types.js +1 -0
  32. package/dist/component-registry.types.js.map +1 -0
  33. package/dist/component-vocabulary.d.ts +33 -0
  34. package/dist/component-vocabulary.d.ts.map +1 -0
  35. package/dist/component-vocabulary.js +105 -0
  36. package/dist/component-vocabulary.js.map +1 -0
  37. package/dist/content-api.interface.d.ts +5 -5
  38. package/dist/content-api.interface.d.ts.map +1 -1
  39. package/dist/content-api.interface.js +1 -0
  40. package/dist/content-api.interface.js.map +1 -0
  41. package/dist/content-filters.d.ts +2 -2
  42. package/dist/content-filters.d.ts.map +1 -1
  43. package/dist/content-filters.js +9 -8
  44. package/dist/content-filters.js.map +1 -0
  45. package/dist/content-index.d.ts +74 -16
  46. package/dist/content-index.d.ts.map +1 -1
  47. package/dist/content-index.js +183 -55
  48. package/dist/content-index.js.map +1 -0
  49. package/dist/content-operations.d.ts +71 -7
  50. package/dist/content-operations.d.ts.map +1 -1
  51. package/dist/content-operations.js +166 -82
  52. package/dist/content-operations.js.map +1 -0
  53. package/dist/content-path.d.ts +64 -0
  54. package/dist/content-path.d.ts.map +1 -0
  55. package/dist/content-path.js +95 -0
  56. package/dist/content-path.js.map +1 -0
  57. package/dist/content-reader.d.ts +2 -2
  58. package/dist/content-reader.d.ts.map +1 -1
  59. package/dist/content-reader.js +2 -1
  60. package/dist/content-reader.js.map +1 -0
  61. package/dist/content-utils.d.ts +53 -10
  62. package/dist/content-utils.d.ts.map +1 -1
  63. package/dist/content-utils.js +103 -34
  64. package/dist/content-utils.js.map +1 -0
  65. package/dist/content-watcher.d.ts +3 -3
  66. package/dist/content-watcher.d.ts.map +1 -1
  67. package/dist/content-watcher.js +13 -10
  68. package/dist/content-watcher.js.map +1 -0
  69. package/dist/data-index.d.ts +1 -1
  70. package/dist/data-index.d.ts.map +1 -1
  71. package/dist/data-index.js +2 -1
  72. package/dist/data-index.js.map +1 -0
  73. package/dist/data.d.ts +5 -13
  74. package/dist/data.d.ts.map +1 -1
  75. package/dist/data.js +7 -6
  76. package/dist/data.js.map +1 -0
  77. package/dist/editor-data-bindings.d.ts +10 -0
  78. package/dist/editor-data-bindings.d.ts.map +1 -0
  79. package/dist/editor-data-bindings.js +67 -0
  80. package/dist/editor-data-bindings.js.map +1 -0
  81. package/dist/etag-utils.d.ts.map +1 -1
  82. package/dist/etag-utils.js +5 -4
  83. package/dist/etag-utils.js.map +1 -0
  84. package/dist/filesystem-content-api.d.ts +45 -18
  85. package/dist/filesystem-content-api.d.ts.map +1 -1
  86. package/dist/filesystem-content-api.js +455 -286
  87. package/dist/filesystem-content-api.js.map +1 -0
  88. package/dist/filesystem-reader-backend.d.ts +46 -0
  89. package/dist/filesystem-reader-backend.d.ts.map +1 -0
  90. package/dist/filesystem-reader-backend.js +119 -0
  91. package/dist/filesystem-reader-backend.js.map +1 -0
  92. package/dist/fragment-index.d.ts +8 -0
  93. package/dist/fragment-index.d.ts.map +1 -0
  94. package/dist/fragment-index.js +8 -0
  95. package/dist/fragment-index.js.map +1 -0
  96. package/dist/fragments.d.ts +16 -0
  97. package/dist/fragments.d.ts.map +1 -0
  98. package/dist/fragments.js +104 -0
  99. package/dist/fragments.js.map +1 -0
  100. package/dist/git-operations.d.ts.map +1 -1
  101. package/dist/git-operations.js +5 -1
  102. package/dist/git-operations.js.map +1 -0
  103. package/dist/header-parser.d.ts +4 -4
  104. package/dist/header-parser.d.ts.map +1 -1
  105. package/dist/header-parser.js +8 -61
  106. package/dist/header-parser.js.map +1 -0
  107. package/dist/in-memory-content-api.d.ts +7 -7
  108. package/dist/in-memory-content-api.d.ts.map +1 -1
  109. package/dist/in-memory-content-api.js +74 -56
  110. package/dist/in-memory-content-api.js.map +1 -0
  111. package/dist/index.d.ts +19 -12
  112. package/dist/index.d.ts.map +1 -1
  113. package/dist/index.js +21 -9
  114. package/dist/index.js.map +1 -0
  115. package/dist/indexing.d.ts +4 -4
  116. package/dist/indexing.d.ts.map +1 -1
  117. package/dist/indexing.js +6 -5
  118. package/dist/indexing.js.map +1 -0
  119. package/dist/json-whitespace-view.js +1 -0
  120. package/dist/json-whitespace-view.js.map +1 -0
  121. package/dist/middleware.d.ts +8 -6
  122. package/dist/middleware.d.ts.map +1 -1
  123. package/dist/middleware.js +178 -142
  124. package/dist/middleware.js.map +1 -0
  125. package/dist/node.d.ts +24 -17
  126. package/dist/node.d.ts.map +1 -1
  127. package/dist/node.js +17 -14
  128. package/dist/node.js.map +1 -0
  129. package/dist/page-references.d.ts +21 -0
  130. package/dist/page-references.d.ts.map +1 -0
  131. package/dist/page-references.js +50 -0
  132. package/dist/page-references.js.map +1 -0
  133. package/dist/read-date.d.ts +3 -0
  134. package/dist/read-date.d.ts.map +1 -0
  135. package/dist/read-date.js +9 -0
  136. package/dist/read-date.js.map +1 -0
  137. package/dist/reader-backend.d.ts +54 -0
  138. package/dist/reader-backend.d.ts.map +1 -0
  139. package/dist/reader-backend.js +2 -0
  140. package/dist/reader-backend.js.map +1 -0
  141. package/dist/reader.d.ts +8 -8
  142. package/dist/reader.d.ts.map +1 -1
  143. package/dist/reader.js +8 -7
  144. package/dist/reader.js.map +1 -0
  145. package/dist/schemas/index.d.ts +6 -6
  146. package/dist/schemas/index.d.ts.map +1 -1
  147. package/dist/schemas/index.js +9 -8
  148. package/dist/schemas/index.js.map +1 -0
  149. package/dist/site-index.d.ts +3 -3
  150. package/dist/site-index.d.ts.map +1 -1
  151. package/dist/site-index.js +9 -5
  152. package/dist/site-index.js.map +1 -0
  153. package/dist/site.d.ts +5 -3
  154. package/dist/site.d.ts.map +1 -1
  155. package/dist/site.js +14 -2
  156. package/dist/site.js.map +1 -0
  157. package/dist/types.d.ts +203 -15
  158. package/dist/types.d.ts.map +1 -1
  159. package/dist/types.js +9 -0
  160. package/dist/types.js.map +1 -0
  161. package/dist/url-safe-base64.js +1 -0
  162. package/dist/url-safe-base64.js.map +1 -0
  163. package/dist/url-validation.d.ts +14 -0
  164. package/dist/url-validation.d.ts.map +1 -1
  165. package/dist/url-validation.js +56 -14
  166. package/dist/url-validation.js.map +1 -0
  167. package/dist/utils/atomic-write.js +1 -0
  168. package/dist/utils/atomic-write.js.map +1 -0
  169. package/dist/utils.d.ts +1 -1
  170. package/dist/utils.js +2 -1
  171. package/dist/utils.js.map +1 -0
  172. package/dist/vite-plugin.d.ts +2 -2
  173. package/dist/vite-plugin.js +5 -4
  174. package/dist/vite-plugin.js.map +1 -0
  175. package/dist/vxjson-serialize.d.ts +5 -6
  176. package/dist/vxjson-serialize.d.ts.map +1 -1
  177. package/dist/vxjson-serialize.js +13 -10
  178. package/dist/vxjson-serialize.js.map +1 -0
  179. package/dist/vxjson.d.ts +4 -3
  180. package/dist/vxjson.d.ts.map +1 -1
  181. package/dist/vxjson.js +10 -20
  182. package/dist/vxjson.js.map +1 -0
  183. package/dist/xxhash.d.ts.map +1 -1
  184. package/dist/xxhash.js +6 -2
  185. package/dist/xxhash.js.map +1 -0
  186. package/package.json +92 -56
  187. package/src/asset-constraints.ts +33 -0
  188. package/src/asset-metadata-store.ts +401 -0
  189. package/src/asset-operations.ts +814 -0
  190. package/src/asset-types.ts +74 -0
  191. package/src/asset-usage.ts +48 -0
  192. package/src/base-content-index.ts +227 -0
  193. package/src/cf-access.ts +85 -0
  194. package/src/component-registry.ts +145 -0
  195. package/src/component-registry.types.ts +12 -0
  196. package/src/component-vocabulary.ts +87 -0
  197. package/src/content-api.interface.ts +94 -0
  198. package/src/content-filters.ts +278 -0
  199. package/src/content-index.ts +642 -0
  200. package/src/content-operations.ts +497 -0
  201. package/src/content-path.ts +121 -0
  202. package/src/content-reader.ts +18 -0
  203. package/src/content-utils.ts +474 -0
  204. package/src/content-watcher.ts +122 -0
  205. package/src/data-index.ts +7 -0
  206. package/src/data.ts +134 -0
  207. package/src/editor-data-bindings.ts +66 -0
  208. package/src/etag-utils.ts +204 -0
  209. package/src/filesystem-content-api.ts +2740 -0
  210. package/src/filesystem-reader-backend.ts +135 -0
  211. package/src/fragment-index.ts +7 -0
  212. package/src/fragments.ts +113 -0
  213. package/src/git-operations.ts +340 -0
  214. package/src/header-parser.ts +272 -0
  215. package/src/in-memory-content-api.ts +760 -0
  216. package/src/index.ts +45 -0
  217. package/src/indexing.ts +8 -0
  218. package/src/json-whitespace-view.ts +155 -0
  219. package/src/middleware.ts +1322 -0
  220. package/src/node.ts +40 -0
  221. package/src/page-references.ts +76 -0
  222. package/src/read-date.ts +7 -0
  223. package/src/reader-backend.ts +54 -0
  224. package/src/reader.ts +15 -0
  225. package/src/schemas/index.ts +113 -0
  226. package/src/site-index.ts +330 -0
  227. package/src/site.ts +198 -0
  228. package/src/types.ts +759 -0
  229. package/src/url-safe-base64.ts +38 -0
  230. package/src/url-validation.ts +121 -0
  231. package/src/utils/atomic-write.ts +20 -0
  232. package/src/utils.ts +84 -0
  233. package/src/vite-plugin.ts +45 -0
  234. package/src/vxjson-serialize.ts +66 -0
  235. package/src/vxjson.ts +442 -0
  236. package/src/xxhash.ts +43 -0
  237. package/dist/asset-manifest.d.ts +0 -23
  238. package/dist/asset-manifest.d.ts.map +0 -1
  239. package/dist/asset-manifest.js +0 -73
  240. package/dist/block-index.d.ts +0 -9
  241. package/dist/block-index.d.ts.map +0 -1
  242. package/dist/block-index.js +0 -11
  243. package/dist/blocks.d.ts +0 -16
  244. package/dist/blocks.d.ts.map +0 -1
  245. package/dist/blocks.js +0 -103
  246. package/dist/component-registry.types-C0ctF9nh.d.mts +0 -71
  247. package/dist/component-registry.types-C0ctF9nh.d.mts.map +0 -1
  248. package/dist/content-index-D092_vk1.mjs +0 -629
  249. package/dist/content-index-D092_vk1.mjs.map +0 -1
  250. package/dist/content-index-D6IVMmAB.d.mts +0 -127
  251. package/dist/content-index-D6IVMmAB.d.mts.map +0 -1
  252. package/dist/content-operations-DIbsxG5A.d.mts +0 -354
  253. package/dist/content-operations-DIbsxG5A.d.mts.map +0 -1
  254. package/dist/content-utils-fWNHTrPy.mjs +0 -280
  255. package/dist/content-utils-fWNHTrPy.mjs.map +0 -1
  256. package/dist/data-DquNIEnQ.mjs +0 -62
  257. package/dist/data-DquNIEnQ.mjs.map +0 -1
  258. package/dist/filesystem-content-api-B1KIQJfk.mjs +0 -2
  259. package/dist/filesystem-content-api-C0HIhqZi.mjs +0 -1620
  260. package/dist/filesystem-content-api-C0HIhqZi.mjs.map +0 -1
  261. package/dist/filesystem-content-api-DCdNi-co.d.mts +0 -134
  262. package/dist/filesystem-content-api-DCdNi-co.d.mts.map +0 -1
  263. package/dist/index-DxVTFK66.d.mts +0 -105
  264. package/dist/index-DxVTFK66.d.mts.map +0 -1
  265. package/dist/index.d.mts +0 -80
  266. package/dist/index.d.mts.map +0 -1
  267. package/dist/index.mjs +0 -78
  268. package/dist/index.mjs.map +0 -1
  269. package/dist/indexing.d.mts +0 -152
  270. package/dist/indexing.d.mts.map +0 -1
  271. package/dist/indexing.mjs +0 -255
  272. package/dist/indexing.mjs.map +0 -1
  273. package/dist/node.d.mts +0 -373
  274. package/dist/node.d.mts.map +0 -1
  275. package/dist/node.mjs +0 -2572
  276. package/dist/node.mjs.map +0 -1
  277. package/dist/reader.d.mts +0 -15
  278. package/dist/reader.d.mts.map +0 -1
  279. package/dist/reader.mjs +0 -22
  280. package/dist/reader.mjs.map +0 -1
  281. package/dist/schemas/index.d.mts +0 -2
  282. package/dist/schemas/index.mjs +0 -2
  283. package/dist/schemas-CFRD0FIQ.mjs +0 -84
  284. package/dist/schemas-CFRD0FIQ.mjs.map +0 -1
  285. package/dist/site-8oaj1Q60.mjs +0 -366
  286. package/dist/site-8oaj1Q60.mjs.map +0 -1
  287. package/dist/site-index-B_254bCc.d.mts +0 -136
  288. package/dist/site-index-B_254bCc.d.mts.map +0 -1
  289. package/dist/types-DOdldbfD.mjs +0 -34
  290. package/dist/types-DOdldbfD.mjs.map +0 -1
  291. package/dist/types-DjfhS272.d.mts +0 -456
  292. package/dist/types-DjfhS272.d.mts.map +0 -1
  293. package/dist/vxjson-qHrgLGip.mjs +0 -555
  294. package/dist/vxjson-qHrgLGip.mjs.map +0 -1
  295. package/dist/vxjson-serialize-geF6qvpn.mjs +0 -34
  296. package/dist/vxjson-serialize-geF6qvpn.mjs.map +0 -1
  297. package/dist/vxjson-serialize.d.mts +0 -17
  298. package/dist/vxjson-serialize.d.mts.map +0 -1
  299. package/dist/vxjson-serialize.mjs +0 -2
package/src/types.ts ADDED
@@ -0,0 +1,759 @@
1
+ export interface ContentAPIOptions {
2
+ contentRoot: string;
3
+ canvasDir?: string;
4
+
5
+ /**
6
+ * Optional override for the mdx-type pages path. The canonical home for
7
+ * this value is the resolved site's `mdxPages` field in `sites.json`.
8
+ * This option, when present, wins over the sites.json value — useful
9
+ * for tests and programmatic content-api setups that don't want to
10
+ * round-trip through a sites.json file on disk.
11
+ *
12
+ * Decouples the storage location of mdx pages from Conloca's main content
13
+ * tree so projects can host them wherever their renderer expects to read
14
+ * from. The rendering pipeline is the project's own choice — Conloca only
15
+ * owns CRUD on the file bytes.
16
+ *
17
+ * When omitted AND no site in sites.json has `mdxPages`, .mdx files
18
+ * fall back to living alongside Puck pages at
19
+ * `{contentRoot}/{site}/pages/`.
20
+ */
21
+ mdxPagesRoot?: string;
22
+
23
+ /**
24
+ * Default locale for mdx pages. The default locale's files live at
25
+ * `{mdxPagesRoot}/{slug}.mdx` (no locale prefix); other locales live at
26
+ * `{mdxPagesRoot}/{locale}/{slug}.mdx`.
27
+ *
28
+ * If omitted, falls back to the first site's `defaultLocale`, or `'en'`.
29
+ */
30
+ mdxPagesDefaultLocale?: string;
31
+
32
+ /**
33
+ * Site name to associate mdx pages with for pathname collision checking.
34
+ * mdx pages share the URL space with that site's puck pages, so two
35
+ * pages — regardless of type — cannot share a pathname.
36
+ *
37
+ * If omitted, falls back to the first site name in sites.json (or
38
+ * `'default'` when no sites are configured).
39
+ */
40
+ mdxPagesSite?: string;
41
+
42
+ /**
43
+ * The site's supported locales. When provided, this wins over the
44
+ * `globalLocales` field in sites.json. The locale-detection parsers
45
+ * use this list to decide whether a folder or filename suffix that
46
+ * looks locale-shaped (e.g. `de`, `en-US`) is actually a locale or
47
+ * just a folder that happens to match the pattern.
48
+ *
49
+ * Omit to fall back to sites.json (current behavior).
50
+ */
51
+ availableLocales?: string[];
52
+
53
+ /**
54
+ * The site's default locale. Wins over both `mdxPagesDefaultLocale`
55
+ * and the per-site `defaultLocale` in sites.json when provided.
56
+ */
57
+ defaultLocale?: string;
58
+ }
59
+
60
+ // Error response format for all API errors
61
+ export interface APIError {
62
+ error: {
63
+ code: string; // Machine-readable error code (e.g., 'CONTENT_NOT_FOUND', 'STALE_WRITE')
64
+ message: string; // Human-readable error message
65
+ details?: any; // Optional additional error details
66
+ };
67
+ }
68
+
69
+ export interface MDXCompileResponse {
70
+ code: string;
71
+ metadata: Record<string, unknown>;
72
+ /**
73
+ * The content's headings, in document order, carrying the ids the compiled
74
+ * markup puts on them. Editing surfaces render the body inside a sandbox
75
+ * they cannot read, so the outline rides the compile they already request
76
+ * rather than being scraped back off the frame.
77
+ */
78
+ outline: readonly MDXHeading[];
79
+ }
80
+
81
+ /** One heading of compiled MDX: the anchor target and the text to label it with. */
82
+ export interface MDXHeading {
83
+ /** Heading level as authored: 2 for `##`, 3 for `###`. */
84
+ depth: number;
85
+ id: string;
86
+ text: string;
87
+ }
88
+
89
+ // Common error codes
90
+ export const ErrorCodes = {
91
+ // Content errors
92
+ CONTENT_NOT_FOUND: 'CONTENT_NOT_FOUND',
93
+ LOCALE_NOT_FOUND: 'LOCALE_NOT_FOUND',
94
+ COLLECTION_NOT_FOUND: 'COLLECTION_NOT_FOUND',
95
+ SITE_NOT_FOUND: 'SITE_NOT_FOUND',
96
+
97
+ // Write errors
98
+ STALE_WRITE: 'STALE_WRITE',
99
+ ALREADY_EXISTS: 'ALREADY_EXISTS',
100
+ PATHNAME_TAKEN: 'PATHNAME_TAKEN',
101
+ INVALID_PATHNAME: 'INVALID_PATHNAME',
102
+ NAME_TAKEN: 'NAME_TAKEN',
103
+ METADATA_TOO_LARGE: 'METADATA_TOO_LARGE',
104
+ WRITE_ERROR: 'WRITE_ERROR',
105
+
106
+ // Validation errors
107
+ MISSING_REQUIRED_FIELD: 'MISSING_REQUIRED_FIELD',
108
+ INVALID_LOCALE: 'INVALID_LOCALE',
109
+ INVALID_CONTENT_TYPE: 'INVALID_CONTENT_TYPE',
110
+ INVALID_REQUEST: 'INVALID_REQUEST',
111
+ MDX_COMPILE_FAILED: 'MDX_COMPILE_FAILED',
112
+
113
+ // Request errors
114
+ /** A write another website sent through the developer's browser. */
115
+ FORBIDDEN: 'FORBIDDEN',
116
+
117
+ // System errors
118
+ INTERNAL_ERROR: 'INTERNAL_ERROR',
119
+ FETCH_ERROR: 'FETCH_ERROR',
120
+
121
+ // Git errors
122
+ GIT_NOT_REPO: 'GIT_NOT_REPO',
123
+ GIT_COMMIT_FAILED: 'GIT_COMMIT_FAILED',
124
+ GIT_PUSH_FAILED: 'GIT_PUSH_FAILED',
125
+ GIT_PULL_FAILED: 'GIT_PULL_FAILED',
126
+ GIT_STATUS_FAILED: 'GIT_STATUS_FAILED',
127
+
128
+ // Asset errors
129
+ ASSET_NOT_FOUND: 'ASSET_NOT_FOUND',
130
+ ASSET_INVALID_FORMAT: 'ASSET_INVALID_FORMAT',
131
+ ASSET_TOO_LARGE: 'ASSET_TOO_LARGE',
132
+ ASSET_UPLOAD_FAILED: 'ASSET_UPLOAD_FAILED',
133
+
134
+ // Preview errors
135
+ /** The target site is not serving the preview endpoint, so a generated
136
+ * preview URL would 404 there. This describes the target deployment, not a
137
+ * failure of the request — callers must not render it as an error. */
138
+ PREVIEW_NOT_DEPLOYED: 'PREVIEW_NOT_DEPLOYED',
139
+ } as const;
140
+
141
+ export type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
142
+
143
+ // Content type - the format of the content
144
+ export type ContentType = 'puck' | 'mdx' | 'json';
145
+
146
+ // Content data - the actual content (puck, mdx, or json data)
147
+ export interface ContentData {
148
+ puckData?: any;
149
+ mdx?: string;
150
+ data?: Record<string, unknown>;
151
+ }
152
+
153
+ // Content property that extends manifests with actual content
154
+ export interface ContentProp {
155
+ content: ContentData;
156
+ }
157
+
158
+ // Base identity fields shared by all content representations
159
+ export interface ContentIdentity {
160
+ id: string;
161
+ type: ContentType;
162
+ kind: 'fragment' | 'page' | 'data';
163
+ site?: string; // Only for pages
164
+ collection: string;
165
+ }
166
+
167
+ // Locale file data derived from file path
168
+ export interface LocalePathData {
169
+ locale: string;
170
+ pathname?: string; // pages only - derived from file path
171
+ name?: string; // fragments only - derived from filename
172
+ }
173
+
174
+ // Localized content manifest - metadata about translated content without the actual content
175
+ export interface LocaleVersion extends LocalePathData {
176
+ etag: string; // Format: "metaEtag.contentEtag"
177
+ created: string;
178
+ modified: string;
179
+ publishAt?: string;
180
+ unpublishAt?: string;
181
+ previousPathnames?: Record<string, string>; // pages only
182
+ meta: ContentMeta; // title, description, seo, etc.
183
+ /**
184
+ * Path of the file backing this locale, as the hydrating backend knows it.
185
+ * Set during filesystem hydration; absent on backends that do not read
186
+ * files and on manifests built in-memory before the first rescan. Diagnostic only — it exists so an error about this locale can
187
+ * name a file a human can open instead of the opaque content id.
188
+ */
189
+ sourcePath?: string;
190
+ }
191
+
192
+ // Manifest for all locales (what's in the index and returned in listings)
193
+ export interface ContentManifest extends ContentIdentity {
194
+ locales: Record<string, LocaleVersion | undefined>;
195
+ }
196
+
197
+ // Single locale without content (used for updates/changes)
198
+ export interface LocalizedManifest extends ContentIdentity {
199
+ localized: LocaleVersion;
200
+ }
201
+
202
+ // Single locale with content
203
+ export interface LocalizedEntry extends ContentIdentity {
204
+ localized: LocaleVersion & ContentProp;
205
+ }
206
+
207
+ // All locales with content
208
+ export interface ContentEntry extends ContentManifest {
209
+ locales: Record<string, LocaleVersion & ContentProp>;
210
+ }
211
+
212
+ // Result types
213
+ export interface UpdateResult {
214
+ success: boolean;
215
+ etag?: string;
216
+ modified?: Date;
217
+ /**
218
+ * The `invalid_pathname`, `pathname_taken` and `pathname_in_redirects`
219
+ * refusals of a page's new path, and the `invalid_name` and `name_taken`
220
+ * refusals of a fragment or data entry's new name, mean what they mean for a
221
+ * create; a backend that does not tell them apart reports `write_error`.
222
+ */
223
+ reason?:
224
+ | 'not_found'
225
+ | 'stale_write'
226
+ | 'write_error'
227
+ | 'invalid_pathname'
228
+ | 'pathname_taken'
229
+ | 'pathname_in_redirects'
230
+ | 'invalid_name'
231
+ | 'name_taken';
232
+ error?: Error;
233
+ currentEtag?: string;
234
+ conflictDetails?: {
235
+ metaChanged: boolean;
236
+ contentChanged: boolean;
237
+ currentMeta?: ContentMeta;
238
+ currentContent?: ContentData;
239
+ localContent?: ContentData;
240
+ };
241
+ }
242
+
243
+ export interface MoveResult {
244
+ moved: boolean;
245
+ previousPathname?: string;
246
+ files?: string[];
247
+ /** `already_exists` also covers a path another page redirects from; `invalid_pathname` is a malformed path. */
248
+ reason?: 'not_found' | 'already_exists' | 'stale_write' | 'write_error' | 'invalid_pathname';
249
+ error?: Error;
250
+ etag?: string;
251
+ }
252
+
253
+ export interface ContentListResult {
254
+ items: ContentManifest[];
255
+ total: number;
256
+ hasMore?: boolean;
257
+ }
258
+
259
+ // Filter types
260
+ export interface GlobalFilters {
261
+ site?: string;
262
+ collection?: string;
263
+ locales?: string[];
264
+ type?: 'puck' | 'mdx' | 'json';
265
+ published?: boolean;
266
+ kind?: 'fragment' | 'page' | 'data';
267
+ localization?: 'complete' | 'partial' | 'one';
268
+ missingLocales?: string[];
269
+ }
270
+
271
+ export interface SiteFilters {
272
+ collection?: string;
273
+ locales?: string[];
274
+ type?: 'puck' | 'mdx';
275
+ published?: boolean;
276
+ }
277
+
278
+ export interface FragmentFilters {
279
+ collection?: string;
280
+ locales?: string[];
281
+ }
282
+
283
+ export interface FindOptions {
284
+ excludeSites?: string[];
285
+ includeUnpublished?: boolean;
286
+ }
287
+
288
+ // Input types
289
+
290
+ export interface CreateContentInput {
291
+ kind: 'fragment' | 'page' | 'data';
292
+ site?: string; // Required for pages, must be undefined for fragments and data
293
+ collection: string;
294
+ type: ContentType;
295
+ created?: string; // Optional, will use current time if not provided
296
+ name?: string; // Internal identifier for fragments and data (same across all locales)
297
+ meta?: Partial<ContentMeta>; // Shared metadata defaults (applied to all locales)
298
+ locales: {
299
+ [locale: string]: {
300
+ pathname?: string; // for pages (locale-specific route)
301
+ publishAt?: string | null | false;
302
+ unpublishAt?: string | null | false;
303
+ meta?: Partial<ContentMeta>;
304
+ } & ContentProp;
305
+ };
306
+ }
307
+
308
+ export interface CreatePageInput {
309
+ collection: string;
310
+ locales: {
311
+ [locale: string]: {
312
+ pathname: string; // Required pathname for each locale
313
+ publishAt?: string | null | false;
314
+ unpublishAt?: string | null | false;
315
+ meta: ContentMeta; // Required metadata with title for each locale
316
+ content: {
317
+ puckData: any;
318
+ };
319
+ };
320
+ };
321
+ }
322
+
323
+ export interface CreateFragmentInput {
324
+ collection: string;
325
+ type: 'mdx';
326
+ name: string; // Internal identifier (same across all locales)
327
+ meta?: Partial<ContentMeta>; // Shared metadata defaults
328
+ locales: {
329
+ [locale: string]: {
330
+ publishAt?: string | null | false;
331
+ unpublishAt?: string | null | false;
332
+ meta?: Partial<ContentMeta>; // Locale-specific metadata overrides
333
+ content: {
334
+ mdx: string;
335
+ };
336
+ };
337
+ };
338
+ }
339
+
340
+ export interface UpdateLocaleInput {
341
+ id: string;
342
+ locale: string;
343
+ data: LocaleUpdateData;
344
+ etag: string;
345
+ }
346
+
347
+ /**
348
+ * A metadata update as a dialog sends it: absent keys are left alone, null
349
+ * clears the stored field. "Cleared" used to travel as undefined, which
350
+ * JSON.stringify drops, so the server's shallow merge silently kept the old
351
+ * value — the dialog reported success and the field reappeared on refresh.
352
+ */
353
+ export type ContentMetaPatch = { [K in keyof ContentMeta]?: ContentMeta[K] | null };
354
+
355
+ export interface LocaleUpdateData {
356
+ pathname?: string; // for pages - update pathname
357
+ name?: string; // for fragments - update name (filename)
358
+ publishAt?: string | null | false;
359
+ unpublishAt?: string | null | false;
360
+ modified?: string; // Optional, will use current time if not provided
361
+ meta?: ContentMetaPatch;
362
+ content?: ContentData;
363
+ }
364
+
365
+ export interface DeleteLocaleInput {
366
+ id: string;
367
+ locale: string;
368
+ etag: string;
369
+ }
370
+
371
+ // Sites configuration
372
+ export interface SitesConfig {
373
+ sites: {
374
+ [siteName: string]: {
375
+ locales: string[];
376
+ defaultLocale: string;
377
+ domains?: {
378
+ [locale: string]: string;
379
+ };
380
+ /**
381
+ * Optional filesystem path for this site's mdx-type pages.
382
+ * When set, .mdx files under this path are surfaced in the CMS
383
+ * as `kind: 'page'` + `type: 'mdx'` content owned by this site.
384
+ *
385
+ * Path is interpreted relative to the project root (the same
386
+ * cwd Astro uses), not the content root, so it can live anywhere
387
+ * the renderer expects (e.g. `./src/content/docs` for Starlight).
388
+ *
389
+ * When omitted, .mdx files for this site are expected to live
390
+ * alongside Puck (`.vxjson`) pages at `{contentRoot}/{site}/pages/`
391
+ * — the file extension determines the page type.
392
+ */
393
+ mdxPages?: string;
394
+ };
395
+ };
396
+ globalLocales: string[];
397
+ }
398
+
399
+ // Batch operations
400
+ export interface BatchResult {
401
+ operations: BatchOperationResult[];
402
+ success: boolean; // true if all operations succeeded
403
+ failed: number;
404
+ updated: number; // number of successfully updated items
405
+ }
406
+
407
+ /**
408
+ * Any value that survives a JSON round trip.
409
+ *
410
+ * Content metadata is serialised into `.vxjson` files on disk, so JSON is the
411
+ * real ceiling on what a meta field can hold. Saying that concretely — rather
412
+ * than `unknown` — keeps the type honest in both directions: readers still
413
+ * have to narrow before using a value, and the structure stays visible to
414
+ * anything that has to prove the type is serialisable in order to carry it.
415
+ */
416
+ export type JsonValue = string | number | boolean | null | JsonArray | JsonObject;
417
+
418
+ /**
419
+ * The array arm of {@link JsonValue}. An interface for the same reason as
420
+ * {@link JsonObject}; `Array<JsonValue>` rather than `JsonValue[]` only
421
+ * because `extends` has no shorthand-array form to use here.
422
+ */
423
+ export interface JsonArray extends Array<JsonValue> {}
424
+
425
+ /**
426
+ * The object arm of {@link JsonValue}, kept as an interface rather than an
427
+ * inline type so the recursion terminates: a structural checker walking this
428
+ * type can defer the interface instead of re-expanding it at every level.
429
+ */
430
+ export interface JsonObject {
431
+ [key: string]: JsonValue;
432
+ }
433
+
434
+ /**
435
+ * Host-declared page-meta fields. Sites augment this from their `pageSchemas`
436
+ * so listing components see `excerpt` / `featuredImage` as real keys instead
437
+ * of an open bag. Empty until a host writes `declare module '@conloca/content-api'`.
438
+ */
439
+ // biome-ignore lint/suspicious/noEmptyInterface: empty interface is the module-augmentation hole hosts fill
440
+ export interface HostPageMeta {}
441
+
442
+ // Common metadata structure for all content types (stored in 'meta' field)
443
+ export interface ContentMeta extends HostPageMeta {
444
+ // Required
445
+ title: string; // Display name for UI
446
+
447
+ // Common optional fields
448
+ description?: string;
449
+ author?: string;
450
+ tags?: string[];
451
+
452
+ // SEO (mainly for pages)
453
+ keywords?: string[];
454
+ ogTitle?: string;
455
+ ogDescription?: string;
456
+ ogImage?: string;
457
+
458
+ // Leftover host fields that were not declared on HostPageMeta.
459
+ [key: string]: JsonValue | undefined;
460
+ }
461
+
462
+ // File format types
463
+
464
+ /**
465
+ * VXJSON (Variant JSON) File Format
466
+ *
467
+ * VXJSON is a specialized JSON format that guarantees:
468
+ * 1. The root is always an object (never an array or primitive)
469
+ * 2. The "content" field always comes last in the object
470
+ * 3. Field order is deterministic for consistent ETag calculation
471
+ *
472
+ * This format enables efficient streaming ETag calculation where metadata
473
+ * can be hashed separately from content, supporting partial updates and
474
+ * conflict resolution in CMS scenarios.
475
+ *
476
+ * Files using this format have the extension .vxjson
477
+ */
478
+ export interface VXJSONFile {
479
+ id: string;
480
+ type: ContentType;
481
+ created: string;
482
+ modified: string;
483
+ publishAt?: string;
484
+ unpublishAt?: string;
485
+ previousPathnames?: Record<string, string>;
486
+ meta: ContentMeta;
487
+ content: ContentData; // Always last field in VXJSON
488
+ }
489
+
490
+ export interface MDXFrontmatter {
491
+ id: string;
492
+ type: 'mdx';
493
+ created: string;
494
+ modified: string;
495
+ publishAt?: string;
496
+ unpublishAt?: string;
497
+ meta: ContentMeta;
498
+ }
499
+
500
+ // All properties are declared in each variant to make destructuring safe and predictable
501
+ export type WriteResult =
502
+ | { success: true; etag: string; modified?: Date; reason?: undefined; error?: undefined; currentEtag?: undefined }
503
+ | {
504
+ success: false;
505
+ etag?: undefined;
506
+ modified?: undefined;
507
+ reason: 'stale_write';
508
+ error?: undefined;
509
+ currentEtag: string;
510
+ }
511
+ | {
512
+ success: false;
513
+ etag?: undefined;
514
+ modified?: undefined;
515
+ reason: 'already_exists';
516
+ error?: undefined;
517
+ currentEtag: string;
518
+ }
519
+ | {
520
+ success: false;
521
+ etag?: undefined;
522
+ modified?: undefined;
523
+ reason: 'write_error';
524
+ error: Error;
525
+ currentEtag?: string;
526
+ };
527
+
528
+ export interface DeleteResult {
529
+ success: boolean;
530
+ error?: Error;
531
+ reason?: 'stale_write' | 'not_found' | 'delete_error';
532
+ currentEtag?: string;
533
+ }
534
+
535
+ export interface CreateResult {
536
+ success: boolean;
537
+ id?: string;
538
+ etag?: string;
539
+ created?: Date;
540
+ reason?:
541
+ | 'already_exists'
542
+ | 'write_error'
543
+ | 'invalid_name'
544
+ | 'invalid_pathname'
545
+ | 'name_taken'
546
+ | 'pathname_taken'
547
+ | 'pathname_in_redirects'
548
+ | 'invalid_collection'
549
+ | 'invalid_locale'
550
+ | 'metadata_too_large'
551
+ | 'missing_field'
552
+ | 'unknown_site'
553
+ | 'no_sites_configured';
554
+ error?: Error;
555
+ existingId?: string;
556
+ /** The input field a caller has to change, when the failure points at one. */
557
+ field?: string;
558
+ }
559
+
560
+ export interface BatchOperationResult {
561
+ id: string;
562
+ locale: string;
563
+ updated: boolean;
564
+ error?: Error;
565
+ etag?: string;
566
+ }
567
+
568
+ // ===== Data Context Types =====
569
+
570
+ /**
571
+ * Minimal page reference for listing/navigation in data context.
572
+ *
573
+ * Used in dataBindings.pages for blog listing components
574
+ * and getStaticPaths() to enumerate available pages.
575
+ */
576
+ export interface PageReference {
577
+ /** Page identifier. */
578
+ id: string;
579
+ /** URL pathname. */
580
+ pathname: string;
581
+ /** Page title (if available without full load). */
582
+ title?: string;
583
+ /** Content collection. */
584
+ collection: string;
585
+ /** Page metadata from content. */
586
+ meta?: ContentMeta;
587
+ /** Page timestamps for sorting and display. */
588
+ timestamps?: {
589
+ /** When the page was created. */
590
+ created?: Date;
591
+ /** When the page was last saved. Page lists never order by it, so an edit does not move a page. */
592
+ modified?: Date;
593
+ /**
594
+ * When the page went or goes live: its publish time (`publishAt`), or its
595
+ * creation time when it has none. Page lists order by it.
596
+ */
597
+ published?: Date;
598
+ };
599
+ }
600
+
601
+ /**
602
+ * A single entry from a data collection.
603
+ *
604
+ * Simplified representation of collection data for use in component resolvers.
605
+ */
606
+ export interface DataCollectionEntry {
607
+ /** Unique identifier for the entry. */
608
+ id: string;
609
+ /** Human-readable name of the entry. */
610
+ name: string;
611
+ /** The entry's data content. */
612
+ data: Record<string, unknown>;
613
+ /** Optional metadata for the entry. */
614
+ meta?: Record<string, unknown>;
615
+ }
616
+
617
+ /**
618
+ * Context Puck hands every block of a page as its metadata: to `resolveData`
619
+ * as `metadata` and to `render` as `puck.metadata`.
620
+ *
621
+ * Contains the page being rendered, the data its route binds and contextual
622
+ * information for data-driven component rendering.
623
+ */
624
+ export interface DataContext {
625
+ /** The page being rendered, with its settings. */
626
+ page: PageReference;
627
+ /** Collection data keyed by collection name. */
628
+ collections: Record<string, DataCollectionEntry[]>;
629
+ /** Pages matching the dataBindings.pages filter. */
630
+ pages?: PageReference[];
631
+ /** Current locale used for data fetching. */
632
+ locale: string;
633
+ /** Site name from routing configuration. */
634
+ siteName: string;
635
+ }
636
+
637
+ /**
638
+ * Configuration for automatic data collection injection into Puck components.
639
+ *
640
+ * Allows components to declare data dependencies on Conloca data collections,
641
+ * which are automatically fetched and injected via Puck's metadata system.
642
+ *
643
+ * @example Route with data bindings
644
+ * ```typescript
645
+ * conlocaCMS({
646
+ * routing: {
647
+ * routes: {
648
+ * pages: {
649
+ * pattern: '/[...slug]',
650
+ * dataBindings: {
651
+ * collections: ['team', 'testimonials'],
652
+ * },
653
+ * },
654
+ * },
655
+ * },
656
+ * });
657
+ * ```
658
+ */
659
+ export interface DataBindingConfig {
660
+ /**
661
+ * Collections to fetch and inject into component resolvers.
662
+ *
663
+ * Each collection name must match a data collection in the content directory.
664
+ * The fetched data will be available in `metadata.collections[collectionName]`
665
+ * within Puck component resolvers.
666
+ *
667
+ * @example ['team', 'testimonials', 'products']
668
+ */
669
+ collections?: string[];
670
+
671
+ /**
672
+ * Locale override for data fetching.
673
+ *
674
+ * Defaults to the route's locale setting (from routing.locale).
675
+ * Use this to fetch data in a specific locale regardless of route config.
676
+ */
677
+ locale?: string;
678
+
679
+ /**
680
+ * Page discovery configuration for listing pages by path prefix.
681
+ *
682
+ * Enables components to access lists of pages matching a URL pattern,
683
+ * useful for blog listings, category pages, and site navigation.
684
+ *
685
+ * @example Blog listing page
686
+ * ```typescript
687
+ * {
688
+ * pattern: '/blog',
689
+ * dataBindings: {
690
+ * pages: {
691
+ * prefix: '/blog/',
692
+ * sort: 'date-desc',
693
+ * limit: 10,
694
+ * },
695
+ * },
696
+ * }
697
+ * ```
698
+ */
699
+ pages?: {
700
+ /**
701
+ * Path prefix to filter pages.
702
+ *
703
+ * Only pages whose pathname starts with this prefix are included.
704
+ * The listing page itself is excluded.
705
+ *
706
+ * @example '/blog/' matches '/blog/post-1', '/blog/post-2'
707
+ */
708
+ prefix: string;
709
+
710
+ /**
711
+ * Maximum number of pages to return.
712
+ *
713
+ * Useful for showing "latest N posts" on a homepage or sidebar.
714
+ */
715
+ limit?: number;
716
+
717
+ /**
718
+ * Sort order for returned pages.
719
+ *
720
+ * - 'date-desc': Newest first by `timestamps.published`, so editing a page never moves it
721
+ * - 'date-asc': Oldest first
722
+ * - 'title': Alphabetical by title
723
+ *
724
+ * Pages that tie are listed by pathname, then id, so every surface shows one order.
725
+ *
726
+ * @default 'date-desc'
727
+ */
728
+ sort?: 'date-desc' | 'date-asc' | 'title';
729
+ };
730
+ }
731
+
732
+ /**
733
+ * What an editor needs to build a page's {@link DataContext} the way the
734
+ * published page gets it: the site and locale the routes read under, and every
735
+ * page collection a route serves, keyed by collection, with that route's
736
+ * bindings. The first route wins when two share a collection.
737
+ */
738
+ export interface EditorDataBindings {
739
+ siteName: string;
740
+ locale: string;
741
+ routes: Record<string, DataBindingConfig>;
742
+ }
743
+
744
+ // Internal type for locale data returned by readLocaleFile
745
+ export interface LocaleFileData {
746
+ locale: string;
747
+ etag: string;
748
+ created: string;
749
+ modified: string;
750
+ publishAt?: string;
751
+ unpublishAt?: string;
752
+ previousPathnames?: Record<string, string>;
753
+ meta: ContentMeta;
754
+ content: {
755
+ puckData?: any;
756
+ mdx?: string;
757
+ data?: Record<string, unknown>;
758
+ };
759
+ }