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.
- package/README.md +96 -96
- package/dist/chunks/auth-schema.mjs +3 -1
- package/dist/chunks/wrangler.mjs +22 -3
- package/dist/cli/index.mjs +448 -221
- package/dist/fate/index.d.ts +29 -22
- package/dist/fate/index.mjs +1 -3
- package/dist/module.d.ts +1 -1
- package/dist/module.mjs +103 -82
- package/dist/runtime/ai.d.ts +2 -2
- package/dist/runtime/app/components/BlobImage.vue +119 -107
- package/dist/runtime/app/components/CMSBlocks.vue +104 -93
- package/dist/runtime/app/components/CMSContent.vue +24 -23
- package/dist/runtime/app/components/CMSImage.vue +49 -49
- package/dist/runtime/app/components/CMSLocaleSwitcher.vue +110 -110
- package/dist/runtime/app/components/CMSPreviewBanner.vue +83 -79
- package/dist/runtime/app/components/CMSVersionBanner.vue +53 -49
- package/dist/runtime/app/components/CMSVersionSwitcher.vue +140 -140
- package/dist/runtime/app/components/ContentRenderer.vue +83 -80
- package/dist/runtime/app/components/FileUpload.vue +200 -196
- package/dist/runtime/app/components/ImpersonationBanner.vue +61 -57
- package/dist/runtime/app/components/QarpeoWelcome.vue +84 -84
- package/dist/runtime/app/components/SignedIn.vue +13 -13
- package/dist/runtime/app/components/SignedOut.vue +13 -13
- package/dist/runtime/app/components/shiki.css +34 -34
- package/dist/runtime/app/composables/ai.d.ts +22 -22
- package/dist/runtime/app/composables/ai.mjs +3 -7
- package/dist/runtime/app/composables/analytics.mjs +1 -1
- package/dist/runtime/app/composables/api-tokens.mjs +1 -1
- package/dist/runtime/app/composables/auth.d.ts +6 -7
- package/dist/runtime/app/composables/auth.mjs +6 -3
- package/dist/runtime/app/composables/chat.mjs +3 -7
- package/dist/runtime/app/composables/cms-preview.d.ts +3 -3
- package/dist/runtime/app/composables/cms-preview.mjs +1 -1
- package/dist/runtime/app/composables/cms.d.ts +3 -5
- package/dist/runtime/app/composables/cms.mjs +2 -2
- package/dist/runtime/app/composables/docs-version.d.ts +8 -7
- package/dist/runtime/app/composables/docs-version.mjs +3 -3
- package/dist/runtime/app/composables/impersonation.mjs +1 -1
- package/dist/runtime/app/composables/notifications.d.ts +5 -5
- package/dist/runtime/app/composables/notifications.mjs +4 -5
- package/dist/runtime/app/composables/organization.mjs +1 -1
- package/dist/runtime/app/composables/passkey.mjs +1 -1
- package/dist/runtime/app/composables/passwordless.mjs +1 -1
- package/dist/runtime/app/composables/payments.d.ts +2 -1
- package/dist/runtime/app/composables/payments.mjs +1 -1
- package/dist/runtime/app/composables/realtime.d.ts +13 -13
- package/dist/runtime/app/composables/realtime.mjs +2 -2
- package/dist/runtime/app/composables/resumable-upload.d.ts +11 -11
- package/dist/runtime/app/composables/resumable-upload.mjs +1 -1
- package/dist/runtime/app/composables/site.mjs +1 -1
- package/dist/runtime/app/composables/storage.d.ts +151 -11
- package/dist/runtime/app/composables/storage.mjs +291 -33
- package/dist/runtime/app/composables/turnstile.mjs +1 -1
- package/dist/runtime/app/composables/two-factor.mjs +1 -1
- package/dist/runtime/app/pages/devtools/agents.vue +716 -716
- package/dist/runtime/app/pages/devtools/analytics.vue +616 -616
- package/dist/runtime/app/pages/devtools/auth.vue +381 -350
- package/dist/runtime/app/pages/devtools/blob.vue +743 -744
- package/dist/runtime/app/pages/devtools/db.vue +545 -545
- package/dist/runtime/app/pages/devtools/domains.vue +771 -771
- package/dist/runtime/app/pages/devtools/kv.vue +827 -828
- package/dist/runtime/app/pages/devtools/logs.vue +649 -653
- package/dist/runtime/app/pages/devtools/mail.vue +388 -388
- package/dist/runtime/app/pages/devtools/overview.vue +391 -389
- package/dist/runtime/app/pages/devtools/realtime.vue +89 -27
- package/dist/runtime/app/pages/devtools/security.vue +20 -5
- package/dist/runtime/app/pages/devtools/settings.vue +559 -559
- package/dist/runtime/app/pages/devtools/tasks.vue +26 -10
- package/dist/runtime/app/pages/devtools.vue +176 -176
- package/dist/runtime/app/plugins/seo.mjs +1 -1
- package/dist/runtime/app/plugins/shortcuts.client.d.ts +1 -4
- package/dist/runtime/app/public/sw-notifications.mjs +47 -52
- package/dist/runtime/blob.mjs +11 -4
- package/dist/runtime/browser.d.ts +1 -1
- package/dist/runtime/browser.mjs +12 -2
- package/dist/runtime/cache.d.ts +2 -1
- package/dist/runtime/kv.mjs +4 -1
- package/dist/runtime/providers/qarpeo.d.ts +3 -3
- package/dist/runtime/server/durable-objects/agent.mjs +1 -1
- package/dist/runtime/server/durable-objects/room.d.ts +2 -2
- package/dist/runtime/server/durable-objects/room.mjs +5 -5
- package/dist/runtime/server/middleware/devtools.mjs +6 -2
- package/dist/runtime/server/plugins/cms.d.ts +4 -2
- package/dist/runtime/server/plugins/dev-proxy.mjs +1 -1
- package/dist/runtime/server/routes/__qarpeo/agents/chat.post.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/agents/chat.post.mjs +4 -1
- package/dist/runtime/server/routes/__qarpeo/analytics/events.get.d.ts +1 -4
- package/dist/runtime/server/routes/__qarpeo/analytics/summary.get.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/analytics/summary.get.mjs +5 -1
- package/dist/runtime/server/routes/__qarpeo/db/tables.get.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/db/tables.get.mjs +1 -1
- package/dist/runtime/server/routes/__qarpeo/logs.get.d.ts +4 -1
- package/dist/runtime/server/routes/__qarpeo/mail/track/click/[id].get.mjs +1 -1
- package/dist/runtime/server/routes/__qarpeo/mail/track/open/[id].get.mjs +2 -2
- package/dist/runtime/server/routes/__qarpeo/overview.get.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/realtime/broadcast.post.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/realtime/broadcast.post.mjs +1 -1
- package/dist/runtime/server/routes/__qarpeo/realtime/clear.post.d.ts +1 -4
- package/dist/runtime/server/routes/__qarpeo/realtime/clear.post.mjs +1 -1
- package/dist/runtime/server/routes/__qarpeo/realtime/disconnect.post.d.ts +1 -4
- package/dist/runtime/server/routes/__qarpeo/realtime/disconnect.post.mjs +1 -1
- package/dist/runtime/server/routes/__qarpeo/realtime/room.get.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/realtime/rooms.get.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/security/analytics.get.d.ts +2 -2
- package/dist/runtime/server/routes/__qarpeo/security/ban.post.d.ts +1 -4
- package/dist/runtime/server/routes/__qarpeo/security/clear.post.d.ts +1 -4
- package/dist/runtime/server/routes/__qarpeo/security/unban.post.d.ts +1 -4
- package/dist/runtime/server/routes/__qarpeo/settings.get.mjs +1 -1
- package/dist/runtime/server/routes/__qarpeo/tasks/run.post.mjs +3 -1
- package/dist/runtime/server/routes/agents/[agent]/chat.post.mjs +8 -2
- package/dist/runtime/server/routes/agents/[agent]/clear.post.mjs +8 -2
- package/dist/runtime/server/routes/agents/[agent]/history.get.mjs +8 -2
- package/dist/runtime/server/routes/ai/embed.post.d.ts +1 -4
- package/dist/runtime/server/routes/ai/search.post.d.ts +2 -2
- package/dist/runtime/server/routes/auth/account.delete.mjs +1 -1
- package/dist/runtime/server/routes/auth/handler.mjs +6 -1
- package/dist/runtime/server/routes/auth/magic-link/verify.get.mjs +1 -1
- package/dist/runtime/server/routes/auth/organization/members/[id].delete.mjs +7 -1
- package/dist/runtime/server/routes/auth/otp/verify.post.mjs +1 -1
- package/dist/runtime/server/routes/auth/sso/login.get.mjs +7 -1
- package/dist/runtime/server/routes/auth/sso/oidc/callback.get.mjs +8 -2
- package/dist/runtime/server/routes/auth/sso/saml/acs.post.mjs +7 -2
- package/dist/runtime/server/routes/auth/webauthn/login/options.post.mjs +1 -1
- package/dist/runtime/server/routes/auth/webauthn/login/verify.post.mjs +7 -2
- package/dist/runtime/server/routes/auth/webauthn/register/options.post.mjs +6 -1
- package/dist/runtime/server/routes/auth/webauthn/register/verify.post.mjs +6 -1
- package/dist/runtime/server/routes/browser/crawl.post.d.ts +1 -2
- package/dist/runtime/server/routes/browser/invoice.post.d.ts +1 -2
- package/dist/runtime/server/routes/browser/og-image.post.d.ts +2 -2
- package/dist/runtime/server/routes/browser/pdf.post.d.ts +1 -2
- package/dist/runtime/server/routes/browser/pdf.post.mjs +6 -1
- package/dist/runtime/server/routes/browser/screenshot.post.d.ts +2 -2
- package/dist/runtime/server/routes/browser/screenshot.post.mjs +5 -1
- package/dist/runtime/server/routes/cms/components/index.get.d.ts +2 -2
- package/dist/runtime/server/routes/cms/preview/disable.get.d.ts +4 -3
- package/dist/runtime/server/routes/cms/preview/enable.get.d.ts +8 -8
- package/dist/runtime/server/routes/cms/search.get.mjs +1 -1
- package/dist/runtime/server/routes/cms/webhooks/[provider].post.d.ts +7 -7
- package/dist/runtime/server/routes/cms/webhooks/[provider].post.mjs +9 -2
- package/dist/runtime/server/routes/docs/search.get.d.ts +9 -9
- package/dist/runtime/server/routes/fate.mjs +5 -8
- package/dist/runtime/server/routes/mail/bounce.post.d.ts +2 -2
- package/dist/runtime/server/routes/mail/unsubscribe.d.ts +2 -2
- package/dist/runtime/server/routes/mail/webhooks.post.d.ts +2 -2
- package/dist/runtime/server/routes/mail/webhooks.post.mjs +7 -1
- package/dist/runtime/server/routes/payments/usage.get.d.ts +8 -8
- package/dist/runtime/server/routes/payments/usage.post.d.ts +2 -2
- package/dist/runtime/server/routes/realtime/history.delete.d.ts +4 -3
- package/dist/runtime/server/routes/realtime/history.get.d.ts +7 -6
- package/dist/runtime/server/routes/realtime/ws.get.mjs +6 -1
- package/dist/runtime/server/routes/robots.txt.get.mjs +1 -1
- package/dist/runtime/server/routes/sitemap.xml.get.mjs +2 -1
- package/dist/runtime/server/routes/storage/multipart/abort.post.d.ts +2 -2
- package/dist/runtime/server/routes/storage/multipart/complete.post.d.ts +2 -2
- package/dist/runtime/server/routes/storage/multipart/complete.post.mjs +2 -2
- package/dist/runtime/server/routes/storage/multipart/create.post.d.ts +2 -2
- package/dist/runtime/server/routes/storage/multipart/create.post.mjs +7 -3
- package/dist/runtime/server/routes/storage/multipart/part.put.d.ts +2 -2
- package/dist/runtime/server/routes/storage/multipart/part.put.mjs +1 -1
- package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/index.delete.mjs +2 -4
- package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/verify.post.mjs +2 -4
- package/dist/runtime/server/routes/tenants/[tenant]/domains/index.get.mjs +1 -1
- package/dist/runtime/server/routes/tenants/[tenant]/domains/index.post.mjs +2 -4
- package/dist/runtime/server/tasks/cms/publish.mjs +1 -1
- package/dist/runtime/server/utils/ai.d.ts +9 -9
- package/dist/runtime/server/utils/ai.mjs +3 -3
- package/dist/runtime/server/utils/auth.d.ts +12 -16
- package/dist/runtime/server/utils/auth.mjs +15 -9
- package/dist/runtime/server/utils/bots.mjs +21 -7
- package/dist/runtime/server/utils/browser-utils.d.ts +44 -41
- package/dist/runtime/server/utils/browser-utils.mjs +14 -4
- package/dist/runtime/server/utils/cache.d.ts +5 -5
- package/dist/runtime/server/utils/cms/common.d.ts +26 -0
- package/dist/runtime/server/utils/cms/common.mjs +68 -0
- package/dist/runtime/server/utils/cms/git.d.ts +24 -0
- package/dist/runtime/server/utils/cms/git.mjs +240 -0
- package/dist/runtime/server/utils/cms/markdown.d.ts +22 -0
- package/dist/runtime/server/utils/cms/markdown.mjs +92 -0
- package/dist/runtime/server/utils/cms/path.d.ts +51 -0
- package/dist/runtime/server/utils/cms/path.mjs +127 -0
- package/dist/runtime/server/utils/cms/search.d.ts +22 -0
- package/dist/runtime/server/utils/cms/search.mjs +221 -0
- package/dist/runtime/server/utils/cms-events.d.ts +1 -1
- package/dist/runtime/server/utils/cms-events.mjs +2 -2
- package/dist/runtime/server/utils/cms-filter.mjs +2 -2
- package/dist/runtime/server/utils/cms.d.ts +17 -149
- package/dist/runtime/server/utils/cms.mjs +52 -761
- package/dist/runtime/server/utils/config.d.ts +5 -4
- package/dist/runtime/server/utils/domains.mjs +7 -4
- package/dist/runtime/server/utils/email-templates.d.ts +10 -7
- package/dist/runtime/server/utils/email-templates.mjs +20 -5
- package/dist/runtime/server/utils/feed.d.ts +2 -2
- package/dist/runtime/server/utils/feed.mjs +3 -1
- package/dist/runtime/server/utils/mail-suppression.d.ts +8 -24
- package/dist/runtime/server/utils/mail-suppression.mjs +2 -2
- package/dist/runtime/server/utils/mail.d.ts +7 -8
- package/dist/runtime/server/utils/mail.mjs +17 -12
- package/dist/runtime/server/utils/multipart-store.d.ts +2 -2
- package/dist/runtime/server/utils/notifications.d.ts +9 -23
- package/dist/runtime/server/utils/organization.mjs +4 -12
- package/dist/runtime/server/utils/passwordless.mjs +1 -1
- package/dist/runtime/server/utils/payments.d.ts +2 -6
- package/dist/runtime/server/utils/payments.mjs +1 -1
- package/dist/runtime/server/utils/queue.d.ts +21 -31
- package/dist/runtime/server/utils/rag.d.ts +4 -4
- package/dist/runtime/server/utils/rag.mjs +8 -8
- package/dist/runtime/server/utils/realtime-store.d.ts +2 -2
- package/dist/runtime/server/utils/realtime.d.ts +26 -28
- package/dist/runtime/server/utils/scheduled-task.d.ts +1 -3
- package/dist/runtime/server/utils/security-store.d.ts +2 -2
- package/dist/runtime/server/utils/session.d.ts +9 -11
- package/dist/runtime/server/utils/sso.d.ts +9 -15
- package/dist/runtime/server/utils/sso.mjs +4 -8
- package/dist/runtime/server/utils/storage.d.ts +19 -2
- package/dist/runtime/server/utils/storage.mjs +36 -7
- package/dist/runtime/server/utils/tenant.mjs +3 -1
- package/dist/runtime/server/utils/turnstile.d.ts +3 -5
- package/dist/runtime/server/utils/vapid.d.ts +5 -8
- package/dist/runtime/server/utils/vapid.mjs +26 -13
- package/dist/runtime/service.d.ts +13 -13
- package/dist/runtime/service.mjs +4 -2
- package/dist/runtime/test-utils.d.ts +20 -30
- package/dist/runtime/test-utils.mjs +5 -4
- package/dist/runtime/types/auth-globals.d.ts +14 -14
- package/dist/runtime/types/imports.d.ts +82 -82
- package/dist/runtime/types/index.d.ts +2 -2
- package/dist/runtime/types/r2.d.ts +5 -0
- package/dist/runtime/types/service.d.ts +11 -18
- package/dist/types.d.ts +100 -107
- package/dist/utils/auth-schema.d.ts +2 -2
- package/dist/utils/cms-sources.d.ts +3 -3
- package/dist/utils/local-db.d.ts +3 -3
- package/dist/utils/notifications-schema.d.ts +1 -3
- package/dist/utils/pkg.d.ts +7 -0
- package/dist/utils/queue.d.ts +3 -3
- package/dist/utils/tasks.d.ts +3 -2
- package/package.json +11 -8
|
@@ -1,279 +1,39 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { createError, useRuntimeConfig, getCookie } from "nuxt/server";
|
|
4
|
-
import { parse as parseYaml, stringify as stringifyYaml } from "yaml";
|
|
5
|
-
import { getD1Binding } from "../../db.mjs";
|
|
1
|
+
import { createError, getCookie, useRuntimeConfig } from "nuxt/server";
|
|
2
|
+
import { parse as parseYaml } from "yaml";
|
|
6
3
|
import { getKVBinding } from "../../kv.mjs";
|
|
7
4
|
import { fireCMSWebhooks, fireCMSDeployTrigger } from "./cms-events.mjs";
|
|
8
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
getCMSDb,
|
|
7
|
+
nanoid,
|
|
8
|
+
getCMSConfig,
|
|
9
|
+
resolveCollectionApproval,
|
|
10
|
+
computeContentHash,
|
|
11
|
+
getCMSTenantId,
|
|
12
|
+
getCMSTenantPrefix
|
|
13
|
+
} from "./cms/common.mjs";
|
|
14
|
+
import { syncEntryToGit, registerEntryFormatter } from "./cms/git.mjs";
|
|
15
|
+
import {
|
|
16
|
+
parseMarkdownAST,
|
|
17
|
+
processMarkdown,
|
|
18
|
+
parseFrontmatter,
|
|
19
|
+
formatFrontmatter
|
|
20
|
+
} from "./cms/markdown.mjs";
|
|
21
|
+
import {
|
|
22
|
+
stripOrderPrefix,
|
|
23
|
+
isGroupSegment,
|
|
24
|
+
extractGroupTitle,
|
|
25
|
+
extractOrderPrefix,
|
|
26
|
+
computeEntryPath,
|
|
27
|
+
resolveCollectionForPath,
|
|
28
|
+
extractTOC
|
|
29
|
+
} from "./cms/path.mjs";
|
|
30
|
+
import { registerEnsureCMSSynced } from "./cms/search.mjs";
|
|
9
31
|
import { getAuthContext } from "./context.mjs";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
function nanoid(size = 21) {
|
|
18
|
-
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
19
|
-
const bytes = crypto.getRandomValues(new Uint8Array(size));
|
|
20
|
-
return Array.from(bytes, (b) => chars[b % chars.length]).join("");
|
|
21
|
-
}
|
|
22
|
-
export function slugifyHeading(text) {
|
|
23
|
-
return text.toLowerCase().replace(/[^\w\s-]/g, "").replace(/[\s_]+/g, "-").replace(/^-+|-+$/g, "");
|
|
24
|
-
}
|
|
25
|
-
export function stripOrderPrefix(segment) {
|
|
26
|
-
return segment.replace(/^\d+\./, "");
|
|
27
|
-
}
|
|
28
|
-
export function isGroupSegment(segment) {
|
|
29
|
-
const stripped = stripOrderPrefix(segment);
|
|
30
|
-
return /^\([^)]+\)$/.test(stripped);
|
|
31
|
-
}
|
|
32
|
-
export function extractGroupTitle(segment) {
|
|
33
|
-
const stripped = stripOrderPrefix(segment);
|
|
34
|
-
const inner = stripped.replace(/^\(|\)$/g, "");
|
|
35
|
-
return inner.split("-").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
|
|
36
|
-
}
|
|
37
|
-
export function extractOrderPrefix(segment) {
|
|
38
|
-
const m = segment.match(/^(\d+)\./);
|
|
39
|
-
return m ? parseInt(m[1], 10) : void 0;
|
|
40
|
-
}
|
|
41
|
-
export function computeEntryPath(filePathRelative, collectionId) {
|
|
42
|
-
const normalized = filePathRelative.replace(/\\/g, "/").replace(/\.md$/, "");
|
|
43
|
-
const segments = normalized.split("/").filter(Boolean);
|
|
44
|
-
const cleaned = segments.filter((seg) => !isGroupSegment(seg)).map(stripOrderPrefix).filter(Boolean);
|
|
45
|
-
if (cleaned[cleaned.length - 1] === "index") {
|
|
46
|
-
cleaned.pop();
|
|
47
|
-
}
|
|
48
|
-
if (collectionId && collectionId !== "content" && cleaned[0] !== collectionId) {
|
|
49
|
-
cleaned.unshift(collectionId);
|
|
50
|
-
}
|
|
51
|
-
if (cleaned.length === 0) return "/";
|
|
52
|
-
return "/" + cleaned.join("/");
|
|
53
|
-
}
|
|
54
|
-
export function matchPathPatterns(entryPath, patterns) {
|
|
55
|
-
if (!patterns) return false;
|
|
56
|
-
const list = Array.isArray(patterns) ? patterns : [patterns];
|
|
57
|
-
if (!list.length) return false;
|
|
58
|
-
const path = ("/" + entryPath.replace(/\\/g, "/").replace(/^\/+/, "")).replace(/\/+$/, "") || "/";
|
|
59
|
-
let matched = false;
|
|
60
|
-
for (const raw of list) {
|
|
61
|
-
const isNeg = raw.startsWith("!");
|
|
62
|
-
const rawPattern = isNeg ? raw.slice(1) : raw;
|
|
63
|
-
const pattern = ("/" + rawPattern.replace(/\\/g, "/").replace(/^\/+/, "")).replace(/\/+$/, "") || "/";
|
|
64
|
-
let isMatch = false;
|
|
65
|
-
if (pattern.endsWith("/**")) {
|
|
66
|
-
const base = pattern.slice(0, -3) || "/";
|
|
67
|
-
isMatch = path === base || path.startsWith(base + "/");
|
|
68
|
-
} else if (pattern.includes("*") || pattern.includes("?")) {
|
|
69
|
-
const regexStr = "^" + pattern.replace(/[.+^${}()|[\]\\]/g, (m) => "\\" + m).replace(/\*\*/g, ".*").replace(/(?<!\.)\*/g, "[^/]*").replace(/\?/g, "[^/]") + "$";
|
|
70
|
-
isMatch = new RegExp(regexStr).test(path);
|
|
71
|
-
} else {
|
|
72
|
-
isMatch = path === pattern;
|
|
73
|
-
}
|
|
74
|
-
if (isMatch) {
|
|
75
|
-
if (isNeg) return false;
|
|
76
|
-
matched = true;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return matched;
|
|
80
|
-
}
|
|
81
|
-
export function resolveCollectionForPath(entryPath, collectionsConfig, fallbackId = "content") {
|
|
82
|
-
if (collectionsConfig) {
|
|
83
|
-
for (const [colId, colConfig] of Object.entries(collectionsConfig)) {
|
|
84
|
-
if (colConfig.path && matchPathPatterns(entryPath, colConfig.path)) {
|
|
85
|
-
return colId;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return fallbackId;
|
|
90
|
-
}
|
|
91
|
-
export function extractTOC(md) {
|
|
92
|
-
const lines = md.split("\n");
|
|
93
|
-
const flat = [];
|
|
94
|
-
for (const line of lines) {
|
|
95
|
-
const m = line.match(/^(#{2,6})\s+(.+)/);
|
|
96
|
-
if (!m) continue;
|
|
97
|
-
const depth = m[1].length;
|
|
98
|
-
const rawText = m[2].trim().replace(/\[([^\]]+)\]\([^)]+\)/g, "$1").replace(/[`*_~]/g, "");
|
|
99
|
-
flat.push({ id: slugifyHeading(rawText), text: rawText, depth });
|
|
100
|
-
}
|
|
101
|
-
const result = [];
|
|
102
|
-
let current2 = null;
|
|
103
|
-
for (const item of flat) {
|
|
104
|
-
if (item.depth === 2) {
|
|
105
|
-
current2 = { ...item, children: [] };
|
|
106
|
-
result.push(current2);
|
|
107
|
-
} else if (current2 && item.depth >= 3) {
|
|
108
|
-
current2.children = current2.children || [];
|
|
109
|
-
current2.children.push(item);
|
|
110
|
-
} else {
|
|
111
|
-
result.push(item);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return result;
|
|
115
|
-
}
|
|
116
|
-
function parseInlineProps(propsStr) {
|
|
117
|
-
const inner = propsStr.replace(/^\{|\}$/g, "");
|
|
118
|
-
const result = {};
|
|
119
|
-
const re = /(\w+)="([^"]*)"/g;
|
|
120
|
-
let m;
|
|
121
|
-
while ((m = re.exec(inner)) !== null) {
|
|
122
|
-
result[m[1]] = m[2];
|
|
123
|
-
}
|
|
124
|
-
return result;
|
|
125
|
-
}
|
|
126
|
-
function escapeAttr(val) {
|
|
127
|
-
return val.replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
128
|
-
}
|
|
129
|
-
export function preprocessMDC(md) {
|
|
130
|
-
let out = md;
|
|
131
|
-
out = out.replace(
|
|
132
|
-
/:::(\w[\w-]*)(\{[^}]*\})?\s*\n([\s\S]*?):::/g,
|
|
133
|
-
(_match, type, propsStr, body) => {
|
|
134
|
-
const attrs = parseInlineProps(propsStr || "");
|
|
135
|
-
const cls = `mdc-${type}`;
|
|
136
|
-
const attrStr = Object.entries(attrs).map(([k, v]) => ` data-${k}="${escapeAttr(v)}"`).join("");
|
|
137
|
-
return `<div class="${cls}"${attrStr}>
|
|
138
|
-
${body.trim()}
|
|
139
|
-
</div>`;
|
|
140
|
-
}
|
|
141
|
-
);
|
|
142
|
-
out = out.replace(/::(\w[\w-]*)\s*\n([\s\S]*?)::/g, (_match, type, body) => {
|
|
143
|
-
return `<div class="mdc-${type}">
|
|
144
|
-
${body.trim()}
|
|
145
|
-
</div>`;
|
|
146
|
-
});
|
|
147
|
-
return out;
|
|
148
|
-
}
|
|
149
|
-
export function getCMSConfig(event) {
|
|
150
|
-
const rc = useRuntimeConfig(event);
|
|
151
|
-
const cfg = rc?.qarpeo?.cms || {};
|
|
152
|
-
return {
|
|
153
|
-
api: cfg.api === true,
|
|
154
|
-
apiPath: cfg.apiPath || "/api/cms",
|
|
155
|
-
contentDir: cfg.contentDir || "content",
|
|
156
|
-
hybrid: cfg.hybrid !== false,
|
|
157
|
-
roles: cfg.roles || ["admin", "editor"],
|
|
158
|
-
revisions: cfg.revisions || { max: 10 },
|
|
159
|
-
cache: cfg.cache !== false,
|
|
160
|
-
collections: cfg.collections || {},
|
|
161
|
-
components: cfg.components || {},
|
|
162
|
-
sources: cfg.sources || [],
|
|
163
|
-
exclude: cfg.exclude || void 0,
|
|
164
|
-
github: cfg.github || void 0,
|
|
165
|
-
deploy: cfg.deploy || void 0,
|
|
166
|
-
webhooks: cfg.webhooks || [],
|
|
167
|
-
webhookSecret: cfg.webhookSecret || void 0,
|
|
168
|
-
approval: cfg.approval || void 0,
|
|
169
|
-
scheduledPublish: cfg.scheduledPublish ?? false,
|
|
170
|
-
shiki: cfg.shiki !== void 0 ? cfg.shiki : true,
|
|
171
|
-
plugins: cfg.plugins || {},
|
|
172
|
-
locales: cfg.locales || ["en"],
|
|
173
|
-
defaultLocale: cfg.defaultLocale || "en"
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
export function resolveCollectionApproval(collectionConfig, globalApproval) {
|
|
177
|
-
const raw = collectionConfig?.approval ?? globalApproval;
|
|
178
|
-
if (!raw) return null;
|
|
179
|
-
if (typeof raw === "object") {
|
|
180
|
-
return {
|
|
181
|
-
roles: raw.roles && raw.roles.length > 0 ? raw.roles : ["admin"],
|
|
182
|
-
allowSelfApproval: raw.allowSelfApproval ?? false
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
return {
|
|
186
|
-
roles: ["admin"],
|
|
187
|
-
allowSelfApproval: false
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
const _cachedPluginsMap = /* @__PURE__ */ new Map();
|
|
191
|
-
async function _resolveMarkdownPlugins(event) {
|
|
192
|
-
const rc = useRuntimeConfig(event);
|
|
193
|
-
const pluginCfg = getQarpeoConfig(event).cms?.plugins || rc?.public?.qarpeo?.cms?.plugins || {};
|
|
194
|
-
const cacheKey = JSON.stringify(pluginCfg);
|
|
195
|
-
if (_cachedPluginsMap.has(cacheKey)) return _cachedPluginsMap.get(cacheKey);
|
|
196
|
-
const plugins = [];
|
|
197
|
-
if (pluginCfg.shiki !== false) {
|
|
198
|
-
try {
|
|
199
|
-
const shikiMod = await import("comark/plugins/shiki");
|
|
200
|
-
const shikiPlugin = shikiMod.default;
|
|
201
|
-
const shikiOptions = typeof pluginCfg.shiki === "object" ? pluginCfg.shiki : {};
|
|
202
|
-
plugins.push(shikiPlugin(shikiOptions));
|
|
203
|
-
} catch {
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
_cachedPluginsMap.set(cacheKey, plugins);
|
|
207
|
-
return plugins;
|
|
208
|
-
}
|
|
209
|
-
export async function parseMarkdownAST(md, event) {
|
|
210
|
-
if (!md) return { nodes: [], frontmatter: {}, meta: {} };
|
|
211
|
-
try {
|
|
212
|
-
const plugins = await _resolveMarkdownPlugins(event);
|
|
213
|
-
return await comarkParseMarkdown(md, { plugins });
|
|
214
|
-
} catch (err) {
|
|
215
|
-
console.error("[qarpeo:cms] parseMarkdownAST failed:", err);
|
|
216
|
-
return { nodes: [], frontmatter: {}, meta: {} };
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
export async function processMarkdown(md, event) {
|
|
220
|
-
if (!md) return { ast: { nodes: [], frontmatter: {}, meta: {} }, html: "" };
|
|
221
|
-
try {
|
|
222
|
-
const plugins = await _resolveMarkdownPlugins(event);
|
|
223
|
-
const ast = await comarkParseMarkdown(md, { plugins });
|
|
224
|
-
const html = (await comarkRender(ast, { format: "text/html" })).trim();
|
|
225
|
-
return { ast, html };
|
|
226
|
-
} catch {
|
|
227
|
-
return { ast: { nodes: [], frontmatter: {}, meta: {} }, html: md };
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
export async function renderMarkdown(md, event) {
|
|
231
|
-
if (!md) return "";
|
|
232
|
-
try {
|
|
233
|
-
const res = await processMarkdown(md, event);
|
|
234
|
-
return res.html;
|
|
235
|
-
} catch {
|
|
236
|
-
return md;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
export async function renderPageMarkdown(md) {
|
|
240
|
-
return renderMarkdown(md);
|
|
241
|
-
}
|
|
242
|
-
export function parseFrontmatter(raw) {
|
|
243
|
-
const clean = raw ? raw.replace(/^\uFEFF/, "") : "";
|
|
244
|
-
const fmMatch = clean.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)/);
|
|
245
|
-
if (!fmMatch) {
|
|
246
|
-
return { data: {}, content: clean };
|
|
247
|
-
}
|
|
248
|
-
const yamlBlock = fmMatch[1] || "";
|
|
249
|
-
const body = fmMatch[2] || "";
|
|
250
|
-
let data = {};
|
|
251
|
-
try {
|
|
252
|
-
const parsed = parseYaml(yamlBlock);
|
|
253
|
-
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
254
|
-
data = parsed;
|
|
255
|
-
}
|
|
256
|
-
} catch (err) {
|
|
257
|
-
console.warn("[qarpeo:cms] Warning: failed to parse YAML frontmatter:", err);
|
|
258
|
-
}
|
|
259
|
-
return { data, content: body };
|
|
260
|
-
}
|
|
261
|
-
export function formatFrontmatter(data, body) {
|
|
262
|
-
const cleanData = {};
|
|
263
|
-
for (const [k, v] of Object.entries(data)) {
|
|
264
|
-
if (v === void 0 || v === null || k.startsWith("_")) continue;
|
|
265
|
-
cleanData[k] = v;
|
|
266
|
-
}
|
|
267
|
-
const yamlStr = Object.keys(cleanData).length > 0 ? stringifyYaml(cleanData).trim() : "";
|
|
268
|
-
if (!yamlStr) {
|
|
269
|
-
return body;
|
|
270
|
-
}
|
|
271
|
-
return `---
|
|
272
|
-
${yamlStr}
|
|
273
|
-
---
|
|
274
|
-
|
|
275
|
-
${body}`;
|
|
276
|
-
}
|
|
32
|
+
export * from "./cms/common.mjs";
|
|
33
|
+
export * from "./cms/path.mjs";
|
|
34
|
+
export * from "./cms/markdown.mjs";
|
|
35
|
+
export * from "./cms/git.mjs";
|
|
36
|
+
export * from "./cms/search.mjs";
|
|
277
37
|
export function formatEntryAsMarkdown(entry) {
|
|
278
38
|
const e = entry;
|
|
279
39
|
let metadata = {};
|
|
@@ -307,231 +67,7 @@ export function formatEntryAsMarkdown(entry) {
|
|
|
307
67
|
const body = e.contentMd ?? e.content_md ?? "";
|
|
308
68
|
return formatFrontmatter(fmData, body);
|
|
309
69
|
}
|
|
310
|
-
|
|
311
|
-
if (typeof Buffer !== "undefined") {
|
|
312
|
-
return Buffer.from(str, "utf8").toString("base64");
|
|
313
|
-
}
|
|
314
|
-
const bytes = new TextEncoder().encode(str);
|
|
315
|
-
let binary = "";
|
|
316
|
-
for (let i = 0; i < bytes.byteLength; i++) {
|
|
317
|
-
binary += String.fromCharCode(bytes[i]);
|
|
318
|
-
}
|
|
319
|
-
return btoa(binary);
|
|
320
|
-
}
|
|
321
|
-
export async function syncEntryToGit(event, collectionId, entry, action) {
|
|
322
|
-
const config = getCMSConfig(event);
|
|
323
|
-
const colConfig = config.collections[collectionId] || {};
|
|
324
|
-
const mode = colConfig.mode || config.mode || "db";
|
|
325
|
-
if (mode !== "hybrid") {
|
|
326
|
-
return null;
|
|
327
|
-
}
|
|
328
|
-
const result = {};
|
|
329
|
-
const e = entry;
|
|
330
|
-
let rawFilePath = e.filePath || e.file_path;
|
|
331
|
-
if (!rawFilePath) {
|
|
332
|
-
const targetDir = colConfig.directory || `${config.contentDir}/${collectionId}`;
|
|
333
|
-
rawFilePath = `${targetDir}/${e.slug}.md`;
|
|
334
|
-
}
|
|
335
|
-
let resolvedFsPath = rawFilePath;
|
|
336
|
-
let fileContent = "";
|
|
337
|
-
try {
|
|
338
|
-
const fs = await import("node:fs/promises");
|
|
339
|
-
const pathMod = await import("node:path");
|
|
340
|
-
resolvedFsPath = pathMod.isAbsolute(rawFilePath) ? rawFilePath : pathMod.resolve(process.cwd(), rawFilePath);
|
|
341
|
-
if (action === "delete") {
|
|
342
|
-
const exists = await fs.stat(resolvedFsPath).catch(() => null);
|
|
343
|
-
if (exists) {
|
|
344
|
-
await fs.unlink(resolvedFsPath);
|
|
345
|
-
result.localFs = true;
|
|
346
|
-
}
|
|
347
|
-
} else {
|
|
348
|
-
fileContent = formatEntryAsMarkdown(entry);
|
|
349
|
-
await fs.mkdir(pathMod.dirname(resolvedFsPath), { recursive: true });
|
|
350
|
-
await fs.writeFile(resolvedFsPath, fileContent, "utf8");
|
|
351
|
-
result.localFs = true;
|
|
352
|
-
const contentHash = await computeContentHash(fileContent);
|
|
353
|
-
result.filePath = resolvedFsPath;
|
|
354
|
-
result.contentHash = contentHash;
|
|
355
|
-
if (e.id) {
|
|
356
|
-
const db = getCMSDb(event);
|
|
357
|
-
await db.prepare(
|
|
358
|
-
"UPDATE _qarpeo_cms_entries SET file_path = ?, content_hash = ?, source = 'file' WHERE id = ?"
|
|
359
|
-
).bind(resolvedFsPath, contentHash, e.id).run();
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
} catch (err) {
|
|
363
|
-
}
|
|
364
|
-
const ghConfig = {
|
|
365
|
-
...config.github || {},
|
|
366
|
-
...colConfig.github || {}
|
|
367
|
-
};
|
|
368
|
-
const repo = ghConfig.repo || (typeof process !== "undefined" ? process.env.GITHUB_REPOSITORY : void 0);
|
|
369
|
-
const token = ghConfig.token || (typeof process !== "undefined" ? process.env.GITHUB_TOKEN || process.env.GH_TOKEN : void 0);
|
|
370
|
-
if (repo && token) {
|
|
371
|
-
try {
|
|
372
|
-
const [owner, repoName] = repo.split("/");
|
|
373
|
-
if (!owner || !repoName) {
|
|
374
|
-
console.warn(`[qarpeo:cms] Invalid GitHub repo format: "${repo}". Expected "owner/repo".`);
|
|
375
|
-
} else {
|
|
376
|
-
let gitPath = resolvedFsPath.replace(/\\/g, "/");
|
|
377
|
-
const match = gitPath.match(/(?:^|[\\/])((?:content|docs)[\\/].*)$/i);
|
|
378
|
-
if (match) {
|
|
379
|
-
gitPath = match[1];
|
|
380
|
-
} else if (colConfig.directory) {
|
|
381
|
-
gitPath = `${colConfig.directory}/${entry.slug}.md`;
|
|
382
|
-
} else {
|
|
383
|
-
gitPath = `${config.contentDir}/${collectionId}/${entry.slug}.md`;
|
|
384
|
-
}
|
|
385
|
-
gitPath = gitPath.replace(/\\/g, "/").replace(/^\/+/, "");
|
|
386
|
-
const baseBranch = ghConfig.branch || "main";
|
|
387
|
-
const actionVerb = action === "create" ? "create" : action === "delete" ? "delete" : "update";
|
|
388
|
-
const template = ghConfig.commitMessage || "content({collection}): {action} {slug}";
|
|
389
|
-
const commitMsg = template.replace("{collection}", collectionId).replace("{slug}", entry.slug).replace("{action}", actionVerb);
|
|
390
|
-
const headers = {
|
|
391
|
-
Accept: "application/vnd.github.v3+json",
|
|
392
|
-
Authorization: `Bearer ${token}`,
|
|
393
|
-
"User-Agent": "qarpeo-cms",
|
|
394
|
-
"Content-Type": "application/json"
|
|
395
|
-
};
|
|
396
|
-
let existingSha;
|
|
397
|
-
try {
|
|
398
|
-
const checkRes = await fetch(
|
|
399
|
-
`https://api.github.com/repos/${owner}/${repoName}/contents/${gitPath}?ref=${baseBranch}`,
|
|
400
|
-
{ headers }
|
|
401
|
-
);
|
|
402
|
-
if (checkRes.ok) {
|
|
403
|
-
const checkData = await checkRes.json();
|
|
404
|
-
existingSha = checkData.sha;
|
|
405
|
-
}
|
|
406
|
-
} catch {
|
|
407
|
-
}
|
|
408
|
-
let targetBranch = baseBranch;
|
|
409
|
-
let prUrl;
|
|
410
|
-
if (ghConfig.pr) {
|
|
411
|
-
try {
|
|
412
|
-
const refRes = await fetch(
|
|
413
|
-
`https://api.github.com/repos/${owner}/${repoName}/git/ref/heads/${ghConfig.prBase || baseBranch}`,
|
|
414
|
-
{ headers }
|
|
415
|
-
);
|
|
416
|
-
if (refRes.ok) {
|
|
417
|
-
const refData = await refRes.json();
|
|
418
|
-
const baseSha = refData.object?.sha;
|
|
419
|
-
const newBranch = `${ghConfig.branchPrefix || "content/"}${collectionId}-${entry.slug}-${Date.now().toString(36)}`;
|
|
420
|
-
const createBranchRes = await fetch(
|
|
421
|
-
`https://api.github.com/repos/${owner}/${repoName}/git/refs`,
|
|
422
|
-
{
|
|
423
|
-
method: "POST",
|
|
424
|
-
headers,
|
|
425
|
-
body: JSON.stringify({
|
|
426
|
-
ref: `refs/heads/${newBranch}`,
|
|
427
|
-
sha: baseSha
|
|
428
|
-
})
|
|
429
|
-
}
|
|
430
|
-
);
|
|
431
|
-
if (createBranchRes.ok) {
|
|
432
|
-
targetBranch = newBranch;
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
} catch {
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
let commitSha;
|
|
439
|
-
if (action === "delete") {
|
|
440
|
-
if (existingSha) {
|
|
441
|
-
const delRes = await fetch(
|
|
442
|
-
`https://api.github.com/repos/${owner}/${repoName}/contents/${gitPath}`,
|
|
443
|
-
{
|
|
444
|
-
method: "DELETE",
|
|
445
|
-
headers,
|
|
446
|
-
body: JSON.stringify({
|
|
447
|
-
message: commitMsg,
|
|
448
|
-
sha: existingSha,
|
|
449
|
-
branch: targetBranch
|
|
450
|
-
})
|
|
451
|
-
}
|
|
452
|
-
);
|
|
453
|
-
if (delRes.ok) {
|
|
454
|
-
const delData = await delRes.json();
|
|
455
|
-
commitSha = delData.commit?.sha;
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
} else {
|
|
459
|
-
if (!fileContent) {
|
|
460
|
-
fileContent = formatEntryAsMarkdown(entry);
|
|
461
|
-
}
|
|
462
|
-
const base64Content = toBase64(fileContent);
|
|
463
|
-
const putRes = await fetch(
|
|
464
|
-
`https://api.github.com/repos/${owner}/${repoName}/contents/${gitPath}`,
|
|
465
|
-
{
|
|
466
|
-
method: "PUT",
|
|
467
|
-
headers,
|
|
468
|
-
body: JSON.stringify({
|
|
469
|
-
message: commitMsg,
|
|
470
|
-
content: base64Content,
|
|
471
|
-
branch: targetBranch,
|
|
472
|
-
...existingSha ? { sha: existingSha } : {}
|
|
473
|
-
})
|
|
474
|
-
}
|
|
475
|
-
);
|
|
476
|
-
if (putRes.ok) {
|
|
477
|
-
const putData = await putRes.json();
|
|
478
|
-
commitSha = putData.commit?.sha;
|
|
479
|
-
} else {
|
|
480
|
-
const errData = await putRes.json().catch(() => ({}));
|
|
481
|
-
console.warn(
|
|
482
|
-
`[qarpeo:cms] GitHub commit failed (${putRes.status}):`,
|
|
483
|
-
errData?.message || putRes.statusText
|
|
484
|
-
);
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
if (ghConfig.pr && targetBranch !== baseBranch) {
|
|
488
|
-
try {
|
|
489
|
-
const prRes = await fetch(`https://api.github.com/repos/${owner}/${repoName}/pulls`, {
|
|
490
|
-
method: "POST",
|
|
491
|
-
headers,
|
|
492
|
-
body: JSON.stringify({
|
|
493
|
-
title: commitMsg,
|
|
494
|
-
head: targetBranch,
|
|
495
|
-
base: ghConfig.prBase || baseBranch,
|
|
496
|
-
body: `Automated content change from Qarpeo CMS for \`${collectionId}/${entry.slug}\`.`
|
|
497
|
-
})
|
|
498
|
-
});
|
|
499
|
-
if (prRes.ok) {
|
|
500
|
-
const prData = await prRes.json();
|
|
501
|
-
prUrl = prData.html_url;
|
|
502
|
-
}
|
|
503
|
-
} catch {
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
result.github = {
|
|
507
|
-
ok: true,
|
|
508
|
-
commitSha,
|
|
509
|
-
prUrl
|
|
510
|
-
};
|
|
511
|
-
}
|
|
512
|
-
} catch (err) {
|
|
513
|
-
console.warn(`[qarpeo:cms] GitHub sync error:`, err?.message || err);
|
|
514
|
-
result.github = {
|
|
515
|
-
ok: false,
|
|
516
|
-
error: err?.message || String(err)
|
|
517
|
-
};
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
return result;
|
|
521
|
-
}
|
|
522
|
-
export async function computeContentHash(text) {
|
|
523
|
-
const enc = new TextEncoder();
|
|
524
|
-
const buf = await crypto.subtle.digest("SHA-256", enc.encode(text));
|
|
525
|
-
return Array.from(new Uint8Array(buf)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
526
|
-
}
|
|
527
|
-
export function getCMSTenantId(event) {
|
|
528
|
-
const tenantId = event?.context?.tenant?.id || event?.context?.tenantId || event?.context?.organizationId || event?.context?.orgId || null;
|
|
529
|
-
return tenantId ? String(tenantId) : null;
|
|
530
|
-
}
|
|
531
|
-
export function getCMSTenantPrefix(event) {
|
|
532
|
-
const tenantId = getCMSTenantId(event);
|
|
533
|
-
return tenantId ? `${tenantId}:` : "";
|
|
534
|
-
}
|
|
70
|
+
registerEntryFormatter(formatEntryAsMarkdown);
|
|
535
71
|
export async function getCMSCollection(event, collectionId) {
|
|
536
72
|
const config = getCMSConfig(event);
|
|
537
73
|
const tenantPrefix = getCMSTenantPrefix(event);
|
|
@@ -749,7 +285,7 @@ export async function getCollectionFields(event, collectionId) {
|
|
|
749
285
|
}
|
|
750
286
|
} catch {
|
|
751
287
|
}
|
|
752
|
-
return { ...configFields
|
|
288
|
+
return { ...configFields, ...dbFields };
|
|
753
289
|
}
|
|
754
290
|
async function fetchEntryRef(event, collectionId, slugOrId) {
|
|
755
291
|
const db = getCMSDb(event);
|
|
@@ -1095,29 +631,6 @@ export async function invalidateCMSEntryCache(event, collectionId, slug) {
|
|
|
1095
631
|
})();
|
|
1096
632
|
runCMSBackgroundTask(event, task);
|
|
1097
633
|
}
|
|
1098
|
-
export async function verifyGitHubSignature(rawBody, signatureHeader, secret) {
|
|
1099
|
-
if (!signatureHeader || !secret) return false;
|
|
1100
|
-
const cleanSig = signatureHeader.replace(/^sha256=/, "").trim();
|
|
1101
|
-
try {
|
|
1102
|
-
const key = await crypto.subtle.importKey(
|
|
1103
|
-
"raw",
|
|
1104
|
-
new TextEncoder().encode(secret),
|
|
1105
|
-
{ name: "HMAC", hash: "SHA-256" },
|
|
1106
|
-
false,
|
|
1107
|
-
["sign"]
|
|
1108
|
-
);
|
|
1109
|
-
const sig = await crypto.subtle.sign("HMAC", key, new TextEncoder().encode(rawBody));
|
|
1110
|
-
const expected = Array.from(new Uint8Array(sig)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
1111
|
-
if (expected.length !== cleanSig.length) return false;
|
|
1112
|
-
let diff = 0;
|
|
1113
|
-
for (let i = 0; i < expected.length; i++) {
|
|
1114
|
-
diff |= expected.charCodeAt(i) ^ cleanSig.charCodeAt(i);
|
|
1115
|
-
}
|
|
1116
|
-
return diff === 0;
|
|
1117
|
-
} catch {
|
|
1118
|
-
return false;
|
|
1119
|
-
}
|
|
1120
|
-
}
|
|
1121
634
|
export async function queryCMSEntries(event, collectionId, opts = {}) {
|
|
1122
635
|
const status = opts.status || "published";
|
|
1123
636
|
const isCacheable = status === "published";
|
|
@@ -1249,13 +762,7 @@ export async function getCMSEntry(event, collectionId, slugOrId, opts = {}) {
|
|
|
1249
762
|
const token = opts.previewToken || cookieObj?.token;
|
|
1250
763
|
const expires = opts.previewExpires || cookieObj?.expires;
|
|
1251
764
|
if (token && expires) {
|
|
1252
|
-
allowDraft = await verifyPreviewToken(
|
|
1253
|
-
event,
|
|
1254
|
-
collectionId,
|
|
1255
|
-
slugOrId,
|
|
1256
|
-
token,
|
|
1257
|
-
expires
|
|
1258
|
-
);
|
|
765
|
+
allowDraft = await verifyPreviewToken(event, collectionId, slugOrId, token, expires);
|
|
1259
766
|
}
|
|
1260
767
|
}
|
|
1261
768
|
}
|
|
@@ -1626,7 +1133,7 @@ export async function publishCMSEntry(event, entryId, targetStatus, targetPublis
|
|
|
1626
1133
|
} catch {
|
|
1627
1134
|
}
|
|
1628
1135
|
metaObj._approval = {
|
|
1629
|
-
...metaObj._approval
|
|
1136
|
+
...metaObj._approval,
|
|
1630
1137
|
approvedBy: auth?.user?.id || null,
|
|
1631
1138
|
approvedByName: auth?.user?.name || auth?.user?.email || "Admin",
|
|
1632
1139
|
approvedAt: now
|
|
@@ -1702,7 +1209,7 @@ export async function submitCMSEntryForReview(event, entryId, note) {
|
|
|
1702
1209
|
} catch {
|
|
1703
1210
|
}
|
|
1704
1211
|
metaObj._approval = {
|
|
1705
|
-
...metaObj._approval
|
|
1212
|
+
...metaObj._approval,
|
|
1706
1213
|
submittedBy: auth?.user?.id || null,
|
|
1707
1214
|
submittedByName: auth?.user?.name || auth?.user?.email || "Editor",
|
|
1708
1215
|
submittedAt: now,
|
|
@@ -1759,7 +1266,7 @@ export async function rejectCMSEntryReview(event, entryId, reason) {
|
|
|
1759
1266
|
} catch {
|
|
1760
1267
|
}
|
|
1761
1268
|
metaObj._approval = {
|
|
1762
|
-
...metaObj._approval
|
|
1269
|
+
...metaObj._approval,
|
|
1763
1270
|
rejectedBy: auth?.user?.id || null,
|
|
1764
1271
|
rejectedByName: auth?.user?.name || auth?.user?.email || "Reviewer",
|
|
1765
1272
|
rejectedAt: now,
|
|
@@ -1871,7 +1378,9 @@ export async function ensureCMSTables(event) {
|
|
|
1871
1378
|
} catch {
|
|
1872
1379
|
}
|
|
1873
1380
|
try {
|
|
1874
|
-
await db.exec(
|
|
1381
|
+
await db.exec(
|
|
1382
|
+
'ALTER TABLE _qarpeo_cms_entries ADD COLUMN "order" INTEGER NOT NULL DEFAULT 0;'
|
|
1383
|
+
);
|
|
1875
1384
|
} catch {
|
|
1876
1385
|
}
|
|
1877
1386
|
try {
|
|
@@ -1883,11 +1392,15 @@ export async function ensureCMSTables(event) {
|
|
|
1883
1392
|
} catch {
|
|
1884
1393
|
}
|
|
1885
1394
|
try {
|
|
1886
|
-
await db.exec(
|
|
1395
|
+
await db.exec(
|
|
1396
|
+
"ALTER TABLE _qarpeo_cms_entries ADD COLUMN locale TEXT NOT NULL DEFAULT 'en';"
|
|
1397
|
+
);
|
|
1887
1398
|
} catch {
|
|
1888
1399
|
}
|
|
1889
1400
|
try {
|
|
1890
|
-
await db.exec(
|
|
1401
|
+
await db.exec(
|
|
1402
|
+
"ALTER TABLE _qarpeo_cms_entries ADD COLUMN version TEXT NOT NULL DEFAULT 'latest';"
|
|
1403
|
+
);
|
|
1891
1404
|
} catch {
|
|
1892
1405
|
}
|
|
1893
1406
|
try {
|
|
@@ -2008,6 +1521,7 @@ export async function ensureCMSSynced(event) {
|
|
|
2008
1521
|
}
|
|
2009
1522
|
}
|
|
2010
1523
|
}
|
|
1524
|
+
registerEnsureCMSSynced(ensureCMSSynced);
|
|
2011
1525
|
export async function seedCollectionsFromConfig(event, collectionsConfig) {
|
|
2012
1526
|
const db = getCMSDb(event);
|
|
2013
1527
|
const now = Date.now();
|
|
@@ -2048,14 +1562,7 @@ export async function seedEntriesIntoDb(event, entries, collectionsConfig = {})
|
|
|
2048
1562
|
const colName = colConfig.name || colId.charAt(0).toUpperCase() + colId.slice(1).replace(/-/g, " ");
|
|
2049
1563
|
await db.prepare(
|
|
2050
1564
|
`INSERT INTO _qarpeo_cms_collections (id, name, description, schema_json, source, "order", created_at, updated_at) VALUES (?, ?, ?, '{}', 'config', ?, ?, ?)`
|
|
2051
|
-
).bind(
|
|
2052
|
-
colId,
|
|
2053
|
-
colName,
|
|
2054
|
-
`Collection ${colName}`,
|
|
2055
|
-
colConfig.order ?? 0,
|
|
2056
|
-
now,
|
|
2057
|
-
now
|
|
2058
|
-
).run();
|
|
1565
|
+
).bind(colId, colName, `Collection ${colName}`, colConfig.order ?? 0, now, now).run();
|
|
2059
1566
|
}
|
|
2060
1567
|
} catch {
|
|
2061
1568
|
}
|
|
@@ -2194,8 +1701,7 @@ export async function syncLocalContentFiles(event, contentDir, collectionsConfig
|
|
|
2194
1701
|
if (existsSync(navYmlPath)) {
|
|
2195
1702
|
try {
|
|
2196
1703
|
const raw = await readFile(navYmlPath);
|
|
2197
|
-
|
|
2198
|
-
return parseYaml2(raw) || {};
|
|
1704
|
+
return parseYaml(raw) || {};
|
|
2199
1705
|
} catch {
|
|
2200
1706
|
}
|
|
2201
1707
|
}
|
|
@@ -2544,8 +2050,7 @@ export async function syncLocalContentFiles(event, contentDir, collectionsConfig
|
|
|
2544
2050
|
}
|
|
2545
2051
|
} else {
|
|
2546
2052
|
try {
|
|
2547
|
-
|
|
2548
|
-
parsed = parseYaml2(rawContent) || {};
|
|
2053
|
+
parsed = parseYaml(rawContent) || {};
|
|
2549
2054
|
} catch {
|
|
2550
2055
|
}
|
|
2551
2056
|
}
|
|
@@ -3464,220 +2969,6 @@ export async function getCMSNavigationTree(event, collectionId, options) {
|
|
|
3464
2969
|
}
|
|
3465
2970
|
return result;
|
|
3466
2971
|
}
|
|
3467
|
-
export function buildFtsQuery(query, operator = "AND") {
|
|
3468
|
-
if (!query) return "";
|
|
3469
|
-
const clean = query.replace(/[^\p{L}\p{N}_\s]/gu, " ").trim();
|
|
3470
|
-
const rawTokens = clean.split(/\s+/).filter(Boolean);
|
|
3471
|
-
if (!rawTokens.length) return "";
|
|
3472
|
-
const reserved = /* @__PURE__ */ new Set(["and", "or", "not", "near"]);
|
|
3473
|
-
const tokens = rawTokens.filter((t) => !reserved.has(t.toLowerCase()));
|
|
3474
|
-
const effectiveTokens = tokens.length > 0 ? tokens : rawTokens;
|
|
3475
|
-
return effectiveTokens.map((t) => `"${t.replace(/"/g, '""')}"*`).join(` ${operator} `);
|
|
3476
|
-
}
|
|
3477
|
-
export async function rebuildCMSFTS(event) {
|
|
3478
|
-
const db = getCMSDb(event);
|
|
3479
|
-
try {
|
|
3480
|
-
await db.exec("DELETE FROM _qarpeo_cms_entries_fts;");
|
|
3481
|
-
await db.exec(
|
|
3482
|
-
"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;"
|
|
3483
|
-
);
|
|
3484
|
-
const res = await db.prepare("SELECT COUNT(*) as total FROM _qarpeo_cms_entries_fts").first();
|
|
3485
|
-
return { total: Number(res?.total || 0) };
|
|
3486
|
-
} catch (err) {
|
|
3487
|
-
console.warn("[qarpeo:cms] rebuildCMSFTS failed:", err);
|
|
3488
|
-
return { total: 0 };
|
|
3489
|
-
}
|
|
3490
|
-
}
|
|
3491
|
-
export async function searchDocs(event, options = {}) {
|
|
3492
|
-
await ensureCMSSynced(event);
|
|
3493
|
-
const db = getCMSDb(event);
|
|
3494
|
-
const q = (options.q || "").trim();
|
|
3495
|
-
if (!q) {
|
|
3496
|
-
return { results: [], total: 0, query: "", mode: "fts" };
|
|
3497
|
-
}
|
|
3498
|
-
const limit = Math.min(100, Math.max(1, options.limit || 20));
|
|
3499
|
-
const locale = options.locale;
|
|
3500
|
-
const tenantId = getCMSTenantId(event);
|
|
3501
|
-
const words = q.toLowerCase().split(/\s+/).filter(Boolean);
|
|
3502
|
-
let rows = [];
|
|
3503
|
-
let modeUsed = "fts";
|
|
3504
|
-
if (options.mode !== "like") {
|
|
3505
|
-
try {
|
|
3506
|
-
const ftsQuery = buildFtsQuery(q, "AND");
|
|
3507
|
-
if (ftsQuery) {
|
|
3508
|
-
let ftsSql = `
|
|
3509
|
-
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
|
|
3510
|
-
FROM _qarpeo_cms_entries e
|
|
3511
|
-
JOIN _qarpeo_cms_entries_fts fts ON e.id = fts.id
|
|
3512
|
-
WHERE fts MATCH ? AND e.status = 'published'
|
|
3513
|
-
`;
|
|
3514
|
-
const ftsBinds = [ftsQuery];
|
|
3515
|
-
if (tenantId) {
|
|
3516
|
-
ftsSql += " AND (e.tenant_id = ? OR e.tenant_id IS NULL)";
|
|
3517
|
-
ftsBinds.push(tenantId);
|
|
3518
|
-
}
|
|
3519
|
-
if (options.collection) {
|
|
3520
|
-
ftsSql += " AND e.collection_id = ?";
|
|
3521
|
-
ftsBinds.push(options.collection);
|
|
3522
|
-
} else {
|
|
3523
|
-
ftsSql += " AND (e.collection_id = 'docs' OR e.collection_id = 'content' OR e.path LIKE '/docs%' OR e.collection_id LIKE '%doc%')";
|
|
3524
|
-
}
|
|
3525
|
-
if (locale) {
|
|
3526
|
-
ftsSql += " AND (e.locale = ? OR e.locale = 'en')";
|
|
3527
|
-
ftsBinds.push(locale);
|
|
3528
|
-
}
|
|
3529
|
-
if (options.version && options.version !== "all") {
|
|
3530
|
-
if (options.version === "latest") {
|
|
3531
|
-
ftsSql += " AND (e.version = 'latest' OR e.version IS NULL OR e.path NOT LIKE '%/docs/v%')";
|
|
3532
|
-
} else {
|
|
3533
|
-
ftsSql += " AND (e.version = ? OR e.path LIKE ?)";
|
|
3534
|
-
ftsBinds.push(options.version, `%/docs/${options.version}%`);
|
|
3535
|
-
}
|
|
3536
|
-
}
|
|
3537
|
-
ftsSql += " ORDER BY fts.rank LIMIT 50";
|
|
3538
|
-
const res = await db.prepare(ftsSql).bind(...ftsBinds).all();
|
|
3539
|
-
rows = res.results || [];
|
|
3540
|
-
if (rows.length === 0 && words.length > 1) {
|
|
3541
|
-
const ftsOrQuery = buildFtsQuery(q, "OR");
|
|
3542
|
-
if (ftsOrQuery && ftsOrQuery !== ftsQuery) {
|
|
3543
|
-
const orBinds = [...ftsBinds];
|
|
3544
|
-
orBinds[0] = ftsOrQuery;
|
|
3545
|
-
const orRes = await db.prepare(ftsSql).bind(...orBinds).all();
|
|
3546
|
-
rows = orRes.results || [];
|
|
3547
|
-
}
|
|
3548
|
-
}
|
|
3549
|
-
}
|
|
3550
|
-
} catch {
|
|
3551
|
-
rows = [];
|
|
3552
|
-
}
|
|
3553
|
-
}
|
|
3554
|
-
if (rows.length === 0) {
|
|
3555
|
-
modeUsed = "like";
|
|
3556
|
-
const searchPattern = `%${words.join("%")}%`;
|
|
3557
|
-
let sql = `
|
|
3558
|
-
SELECT id, collection_id, slug, path, title, description, content_md, metadata_json, locale
|
|
3559
|
-
FROM _qarpeo_cms_entries
|
|
3560
|
-
WHERE status = 'published'
|
|
3561
|
-
`;
|
|
3562
|
-
const binds = [];
|
|
3563
|
-
if (tenantId) {
|
|
3564
|
-
sql += " AND (tenant_id = ? OR tenant_id IS NULL)";
|
|
3565
|
-
binds.push(tenantId);
|
|
3566
|
-
}
|
|
3567
|
-
if (options.collection) {
|
|
3568
|
-
sql += " AND collection_id = ?";
|
|
3569
|
-
binds.push(options.collection);
|
|
3570
|
-
} else {
|
|
3571
|
-
sql += " AND (collection_id = 'docs' OR collection_id = 'content' OR path LIKE '/docs%' OR collection_id LIKE '%doc%')";
|
|
3572
|
-
}
|
|
3573
|
-
if (locale) {
|
|
3574
|
-
sql += " AND (locale = ? OR locale = 'en')";
|
|
3575
|
-
binds.push(locale);
|
|
3576
|
-
}
|
|
3577
|
-
if (options.version && options.version !== "all") {
|
|
3578
|
-
if (options.version === "latest") {
|
|
3579
|
-
sql += " AND (version = 'latest' OR version IS NULL OR path NOT LIKE '%/docs/v%')";
|
|
3580
|
-
} else {
|
|
3581
|
-
sql += " AND (version = ? OR path LIKE ?)";
|
|
3582
|
-
binds.push(options.version, `%/docs/${options.version}%`);
|
|
3583
|
-
}
|
|
3584
|
-
}
|
|
3585
|
-
sql += " AND (LOWER(title) LIKE ? OR LOWER(description) LIKE ? OR LOWER(content_md) LIKE ? OR LOWER(tags) LIKE ?)";
|
|
3586
|
-
binds.push(searchPattern, searchPattern, searchPattern, searchPattern);
|
|
3587
|
-
sql += " LIMIT 50";
|
|
3588
|
-
const res = await db.prepare(sql).bind(...binds).all();
|
|
3589
|
-
rows = res.results || [];
|
|
3590
|
-
}
|
|
3591
|
-
const sections = [];
|
|
3592
|
-
for (const row of rows) {
|
|
3593
|
-
const pageTitle = row.title || "Documentation";
|
|
3594
|
-
const docPath = row.path || `/${row.collection_id}/${row.slug}`;
|
|
3595
|
-
const md = row.content_md || "";
|
|
3596
|
-
const headingLines = md.split("\n");
|
|
3597
|
-
const rawSections = [];
|
|
3598
|
-
let currentSection = {
|
|
3599
|
-
heading: pageTitle,
|
|
3600
|
-
level: 1,
|
|
3601
|
-
anchor: "",
|
|
3602
|
-
lines: []
|
|
3603
|
-
};
|
|
3604
|
-
rawSections.push(currentSection);
|
|
3605
|
-
for (const line of headingLines) {
|
|
3606
|
-
const match = line.match(/^(#{1,4})\s+(.+)$/);
|
|
3607
|
-
if (match) {
|
|
3608
|
-
const level = match[1].length;
|
|
3609
|
-
const headingText = match[2].trim().replace(/\s*\{#.*\}\s*$/, "");
|
|
3610
|
-
const slugAnchor = headingText.toLowerCase().replace(/[^\w\s-]/g, "").replace(/\s+/g, "-");
|
|
3611
|
-
currentSection = {
|
|
3612
|
-
heading: headingText,
|
|
3613
|
-
level,
|
|
3614
|
-
anchor: `#${slugAnchor}`,
|
|
3615
|
-
lines: []
|
|
3616
|
-
};
|
|
3617
|
-
rawSections.push(currentSection);
|
|
3618
|
-
} else {
|
|
3619
|
-
currentSection.lines.push(line);
|
|
3620
|
-
}
|
|
3621
|
-
}
|
|
3622
|
-
for (const sec of rawSections) {
|
|
3623
|
-
const rawText = sec.lines.join(" ");
|
|
3624
|
-
const cleanContent = rawText.replace(/```[\s\S]*?```/g, " ").replace(/`([^`]+)`/g, "$1").replace(/\[([^\]]+)\]\([^)]+\)/g, "$1").replace(/[*_~#]/g, "").replace(/\s+/g, " ").trim();
|
|
3625
|
-
const textLower = cleanContent.toLowerCase();
|
|
3626
|
-
const headingLower = sec.heading.toLowerCase();
|
|
3627
|
-
const pageTitleLower = pageTitle.toLowerCase();
|
|
3628
|
-
let score = 0;
|
|
3629
|
-
let matchIdx = -1;
|
|
3630
|
-
for (const w of words) {
|
|
3631
|
-
if (headingLower.includes(w)) {
|
|
3632
|
-
score += 15;
|
|
3633
|
-
}
|
|
3634
|
-
if (pageTitleLower.includes(w)) {
|
|
3635
|
-
score += 8;
|
|
3636
|
-
}
|
|
3637
|
-
const idx = textLower.indexOf(w);
|
|
3638
|
-
if (idx !== -1) {
|
|
3639
|
-
score += 5;
|
|
3640
|
-
if (matchIdx === -1 || idx < matchIdx) {
|
|
3641
|
-
matchIdx = idx;
|
|
3642
|
-
}
|
|
3643
|
-
}
|
|
3644
|
-
}
|
|
3645
|
-
if (score === 0 && row.fts_rank !== void 0 && sec === rawSections[0]) {
|
|
3646
|
-
score = 10;
|
|
3647
|
-
}
|
|
3648
|
-
if (score > 0) {
|
|
3649
|
-
let excerpt = "";
|
|
3650
|
-
if (matchIdx !== -1) {
|
|
3651
|
-
const start = Math.max(0, matchIdx - 40);
|
|
3652
|
-
const end = Math.min(cleanContent.length, matchIdx + 110);
|
|
3653
|
-
excerpt = (start > 0 ? "... " : "") + cleanContent.slice(start, end).trim() + (end < cleanContent.length ? " ..." : "");
|
|
3654
|
-
} else {
|
|
3655
|
-
excerpt = cleanContent.slice(0, 140) + (cleanContent.length > 140 ? " ..." : "");
|
|
3656
|
-
}
|
|
3657
|
-
const titles = sec.heading !== pageTitle ? [pageTitle, sec.heading] : [pageTitle];
|
|
3658
|
-
sections.push({
|
|
3659
|
-
id: `${docPath}${sec.anchor}`,
|
|
3660
|
-
path: docPath,
|
|
3661
|
-
title: sec.heading,
|
|
3662
|
-
pageTitle,
|
|
3663
|
-
titles,
|
|
3664
|
-
content: excerpt || row.description || pageTitle,
|
|
3665
|
-
section: sec.anchor || void 0,
|
|
3666
|
-
locale: row.locale || "en",
|
|
3667
|
-
level: sec.level || 1,
|
|
3668
|
-
score
|
|
3669
|
-
});
|
|
3670
|
-
}
|
|
3671
|
-
}
|
|
3672
|
-
}
|
|
3673
|
-
sections.sort((a, b) => b.score - a.score);
|
|
3674
|
-
return {
|
|
3675
|
-
results: sections.slice(0, limit),
|
|
3676
|
-
total: sections.length,
|
|
3677
|
-
query: q,
|
|
3678
|
-
mode: modeUsed
|
|
3679
|
-
};
|
|
3680
|
-
}
|
|
3681
2972
|
export function queryCollection(event, collection) {
|
|
3682
2973
|
let _path = null;
|
|
3683
2974
|
let _locale = null;
|