qarpeo 0.1.18 → 0.1.21

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 (237) hide show
  1. package/README.md +96 -96
  2. package/dist/chunks/auth-schema.mjs +3 -1
  3. package/dist/chunks/wrangler.mjs +22 -3
  4. package/dist/cli/index.mjs +448 -221
  5. package/dist/fate/index.d.ts +29 -22
  6. package/dist/fate/index.mjs +1 -3
  7. package/dist/module.d.ts +1 -1
  8. package/dist/module.mjs +103 -82
  9. package/dist/runtime/ai.d.ts +2 -2
  10. package/dist/runtime/app/components/BlobImage.vue +119 -107
  11. package/dist/runtime/app/components/CMSBlocks.vue +104 -93
  12. package/dist/runtime/app/components/CMSContent.vue +24 -23
  13. package/dist/runtime/app/components/CMSImage.vue +49 -49
  14. package/dist/runtime/app/components/CMSLocaleSwitcher.vue +110 -110
  15. package/dist/runtime/app/components/CMSPreviewBanner.vue +83 -79
  16. package/dist/runtime/app/components/CMSVersionBanner.vue +53 -49
  17. package/dist/runtime/app/components/CMSVersionSwitcher.vue +140 -140
  18. package/dist/runtime/app/components/ContentRenderer.vue +83 -80
  19. package/dist/runtime/app/components/FileUpload.vue +200 -196
  20. package/dist/runtime/app/components/ImpersonationBanner.vue +61 -57
  21. package/dist/runtime/app/components/QarpeoWelcome.vue +84 -84
  22. package/dist/runtime/app/components/SignedIn.vue +13 -13
  23. package/dist/runtime/app/components/SignedOut.vue +13 -13
  24. package/dist/runtime/app/components/shiki.css +34 -34
  25. package/dist/runtime/app/composables/ai.d.ts +22 -22
  26. package/dist/runtime/app/composables/ai.mjs +3 -7
  27. package/dist/runtime/app/composables/analytics.mjs +1 -1
  28. package/dist/runtime/app/composables/api-tokens.mjs +1 -1
  29. package/dist/runtime/app/composables/auth.d.ts +6 -7
  30. package/dist/runtime/app/composables/auth.mjs +6 -3
  31. package/dist/runtime/app/composables/chat.mjs +3 -7
  32. package/dist/runtime/app/composables/cms-preview.d.ts +3 -3
  33. package/dist/runtime/app/composables/cms-preview.mjs +1 -1
  34. package/dist/runtime/app/composables/cms.d.ts +3 -5
  35. package/dist/runtime/app/composables/cms.mjs +2 -2
  36. package/dist/runtime/app/composables/docs-version.d.ts +8 -7
  37. package/dist/runtime/app/composables/docs-version.mjs +3 -3
  38. package/dist/runtime/app/composables/impersonation.mjs +1 -1
  39. package/dist/runtime/app/composables/notifications.d.ts +5 -5
  40. package/dist/runtime/app/composables/notifications.mjs +4 -5
  41. package/dist/runtime/app/composables/organization.mjs +1 -1
  42. package/dist/runtime/app/composables/passkey.mjs +1 -1
  43. package/dist/runtime/app/composables/passwordless.mjs +1 -1
  44. package/dist/runtime/app/composables/payments.d.ts +2 -1
  45. package/dist/runtime/app/composables/payments.mjs +1 -1
  46. package/dist/runtime/app/composables/realtime.d.ts +13 -13
  47. package/dist/runtime/app/composables/realtime.mjs +2 -2
  48. package/dist/runtime/app/composables/resumable-upload.d.ts +11 -11
  49. package/dist/runtime/app/composables/resumable-upload.mjs +1 -1
  50. package/dist/runtime/app/composables/site.mjs +1 -1
  51. package/dist/runtime/app/composables/storage.d.ts +151 -11
  52. package/dist/runtime/app/composables/storage.mjs +291 -33
  53. package/dist/runtime/app/composables/turnstile.mjs +1 -1
  54. package/dist/runtime/app/composables/two-factor.mjs +1 -1
  55. package/dist/runtime/app/pages/devtools/agents.vue +716 -716
  56. package/dist/runtime/app/pages/devtools/analytics.vue +616 -616
  57. package/dist/runtime/app/pages/devtools/auth.vue +381 -350
  58. package/dist/runtime/app/pages/devtools/blob.vue +743 -744
  59. package/dist/runtime/app/pages/devtools/db.vue +545 -545
  60. package/dist/runtime/app/pages/devtools/domains.vue +771 -771
  61. package/dist/runtime/app/pages/devtools/kv.vue +827 -828
  62. package/dist/runtime/app/pages/devtools/logs.vue +649 -653
  63. package/dist/runtime/app/pages/devtools/mail.vue +388 -388
  64. package/dist/runtime/app/pages/devtools/overview.vue +391 -389
  65. package/dist/runtime/app/pages/devtools/realtime.vue +89 -27
  66. package/dist/runtime/app/pages/devtools/security.vue +20 -5
  67. package/dist/runtime/app/pages/devtools/settings.vue +559 -559
  68. package/dist/runtime/app/pages/devtools/tasks.vue +26 -10
  69. package/dist/runtime/app/pages/devtools.vue +176 -176
  70. package/dist/runtime/app/plugins/seo.mjs +1 -1
  71. package/dist/runtime/app/plugins/shortcuts.client.d.ts +1 -4
  72. package/dist/runtime/app/public/sw-notifications.mjs +47 -52
  73. package/dist/runtime/blob.mjs +11 -4
  74. package/dist/runtime/browser.d.ts +1 -1
  75. package/dist/runtime/browser.mjs +12 -2
  76. package/dist/runtime/cache.d.ts +2 -1
  77. package/dist/runtime/kv.mjs +4 -1
  78. package/dist/runtime/providers/qarpeo.d.ts +3 -3
  79. package/dist/runtime/server/durable-objects/agent.mjs +1 -1
  80. package/dist/runtime/server/durable-objects/room.d.ts +2 -2
  81. package/dist/runtime/server/durable-objects/room.mjs +5 -5
  82. package/dist/runtime/server/middleware/devtools.mjs +6 -2
  83. package/dist/runtime/server/plugins/cms.d.ts +4 -2
  84. package/dist/runtime/server/plugins/dev-proxy.mjs +1 -1
  85. package/dist/runtime/server/routes/__qarpeo/agents/chat.post.d.ts +2 -2
  86. package/dist/runtime/server/routes/__qarpeo/agents/chat.post.mjs +4 -1
  87. package/dist/runtime/server/routes/__qarpeo/analytics/events.get.d.ts +1 -4
  88. package/dist/runtime/server/routes/__qarpeo/analytics/summary.get.d.ts +2 -2
  89. package/dist/runtime/server/routes/__qarpeo/analytics/summary.get.mjs +5 -1
  90. package/dist/runtime/server/routes/__qarpeo/db/tables.get.d.ts +2 -2
  91. package/dist/runtime/server/routes/__qarpeo/db/tables.get.mjs +1 -1
  92. package/dist/runtime/server/routes/__qarpeo/logs.get.d.ts +4 -1
  93. package/dist/runtime/server/routes/__qarpeo/mail/track/click/[id].get.mjs +1 -1
  94. package/dist/runtime/server/routes/__qarpeo/mail/track/open/[id].get.mjs +2 -2
  95. package/dist/runtime/server/routes/__qarpeo/overview.get.d.ts +2 -2
  96. package/dist/runtime/server/routes/__qarpeo/realtime/broadcast.post.d.ts +2 -2
  97. package/dist/runtime/server/routes/__qarpeo/realtime/broadcast.post.mjs +1 -1
  98. package/dist/runtime/server/routes/__qarpeo/realtime/clear.post.d.ts +1 -4
  99. package/dist/runtime/server/routes/__qarpeo/realtime/clear.post.mjs +1 -1
  100. package/dist/runtime/server/routes/__qarpeo/realtime/disconnect.post.d.ts +1 -4
  101. package/dist/runtime/server/routes/__qarpeo/realtime/disconnect.post.mjs +1 -1
  102. package/dist/runtime/server/routes/__qarpeo/realtime/room.get.d.ts +2 -2
  103. package/dist/runtime/server/routes/__qarpeo/realtime/rooms.get.d.ts +2 -2
  104. package/dist/runtime/server/routes/__qarpeo/security/analytics.get.d.ts +2 -2
  105. package/dist/runtime/server/routes/__qarpeo/security/ban.post.d.ts +1 -4
  106. package/dist/runtime/server/routes/__qarpeo/security/clear.post.d.ts +1 -4
  107. package/dist/runtime/server/routes/__qarpeo/security/unban.post.d.ts +1 -4
  108. package/dist/runtime/server/routes/__qarpeo/settings.get.mjs +1 -1
  109. package/dist/runtime/server/routes/__qarpeo/tasks/run.post.mjs +3 -1
  110. package/dist/runtime/server/routes/agents/[agent]/chat.post.mjs +8 -2
  111. package/dist/runtime/server/routes/agents/[agent]/clear.post.mjs +8 -2
  112. package/dist/runtime/server/routes/agents/[agent]/history.get.mjs +8 -2
  113. package/dist/runtime/server/routes/ai/embed.post.d.ts +1 -4
  114. package/dist/runtime/server/routes/ai/search.post.d.ts +2 -2
  115. package/dist/runtime/server/routes/auth/account.delete.mjs +1 -1
  116. package/dist/runtime/server/routes/auth/handler.mjs +6 -1
  117. package/dist/runtime/server/routes/auth/magic-link/verify.get.mjs +1 -1
  118. package/dist/runtime/server/routes/auth/organization/members/[id].delete.mjs +7 -1
  119. package/dist/runtime/server/routes/auth/otp/verify.post.mjs +1 -1
  120. package/dist/runtime/server/routes/auth/sso/login.get.mjs +7 -1
  121. package/dist/runtime/server/routes/auth/sso/oidc/callback.get.mjs +8 -2
  122. package/dist/runtime/server/routes/auth/sso/saml/acs.post.mjs +7 -2
  123. package/dist/runtime/server/routes/auth/webauthn/login/options.post.mjs +1 -1
  124. package/dist/runtime/server/routes/auth/webauthn/login/verify.post.mjs +7 -2
  125. package/dist/runtime/server/routes/auth/webauthn/register/options.post.mjs +6 -1
  126. package/dist/runtime/server/routes/auth/webauthn/register/verify.post.mjs +6 -1
  127. package/dist/runtime/server/routes/browser/crawl.post.d.ts +1 -2
  128. package/dist/runtime/server/routes/browser/invoice.post.d.ts +1 -2
  129. package/dist/runtime/server/routes/browser/og-image.post.d.ts +2 -2
  130. package/dist/runtime/server/routes/browser/pdf.post.d.ts +1 -2
  131. package/dist/runtime/server/routes/browser/pdf.post.mjs +6 -1
  132. package/dist/runtime/server/routes/browser/screenshot.post.d.ts +2 -2
  133. package/dist/runtime/server/routes/browser/screenshot.post.mjs +5 -1
  134. package/dist/runtime/server/routes/cms/components/index.get.d.ts +2 -2
  135. package/dist/runtime/server/routes/cms/preview/disable.get.d.ts +4 -3
  136. package/dist/runtime/server/routes/cms/preview/enable.get.d.ts +8 -8
  137. package/dist/runtime/server/routes/cms/search.get.mjs +1 -1
  138. package/dist/runtime/server/routes/cms/webhooks/[provider].post.d.ts +7 -7
  139. package/dist/runtime/server/routes/cms/webhooks/[provider].post.mjs +9 -2
  140. package/dist/runtime/server/routes/docs/search.get.d.ts +9 -9
  141. package/dist/runtime/server/routes/fate.mjs +5 -8
  142. package/dist/runtime/server/routes/mail/bounce.post.d.ts +2 -2
  143. package/dist/runtime/server/routes/mail/unsubscribe.d.ts +2 -2
  144. package/dist/runtime/server/routes/mail/webhooks.post.d.ts +2 -2
  145. package/dist/runtime/server/routes/mail/webhooks.post.mjs +7 -1
  146. package/dist/runtime/server/routes/payments/usage.get.d.ts +8 -8
  147. package/dist/runtime/server/routes/payments/usage.post.d.ts +2 -2
  148. package/dist/runtime/server/routes/realtime/history.delete.d.ts +4 -3
  149. package/dist/runtime/server/routes/realtime/history.get.d.ts +7 -6
  150. package/dist/runtime/server/routes/realtime/ws.get.mjs +6 -1
  151. package/dist/runtime/server/routes/robots.txt.get.mjs +1 -1
  152. package/dist/runtime/server/routes/sitemap.xml.get.mjs +2 -1
  153. package/dist/runtime/server/routes/storage/multipart/abort.post.d.ts +2 -2
  154. package/dist/runtime/server/routes/storage/multipart/complete.post.d.ts +2 -2
  155. package/dist/runtime/server/routes/storage/multipart/complete.post.mjs +2 -2
  156. package/dist/runtime/server/routes/storage/multipart/create.post.d.ts +2 -2
  157. package/dist/runtime/server/routes/storage/multipart/create.post.mjs +7 -3
  158. package/dist/runtime/server/routes/storage/multipart/part.put.d.ts +2 -2
  159. package/dist/runtime/server/routes/storage/multipart/part.put.mjs +1 -1
  160. package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/index.delete.mjs +2 -4
  161. package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/verify.post.mjs +2 -4
  162. package/dist/runtime/server/routes/tenants/[tenant]/domains/index.get.mjs +1 -1
  163. package/dist/runtime/server/routes/tenants/[tenant]/domains/index.post.mjs +2 -4
  164. package/dist/runtime/server/tasks/cms/publish.mjs +1 -1
  165. package/dist/runtime/server/utils/ai.d.ts +9 -9
  166. package/dist/runtime/server/utils/ai.mjs +3 -3
  167. package/dist/runtime/server/utils/auth.d.ts +12 -16
  168. package/dist/runtime/server/utils/auth.mjs +15 -9
  169. package/dist/runtime/server/utils/bots.mjs +21 -7
  170. package/dist/runtime/server/utils/browser-utils.d.ts +44 -41
  171. package/dist/runtime/server/utils/browser-utils.mjs +14 -4
  172. package/dist/runtime/server/utils/cache.d.ts +5 -5
  173. package/dist/runtime/server/utils/cms/common.d.ts +26 -0
  174. package/dist/runtime/server/utils/cms/common.mjs +68 -0
  175. package/dist/runtime/server/utils/cms/git.d.ts +24 -0
  176. package/dist/runtime/server/utils/cms/git.mjs +240 -0
  177. package/dist/runtime/server/utils/cms/markdown.d.ts +22 -0
  178. package/dist/runtime/server/utils/cms/markdown.mjs +92 -0
  179. package/dist/runtime/server/utils/cms/path.d.ts +51 -0
  180. package/dist/runtime/server/utils/cms/path.mjs +127 -0
  181. package/dist/runtime/server/utils/cms/search.d.ts +22 -0
  182. package/dist/runtime/server/utils/cms/search.mjs +221 -0
  183. package/dist/runtime/server/utils/cms-events.d.ts +1 -1
  184. package/dist/runtime/server/utils/cms-events.mjs +2 -2
  185. package/dist/runtime/server/utils/cms-filter.mjs +2 -2
  186. package/dist/runtime/server/utils/cms.d.ts +17 -149
  187. package/dist/runtime/server/utils/cms.mjs +52 -761
  188. package/dist/runtime/server/utils/config.d.ts +5 -4
  189. package/dist/runtime/server/utils/domains.mjs +7 -4
  190. package/dist/runtime/server/utils/email-templates.d.ts +10 -7
  191. package/dist/runtime/server/utils/email-templates.mjs +20 -5
  192. package/dist/runtime/server/utils/feed.d.ts +2 -2
  193. package/dist/runtime/server/utils/feed.mjs +3 -1
  194. package/dist/runtime/server/utils/mail-suppression.d.ts +8 -24
  195. package/dist/runtime/server/utils/mail-suppression.mjs +2 -2
  196. package/dist/runtime/server/utils/mail.d.ts +7 -8
  197. package/dist/runtime/server/utils/mail.mjs +17 -12
  198. package/dist/runtime/server/utils/multipart-store.d.ts +2 -2
  199. package/dist/runtime/server/utils/notifications.d.ts +9 -23
  200. package/dist/runtime/server/utils/organization.mjs +4 -12
  201. package/dist/runtime/server/utils/passwordless.mjs +1 -1
  202. package/dist/runtime/server/utils/payments.d.ts +2 -6
  203. package/dist/runtime/server/utils/payments.mjs +1 -1
  204. package/dist/runtime/server/utils/queue.d.ts +21 -31
  205. package/dist/runtime/server/utils/rag.d.ts +4 -4
  206. package/dist/runtime/server/utils/rag.mjs +8 -8
  207. package/dist/runtime/server/utils/realtime-store.d.ts +2 -2
  208. package/dist/runtime/server/utils/realtime.d.ts +26 -28
  209. package/dist/runtime/server/utils/scheduled-task.d.ts +1 -3
  210. package/dist/runtime/server/utils/security-store.d.ts +2 -2
  211. package/dist/runtime/server/utils/session.d.ts +9 -11
  212. package/dist/runtime/server/utils/sso.d.ts +9 -15
  213. package/dist/runtime/server/utils/sso.mjs +4 -8
  214. package/dist/runtime/server/utils/storage.d.ts +19 -2
  215. package/dist/runtime/server/utils/storage.mjs +36 -7
  216. package/dist/runtime/server/utils/tenant.mjs +3 -1
  217. package/dist/runtime/server/utils/turnstile.d.ts +3 -5
  218. package/dist/runtime/server/utils/vapid.d.ts +5 -8
  219. package/dist/runtime/server/utils/vapid.mjs +26 -13
  220. package/dist/runtime/service.d.ts +13 -13
  221. package/dist/runtime/service.mjs +4 -2
  222. package/dist/runtime/test-utils.d.ts +20 -30
  223. package/dist/runtime/test-utils.mjs +5 -4
  224. package/dist/runtime/types/auth-globals.d.ts +14 -14
  225. package/dist/runtime/types/imports.d.ts +82 -82
  226. package/dist/runtime/types/index.d.ts +2 -2
  227. package/dist/runtime/types/r2.d.ts +5 -0
  228. package/dist/runtime/types/service.d.ts +11 -18
  229. package/dist/types.d.ts +100 -107
  230. package/dist/utils/auth-schema.d.ts +2 -2
  231. package/dist/utils/cms-sources.d.ts +3 -3
  232. package/dist/utils/local-db.d.ts +3 -3
  233. package/dist/utils/notifications-schema.d.ts +1 -3
  234. package/dist/utils/pkg.d.ts +7 -0
  235. package/dist/utils/queue.d.ts +3 -3
  236. package/dist/utils/tasks.d.ts +3 -2
  237. package/package.json +11 -8
