convex-cms 0.0.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 (379) hide show
  1. package/dist/cli/commands/admin.d.ts +16 -0
  2. package/dist/cli/commands/admin.d.ts.map +1 -0
  3. package/dist/cli/commands/admin.js +88 -0
  4. package/dist/cli/commands/admin.js.map +1 -0
  5. package/dist/cli/index.d.ts +3 -0
  6. package/dist/cli/index.d.ts.map +1 -0
  7. package/dist/cli/index.js +18 -0
  8. package/dist/cli/index.js.map +1 -0
  9. package/dist/cli/utils/detectConvexUrl.d.ts +13 -0
  10. package/dist/cli/utils/detectConvexUrl.d.ts.map +1 -0
  11. package/dist/cli/utils/detectConvexUrl.js +48 -0
  12. package/dist/cli/utils/detectConvexUrl.js.map +1 -0
  13. package/dist/cli/utils/openBrowser.d.ts +7 -0
  14. package/dist/cli/utils/openBrowser.d.ts.map +1 -0
  15. package/dist/cli/utils/openBrowser.js +17 -0
  16. package/dist/cli/utils/openBrowser.js.map +1 -0
  17. package/dist/client/admin-config.d.ts +126 -0
  18. package/dist/client/admin-config.d.ts.map +1 -0
  19. package/dist/client/admin-config.js +117 -0
  20. package/dist/client/admin-config.js.map +1 -0
  21. package/dist/client/adminApi.d.ts +2273 -0
  22. package/dist/client/adminApi.d.ts.map +1 -0
  23. package/dist/client/adminApi.js +716 -0
  24. package/dist/client/adminApi.js.map +1 -0
  25. package/dist/client/agentTools.d.ts +933 -0
  26. package/dist/client/agentTools.d.ts.map +1 -0
  27. package/dist/client/agentTools.js +1004 -0
  28. package/dist/client/agentTools.js.map +1 -0
  29. package/dist/client/argTypes.d.ts +212 -0
  30. package/dist/client/argTypes.d.ts.map +1 -0
  31. package/dist/client/argTypes.js +5 -0
  32. package/dist/client/argTypes.js.map +1 -0
  33. package/dist/client/field-types.d.ts +55 -0
  34. package/dist/client/field-types.d.ts.map +1 -0
  35. package/dist/client/field-types.js +152 -0
  36. package/dist/client/field-types.js.map +1 -0
  37. package/dist/client/index.d.ts +189 -0
  38. package/dist/client/index.d.ts.map +1 -0
  39. package/dist/client/index.js +668 -0
  40. package/dist/client/index.js.map +1 -0
  41. package/dist/client/queryBuilder.d.ts +765 -0
  42. package/dist/client/queryBuilder.d.ts.map +1 -0
  43. package/dist/client/queryBuilder.js +970 -0
  44. package/dist/client/queryBuilder.js.map +1 -0
  45. package/dist/client/schema/codegen.d.ts +128 -0
  46. package/dist/client/schema/codegen.d.ts.map +1 -0
  47. package/dist/client/schema/codegen.js +318 -0
  48. package/dist/client/schema/codegen.js.map +1 -0
  49. package/dist/client/schema/defineContentType.d.ts +221 -0
  50. package/dist/client/schema/defineContentType.d.ts.map +1 -0
  51. package/dist/client/schema/defineContentType.js +380 -0
  52. package/dist/client/schema/defineContentType.js.map +1 -0
  53. package/dist/client/schema/index.d.ts +85 -0
  54. package/dist/client/schema/index.d.ts.map +1 -0
  55. package/dist/client/schema/index.js +92 -0
  56. package/dist/client/schema/index.js.map +1 -0
  57. package/dist/client/schema/schemaDrift.d.ts +199 -0
  58. package/dist/client/schema/schemaDrift.d.ts.map +1 -0
  59. package/dist/client/schema/schemaDrift.js +340 -0
  60. package/dist/client/schema/schemaDrift.js.map +1 -0
  61. package/dist/client/schema/typedClient.d.ts +401 -0
  62. package/dist/client/schema/typedClient.d.ts.map +1 -0
  63. package/dist/client/schema/typedClient.js +269 -0
  64. package/dist/client/schema/typedClient.js.map +1 -0
  65. package/dist/client/schema/types.d.ts +477 -0
  66. package/dist/client/schema/types.d.ts.map +1 -0
  67. package/dist/client/schema/types.js +39 -0
  68. package/dist/client/schema/types.js.map +1 -0
  69. package/dist/client/types.d.ts +449 -0
  70. package/dist/client/types.d.ts.map +1 -0
  71. package/dist/client/types.js +149 -0
  72. package/dist/client/types.js.map +1 -0
  73. package/dist/client/workflows.d.ts +51 -0
  74. package/dist/client/workflows.d.ts.map +1 -0
  75. package/dist/client/workflows.js +103 -0
  76. package/dist/client/workflows.js.map +1 -0
  77. package/dist/client/wrapper.d.ts +2198 -0
  78. package/dist/client/wrapper.d.ts.map +1 -0
  79. package/dist/client/wrapper.js +2651 -0
  80. package/dist/client/wrapper.js.map +1 -0
  81. package/dist/component/_generated/api.d.ts +124 -0
  82. package/dist/component/_generated/api.d.ts.map +1 -0
  83. package/dist/component/_generated/api.js +31 -0
  84. package/dist/component/_generated/api.js.map +1 -0
  85. package/dist/component/_generated/component.d.ts +4321 -0
  86. package/dist/component/_generated/component.d.ts.map +1 -0
  87. package/dist/component/_generated/component.js +11 -0
  88. package/dist/component/_generated/component.js.map +1 -0
  89. package/dist/component/_generated/dataModel.d.ts +46 -0
  90. package/dist/component/_generated/dataModel.d.ts.map +1 -0
  91. package/dist/component/_generated/dataModel.js +11 -0
  92. package/dist/component/_generated/dataModel.js.map +1 -0
  93. package/dist/component/_generated/server.d.ts +121 -0
  94. package/dist/component/_generated/server.d.ts.map +1 -0
  95. package/dist/component/_generated/server.js +78 -0
  96. package/dist/component/_generated/server.js.map +1 -0
  97. package/dist/component/auditLog.d.ts +410 -0
  98. package/dist/component/auditLog.d.ts.map +1 -0
  99. package/dist/component/auditLog.js +607 -0
  100. package/dist/component/auditLog.js.map +1 -0
  101. package/dist/component/authorization.d.ts +323 -0
  102. package/dist/component/authorization.d.ts.map +1 -0
  103. package/dist/component/authorization.js +464 -0
  104. package/dist/component/authorization.js.map +1 -0
  105. package/dist/component/authorizationHooks.d.ts +184 -0
  106. package/dist/component/authorizationHooks.d.ts.map +1 -0
  107. package/dist/component/authorizationHooks.js +521 -0
  108. package/dist/component/authorizationHooks.js.map +1 -0
  109. package/dist/component/bulkOperations.d.ts +200 -0
  110. package/dist/component/bulkOperations.d.ts.map +1 -0
  111. package/dist/component/bulkOperations.js +568 -0
  112. package/dist/component/bulkOperations.js.map +1 -0
  113. package/dist/component/contentEntries.d.ts +719 -0
  114. package/dist/component/contentEntries.d.ts.map +1 -0
  115. package/dist/component/contentEntries.js +1617 -0
  116. package/dist/component/contentEntries.js.map +1 -0
  117. package/dist/component/contentEntryMutations.d.ts +505 -0
  118. package/dist/component/contentEntryMutations.d.ts.map +1 -0
  119. package/dist/component/contentEntryMutations.js +1009 -0
  120. package/dist/component/contentEntryMutations.js.map +1 -0
  121. package/dist/component/contentEntryValidation.d.ts +115 -0
  122. package/dist/component/contentEntryValidation.d.ts.map +1 -0
  123. package/dist/component/contentEntryValidation.js +546 -0
  124. package/dist/component/contentEntryValidation.js.map +1 -0
  125. package/dist/component/contentLock.d.ts +328 -0
  126. package/dist/component/contentLock.d.ts.map +1 -0
  127. package/dist/component/contentLock.js +471 -0
  128. package/dist/component/contentLock.js.map +1 -0
  129. package/dist/component/contentTypeMigration.d.ts +411 -0
  130. package/dist/component/contentTypeMigration.d.ts.map +1 -0
  131. package/dist/component/contentTypeMigration.js +805 -0
  132. package/dist/component/contentTypeMigration.js.map +1 -0
  133. package/dist/component/contentTypeMutations.d.ts +975 -0
  134. package/dist/component/contentTypeMutations.d.ts.map +1 -0
  135. package/dist/component/contentTypeMutations.js +768 -0
  136. package/dist/component/contentTypeMutations.js.map +1 -0
  137. package/dist/component/contentTypes.d.ts +538 -0
  138. package/dist/component/contentTypes.d.ts.map +1 -0
  139. package/dist/component/contentTypes.js +304 -0
  140. package/dist/component/contentTypes.js.map +1 -0
  141. package/dist/component/convex.config.d.ts +42 -0
  142. package/dist/component/convex.config.d.ts.map +1 -0
  143. package/dist/component/convex.config.js +43 -0
  144. package/dist/component/convex.config.js.map +1 -0
  145. package/dist/component/documentTypes.d.ts +186 -0
  146. package/dist/component/documentTypes.d.ts.map +1 -0
  147. package/dist/component/documentTypes.js +23 -0
  148. package/dist/component/documentTypes.js.map +1 -0
  149. package/dist/component/eventEmitter.d.ts +281 -0
  150. package/dist/component/eventEmitter.d.ts.map +1 -0
  151. package/dist/component/eventEmitter.js +300 -0
  152. package/dist/component/eventEmitter.js.map +1 -0
  153. package/dist/component/exportImport.d.ts +1120 -0
  154. package/dist/component/exportImport.d.ts.map +1 -0
  155. package/dist/component/exportImport.js +931 -0
  156. package/dist/component/exportImport.js.map +1 -0
  157. package/dist/component/index.d.ts +28 -0
  158. package/dist/component/index.d.ts.map +1 -0
  159. package/dist/component/index.js +142 -0
  160. package/dist/component/index.js.map +1 -0
  161. package/dist/component/lib/deepReferenceResolver.d.ts +252 -0
  162. package/dist/component/lib/deepReferenceResolver.d.ts.map +1 -0
  163. package/dist/component/lib/deepReferenceResolver.js +601 -0
  164. package/dist/component/lib/deepReferenceResolver.js.map +1 -0
  165. package/dist/component/lib/errors.d.ts +306 -0
  166. package/dist/component/lib/errors.d.ts.map +1 -0
  167. package/dist/component/lib/errors.js +407 -0
  168. package/dist/component/lib/errors.js.map +1 -0
  169. package/dist/component/lib/index.d.ts +10 -0
  170. package/dist/component/lib/index.d.ts.map +1 -0
  171. package/dist/component/lib/index.js +33 -0
  172. package/dist/component/lib/index.js.map +1 -0
  173. package/dist/component/lib/mediaReferenceResolver.d.ts +217 -0
  174. package/dist/component/lib/mediaReferenceResolver.d.ts.map +1 -0
  175. package/dist/component/lib/mediaReferenceResolver.js +326 -0
  176. package/dist/component/lib/mediaReferenceResolver.js.map +1 -0
  177. package/dist/component/lib/metadataExtractor.d.ts +245 -0
  178. package/dist/component/lib/metadataExtractor.d.ts.map +1 -0
  179. package/dist/component/lib/metadataExtractor.js +548 -0
  180. package/dist/component/lib/metadataExtractor.js.map +1 -0
  181. package/dist/component/lib/mutationAuth.d.ts +95 -0
  182. package/dist/component/lib/mutationAuth.d.ts.map +1 -0
  183. package/dist/component/lib/mutationAuth.js +146 -0
  184. package/dist/component/lib/mutationAuth.js.map +1 -0
  185. package/dist/component/lib/queries.d.ts +17 -0
  186. package/dist/component/lib/queries.d.ts.map +1 -0
  187. package/dist/component/lib/queries.js +49 -0
  188. package/dist/component/lib/queries.js.map +1 -0
  189. package/dist/component/lib/ragContentChunker.d.ts +423 -0
  190. package/dist/component/lib/ragContentChunker.d.ts.map +1 -0
  191. package/dist/component/lib/ragContentChunker.js +897 -0
  192. package/dist/component/lib/ragContentChunker.js.map +1 -0
  193. package/dist/component/lib/referenceResolver.d.ts +175 -0
  194. package/dist/component/lib/referenceResolver.d.ts.map +1 -0
  195. package/dist/component/lib/referenceResolver.js +293 -0
  196. package/dist/component/lib/referenceResolver.js.map +1 -0
  197. package/dist/component/lib/slugGenerator.d.ts +71 -0
  198. package/dist/component/lib/slugGenerator.d.ts.map +1 -0
  199. package/dist/component/lib/slugGenerator.js +207 -0
  200. package/dist/component/lib/slugGenerator.js.map +1 -0
  201. package/dist/component/lib/slugUniqueness.d.ts +131 -0
  202. package/dist/component/lib/slugUniqueness.d.ts.map +1 -0
  203. package/dist/component/lib/slugUniqueness.js +229 -0
  204. package/dist/component/lib/slugUniqueness.js.map +1 -0
  205. package/dist/component/lib/softDelete.d.ts +18 -0
  206. package/dist/component/lib/softDelete.d.ts.map +1 -0
  207. package/dist/component/lib/softDelete.js +29 -0
  208. package/dist/component/lib/softDelete.js.map +1 -0
  209. package/dist/component/localeFallbackChain.d.ts +410 -0
  210. package/dist/component/localeFallbackChain.d.ts.map +1 -0
  211. package/dist/component/localeFallbackChain.js +467 -0
  212. package/dist/component/localeFallbackChain.js.map +1 -0
  213. package/dist/component/localeFields.d.ts +508 -0
  214. package/dist/component/localeFields.d.ts.map +1 -0
  215. package/dist/component/localeFields.js +592 -0
  216. package/dist/component/localeFields.js.map +1 -0
  217. package/dist/component/mediaAssetMutations.d.ts +235 -0
  218. package/dist/component/mediaAssetMutations.d.ts.map +1 -0
  219. package/dist/component/mediaAssetMutations.js +558 -0
  220. package/dist/component/mediaAssetMutations.js.map +1 -0
  221. package/dist/component/mediaAssets.d.ts +168 -0
  222. package/dist/component/mediaAssets.d.ts.map +1 -0
  223. package/dist/component/mediaAssets.js +618 -0
  224. package/dist/component/mediaAssets.js.map +1 -0
  225. package/dist/component/mediaFolderMutations.d.ts +642 -0
  226. package/dist/component/mediaFolderMutations.d.ts.map +1 -0
  227. package/dist/component/mediaFolderMutations.js +849 -0
  228. package/dist/component/mediaFolderMutations.js.map +1 -0
  229. package/dist/component/mediaUploadMutations.d.ts +136 -0
  230. package/dist/component/mediaUploadMutations.d.ts.map +1 -0
  231. package/dist/component/mediaUploadMutations.js +205 -0
  232. package/dist/component/mediaUploadMutations.js.map +1 -0
  233. package/dist/component/mediaVariantMutations.d.ts +468 -0
  234. package/dist/component/mediaVariantMutations.d.ts.map +1 -0
  235. package/dist/component/mediaVariantMutations.js +737 -0
  236. package/dist/component/mediaVariantMutations.js.map +1 -0
  237. package/dist/component/mediaVariants.d.ts +525 -0
  238. package/dist/component/mediaVariants.d.ts.map +1 -0
  239. package/dist/component/mediaVariants.js +661 -0
  240. package/dist/component/mediaVariants.js.map +1 -0
  241. package/dist/component/ragContentIndexer.d.ts +595 -0
  242. package/dist/component/ragContentIndexer.d.ts.map +1 -0
  243. package/dist/component/ragContentIndexer.js +794 -0
  244. package/dist/component/ragContentIndexer.js.map +1 -0
  245. package/dist/component/rateLimitHooks.d.ts +266 -0
  246. package/dist/component/rateLimitHooks.d.ts.map +1 -0
  247. package/dist/component/rateLimitHooks.js +412 -0
  248. package/dist/component/rateLimitHooks.js.map +1 -0
  249. package/dist/component/roles.d.ts +649 -0
  250. package/dist/component/roles.d.ts.map +1 -0
  251. package/dist/component/roles.js +884 -0
  252. package/dist/component/roles.js.map +1 -0
  253. package/dist/component/scheduledPublish.d.ts +182 -0
  254. package/dist/component/scheduledPublish.d.ts.map +1 -0
  255. package/dist/component/scheduledPublish.js +304 -0
  256. package/dist/component/scheduledPublish.js.map +1 -0
  257. package/dist/component/schema.d.ts +4114 -0
  258. package/dist/component/schema.d.ts.map +1 -0
  259. package/dist/component/schema.js +469 -0
  260. package/dist/component/schema.js.map +1 -0
  261. package/dist/component/taxonomies.d.ts +476 -0
  262. package/dist/component/taxonomies.d.ts.map +1 -0
  263. package/dist/component/taxonomies.js +785 -0
  264. package/dist/component/taxonomies.js.map +1 -0
  265. package/dist/component/taxonomyMutations.d.ts +206 -0
  266. package/dist/component/taxonomyMutations.d.ts.map +1 -0
  267. package/dist/component/taxonomyMutations.js +1001 -0
  268. package/dist/component/taxonomyMutations.js.map +1 -0
  269. package/dist/component/trash.d.ts +265 -0
  270. package/dist/component/trash.d.ts.map +1 -0
  271. package/dist/component/trash.js +621 -0
  272. package/dist/component/trash.js.map +1 -0
  273. package/dist/component/types.d.ts +4 -0
  274. package/dist/component/types.d.ts.map +1 -0
  275. package/dist/component/types.js +2 -0
  276. package/dist/component/types.js.map +1 -0
  277. package/dist/component/userContext.d.ts +508 -0
  278. package/dist/component/userContext.d.ts.map +1 -0
  279. package/dist/component/userContext.js +615 -0
  280. package/dist/component/userContext.js.map +1 -0
  281. package/dist/component/validation.d.ts +387 -0
  282. package/dist/component/validation.d.ts.map +1 -0
  283. package/dist/component/validation.js +1052 -0
  284. package/dist/component/validation.js.map +1 -0
  285. package/dist/component/validators.d.ts +4645 -0
  286. package/dist/component/validators.d.ts.map +1 -0
  287. package/dist/component/validators.js +641 -0
  288. package/dist/component/validators.js.map +1 -0
  289. package/dist/component/versionMutations.d.ts +216 -0
  290. package/dist/component/versionMutations.d.ts.map +1 -0
  291. package/dist/component/versionMutations.js +321 -0
  292. package/dist/component/versionMutations.js.map +1 -0
  293. package/dist/component/webhookTrigger.d.ts +770 -0
  294. package/dist/component/webhookTrigger.d.ts.map +1 -0
  295. package/dist/component/webhookTrigger.js +1413 -0
  296. package/dist/component/webhookTrigger.js.map +1 -0
  297. package/dist/react/index.d.ts +316 -0
  298. package/dist/react/index.d.ts.map +1 -0
  299. package/dist/react/index.js +558 -0
  300. package/dist/react/index.js.map +1 -0
  301. package/dist/test.d.ts +2230 -0
  302. package/dist/test.d.ts.map +1 -0
  303. package/dist/test.js +1107 -0
  304. package/dist/test.js.map +1 -0
  305. package/package.json +95 -0
  306. package/src/cli/commands/admin.ts +104 -0
  307. package/src/cli/index.ts +21 -0
  308. package/src/cli/utils/detectConvexUrl.ts +54 -0
  309. package/src/cli/utils/openBrowser.ts +16 -0
  310. package/src/client/admin-config.ts +138 -0
  311. package/src/client/adminApi.ts +942 -0
  312. package/src/client/agentTools.ts +1311 -0
  313. package/src/client/argTypes.ts +316 -0
  314. package/src/client/field-types.ts +187 -0
  315. package/src/client/index.ts +1301 -0
  316. package/src/client/queryBuilder.ts +1100 -0
  317. package/src/client/schema/codegen.ts +500 -0
  318. package/src/client/schema/defineContentType.ts +501 -0
  319. package/src/client/schema/index.ts +169 -0
  320. package/src/client/schema/schemaDrift.ts +574 -0
  321. package/src/client/schema/typedClient.ts +688 -0
  322. package/src/client/schema/types.ts +666 -0
  323. package/src/client/types.ts +723 -0
  324. package/src/client/workflows.ts +141 -0
  325. package/src/client/wrapper.ts +4304 -0
  326. package/src/component/_generated/api.ts +140 -0
  327. package/src/component/_generated/component.ts +5029 -0
  328. package/src/component/_generated/dataModel.ts +60 -0
  329. package/src/component/_generated/server.ts +156 -0
  330. package/src/component/authorization.ts +647 -0
  331. package/src/component/authorizationHooks.ts +668 -0
  332. package/src/component/bulkOperations.ts +687 -0
  333. package/src/component/contentEntries.ts +1976 -0
  334. package/src/component/contentEntryMutations.ts +1223 -0
  335. package/src/component/contentEntryValidation.ts +707 -0
  336. package/src/component/contentLock.ts +550 -0
  337. package/src/component/contentTypeMigration.ts +1064 -0
  338. package/src/component/contentTypeMutations.ts +969 -0
  339. package/src/component/contentTypes.ts +346 -0
  340. package/src/component/convex.config.ts +44 -0
  341. package/src/component/documentTypes.ts +240 -0
  342. package/src/component/eventEmitter.ts +485 -0
  343. package/src/component/exportImport.ts +1169 -0
  344. package/src/component/index.ts +491 -0
  345. package/src/component/lib/deepReferenceResolver.ts +999 -0
  346. package/src/component/lib/errors.ts +816 -0
  347. package/src/component/lib/index.ts +145 -0
  348. package/src/component/lib/mediaReferenceResolver.ts +495 -0
  349. package/src/component/lib/metadataExtractor.ts +792 -0
  350. package/src/component/lib/mutationAuth.ts +199 -0
  351. package/src/component/lib/queries.ts +79 -0
  352. package/src/component/lib/ragContentChunker.ts +1371 -0
  353. package/src/component/lib/referenceResolver.ts +430 -0
  354. package/src/component/lib/slugGenerator.ts +262 -0
  355. package/src/component/lib/slugUniqueness.ts +333 -0
  356. package/src/component/lib/softDelete.ts +44 -0
  357. package/src/component/localeFallbackChain.ts +673 -0
  358. package/src/component/localeFields.ts +896 -0
  359. package/src/component/mediaAssetMutations.ts +725 -0
  360. package/src/component/mediaAssets.ts +932 -0
  361. package/src/component/mediaFolderMutations.ts +1046 -0
  362. package/src/component/mediaUploadMutations.ts +224 -0
  363. package/src/component/mediaVariantMutations.ts +900 -0
  364. package/src/component/mediaVariants.ts +793 -0
  365. package/src/component/ragContentIndexer.ts +1067 -0
  366. package/src/component/rateLimitHooks.ts +572 -0
  367. package/src/component/roles.ts +1360 -0
  368. package/src/component/scheduledPublish.ts +358 -0
  369. package/src/component/schema.ts +617 -0
  370. package/src/component/taxonomies.ts +949 -0
  371. package/src/component/taxonomyMutations.ts +1210 -0
  372. package/src/component/trash.ts +724 -0
  373. package/src/component/userContext.ts +898 -0
  374. package/src/component/validation.ts +1388 -0
  375. package/src/component/validators.ts +949 -0
  376. package/src/component/versionMutations.ts +392 -0
  377. package/src/component/webhookTrigger.ts +1922 -0
  378. package/src/react/index.ts +898 -0
  379. package/src/test.ts +1580 -0
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Mutation-Level Authorization Helper
3
+ *
4
+ * Provides defense-in-depth authorization for component mutations.
5
+ * When auth context is provided, mutations verify the role has permission.
6
+ *
7
+ * This complements the client wrapper's authorization:
8
+ * - Client wrapper: Primary authorization layer (runs hooks, RBAC)
9
+ * - Mutation auth: Secondary validation layer (pure RBAC check)
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * import { requireMutationAuth } from "./lib/mutationAuth.js";
14
+ *
15
+ * export const createEntry = mutation({
16
+ * args: {
17
+ * ...createContentEntryArgs.fields,
18
+ * _auth: v.optional(mutationAuthContext),
19
+ * },
20
+ * handler: async (ctx, args) => {
21
+ * requireMutationAuth(args._auth, "contentEntries", "create");
22
+ * // ... mutation logic
23
+ * },
24
+ * });
25
+ * ```
26
+ */
27
+ import { hasPermission } from "../roles.js";
28
+ import { permissionDenied } from "./errors.js";
29
+ /**
30
+ * Verify the auth context has permission for the requested operation.
31
+ *
32
+ * This function:
33
+ * 1. If `_auth` is undefined, does nothing (backwards compatible)
34
+ * 2. If `_auth` is provided, checks the role has permission
35
+ * 3. Throws CMSError with PERMISSION_DENIED if check fails
36
+ *
37
+ * For ownership-scoped permissions (e.g., author editing their own content):
38
+ * - If the role only has "own" scope, verifies resourceOwnerId matches userId
39
+ * - If the role has "all" scope, ownership is not checked
40
+ *
41
+ * @param auth - The auth context from mutation args (may be undefined)
42
+ * @param resource - The resource being accessed (e.g., "contentEntries")
43
+ * @param action - The action being performed (e.g., "create", "update")
44
+ * @param options - Optional configuration including custom roles
45
+ * @throws CMSError with code PERMISSION_DENIED if authorization fails
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * // Basic usage - check if role can create content entries
50
+ * requireMutationAuth(args._auth, "contentEntries", "create");
51
+ *
52
+ * // For update/delete - include resource owner for "own" scope check
53
+ * const entry = await ctx.db.get(args.id);
54
+ * requireMutationAuth(
55
+ * { ...args._auth, resourceOwnerId: entry.createdBy },
56
+ * "contentEntries",
57
+ * "update"
58
+ * );
59
+ * ```
60
+ */
61
+ export function requireMutationAuth(auth, resource, action, options) {
62
+ // If no auth context provided, skip authorization (backwards compatible)
63
+ // Security note: Caller is responsible for ensuring authorization was done elsewhere
64
+ if (!auth) {
65
+ return;
66
+ }
67
+ const { userId, role, resourceOwnerId } = auth;
68
+ // No role means no permissions
69
+ if (!role) {
70
+ throw permissionDenied(action, resource);
71
+ }
72
+ // Check if role has "all" scope permission
73
+ const hasAllScope = hasPermission(role, { resource, action, scope: "all" }, options?.customRoles);
74
+ if (hasAllScope) {
75
+ return; // Authorized with "all" scope
76
+ }
77
+ // Check if role has "own" scope permission
78
+ const hasOwnScope = hasPermission(role, { resource, action, scope: "own" }, options?.customRoles);
79
+ if (hasOwnScope) {
80
+ // "own" scope requires ownership verification
81
+ if (resourceOwnerId && resourceOwnerId === userId) {
82
+ return; // Authorized - user owns the resource
83
+ }
84
+ // For create operations, ownership is always satisfied (user will own it)
85
+ if (action === "create") {
86
+ return; // Authorized - creating own resource
87
+ }
88
+ // Ownership check failed
89
+ throw permissionDenied(`${action} other users'`, resource);
90
+ }
91
+ // No permission found
92
+ throw permissionDenied(action, resource);
93
+ }
94
+ /**
95
+ * Check if auth context has permission without throwing.
96
+ *
97
+ * Useful for conditional logic based on permissions.
98
+ *
99
+ * @param auth - The auth context from mutation args
100
+ * @param resource - The resource being accessed
101
+ * @param action - The action being performed
102
+ * @param options - Optional configuration including custom roles
103
+ * @returns true if authorized, false otherwise
104
+ */
105
+ export function hasMutationAuth(auth, resource, action, options) {
106
+ if (!auth) {
107
+ return true; // No auth = no restriction (backwards compatible)
108
+ }
109
+ const { userId, role, resourceOwnerId } = auth;
110
+ if (!role) {
111
+ return false;
112
+ }
113
+ // Check "all" scope first
114
+ if (hasPermission(role, { resource, action, scope: "all" }, options?.customRoles)) {
115
+ return true;
116
+ }
117
+ // Check "own" scope
118
+ if (hasPermission(role, { resource, action, scope: "own" }, options?.customRoles)) {
119
+ // For "own" scope, verify ownership or it's a create action
120
+ if (action === "create") {
121
+ return true;
122
+ }
123
+ if (resourceOwnerId && resourceOwnerId === userId) {
124
+ return true;
125
+ }
126
+ return false;
127
+ }
128
+ return false;
129
+ }
130
+ /**
131
+ * Augment auth context with resource owner information.
132
+ *
133
+ * Use this when you have an auth context and need to add ownership info
134
+ * for permission checks on existing resources.
135
+ *
136
+ * @param auth - The original auth context
137
+ * @param resourceOwnerId - The owner of the resource being accessed
138
+ * @returns Auth context with resourceOwnerId set
139
+ */
140
+ export function withResourceOwner(auth, resourceOwnerId) {
141
+ if (!auth) {
142
+ return undefined;
143
+ }
144
+ return { ...auth, resourceOwnerId };
145
+ }
146
+ //# sourceMappingURL=mutationAuth.js.map
@@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AAS,CAAC;IACnB,CAAC;IACD,OAAO,EAAE,GAAG,IAAI,EAAE,eAAe,EAAE,CAAC;AACtC,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Common query helpers for the CMS component.
3
+ *
4
+ * Provides reusable query patterns for looking up documents by name,
5
+ * ID, or other common patterns with soft-delete awareness.
6
+ */
7
+ import type { QueryCtx } from "../_generated/server.js";
8
+ import type { Id, Doc, TableNames } from "../_generated/dataModel.js";
9
+ export interface GetByIdOptions {
10
+ includeDeleted?: boolean;
11
+ }
12
+ export declare function getContentTypeByName(ctx: QueryCtx, name: string, options?: GetByIdOptions): Promise<Doc<"contentTypes"> | null>;
13
+ export declare function getTaxonomyByName(ctx: QueryCtx, name: string, options?: GetByIdOptions): Promise<Doc<"taxonomies"> | null>;
14
+ export declare function contentTypeExists(ctx: QueryCtx, name: string, options?: GetByIdOptions): Promise<boolean>;
15
+ export declare function taxonomyExists(ctx: QueryCtx, name: string, options?: GetByIdOptions): Promise<boolean>;
16
+ export declare function getActiveById<T extends TableNames>(ctx: QueryCtx, id: Id<T>, options?: GetByIdOptions): Promise<Doc<T> | null>;
17
+ //# sourceMappingURL=queries.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../../../src/component/lib/queries.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,KAAK,EAAE,EAAE,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAGtE,MAAM,WAAW,cAAc;IAC7B,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,wBAAsB,oBAAoB,CACxC,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,cAAmB,GAC3B,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC,CASrC;AAED,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,cAAmB,GAC3B,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC,CASnC;AAED,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,cAAmB,GAC3B,OAAO,CAAC,OAAO,CAAC,CAGlB;AAED,wBAAsB,cAAc,CAClC,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,cAAmB,GAC3B,OAAO,CAAC,OAAO,CAAC,CAGlB;AAED,wBAAsB,aAAa,CAAC,CAAC,SAAS,UAAU,EACtD,GAAG,EAAE,QAAQ,EACb,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,EACT,OAAO,GAAE,cAAmB,GAC3B,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAWxB"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Common query helpers for the CMS component.
3
+ *
4
+ * Provides reusable query patterns for looking up documents by name,
5
+ * ID, or other common patterns with soft-delete awareness.
6
+ */
7
+ import { isDeleted } from "./softDelete.js";
8
+ export async function getContentTypeByName(ctx, name, options = {}) {
9
+ const contentType = await ctx.db
10
+ .query("contentTypes")
11
+ .withIndex("by_name", (q) => q.eq("name", name))
12
+ .first();
13
+ if (!contentType)
14
+ return null;
15
+ if (!options.includeDeleted && isDeleted(contentType))
16
+ return null;
17
+ return contentType;
18
+ }
19
+ export async function getTaxonomyByName(ctx, name, options = {}) {
20
+ const taxonomy = await ctx.db
21
+ .query("taxonomies")
22
+ .withIndex("by_name", (q) => q.eq("name", name))
23
+ .first();
24
+ if (!taxonomy)
25
+ return null;
26
+ if (!options.includeDeleted && isDeleted(taxonomy))
27
+ return null;
28
+ return taxonomy;
29
+ }
30
+ export async function contentTypeExists(ctx, name, options = {}) {
31
+ const contentType = await getContentTypeByName(ctx, name, options);
32
+ return contentType !== null;
33
+ }
34
+ export async function taxonomyExists(ctx, name, options = {}) {
35
+ const taxonomy = await getTaxonomyByName(ctx, name, options);
36
+ return taxonomy !== null;
37
+ }
38
+ export async function getActiveById(ctx, id, options = {}) {
39
+ const doc = await ctx.db.get(id);
40
+ if (!doc)
41
+ return null;
42
+ if (!options.includeDeleted &&
43
+ "deletedAt" in doc &&
44
+ doc.deletedAt !== undefined) {
45
+ return null;
46
+ }
47
+ return doc;
48
+ }
49
+ //# sourceMappingURL=queries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queries.js","sourceRoot":"","sources":["../../../src/component/lib/queries.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAM5C,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,GAAa,EACb,IAAY,EACZ,UAA0B,EAAE;IAE5B,MAAM,WAAW,GAAG,MAAM,GAAG,CAAC,EAAE;SAC7B,KAAK,CAAC,cAAc,CAAC;SACrB,SAAS,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;SAC/C,KAAK,EAAE,CAAC;IAEX,IAAI,CAAC,WAAW;QAAE,OAAO,IAAI,CAAC;IAC9B,IAAI,CAAC,OAAO,CAAC,cAAc,IAAI,SAAS,CAAC,WAAW,CAAC;QAAE,OAAO,IAAI,CAAC;IACnE,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,GAAa,EACb,IAAY,EACZ,UAA0B,EAAE;IAE5B,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,EAAE;SAC1B,KAAK,CAAC,YAAY,CAAC;SACnB,SAAS,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;SAC/C,KAAK,EAAE,CAAC;IAEX,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC3B,IAAI,CAAC,OAAO,CAAC,cAAc,IAAI,SAAS,CAAC,QAAQ,CAAC;QAAE,OAAO,IAAI,CAAC;IAChE,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,GAAa,EACb,IAAY,EACZ,UAA0B,EAAE;IAE5B,MAAM,WAAW,GAAG,MAAM,oBAAoB,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACnE,OAAO,WAAW,KAAK,IAAI,CAAC;AAC9B,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,GAAa,EACb,IAAY,EACZ,UAA0B,EAAE;IAE5B,MAAM,QAAQ,GAAG,MAAM,iBAAiB,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAC7D,OAAO,QAAQ,KAAK,IAAI,CAAC;AAC3B,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,GAAa,EACb,EAAS,EACT,UAA0B,EAAE;IAE5B,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACjC,IAAI,CAAC,GAAG;QAAE,OAAO,IAAI,CAAC;IACtB,IACE,CAAC,OAAO,CAAC,cAAc;QACvB,WAAW,IAAI,GAAG;QACjB,GAA8B,CAAC,SAAS,KAAK,SAAS,EACvD,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,423 @@
1
+ /**
2
+ * RAG Content Chunker
3
+ *
4
+ * Utility to extract and structure content from CMS entries for @convex-dev/rag indexing.
5
+ * This module provides:
6
+ *
7
+ * 1. **Content Extraction**: Extracts text from various CMS field types (text, richText, json, etc.)
8
+ * 2. **Semantic Chunking**: Splits content into meaningful chunks optimized for embedding
9
+ * 3. **Metadata Tagging**: Attaches relevant metadata (content type, field source, locale, etc.)
10
+ * 4. **Reference Handling**: Processes embedded references and includes contextual information
11
+ *
12
+ * The output is designed to be directly compatible with @convex-dev/rag's `add()` function.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * import { extractContentForRag, chunkContentEntry } from "@convex-cms/core/lib";
17
+ * import { rag } from "@convex-dev/rag";
18
+ *
19
+ * // In a Convex action
20
+ * const chunks = await chunkContentEntry(ctx, entry, contentType, {
21
+ * includeMetadata: true,
22
+ * chunkOptions: { maxCharsSoftLimit: 1000 },
23
+ * });
24
+ *
25
+ * await rag.add(ctx, {
26
+ * namespace: "cms-content",
27
+ * key: entry._id,
28
+ * chunks: chunks.map(c => c.text),
29
+ * title: chunks[0]?.metadata?.title,
30
+ * });
31
+ * ```
32
+ *
33
+ * @module
34
+ */
35
+ /**
36
+ * Field definition structure from the CMS schema.
37
+ */
38
+ export interface FieldDefinition {
39
+ name: string;
40
+ label: string;
41
+ type: string;
42
+ required: boolean;
43
+ searchable?: boolean;
44
+ localized?: boolean;
45
+ description?: string;
46
+ options?: {
47
+ allowedContentTypes?: string[];
48
+ multiple?: boolean;
49
+ [key: string]: unknown;
50
+ };
51
+ }
52
+ /**
53
+ * Content type structure from the CMS.
54
+ */
55
+ export interface ContentTypeInfo {
56
+ _id: string;
57
+ name: string;
58
+ displayName: string;
59
+ fields: FieldDefinition[];
60
+ titleField?: string;
61
+ slugField?: string;
62
+ }
63
+ /**
64
+ * Content entry structure from the CMS.
65
+ */
66
+ export interface ContentEntryInfo {
67
+ _id: string;
68
+ contentTypeId: string;
69
+ slug: string;
70
+ status: string;
71
+ data: Record<string, unknown>;
72
+ locale?: string;
73
+ version: number;
74
+ _creationTime: number;
75
+ firstPublishedAt?: number;
76
+ lastPublishedAt?: number;
77
+ }
78
+ /**
79
+ * A resolved reference for context enrichment.
80
+ */
81
+ export interface ResolvedReferenceInfo {
82
+ id: string;
83
+ contentTypeName: string;
84
+ title?: string;
85
+ slug?: string;
86
+ }
87
+ /**
88
+ * Metadata attached to each content chunk.
89
+ * This metadata helps with filtering and relevance scoring during retrieval.
90
+ */
91
+ export interface ChunkMetadata {
92
+ /** The content entry ID this chunk came from */
93
+ entryId: string;
94
+ /** The content type name (e.g., "blog_post") */
95
+ contentType: string;
96
+ /** The content type display name (e.g., "Blog Post") */
97
+ contentTypeDisplayName: string;
98
+ /** The entry's URL slug */
99
+ slug: string;
100
+ /** Publishing status of the entry */
101
+ status: string;
102
+ /** Locale code if localized content */
103
+ locale?: string;
104
+ /** The field name(s) this chunk was extracted from */
105
+ sourceFields: string[];
106
+ /** The chunk index within the entry (0-based) */
107
+ chunkIndex: number;
108
+ /** Total number of chunks for this entry */
109
+ totalChunks: number;
110
+ /** The entry's title (if available) */
111
+ title?: string;
112
+ /** ISO timestamp when the entry was created */
113
+ createdAt: string;
114
+ /** ISO timestamp when the entry was first published */
115
+ firstPublishedAt?: string;
116
+ /** ISO timestamp when the entry was last published */
117
+ lastPublishedAt?: string;
118
+ /** Version number of the entry */
119
+ version: number;
120
+ /** IDs of referenced content entries (for relationship tracking) */
121
+ referencedEntryIds?: string[];
122
+ /** IDs of referenced media assets */
123
+ referencedMediaIds?: string[];
124
+ /** Semantic type of the chunk (heading, paragraph, list, etc.) */
125
+ semanticType?: ChunkSemanticType;
126
+ }
127
+ /**
128
+ * Semantic type classification for chunks.
129
+ * Helps with relevance scoring and filtering.
130
+ */
131
+ export type ChunkSemanticType = "title" | "heading" | "paragraph" | "list" | "quote" | "code" | "table" | "mixed" | "field_value";
132
+ /**
133
+ * A single content chunk ready for RAG indexing.
134
+ */
135
+ export interface ContentChunk {
136
+ /** The text content of the chunk */
137
+ text: string;
138
+ /** Metadata for filtering and context */
139
+ metadata: ChunkMetadata;
140
+ /** Optional custom embedding text (if different from display text) */
141
+ embeddingText?: string;
142
+ }
143
+ /**
144
+ * Options for the chunking algorithm.
145
+ */
146
+ export interface ChunkOptions {
147
+ /**
148
+ * Minimum number of lines before creating a chunk.
149
+ * Helps avoid very small chunks.
150
+ * @default 1
151
+ */
152
+ minLines?: number;
153
+ /**
154
+ * Soft minimum character limit for chunks.
155
+ * Chunker will try to create chunks at least this size.
156
+ * @default 100
157
+ */
158
+ minCharsSoftLimit?: number;
159
+ /**
160
+ * Soft maximum character limit for chunks.
161
+ * Chunker will try to split at natural boundaries before this limit.
162
+ * @default 1000
163
+ */
164
+ maxCharsSoftLimit?: number;
165
+ /**
166
+ * Hard maximum character limit for chunks.
167
+ * Chunks will be force-split at this limit.
168
+ * @default 4000
169
+ */
170
+ maxCharsHardLimit?: number;
171
+ /**
172
+ * Primary delimiter for splitting text into chunks.
173
+ * @default "\n\n" (paragraph breaks)
174
+ */
175
+ delimiter?: string;
176
+ /**
177
+ * Secondary delimiters to try when primary doesn't work.
178
+ * @default ["\n", ". ", ", "]
179
+ */
180
+ fallbackDelimiters?: string[];
181
+ /**
182
+ * Whether to preserve heading context in each chunk.
183
+ * When true, includes the most recent heading at the start of each chunk.
184
+ * @default true
185
+ */
186
+ preserveHeadingContext?: boolean;
187
+ /**
188
+ * Overlap characters between chunks for context continuity.
189
+ * @default 50
190
+ */
191
+ overlapChars?: number;
192
+ }
193
+ /**
194
+ * Options for content extraction and chunking.
195
+ */
196
+ export interface RagExtractionOptions {
197
+ /**
198
+ * Whether to include metadata with each chunk.
199
+ * @default true
200
+ */
201
+ includeMetadata?: boolean;
202
+ /**
203
+ * Field names to include in extraction.
204
+ * If not specified, all text-bearing fields are included.
205
+ */
206
+ includeFields?: string[];
207
+ /**
208
+ * Field names to exclude from extraction.
209
+ */
210
+ excludeFields?: string[];
211
+ /**
212
+ * Whether to extract text from rich text fields.
213
+ * @default true
214
+ */
215
+ extractRichText?: boolean;
216
+ /**
217
+ * Whether to extract text from JSON fields.
218
+ * @default true
219
+ */
220
+ extractJson?: boolean;
221
+ /**
222
+ * Whether to include reference context (titles of referenced entries).
223
+ * Requires passing resolved references.
224
+ * @default true
225
+ */
226
+ includeReferenceContext?: boolean;
227
+ /**
228
+ * Chunking algorithm options.
229
+ */
230
+ chunkOptions?: ChunkOptions;
231
+ /**
232
+ * Custom prefix for each chunk (e.g., for entry context).
233
+ * Supports placeholders: {contentType}, {title}, {slug}
234
+ */
235
+ chunkPrefix?: string;
236
+ /**
237
+ * Custom suffix for each chunk.
238
+ */
239
+ chunkSuffix?: string;
240
+ /**
241
+ * Whether to create a separate "summary" chunk with key fields.
242
+ * @default false
243
+ */
244
+ createSummaryChunk?: boolean;
245
+ /**
246
+ * Fields to include in the summary chunk.
247
+ * @default ["title", first searchable field]
248
+ */
249
+ summaryFields?: string[];
250
+ }
251
+ /**
252
+ * Result of content extraction before chunking.
253
+ */
254
+ export interface ExtractedContent {
255
+ /** Combined text content from all fields */
256
+ fullText: string;
257
+ /** Text content organized by field name */
258
+ fieldTexts: Record<string, string>;
259
+ /** Entry title (if available) */
260
+ title?: string;
261
+ /** Referenced entry IDs found in content */
262
+ referencedEntryIds: string[];
263
+ /** Referenced media IDs found in content */
264
+ referencedMediaIds: string[];
265
+ /** Source field information for tracking */
266
+ sourceInfo: Array<{
267
+ fieldName: string;
268
+ fieldLabel: string;
269
+ fieldType: string;
270
+ charCount: number;
271
+ }>;
272
+ }
273
+ declare const DEFAULT_CHUNK_OPTIONS: Required<ChunkOptions>;
274
+ declare const DEFAULT_EXTRACTION_OPTIONS: Required<RagExtractionOptions>;
275
+ /**
276
+ * Extracts plain text from a rich text field value.
277
+ *
278
+ * Handles common rich text formats:
279
+ * - HTML strings (strips tags)
280
+ * - ProseMirror/Tiptap JSON structure
281
+ * - Markdown strings
282
+ * - Plain text strings
283
+ *
284
+ * @param value - The rich text field value
285
+ * @returns Plain text content
286
+ */
287
+ export declare function extractTextFromRichText(value: unknown): string;
288
+ /**
289
+ * Strips HTML tags from a string, preserving structure where possible.
290
+ */
291
+ export declare function stripHtmlTags(html: string): string;
292
+ /**
293
+ * Extracts text from a JSON field value.
294
+ *
295
+ * Recursively extracts string values from objects and arrays.
296
+ * Useful for structured data fields that may contain text content.
297
+ *
298
+ * @param value - The JSON field value
299
+ * @param maxDepth - Maximum recursion depth
300
+ * @returns Extracted text content
301
+ */
302
+ export declare function extractTextFromJson(value: unknown, maxDepth?: number): string;
303
+ /**
304
+ * Extracts text from a select or multiSelect field value.
305
+ */
306
+ export declare function extractTextFromSelect(value: unknown): string;
307
+ /**
308
+ * Extracts text content from a content entry based on its content type schema.
309
+ *
310
+ * This function:
311
+ * 1. Iterates through fields defined in the content type
312
+ * 2. Extracts text from each field based on its type
313
+ * 3. Tracks references (content and media)
314
+ * 4. Builds a combined text representation
315
+ *
316
+ * @param entry - The content entry to extract from
317
+ * @param contentType - The content type definition
318
+ * @param options - Extraction options
319
+ * @param resolvedReferences - Optional map of resolved reference information
320
+ * @returns Extracted content with metadata
321
+ *
322
+ * @example
323
+ * ```typescript
324
+ * const extracted = extractContent(entry, contentType, {
325
+ * includeFields: ["title", "content", "excerpt"],
326
+ * extractRichText: true,
327
+ * });
328
+ *
329
+ * console.log(extracted.fullText);
330
+ * // "My Blog Post\n\nThis is the main content...\n\nA brief excerpt."
331
+ * ```
332
+ */
333
+ export declare function extractContent(entry: ContentEntryInfo, contentType: ContentTypeInfo, options?: Partial<RagExtractionOptions>, resolvedReferences?: Map<string, ResolvedReferenceInfo>): ExtractedContent;
334
+ /**
335
+ * Splits text into semantic chunks optimized for embedding.
336
+ *
337
+ * The algorithm:
338
+ * 1. First tries to split on paragraph breaks (default delimiter)
339
+ * 2. Falls back to line breaks if paragraphs are too large
340
+ * 3. Falls back to sentence boundaries if lines are too large
341
+ * 4. Force-splits at hard limit if necessary
342
+ * 5. Optionally preserves heading context
343
+ *
344
+ * @param text - The text to chunk
345
+ * @param options - Chunking options
346
+ * @returns Array of text chunks
347
+ *
348
+ * @example
349
+ * ```typescript
350
+ * const chunks = chunkText(longArticle, {
351
+ * maxCharsSoftLimit: 1000,
352
+ * preserveHeadingContext: true,
353
+ * });
354
+ * ```
355
+ */
356
+ export declare function chunkText(text: string, options?: Partial<ChunkOptions>): string[];
357
+ /**
358
+ * Processes a content entry into chunks ready for RAG indexing.
359
+ *
360
+ * This is the main function to use for preparing CMS content for @convex-dev/rag.
361
+ * It combines extraction and chunking with full metadata.
362
+ *
363
+ * @param entry - The content entry to process
364
+ * @param contentType - The content type definition
365
+ * @param options - Extraction and chunking options
366
+ * @param resolvedReferences - Optional map of resolved references for context
367
+ * @returns Array of content chunks with metadata
368
+ *
369
+ * @example
370
+ * ```typescript
371
+ * // In a Convex action
372
+ * export const indexEntry = action({
373
+ * args: { entryId: v.id("contentEntries") },
374
+ * handler: async (ctx, { entryId }) => {
375
+ * const entry = await ctx.runQuery(api.contentEntries.get, { id: entryId });
376
+ * const contentType = await ctx.runQuery(api.contentTypes.get, {
377
+ * id: entry.contentTypeId
378
+ * });
379
+ *
380
+ * const chunks = chunkContentEntry(entry, contentType, {
381
+ * chunkOptions: { maxCharsSoftLimit: 800 },
382
+ * includeMetadata: true,
383
+ * });
384
+ *
385
+ * // Add to RAG index
386
+ * await rag.add(ctx, {
387
+ * namespace: `cms:${contentType.name}`,
388
+ * key: entryId,
389
+ * chunks: chunks.map(c => c.text),
390
+ * title: entry.data.title,
391
+ * });
392
+ *
393
+ * return { indexed: chunks.length };
394
+ * },
395
+ * });
396
+ * ```
397
+ */
398
+ export declare function chunkContentEntry(entry: ContentEntryInfo, contentType: ContentTypeInfo, options?: Partial<RagExtractionOptions>, resolvedReferences?: Map<string, ResolvedReferenceInfo>): ContentChunk[];
399
+ /**
400
+ * Processes multiple content entries into chunks.
401
+ *
402
+ * Useful for batch indexing operations.
403
+ *
404
+ * @param entries - Array of content entries
405
+ * @param contentTypes - Map of content type ID to content type
406
+ * @param options - Extraction options
407
+ * @returns Map of entry ID to chunks
408
+ */
409
+ export declare function chunkMultipleEntries(entries: ContentEntryInfo[], contentTypes: Map<string, ContentTypeInfo>, options?: Partial<RagExtractionOptions>): Map<string, ContentChunk[]>;
410
+ /**
411
+ * Calculates the total character count and chunk count for entries.
412
+ *
413
+ * Useful for estimating indexing costs.
414
+ */
415
+ export declare function estimateChunkingStats(entries: ContentEntryInfo[], contentTypes: Map<string, ContentTypeInfo>, options?: Partial<RagExtractionOptions>): {
416
+ totalEntries: number;
417
+ totalChunks: number;
418
+ totalCharacters: number;
419
+ averageChunksPerEntry: number;
420
+ averageCharsPerChunk: number;
421
+ };
422
+ export { DEFAULT_CHUNK_OPTIONS, DEFAULT_EXTRACTION_OPTIONS };
423
+ //# sourceMappingURL=ragContentChunker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ragContentChunker.d.ts","sourceRoot":"","sources":["../../../src/component/lib/ragContentChunker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAMH;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE;QACT,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;QAC/B,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACvB,CAAC;CACF;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAChC,G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