@@ -0,0 +1,221 @@
1
+ import { getCMSDb, getCMSTenantId } from "./common.mjs";
2
+ let _ensureCMSSynced = null;
3
+ export function registerEnsureCMSSynced(fn) {
4
+ _ensureCMSSynced = fn;
5
+ }
6
+ export function buildFtsQuery(query, operator = "AND") {
7
+ if (!query) return "";
8
+ const clean = query.replace(/[^\p{L}\p{N}_\s]/gu, " ").trim();
9
+ const rawTokens = clean.split(/\s+/).filter(Boolean);
10
+ if (!rawTokens.length) return "";
11
+ const reserved = /* @__PURE__ */ new Set(["and", "or", "not", "near"]);
12
+ const tokens = rawTokens.filter((t) => !reserved.has(t.toLowerCase()));
13
+ const effectiveTokens = tokens.length > 0 ? tokens : rawTokens;
14
+ return effectiveTokens.map((t) => `"${t.replace(/"/g, '""')}"*`).join(` ${operator} `);
15
+ }
16
+ export async function rebuildCMSFTS(event) {
17
+ const db = getCMSDb(event);
18
+ try {
19
+ await db.exec("DELETE FROM _qarpeo_cms_entries_fts;");
20
+ await db.exec(
21
+ "INSERT INTO _qarpeo_cms_entries_fts(id, slug, title, description, content_md, tags) SELECT id, slug, title, coalesce(description, ''), content_md, coalesce(tags, '') FROM _qarpeo_cms_entries;"
22
+ );
23
+ const res = await db.prepare("SELECT COUNT(*) as total FROM _qarpeo_cms_entries_fts").first();
24
+ return { total: Number(res?.total || 0) };
25
+ } catch (err) {
26
+ console.warn("[qarpeo:cms] rebuildCMSFTS failed:", err);
27
+ return { total: 0 };
28
+ }
29
+ }
30
+ export async function searchDocs(event, options = {}) {
31
+ if (_ensureCMSSynced) {
32
+ await _ensureCMSSynced(event);
33
+ }
34
+ const db = getCMSDb(event);
35
+ const q = (options.q || "").trim();
36
+ if (!q) {
37
+ return { results: [], total: 0, query: "", mode: "fts" };
38
+ }
39
+ const limit = Math.min(100, Math.max(1, options.limit || 20));
40
+ const locale = options.locale;
41
+ const tenantId = getCMSTenantId(event);
42
+ const words = q.toLowerCase().split(/\s+/).filter(Boolean);
43
+ let rows = [];
44
+ let modeUsed = "fts";
45
+ if (options.mode !== "like") {
46
+ try {
47
+ const ftsQuery = buildFtsQuery(q, "AND");
48
+ if (ftsQuery) {
49
+ let ftsSql = `
50
+ SELECT e.id, e.collection_id, e.slug, e.path, e.title, e.description, e.content_md, e.metadata_json, e.locale, fts.rank as fts_rank
51
+ FROM _qarpeo_cms_entries e
52
+ JOIN _qarpeo_cms_entries_fts fts ON e.id = fts.id
53
+ WHERE fts MATCH ? AND e.status = 'published'
54
+ `;
55
+ const ftsBinds = [ftsQuery];
56
+ if (tenantId) {
57
+ ftsSql += " AND (e.tenant_id = ? OR e.tenant_id IS NULL)";
58
+ ftsBinds.push(tenantId);
59
+ }
60
+ if (options.collection) {
61
+ ftsSql += " AND e.collection_id = ?";
62
+ ftsBinds.push(options.collection);
63
+ } else {
64
+ ftsSql += " AND (e.collection_id = 'docs' OR e.collection_id = 'content' OR e.path LIKE '/docs%' OR e.collection_id LIKE '%doc%')";
65
+ }
66
+ if (locale) {
67
+ ftsSql += " AND (e.locale = ? OR e.locale = 'en')";
68
+ ftsBinds.push(locale);
69
+ }
70
+ if (options.version && options.version !== "all") {
71
+ if (options.version === "latest") {
72
+ ftsSql += " AND (e.version = 'latest' OR e.version IS NULL OR e.path NOT LIKE '%/docs/v%')";
73
+ } else {
74
+ ftsSql += " AND (e.version = ? OR e.path LIKE ?)";
75
+ ftsBinds.push(options.version, `%/docs/${options.version}%`);
76
+ }
77
+ }
78
+ ftsSql += " ORDER BY fts.rank LIMIT 50";
79
+ const res = await db.prepare(ftsSql).bind(...ftsBinds).all();
80
+ rows = res.results || [];
81
+ if (rows.length === 0 && words.length > 1) {
82
+ const ftsOrQuery = buildFtsQuery(q, "OR");
83
+ if (ftsOrQuery && ftsOrQuery !== ftsQuery) {
84
+ const orBinds = [...ftsBinds];
85
+ orBinds[0] = ftsOrQuery;
86
+ const orRes = await db.prepare(ftsSql).bind(...orBinds).all();
87
+ rows = orRes.results || [];
88
+ }
89
+ }
90
+ }
91
+ } catch {
92
+ rows = [];
93
+ }
94
+ }
95
+ if (rows.length === 0) {
96
+ modeUsed = "like";
97
+ const searchPattern = `%${words.join("%")}%`;
98
+ let sql = `
99
+ SELECT id, collection_id, slug, path, title, description, content_md, metadata_json, locale
100
+ FROM _qarpeo_cms_entries
101
+ WHERE status = 'published'
102
+ `;
103
+ const binds = [];
104
+ if (tenantId) {
105
+ sql += " AND (tenant_id = ? OR tenant_id IS NULL)";
106
+ binds.push(tenantId);
107
+ }
108
+ if (options.collection) {
109
+ sql += " AND collection_id = ?";
110
+ binds.push(options.collection);
111
+ } else {
112
+ sql += " AND (collection_id = 'docs' OR collection_id = 'content' OR path LIKE '/docs%' OR collection_id LIKE '%doc%')";
113
+ }
114
+ if (locale) {
115
+ sql += " AND (locale = ? OR locale = 'en')";
116
+ binds.push(locale);
117
+ }
118
+ if (options.version && options.version !== "all") {
119
+ if (options.version === "latest") {
120
+ sql += " AND (version = 'latest' OR version IS NULL OR path NOT LIKE '%/docs/v%')";
121
+ } else {
122
+ sql += " AND (version = ? OR path LIKE ?)";
123
+ binds.push(options.version, `%/docs/${options.version}%`);
124
+ }
125
+ }
126
+ sql += " AND (LOWER(title) LIKE ? OR LOWER(description) LIKE ? OR LOWER(content_md) LIKE ? OR LOWER(tags) LIKE ?)";
127
+ binds.push(searchPattern, searchPattern, searchPattern, searchPattern);
128
+ sql += " LIMIT 50";
129
+ const res = await db.prepare(sql).bind(...binds).all();
130
+ rows = res.results || [];
131
+ }
132
+ const sections = [];
133
+ for (const row of rows) {
134
+ const pageTitle = row.title || "Documentation";
135
+ const docPath = row.path || `/${row.collection_id}/${row.slug}`;
136
+ const md = row.content_md || "";
137
+ const headingLines = md.split("\n");
138
+ const rawSections = [];
139
+ let currentSection = {
140
+ heading: pageTitle,
141
+ level: 1,
142
+ anchor: "",
143
+ lines: []
144
+ };
145
+ rawSections.push(currentSection);
146
+ for (const line of headingLines) {
147
+ const match = line.match(/^(#{1,4})\s+(.+)$/);
148
+ if (match) {
149
+ const level = match[1].length;
150
+ const headingText = match[2].trim().replace(/\s*\{#.*\}\s*$/, "");
151
+ const slugAnchor = headingText.toLowerCase().replace(/[^\w\s-]/g, "").replace(/\s+/g, "-");
152
+ currentSection = {
153
+ heading: headingText,
154
+ level,
155
+ anchor: `#${slugAnchor}`,
156
+ lines: []
157
+ };
158
+ rawSections.push(currentSection);
159
+ } else {
160
+ currentSection.lines.push(line);
161
+ }
162
+ }
163
+ for (const sec of rawSections) {
164
+ const rawText = sec.lines.join(" ");
165
+ const cleanContent = rawText.replace(/```[\s\S]*?```/g, " ").replace(/`([^`]+)`/g, "$1").replace(/\[([^\]]+)\]\([^)]+\)/g, "$1").replace(/[*_~#]/g, "").replace(/\s+/g, " ").trim();
166
+ const textLower = cleanContent.toLowerCase();
167
+ const headingLower = sec.heading.toLowerCase();
168
+ const pageTitleLower = pageTitle.toLowerCase();
169
+ let score = 0;
170
+ let matchIdx = -1;
171
+ for (const w of words) {
172
+ if (headingLower.includes(w)) {
173
+ score += 15;
174
+ }
175
+ if (pageTitleLower.includes(w)) {
176
+ score += 8;
177
+ }
178
+ const idx = textLower.indexOf(w);
179
+ if (idx !== -1) {
180
+ score += 5;
181
+ if (matchIdx === -1 || idx < matchIdx) {
182
+ matchIdx = idx;
183
+ }
184
+ }
185
+ }
186
+ if (score === 0 && row.fts_rank !== void 0 && sec === rawSections[0]) {
187
+ score = 10;
188
+ }
189
+ if (score > 0) {
190
+ let excerpt = "";
191
+ if (matchIdx !== -1) {
192
+ const start = Math.max(0, matchIdx - 40);
193
+ const end = Math.min(cleanContent.length, matchIdx + 110);
194
+ excerpt = (start > 0 ? "... " : "") + cleanContent.slice(start, end).trim() + (end < cleanContent.length ? " ..." : "");
195
+ } else {
196
+ excerpt = cleanContent.slice(0, 140) + (cleanContent.length > 140 ? " ..." : "");
197
+ }
198
+ const titles = sec.heading !== pageTitle ? [pageTitle, sec.heading] : [pageTitle];
199
+ sections.push({
200
+ id: `${docPath}${sec.anchor}`,
201
+ path: docPath,
202
+ title: sec.heading,
203
+ pageTitle,
204
+ titles,
205
+ content: excerpt || row.description || pageTitle,
206
+ section: sec.anchor || void 0,
207
+ locale: row.locale || "en",
208
+ level: sec.level || 1,
209
+ score
210
+ });
211
+ }
212
+ }
213
+ }
214
+ sections.sort((a, b) => b.score - a.score);
215
+ return {
216
+ results: sections.slice(0, limit),
217
+ total: sections.length,
218
+ query: q,
219
+ mode: modeUsed
220
+ };
221
+ }
@@ -13,5 +13,5 @@ export declare function fireCMSWebhooks(config: CMSConfig, collectionId: string,
13
13
  * === "on-publish" (default) and event is "publish" or "unpublish". Merges global deploy config
14
14
  * with per-collection deploy config (collection config wins).
15
15
  */
16
- export declare function fireCMSDeployTrigger(config: CMSConfig, collectionId: string, event: "publish" | "unpublish"): Promise<void>;
16
+ export declare function fireCMSDeployTrigger(config: CMSConfig, collectionId: string, _event: "publish" | "unpublish"): Promise<void>;
17
17
  export {};
@@ -22,7 +22,7 @@ export async function fireCMSWebhooks(config, collectionId, event, entry) {
22
22
  if (!hookEvents.includes(event)) continue;
23
23
  const headers = {
24
24
  "Content-Type": "application/json",
25
- ...hook.headers || {}
25
+ ...hook.headers
26
26
  };
27
27
  if (hook.secret) {
28
28
  try {
@@ -44,7 +44,7 @@ export async function fireCMSWebhooks(config, collectionId, event, entry) {
44
44
  });
45
45
  }
46
46
  }
47
- export async function fireCMSDeployTrigger(config, collectionId, event) {
47
+ export async function fireCMSDeployTrigger(config, collectionId, _event) {
48
48
  const colConfig = config.collections?.[collectionId] || {};
49
49
  const deploy = colConfig.deploy || config.deploy;
50
50
  if (!deploy) return;
@@ -5,7 +5,7 @@ export function matchesSourceFilters(relPath, include, exclude) {
5
5
  for (const raw of list) {
6
6
  if (!raw) continue;
7
7
  try {
8
- const pattern = raw.replace(/\\/g, "/").replace(/[.+^$\{\}\|\[\]\\]/g, (m) => "\\" + m).replace(/\*\*/g, ".*").replace(/(?<!\.)\*/g, "[^/]*").replace(/\?/g, "[^/]");
8
+ const pattern = raw.replace(/\\/g, "/").replace(/[.+^${}|[\]\\]/g, (m) => "\\" + m).replace(/\*\*/g, ".*").replace(/(?<!\.)\*/g, "[^/]*").replace(/\?/g, "[^/]");
9
9
  const exRegex = new RegExp(pattern);
10
10
  if (exRegex.test(p)) return false;
11
11
  } catch {
@@ -18,7 +18,7 @@ export function matchesSourceFilters(relPath, include, exclude) {
18
18
  for (const raw of list) {
19
19
  if (!raw) continue;
20
20
  try {
21
- const pattern = raw.replace(/\\/g, "/").replace(/[.+^$\{\}\|\[\]\\]/g, (m) => "\\" + m).replace(/\*\*/g, ".*").replace(/(?<!\.)\*/g, "[^/]*").replace(/\?/g, "[^/]");
21
+ const pattern = raw.replace(/\\/g, "/").replace(/[.+^${}|[\]\\]/g, (m) => "\\" + m).replace(/\*\*/g, ".*").replace(/(?<!\.)\*/g, "[^/]*").replace(/\?/g, "[^/]");
22
22
  const incRegex = new RegExp(pattern);
23
23
  if (incRegex.test(p)) {
24
24
  matched = true;
@@ -1,122 +1,15 @@
1
1
  import { type RequestEvent } from "nuxt/server";
2
- import type { CMSComponentDefinition, CMSOptions, CMSEntry, CMSEntryStatus, CMSCollection, CMSCollectionConfig, CMSGitHubConfig, CMSDeployTriggerConfig, CMSApprovalConfig, CMSCreateInput, CMSUpdateInput, CMSQueryOptions, CMSFieldDefinition, CMSHeadingLink, CMSNavigationItem, CMSNavigationOptions, DocsSearchOptions, DocsSearchResponse } from "../../../types";
3
- /** Converts a heading text to a URL-safe slug ID. e.g. "Getting Started" → "getting-started" */
4
- export declare function slugifyHeading(text: string): string;
5
- /**
6
- * Strips number-sort prefixes from path segments used for ordering. e.g. "1.docs" → "docs",
7
- * "01.index" → "index", "2.getting-started" → "getting-started"
8
- */
9
- export declare function stripOrderPrefix(segment: string): string;
10
- /**
11
- * Checks whether a path segment is a route group enclosed in parentheses. e.g. "(overview)" → true,
12
- * "1.(overview)" → true, "01.(setup)" → true, "guide" → false
13
- */
14
- export declare function isGroupSegment(segment: string): boolean;
15
- /**
16
- * Extracts a clean human-readable title from a group segment. e.g. "(overview)" → "Overview",
17
- * "1.(quick-start)" → "Quick Start", "02.(faq)" → "FAQ"
18
- */
19
- export declare function extractGroupTitle(segment: string): string;
20
- /**
21
- * Extracts the numeric order prefix from a directory/file name. e.g. "1.docs" → 1,
22
- * "01.getting-started" → 1, "docs" → undefined
23
- */
24
- export declare function extractOrderPrefix(segment: string): number | undefined;
25
- /**
26
- * Computes a clean URL path from a file path relative to contentDir. Strips numeric order prefixes
27
- * and route groups like `(overview)`. e.g. "1.docs/1.getting-started/(overview)/01.index.md" →
28
- * "/docs/getting-started" "1.docs/1.getting-started/(overview)/02.intro.md" →
29
- * "/docs/getting-started/intro" "1.docs/2.installation.md" → "/docs/installation"
30
- * "blog/hello-world.md" → "/blog/hello-world"
31
- */
32
- export declare function computeEntryPath(filePathRelative: string, collectionId?: string): string;
33
- /**
34
- * Tests whether an entry path matches one or more glob patterns. Supports:
35
- *
36
- * - Glob paths: `"/docs/**"`, `"/blog/*"`
37
- * - Arrays: `["/docs/**", "/guides/**"]`
38
- * - Negative excludes: `"!/docs/internal/**"`
39
- */
40
- export declare function matchPathPatterns(entryPath: string, patterns?: string | string[]): boolean;
41
- /**
42
- * Resolves which collection an entryPath belongs to, checking configured collections' `path`
43
- * patterns first, then falling back to fallbackId.
44
- */
45
- export declare function resolveCollectionForPath(entryPath: string, collectionsConfig?: Record<string, any>, fallbackId?: string): string;
46
- /**
47
- * Extracts a table-of-contents array from raw markdown. Only processes ATX headings (## Foo, ###
48
- * Bar — not h1).
49
- */
50
- export declare function extractTOC(md: string): CMSHeadingLink[];
51
- /** Pre-processes MDC (Markdown Components) syntax to HTML before passing to micromark. */
52
- export declare function preprocessMDC(md: string): string;
53
- export declare function getCMSConfig(event?: RequestEvent): Omit<Required<CMSOptions>, "github" | "deploy" | "approval" | "exclude" | "webhookSecret"> & {
54
- collections: Record<string, CMSCollectionConfig>;
55
- github?: CMSGitHubConfig;
56
- deploy?: CMSDeployTriggerConfig;
57
- approval?: boolean | CMSApprovalConfig;
58
- exclude?: string | string[];
59
- webhookSecret?: string;
60
- };
61
- /**
62
- * Resolves the effective approval workflow configuration for a collection. Returns null if approval
63
- * is disabled for the collection.
64
- */
65
- export declare function resolveCollectionApproval(collectionConfig?: CMSCollectionConfig, globalApproval?: boolean | CMSApprovalConfig): CMSApprovalConfig | null;
66
- /** Parses markdown to Comark AST document ({ nodes, frontmatter, meta }). */
67
- export declare function parseMarkdownAST(md: string, event?: RequestEvent): Promise<any>;
68
- /** Parses markdown and renders to both AST and HTML in a single pass. */
69
- export declare function processMarkdown(md: string, event?: RequestEvent): Promise<{
70
- ast: any;
71
- html: string;
72
- }>;
73
- /** Renders markdown with Comark to HTML string. */
74
- export declare function renderMarkdown(md: string, event?: RequestEvent): Promise<string>;
75
- /** Renders page markdown with Comark to HTML string. */
76
- export declare function renderPageMarkdown(md: string): Promise<string>;
77
- /**
78
- * Parses a raw markdown file string with YAML frontmatter. Returns `{ data, content }` where `data`
79
- * is the frontmatter key-value map and `content` is the body markdown text.
80
- */
81
- export declare function parseFrontmatter(raw: string): {
82
- data: Record<string, unknown>;
83
- content: string;
84
- };
85
- /** Serialises entry data back to a markdown file with YAML frontmatter. */
86
- export declare function formatFrontmatter(data: Record<string, unknown>, body: string): string;
2
+ import type { CMSComponentDefinition, CMSEntry, CMSEntryStatus, CMSCollection, CMSCollectionConfig, CMSCreateInput, CMSUpdateInput, CMSQueryOptions, CMSFieldDefinition, CMSNavigationItem, CMSNavigationOptions } from "../../../types";
3
+ export * from "./cms/common";
4
+ export * from "./cms/path";
5
+ export * from "./cms/markdown";
6
+ export * from "./cms/git";
7
+ export * from "./cms/search";
87
8
  /**
88
9
  * Formats a CMSEntry into standard markdown with YAML frontmatter. Omits internal system fields
89
10
  * starting with `_`.
90
11
  */
91
12
  export declare function formatEntryAsMarkdown(entry: CMSEntry | Record<string, any>): string;
92
- export interface GitSyncResult {
93
- filePath?: string;
94
- contentHash?: string;
95
- localFs?: boolean;
96
- github?: {
97
- ok: boolean;
98
- commitSha?: string;
99
- prUrl?: string;
100
- error?: string;
101
- };
102
- }
103
- /**
104
- * Synchronizes a CMS entry modification back to Git / filesystem when mode is 'git-sync'.
105
- *
106
- * - In local dev (Node.js): Writes or deletes the markdown file on local disk and updates D1
107
- * content_hash.
108
- * - In production (or when GitHub repo is configured): Commits directly or opens a PR via GitHub API.
109
- */
110
- export declare function syncEntryToGit(event: RequestEvent, collectionId: string, entry: CMSEntry | Record<string, any>, action: "create" | "update" | "delete" | "publish"): Promise<GitSyncResult | null>;
111
- /**
112
- * Computes a hex SHA-256 digest of the given text using Web Crypto. Used for deterministic change
113
- * detection in the hybrid sync engine.
114
- */
115
- export declare function computeContentHash(text: string): Promise<string>;
116
- /** Resolves the active tenant ID for CMS scoping from the current event context. */
117
- export declare function getCMSTenantId(event: RequestEvent): string | null;
118
- /** Returns the tenant key prefix (e.g. 'tenant_123:') for namespacing KV caches. */
119
- export declare function getCMSTenantPrefix(event: RequestEvent): string;
120
13
  /** Returns a single collection by ID. Reads from KV (TTL 5 min) with D1 fallback. */
121
14
  export declare function getCMSCollection(event: RequestEvent, collectionId: string): Promise<CMSCollection | null>;
122
15
  /** Lists all collections from D1. */
@@ -144,6 +37,7 @@ export declare function projectCMSEntry(entry: CMSEntry | null, fields?: string[
144
37
  export declare function getCollectionFields(event: RequestEvent, collectionId: string): Promise<Record<string, CMSFieldDefinition>>;
145
38
  /**
146
39
  * Returns a typed component definition from the CMS config by name, or null if not found.
40
+ *
147
41
  * @public
148
42
  */
149
43
  export declare function defineCMSComponent(def: CMSComponentDefinition): CMSComponentDefinition;
@@ -157,11 +51,6 @@ export declare function resolveReference(event: RequestEvent, ref: {
157
51
  slug?: string;
158
52
  }): Promise<CMSEntry | null>;
159
53
  export declare function invalidateCMSEntryCache(event: RequestEvent, collectionId: string, slug?: string): Promise<void>;
160
- /**
161
- * Verifies an incoming GitHub webhook HMAC-SHA256 signature (`X-Hub-Signature-256`)
162
- * using Web Crypto subtle API in constant time.
163
- */
164
- export declare function verifyGitHubSignature(rawBody: string, signatureHeader: string | null | undefined, secret: string): Promise<boolean>;
165
54
  /** Queries entries for a collection with filtering, pagination, and sorting. */
166
55
  export declare function queryCMSEntries(event: RequestEvent, collectionId: string, opts?: CMSQueryOptions): Promise<{
167
56
  entries: CMSEntry[];
@@ -211,8 +100,8 @@ export declare function generatePreviewToken(event: RequestEvent, collection: st
211
100
  expires: number;
212
101
  }>;
213
102
  /**
214
- * Verifies an HMAC-SHA256 preview token.
215
- * Tests against both `slugOrId` and alternate identifier (id vs slug) if available in D1.
103
+ * Verifies an HMAC-SHA256 preview token. Tests against both `slugOrId` and alternate identifier (id
104
+ * vs slug) if available in D1.
216
105
  */
217
106
  export declare function verifyPreviewToken(event: RequestEvent, collection: string, slugOrId: string, token: string, expiresStr: string | number): Promise<boolean>;
218
107
  export declare function ensureCMSTables(event?: RequestEvent): Promise<any>;
@@ -225,8 +114,8 @@ export declare function ensureCMSSynced(event?: RequestEvent): Promise<void>;
225
114
  */
226
115
  export declare function seedCollectionsFromConfig(event: RequestEvent, collectionsConfig: Record<string, CMSCollectionConfig>): Promise<void>;
227
116
  /**
228
- * Seeds or updates pre-scanned content entries into D1 database.
229
- * Used by both build-time manifest auto-restore and dev-mode local file sync.
117
+ * Seeds or updates pre-scanned content entries into D1 database. Used by both build-time manifest
118
+ * auto-restore and dev-mode local file sync.
230
119
  */
231
120
  export declare function seedEntriesIntoDb(event: RequestEvent, entries: any[], collectionsConfig?: Record<string, CMSCollectionConfig>): Promise<{
232
121
  synced: number;
@@ -249,8 +138,8 @@ export declare function syncLocalContentFiles(event: RequestEvent, contentDir: s
249
138
  }>;
250
139
  /**
251
140
  * Fetches a single "page" collection entry by its computed URL path. e.g. path =
252
- * "/docs/getting-started". Supports draft preview via editor session, HMAC preview token,
253
- * or preview cookie.
141
+ * "/docs/getting-started". Supports draft preview via editor session, HMAC preview token, or
142
+ * preview cookie.
254
143
  */
255
144
  export declare function getCMSEntryByPath(event: RequestEvent, collectionId: string, path: string, locale?: string, options?: {
256
145
  preview?: boolean;
@@ -270,32 +159,11 @@ export declare function getCMSEntrySurroundings(event: RequestEvent, collectionI
270
159
  */
271
160
  export declare function getCMSNavigationTree(event: RequestEvent, collectionId: string, options?: CMSNavigationOptions): Promise<CMSNavigationItem[]>;
272
161
  /**
273
- * Sanitizes and formats an input search query for SQLite FTS5 MATCH expressions.
274
- * Strips special operator characters that would otherwise trigger FTS5 syntax errors,
275
- * cleans whitespace, and formats tokens with prefix matching ("token"*).
276
- */
277
- export declare function buildFtsQuery(query: string, operator?: "AND" | "OR"): string;
278
- /**
279
- * Rebuilds the FTS5 virtual table from current `_qarpeo_cms_entries` records.
280
- * Can be used after schema migrations or to re-index all content.
281
- */
282
- export declare function rebuildCMSFTS(event?: RequestEvent): Promise<{
283
- total: number;
284
- }>;
285
- /**
286
- * High-performance edge search engine for documentation content.
287
- * Queries the SQLite FTS5 full-text index with automatic fallback to LIKE search,
288
- * splits markdown documents into heading-anchored sections, scores matches,
289
- * and extracts highlighted context excerpts.
290
- */
291
- export declare function searchDocs(event: RequestEvent, options?: DocsSearchOptions): Promise<DocsSearchResponse>;
292
- /**
293
- * Server-side chainable query builder for CMS collections.
294
- * Queries directly against D1 / SQLite with KV caching, with zero HTTP fetch overhead.
162
+ * Server-side chainable query builder for CMS collections. Queries directly against D1 / SQLite
163
+ * with KV caching, with zero HTTP fetch overhead.
295
164
  *
296
- * Usage:
297
- * const page = await queryCollection(event, "docs").path("/docs/intro").first()
298
- * const posts = await queryCollection(event, "blog").order("published_at", "DESC").limit(10).all()
165
+ * Usage: const page = await queryCollection(event, "docs").path("/docs/intro").first() const posts
166
+ * = await queryCollection(event, "blog").order("published_at", "DESC").limit(10).all()
299
167
  */
300
168
  export declare function queryCollection(event: RequestEvent, collection: string): {
301
169
  select(...fields: string[]): /*elided*/ any;