qarpeo 0.2.1 → 0.3.0
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/dist/chunks/tools.mjs +993 -31
- package/dist/cli/index.mjs +1071 -31
- package/dist/fate/index.d.ts +9 -1
- package/dist/fate/index.mjs +20 -3
- package/dist/module.mjs +292 -748
- package/dist/runtime/browser.mjs +2 -2
- package/dist/runtime/comments-server.d.ts +3 -0
- package/dist/runtime/comments-server.mjs +2 -0
- package/dist/runtime/comments.d.ts +0 -2
- package/dist/runtime/comments.mjs +0 -2
- package/dist/runtime/db.d.ts +10 -9
- package/dist/runtime/db.mjs +79 -8
- package/dist/runtime/drizzle.mjs +21 -6
- package/dist/runtime/index.d.ts +4 -0
- package/dist/runtime/realtime-server.d.ts +4 -0
- package/dist/runtime/realtime-server.mjs +13 -0
- package/dist/runtime/realtime.d.ts +1 -4
- package/dist/runtime/realtime.mjs +0 -13
- package/dist/runtime/replica.d.ts +27 -0
- package/dist/runtime/replica.mjs +229 -0
- package/dist/runtime/server/durable-objects/agent.mjs +14 -2
- package/dist/runtime/server/durable-objects/room.d.ts +10 -0
- package/dist/runtime/server/durable-objects/room.mjs +119 -28
- package/dist/runtime/server/middleware/devtools.mjs +1 -1
- package/dist/runtime/server/middleware/tenancy.mjs +7 -4
- package/dist/runtime/server/plugins/store.mjs +1 -1
- package/dist/runtime/server/routes/__qarpeo/mail/track/click/[id].get.mjs +57 -17
- package/dist/runtime/server/routes/agents/[agent]/chat.post.mjs +19 -12
- package/dist/runtime/server/routes/agents/[agent]/clear.post.mjs +8 -9
- package/dist/runtime/server/routes/agents/[agent]/history.get.mjs +8 -9
- package/dist/runtime/server/routes/analytics/events.get.mjs +12 -2
- package/dist/runtime/server/routes/analytics/pageviews.get.mjs +10 -1
- package/dist/runtime/server/routes/analytics/summary.get.mjs +10 -1
- package/dist/runtime/server/routes/auth/2fa/disable.post.mjs +11 -2
- package/dist/runtime/server/routes/auth/2fa/setup.post.mjs +7 -0
- package/dist/runtime/server/routes/auth/2fa/verify.post.mjs +11 -2
- package/dist/runtime/server/routes/auth/account.delete.mjs +7 -0
- package/dist/runtime/server/routes/auth/magic-link/verify.get.mjs +5 -3
- package/dist/runtime/server/routes/auth/organization/sso/index.post.mjs +10 -0
- package/dist/runtime/server/routes/auth/otp/verify.post.mjs +5 -3
- package/dist/runtime/server/routes/auth/sso/saml/acs.post.mjs +18 -0
- package/dist/runtime/server/routes/auth/webauthn/login/options.post.d.ts +1 -1
- package/dist/runtime/server/routes/auth/webauthn/login/options.post.mjs +11 -2
- package/dist/runtime/server/routes/auth/webauthn/login/verify.post.mjs +10 -1
- package/dist/runtime/server/routes/auth/webauthn/register/options.post.d.ts +1 -1
- package/dist/runtime/server/routes/auth/webauthn/register/options.post.mjs +10 -1
- package/dist/runtime/server/routes/auth/webauthn/register/verify.post.mjs +10 -1
- package/dist/runtime/server/routes/browser/crawl.post.mjs +13 -0
- package/dist/runtime/server/routes/browser/invoice.post.mjs +15 -1
- package/dist/runtime/server/routes/browser/og-image.post.mjs +13 -0
- package/dist/runtime/server/routes/browser/pdf.post.mjs +15 -1
- package/dist/runtime/server/routes/browser/screenshot.post.mjs +13 -0
- package/dist/runtime/server/routes/cms/[collection]/[id]/preview-token.post.mjs +23 -8
- package/dist/runtime/server/routes/cms/[collection]/[id]/publish.post.mjs +2 -1
- package/dist/runtime/server/routes/cms/[collection]/[id]/review.post.mjs +2 -1
- package/dist/runtime/server/routes/cms/[collection]/[id]/revisions/[revId]/restore.post.mjs +2 -1
- package/dist/runtime/server/routes/cms/[collection]/[id].delete.mjs +2 -1
- package/dist/runtime/server/routes/cms/[collection]/[id].put.mjs +2 -1
- package/dist/runtime/server/routes/cms/[collection]/index.post.mjs +2 -1
- package/dist/runtime/server/routes/cms/categories/[id].delete.mjs +2 -1
- package/dist/runtime/server/routes/cms/categories/[id].put.mjs +2 -1
- package/dist/runtime/server/routes/cms/categories.post.mjs +2 -1
- package/dist/runtime/server/routes/cms/collections/[id].delete.mjs +2 -1
- package/dist/runtime/server/routes/cms/collections/[id].put.mjs +2 -1
- package/dist/runtime/server/routes/cms/collections/index.post.mjs +2 -1
- package/dist/runtime/server/routes/cms/export.post.mjs +1 -1
- package/dist/runtime/server/routes/cms/subscribers/[id].delete.mjs +2 -1
- package/dist/runtime/server/routes/cms/subscribers/[id].patch.mjs +2 -1
- package/dist/runtime/server/routes/cms/tags/[id].delete.mjs +2 -1
- package/dist/runtime/server/routes/cms/tags.post.mjs +2 -1
- package/dist/runtime/server/routes/comments/[id]/react.post.mjs +7 -3
- package/dist/runtime/server/routes/comments/[id]/report.post.mjs +3 -0
- package/dist/runtime/server/routes/comments/[id].delete.mjs +1 -1
- package/dist/runtime/server/routes/comments/[id].get.mjs +13 -0
- package/dist/runtime/server/routes/comments/[id].patch.mjs +1 -1
- package/dist/runtime/server/routes/fate.d.ts +6 -0
- package/dist/runtime/server/routes/fate.mjs +32 -3
- package/dist/runtime/server/routes/mail/bounce.post.mjs +14 -2
- package/dist/runtime/server/routes/mail/unsubscribe.mjs +2 -1
- package/dist/runtime/server/routes/mail/webhooks.post.mjs +18 -4
- package/dist/runtime/server/routes/notifications/[id].get.mjs +3 -4
- package/dist/runtime/server/routes/notifications/index.get.mjs +4 -2
- package/dist/runtime/server/routes/notifications/push/subscribe.post.mjs +3 -1
- package/dist/runtime/server/routes/notifications/push/unsubscribe.post.mjs +5 -3
- package/dist/runtime/server/routes/notifications/read-all.post.mjs +6 -2
- package/dist/runtime/server/routes/notifications/send.post.mjs +13 -2
- package/dist/runtime/server/routes/payments/cancel.post.mjs +1 -1
- package/dist/runtime/server/routes/payments/change-plan.post.mjs +1 -1
- package/dist/runtime/server/routes/payments/checkout.post.mjs +1 -1
- package/dist/runtime/server/routes/payments/pause.post.mjs +1 -1
- package/dist/runtime/server/routes/payments/portal.post.mjs +1 -1
- package/dist/runtime/server/routes/payments/subscription.get.mjs +1 -1
- package/dist/runtime/server/routes/payments/usage.get.mjs +1 -1
- package/dist/runtime/server/routes/payments/usage.post.mjs +1 -1
- package/dist/runtime/server/routes/payments/webhook.post.mjs +8 -1
- package/dist/runtime/server/routes/realtime/broadcast.post.mjs +3 -2
- package/dist/runtime/server/routes/realtime/history.delete.mjs +2 -2
- package/dist/runtime/server/routes/realtime/history.get.mjs +2 -2
- package/dist/runtime/server/routes/realtime/presence.get.mjs +3 -3
- package/dist/runtime/server/routes/realtime/state.get.mjs +3 -3
- package/dist/runtime/server/routes/realtime/state.post.mjs +13 -4
- package/dist/runtime/server/routes/realtime/ws.get.mjs +2 -2
- package/dist/runtime/server/routes/storage/file/[...key].delete.mjs +1 -1
- package/dist/runtime/server/routes/storage/file/[...key].get.mjs +7 -0
- package/dist/runtime/server/routes/storage/files.get.d.ts +1 -1
- package/dist/runtime/server/routes/storage/files.get.mjs +24 -4
- package/dist/runtime/server/routes/storage/multipart/abort.post.mjs +16 -1
- package/dist/runtime/server/routes/storage/multipart/complete.post.d.ts +1 -1
- package/dist/runtime/server/routes/storage/multipart/complete.post.mjs +15 -1
- package/dist/runtime/server/routes/storage/multipart/create.post.mjs +7 -0
- package/dist/runtime/server/routes/storage/multipart/part.put.mjs +15 -1
- package/dist/runtime/server/routes/storage/presigned-r2.post.mjs +8 -1
- package/dist/runtime/server/routes/storage/presigned.post.d.ts +1 -1
- package/dist/runtime/server/routes/storage/presigned.post.mjs +8 -1
- package/dist/runtime/server/routes/storage/sign.post.mjs +7 -0
- package/dist/runtime/server/routes/storage/upload.post.d.ts +2 -2
- package/dist/runtime/server/routes/store/cart/index.delete.mjs +3 -4
- package/dist/runtime/server/routes/store/cart/index.get.mjs +3 -10
- package/dist/runtime/server/routes/store/cart/items/[id].delete.mjs +6 -4
- package/dist/runtime/server/routes/store/cart/items/[id].patch.mjs +12 -4
- package/dist/runtime/server/routes/store/cart/items.post.mjs +9 -10
- package/dist/runtime/server/routes/store/categories/index.get.mjs +4 -2
- package/dist/runtime/server/routes/store/checkout.post.mjs +13 -3
- package/dist/runtime/server/routes/store/coupons/apply.post.mjs +6 -5
- package/dist/runtime/server/routes/store/orders/[id].get.mjs +2 -2
- package/dist/runtime/server/routes/store/orders/download/[token].get.mjs +6 -3
- package/dist/runtime/server/routes/store/orders/index.get.mjs +1 -1
- package/dist/runtime/server/routes/store/products/[slug].get.mjs +2 -2
- package/dist/runtime/server/routes/store/products/index.get.mjs +1 -1
- package/dist/runtime/server/routes/store/tax/calculate.post.mjs +10 -0
- package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/index.delete.mjs +26 -25
- package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/verify.post.mjs +26 -25
- package/dist/runtime/server/utils/ai.d.ts +6 -0
- package/dist/runtime/server/utils/ai.mjs +12 -2
- package/dist/runtime/server/utils/analytics-query.mjs +8 -4
- package/dist/runtime/server/utils/browser-utils.d.ts +9 -0
- package/dist/runtime/server/utils/browser-utils.mjs +135 -0
- package/dist/runtime/server/utils/cms/cache.d.ts +13 -0
- package/dist/runtime/server/utils/cms/cache.mjs +95 -0
- package/dist/runtime/server/utils/cms/common.mjs +1 -1
- package/dist/runtime/server/utils/cms/markdown.mjs +38 -8
- package/dist/runtime/server/utils/cms/mutations.d.ts +26 -0
- package/dist/runtime/server/utils/cms/mutations.mjs +569 -0
- package/dist/runtime/server/utils/cms/path.d.ts +8 -0
- package/dist/runtime/server/utils/cms/path.mjs +23 -0
- package/dist/runtime/server/utils/cms/queries.d.ts +27 -0
- package/dist/runtime/server/utils/cms/queries.mjs +366 -0
- package/dist/runtime/server/utils/cms/references.d.ts +48 -0
- package/dist/runtime/server/utils/cms/references.mjs +309 -0
- package/dist/runtime/server/utils/cms/revisions.d.ts +7 -0
- package/dist/runtime/server/utils/cms/revisions.mjs +60 -0
- package/dist/runtime/server/utils/cms/sync.mjs +3 -3
- package/dist/runtime/server/utils/cms.d.ts +5 -82
- package/dist/runtime/server/utils/cms.mjs +28 -1367
- package/dist/runtime/server/utils/comments.d.ts +11 -0
- package/dist/runtime/server/utils/comments.mjs +65 -17
- package/dist/runtime/server/utils/crypto.mjs +1 -1
- package/dist/runtime/server/utils/domains.mjs +9 -0
- package/dist/runtime/server/utils/drizzle.d.ts +26 -1
- package/dist/runtime/server/utils/drizzle.mjs +78 -19
- package/dist/runtime/server/utils/email-inbound.mjs +9 -1
- package/dist/runtime/server/utils/impersonation.mjs +58 -1
- package/dist/runtime/server/utils/lock.d.ts +11 -0
- package/dist/runtime/server/utils/lock.mjs +4 -0
- package/dist/runtime/server/utils/mail-suppression.mjs +48 -13
- package/dist/runtime/server/utils/mail.d.ts +2 -1
- package/dist/runtime/server/utils/mail.mjs +17 -11
- package/dist/runtime/server/utils/notifications.d.ts +13 -4
- package/dist/runtime/server/utils/notifications.mjs +20 -4
- package/dist/runtime/server/utils/organization.mjs +36 -1
- package/dist/runtime/server/utils/passwordless.mjs +8 -0
- package/dist/runtime/server/utils/payments/checkout.d.ts +34 -0
- package/dist/runtime/server/utils/payments/checkout.mjs +158 -0
- package/dist/runtime/server/utils/payments/common.d.ts +45 -0
- package/dist/runtime/server/utils/payments/common.mjs +234 -0
- package/dist/runtime/server/utils/payments/index.d.ts +9 -0
- package/dist/runtime/server/utils/payments/index.mjs +21 -0
- package/dist/runtime/server/utils/payments/lemonsqueezy.d.ts +7 -0
- package/dist/runtime/server/utils/payments/lemonsqueezy.mjs +55 -0
- package/dist/runtime/server/utils/payments/paddle.d.ts +7 -0
- package/dist/runtime/server/utils/payments/paddle.mjs +92 -0
- package/dist/runtime/server/utils/payments/polar.d.ts +11 -0
- package/dist/runtime/server/utils/payments/polar.mjs +66 -0
- package/dist/runtime/server/utils/payments/stripe.d.ts +7 -0
- package/dist/runtime/server/utils/payments/stripe.mjs +159 -0
- package/dist/runtime/server/utils/payments/subscriptions.d.ts +89 -0
- package/dist/runtime/server/utils/payments/subscriptions.mjs +236 -0
- package/dist/runtime/server/utils/payments/usage.d.ts +12 -0
- package/dist/runtime/server/utils/payments/usage.mjs +143 -0
- package/dist/runtime/server/utils/payments/webhooks.d.ts +10 -0
- package/dist/runtime/server/utils/payments/webhooks.mjs +200 -0
- package/dist/runtime/server/utils/payments.d.ts +1 -158
- package/dist/runtime/server/utils/payments.mjs +1 -1289
- package/dist/runtime/server/utils/queue.d.ts +2 -0
- package/dist/runtime/server/utils/queue.mjs +34 -21
- package/dist/runtime/server/utils/rag.mjs +30 -17
- package/dist/runtime/server/utils/realtime.d.ts +5 -1
- package/dist/runtime/server/utils/realtime.mjs +43 -7
- package/dist/runtime/server/utils/session.mjs +16 -3
- package/dist/runtime/server/utils/sso.d.ts +3 -0
- package/dist/runtime/server/utils/sso.mjs +43 -0
- package/dist/runtime/server/utils/storage.mjs +12 -1
- package/dist/runtime/server/utils/store/cart.d.ts +63 -0
- package/dist/runtime/server/utils/store/cart.mjs +542 -0
- package/dist/runtime/server/utils/store/checkout.d.ts +14 -0
- package/dist/runtime/server/utils/store/checkout.mjs +118 -0
- package/dist/runtime/server/utils/store/common.d.ts +29 -0
- package/dist/runtime/server/utils/store/common.mjs +479 -0
- package/dist/runtime/server/utils/store/index.d.ts +7 -0
- package/dist/runtime/server/utils/store/index.mjs +30 -0
- package/dist/runtime/server/utils/store/inventory.d.ts +25 -0
- package/dist/runtime/server/utils/store/inventory.mjs +190 -0
- package/dist/runtime/server/utils/store/orders.d.ts +60 -0
- package/dist/runtime/server/utils/store/orders.mjs +590 -0
- package/dist/runtime/server/utils/store/products.d.ts +35 -0
- package/dist/runtime/server/utils/store/products.mjs +461 -0
- package/dist/runtime/server/utils/store/vendor.d.ts +18 -0
- package/dist/runtime/server/utils/store/vendor.mjs +68 -0
- package/dist/runtime/server/utils/store.d.ts +1 -207
- package/dist/runtime/server/utils/store.mjs +1 -2227
- package/dist/runtime/server/utils/string.d.ts +1 -1
- package/dist/runtime/server/utils/string.mjs +12 -4
- package/dist/runtime/server/utils/tenant.mjs +19 -5
- package/dist/runtime/server/utils/tracker.mjs +2 -0
- package/dist/runtime/server.d.ts +3 -3
- package/dist/runtime/server.mjs +4 -4
- package/dist/runtime/storage-server.d.ts +2 -0
- package/dist/runtime/storage-server.mjs +1 -0
- package/dist/runtime/storage.d.ts +1 -1
- package/dist/runtime/storage.mjs +0 -1
- package/dist/runtime/store.d.ts +0 -1
- package/dist/runtime/store.mjs +0 -1
- package/dist/runtime/test-utils.d.ts +4 -0
- package/dist/runtime/test-utils.mjs +54 -0
- package/dist/runtime/types/d1.d.ts +43 -0
- package/dist/runtime/types/drizzle.d.ts +6 -0
- package/dist/runtime/types/store.d.ts +1 -1
- package/dist/types/analytics.d.ts +80 -0
- package/dist/types/auth.d.ts +282 -0
- package/dist/types/cache.d.ts +55 -0
- package/dist/types/comments.d.ts +130 -0
- package/dist/types/db.d.ts +29 -0
- package/dist/types/email.d.ts +182 -0
- package/dist/types/index.d.ts +22 -0
- package/dist/types/jobs.d.ts +58 -0
- package/dist/types/notifications.d.ts +77 -0
- package/dist/types/options.d.ts +363 -0
- package/dist/types/payments.d.ts +145 -0
- package/dist/types/ratelimit.d.ts +71 -0
- package/dist/types/realtime.d.ts +136 -0
- package/dist/types/site.d.ts +121 -0
- package/dist/types/storage.d.ts +164 -0
- package/dist/types/store-options.d.ts +199 -0
- package/dist/types/tenant.d.ts +100 -0
- package/dist/types.d.ts +1 -2174
- package/dist/utils/migration-lock.d.ts +139 -0
- package/dist/utils/pkg.d.ts +14 -1
- package/dist/utils/schema-diff.d.ts +39 -0
- package/package.json +55 -17
- package/dist/chunks/auth-schema.mjs +0 -364
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
import { getCookie } from "nuxt/server";
|
|
2
|
+
import { getAuthContext } from "../context.mjs";
|
|
3
|
+
import { getCachedEntry, setCachedEntry, getCachedList, setCachedList } from "./cache.mjs";
|
|
4
|
+
import { getCMSDb, getCMSConfig, getCMSTenantId, cmsEntryTbl, cmsCategoryTbl } from "./common.mjs";
|
|
5
|
+
import { registerEntryFormatter } from "./git.mjs";
|
|
6
|
+
import { parseMarkdownAST, formatFrontmatter } from "./markdown.mjs";
|
|
7
|
+
import { verifyPreviewToken } from "./preview.mjs";
|
|
8
|
+
import { populateReferenceFields, serializeReferencesForFrontmatter } from "./references.mjs";
|
|
9
|
+
export function formatEntryAsMarkdown(entry) {
|
|
10
|
+
const e = entry;
|
|
11
|
+
let metadata = {};
|
|
12
|
+
try {
|
|
13
|
+
if (e.metadata && typeof e.metadata === "object") {
|
|
14
|
+
metadata = e.metadata;
|
|
15
|
+
} else if (e.metadataJson || e.metadata_json) {
|
|
16
|
+
metadata = JSON.parse(e.metadataJson || e.metadata_json);
|
|
17
|
+
}
|
|
18
|
+
} catch {
|
|
19
|
+
}
|
|
20
|
+
const cleanMetadata = {};
|
|
21
|
+
for (const [k, v] of Object.entries(metadata)) {
|
|
22
|
+
if (!k.startsWith("_")) {
|
|
23
|
+
cleanMetadata[k] = v;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const serializedMetadata = serializeReferencesForFrontmatter(cleanMetadata);
|
|
27
|
+
const rawTags = e.tags;
|
|
28
|
+
const tags = Array.isArray(rawTags) ? rawTags : typeof rawTags === "string" && rawTags.length > 0 ? rawTags.split(",").map((t) => t.trim()) : void 0;
|
|
29
|
+
const fmData = {
|
|
30
|
+
title: e.title,
|
|
31
|
+
slug: e.slug,
|
|
32
|
+
...e.description ? { description: e.description } : {},
|
|
33
|
+
...e.coverImage || e.cover_image ? { coverImage: e.coverImage || e.cover_image } : {},
|
|
34
|
+
...tags && tags.length > 0 ? { tags } : {},
|
|
35
|
+
...typeof e.order === "number" && e.order !== 0 ? { order: e.order } : {},
|
|
36
|
+
...e.status && e.status !== "published" ? { status: e.status } : {},
|
|
37
|
+
...serializedMetadata
|
|
38
|
+
};
|
|
39
|
+
const body = e.contentMd ?? e.content_md ?? "";
|
|
40
|
+
return formatFrontmatter(fmData, body);
|
|
41
|
+
}
|
|
42
|
+
registerEntryFormatter(formatEntryAsMarkdown);
|
|
43
|
+
export function projectCMSEntry(entry, fields) {
|
|
44
|
+
if (!entry) return null;
|
|
45
|
+
if (!fields) return entry;
|
|
46
|
+
const fieldList = Array.isArray(fields) ? fields.flatMap((f) => typeof f === "string" ? f.split(",") : []).map((s) => s.trim()).filter(Boolean) : String(fields).split(",").map((s) => s.trim()).filter(Boolean);
|
|
47
|
+
if (!fieldList.length) return entry;
|
|
48
|
+
const projected = {};
|
|
49
|
+
for (const field of fieldList) {
|
|
50
|
+
if (field in entry) {
|
|
51
|
+
projected[field] = entry[field];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return projected;
|
|
55
|
+
}
|
|
56
|
+
export function rowToEntry(row) {
|
|
57
|
+
let metadata;
|
|
58
|
+
try {
|
|
59
|
+
metadata = JSON.parse(row.metadata_json || "{}");
|
|
60
|
+
} catch {
|
|
61
|
+
metadata = {};
|
|
62
|
+
}
|
|
63
|
+
const toc = metadata?._toc || void 0;
|
|
64
|
+
const nav = metadata?._nav || void 0;
|
|
65
|
+
const tocObj = toc || { links: [] };
|
|
66
|
+
const ast = metadata?._ast || void 0;
|
|
67
|
+
if (metadata) {
|
|
68
|
+
delete metadata._ast;
|
|
69
|
+
delete metadata._toc;
|
|
70
|
+
delete metadata._nav;
|
|
71
|
+
}
|
|
72
|
+
const body = ast && Array.isArray(ast.nodes) ? {
|
|
73
|
+
...ast,
|
|
74
|
+
toc: tocObj
|
|
75
|
+
} : {
|
|
76
|
+
value: row.content_md || "",
|
|
77
|
+
content: row.content_md || "",
|
|
78
|
+
toc: tocObj
|
|
79
|
+
};
|
|
80
|
+
const rawText = row.content_md || "";
|
|
81
|
+
const words = rawText.trim() ? rawText.trim().split(/\s+/).length : 0;
|
|
82
|
+
const calculatedReadingTime = Math.max(1, Math.ceil(words / 200));
|
|
83
|
+
const readingTime = row.reading_time || metadata?.readingTime || metadata?.reading_time || calculatedReadingTime;
|
|
84
|
+
return {
|
|
85
|
+
...metadata,
|
|
86
|
+
id: row.id,
|
|
87
|
+
collectionId: row.collection_id,
|
|
88
|
+
slug: row.slug,
|
|
89
|
+
path: row.path || void 0,
|
|
90
|
+
title: row.title,
|
|
91
|
+
description: row.description,
|
|
92
|
+
coverImage: row.cover_image,
|
|
93
|
+
tags: row.tags,
|
|
94
|
+
order: row.order,
|
|
95
|
+
contentMd: row.content_md,
|
|
96
|
+
contentHtml: row.content_html,
|
|
97
|
+
body,
|
|
98
|
+
toc: toc || { links: [] },
|
|
99
|
+
navigation: nav,
|
|
100
|
+
readingTime,
|
|
101
|
+
categoryId: row.category_id || void 0,
|
|
102
|
+
subCategoryId: row.sub_category_id || void 0,
|
|
103
|
+
featured: Boolean(row.featured),
|
|
104
|
+
viewCount: row.view_count || 0,
|
|
105
|
+
metadataJson: row.metadata_json,
|
|
106
|
+
metadata: { ...metadata, readingTime },
|
|
107
|
+
status: row.status,
|
|
108
|
+
source: row.source,
|
|
109
|
+
filePath: row.file_path,
|
|
110
|
+
contentHash: row.content_hash,
|
|
111
|
+
authorId: row.author_id,
|
|
112
|
+
publishedAt: row.published_at,
|
|
113
|
+
tenantId: row.tenant_id || void 0,
|
|
114
|
+
locale: row.locale || "en",
|
|
115
|
+
version: row.version || "latest",
|
|
116
|
+
createdAt: row.created_at,
|
|
117
|
+
updatedAt: row.updated_at
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
export async function queryCMSEntries(event, collectionId, opts = {}) {
|
|
121
|
+
const status = opts.status || "published";
|
|
122
|
+
const isCacheable = status === "published";
|
|
123
|
+
const fieldsKey = opts.fields ? Array.isArray(opts.fields) ? opts.fields.join(",") : String(opts.fields) : "";
|
|
124
|
+
const listCacheKey = isCacheable && !opts.populate ? `cms:list:${collectionId}:${opts.page || 1}:${opts.limit || 10}:${opts.sort || ""}:${opts.tag || ""}:${opts.category || ""}:${opts.categoryId || ""}:${opts.authorId || ""}:${opts.locale || ""}:${opts.version || ""}:${opts.search || ""}:${fieldsKey}:${opts.where ? JSON.stringify(opts.where) : ""}` : null;
|
|
125
|
+
if (listCacheKey) {
|
|
126
|
+
const cached = await getCachedList(event, listCacheKey);
|
|
127
|
+
if (cached) return cached;
|
|
128
|
+
}
|
|
129
|
+
const db = getCMSDb(event);
|
|
130
|
+
const page = Math.max(1, opts.page || 1);
|
|
131
|
+
const limit = Math.min(100, opts.limit || 10);
|
|
132
|
+
const offset = (page - 1) * limit;
|
|
133
|
+
const conditions = ["collection_id = ?"];
|
|
134
|
+
const binds = [collectionId];
|
|
135
|
+
const tenantId = getCMSTenantId(event);
|
|
136
|
+
if (tenantId) {
|
|
137
|
+
conditions.push("(tenant_id = ? OR tenant_id IS NULL)");
|
|
138
|
+
binds.push(tenantId);
|
|
139
|
+
}
|
|
140
|
+
if (status !== "all") {
|
|
141
|
+
conditions.push("status = ?");
|
|
142
|
+
binds.push(status);
|
|
143
|
+
}
|
|
144
|
+
if (opts.categoryId) {
|
|
145
|
+
conditions.push("category_id = ?");
|
|
146
|
+
binds.push(opts.categoryId);
|
|
147
|
+
}
|
|
148
|
+
if (opts.category) {
|
|
149
|
+
conditions.push(
|
|
150
|
+
`(category_id IN (SELECT id FROM ${cmsCategoryTbl(event)} WHERE slug = ?) OR category_id = ?)`
|
|
151
|
+
);
|
|
152
|
+
binds.push(opts.category, opts.category);
|
|
153
|
+
}
|
|
154
|
+
if (opts.authorId) {
|
|
155
|
+
conditions.push("author_id = ?");
|
|
156
|
+
binds.push(opts.authorId);
|
|
157
|
+
}
|
|
158
|
+
if (opts.locale) {
|
|
159
|
+
conditions.push("locale = ?");
|
|
160
|
+
binds.push(opts.locale);
|
|
161
|
+
}
|
|
162
|
+
if (opts.version) {
|
|
163
|
+
conditions.push("version = ?");
|
|
164
|
+
binds.push(opts.version);
|
|
165
|
+
}
|
|
166
|
+
if (opts.search) {
|
|
167
|
+
conditions.push("(title LIKE ? OR description LIKE ?)");
|
|
168
|
+
const term = `%${opts.search}%`;
|
|
169
|
+
binds.push(term, term);
|
|
170
|
+
}
|
|
171
|
+
if (opts.tag) {
|
|
172
|
+
conditions.push("(tags LIKE ? OR tags LIKE ? OR tags LIKE ? OR tags = ?)");
|
|
173
|
+
binds.push(`${opts.tag},%`, `%,${opts.tag},%`, `%,${opts.tag}`, opts.tag);
|
|
174
|
+
}
|
|
175
|
+
if (opts.where && typeof opts.where === "object") {
|
|
176
|
+
for (const [key, value] of Object.entries(opts.where)) {
|
|
177
|
+
if (value === void 0 || !/^[a-zA-Z0-9_]+$/.test(key)) continue;
|
|
178
|
+
const jsonPath = `$.${key}`;
|
|
179
|
+
if (value === null) {
|
|
180
|
+
conditions.push("json_extract(metadata_json, ?) IS NULL");
|
|
181
|
+
binds.push(jsonPath);
|
|
182
|
+
} else if (typeof value === "boolean") {
|
|
183
|
+
conditions.push("json_extract(metadata_json, ?) = ?");
|
|
184
|
+
binds.push(jsonPath, value ? 1 : 0);
|
|
185
|
+
} else {
|
|
186
|
+
conditions.push("json_extract(metadata_json, ?) = ?");
|
|
187
|
+
binds.push(jsonPath, value);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
const where = `WHERE ${conditions.join(" AND ")}`;
|
|
192
|
+
const [sortField, sortDir] = (opts.sort || "published_at:desc").split(":");
|
|
193
|
+
const safeSortField = [
|
|
194
|
+
"published_at",
|
|
195
|
+
"created_at",
|
|
196
|
+
"updated_at",
|
|
197
|
+
"title",
|
|
198
|
+
"order",
|
|
199
|
+
"view_count",
|
|
200
|
+
"reading_time",
|
|
201
|
+
"featured"
|
|
202
|
+
].includes(sortField) ? sortField : "published_at";
|
|
203
|
+
const safeDir = sortDir === "asc" ? "ASC" : "DESC";
|
|
204
|
+
let countResult = null;
|
|
205
|
+
let dataResult = null;
|
|
206
|
+
if (db) {
|
|
207
|
+
try {
|
|
208
|
+
;
|
|
209
|
+
[countResult, dataResult] = await Promise.all([
|
|
210
|
+
db.prepare(`SELECT COUNT(*) as total FROM ${cmsEntryTbl(event)} ${where}`).bind(...binds).first(),
|
|
211
|
+
db.prepare(
|
|
212
|
+
`SELECT * FROM ${cmsEntryTbl(event)} ${where} ORDER BY ${safeSortField} ${safeDir} LIMIT ? OFFSET ?`
|
|
213
|
+
).bind(...binds, limit, offset).all()
|
|
214
|
+
]);
|
|
215
|
+
} catch {
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
let total = countResult?.total ?? 0;
|
|
219
|
+
let rawRows = dataResult?.results || [];
|
|
220
|
+
if (!rawRows.length) {
|
|
221
|
+
try {
|
|
222
|
+
const { manifestEntries } = await import("#qarpeo/cms/manifest");
|
|
223
|
+
let matching = (manifestEntries || []).filter(
|
|
224
|
+
(e) => e.collection_id === collectionId || collectionId === "content"
|
|
225
|
+
);
|
|
226
|
+
if (status !== "all") {
|
|
227
|
+
matching = matching.filter((e) => e.status === status);
|
|
228
|
+
}
|
|
229
|
+
total = matching.length;
|
|
230
|
+
rawRows = matching.slice(offset, offset + limit).map((e) => ({
|
|
231
|
+
id: e.slug || e.id,
|
|
232
|
+
collection_id: e.collection_id,
|
|
233
|
+
slug: e.slug,
|
|
234
|
+
title: e.title,
|
|
235
|
+
description: e.description,
|
|
236
|
+
cover_image: e.cover_image,
|
|
237
|
+
tags: e.tags,
|
|
238
|
+
order: e.order ?? 0,
|
|
239
|
+
content_md: e.content_md || "",
|
|
240
|
+
content_html: e.content_html || "",
|
|
241
|
+
metadata_json: typeof e.metadata_json === "string" ? e.metadata_json : JSON.stringify(e.metadata || {}),
|
|
242
|
+
status: e.status || "published",
|
|
243
|
+
source: "file",
|
|
244
|
+
path: e.path,
|
|
245
|
+
file_path: e.file_path,
|
|
246
|
+
content_hash: e.content_hash,
|
|
247
|
+
published_at: e.published_at || Date.now(),
|
|
248
|
+
created_at: e.created_at || Date.now(),
|
|
249
|
+
updated_at: e.updated_at || Date.now()
|
|
250
|
+
}));
|
|
251
|
+
} catch {
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
const entries = rawRows.map(rowToEntry);
|
|
255
|
+
const populatedEntries = opts.populate ? await Promise.all(entries.map((e) => populateReferenceFields(event, e, opts.populate))) : entries;
|
|
256
|
+
const projectedEntries = opts.fields ? populatedEntries.map((e) => projectCMSEntry(e, opts.fields)) : populatedEntries;
|
|
257
|
+
const result = { entries: projectedEntries, total, page, limit };
|
|
258
|
+
if (listCacheKey) {
|
|
259
|
+
await setCachedList(event, listCacheKey, result);
|
|
260
|
+
}
|
|
261
|
+
return result;
|
|
262
|
+
}
|
|
263
|
+
export async function getCMSEntry(event, collectionId, slugOrId, opts = {}) {
|
|
264
|
+
const db = getCMSDb(event);
|
|
265
|
+
let allowDraft = false;
|
|
266
|
+
const previewCookie = event ? getCookie(event, "qarpeo_preview") : null;
|
|
267
|
+
let cookieObj = null;
|
|
268
|
+
if (previewCookie) {
|
|
269
|
+
try {
|
|
270
|
+
cookieObj = typeof previewCookie === "string" ? JSON.parse(previewCookie) : previewCookie;
|
|
271
|
+
} catch {
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
const isMatchingCookie = Boolean(
|
|
275
|
+
cookieObj && (!cookieObj.collection || cookieObj.collection === collectionId) && (!cookieObj.slug || cookieObj.slug === slugOrId)
|
|
276
|
+
);
|
|
277
|
+
const isPreviewRequested = opts.preview || isMatchingCookie;
|
|
278
|
+
if (isPreviewRequested) {
|
|
279
|
+
const auth = await getAuthContext(event).catch(() => null);
|
|
280
|
+
const config = getCMSConfig(event);
|
|
281
|
+
if (auth?.user && config.roles.some((r) => r === auth.role || auth.isAdmin)) {
|
|
282
|
+
allowDraft = true;
|
|
283
|
+
}
|
|
284
|
+
if (!allowDraft) {
|
|
285
|
+
const token = opts.previewToken || (isMatchingCookie ? cookieObj?.token : void 0);
|
|
286
|
+
const expires = opts.previewExpires || (isMatchingCookie ? cookieObj?.expires : void 0);
|
|
287
|
+
if (token && expires) {
|
|
288
|
+
allowDraft = await verifyPreviewToken(event, collectionId, slugOrId, token, expires);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
if (!allowDraft) {
|
|
293
|
+
const cached = await getCachedEntry(event, collectionId, slugOrId);
|
|
294
|
+
if (cached) return cached;
|
|
295
|
+
}
|
|
296
|
+
const statusClause = allowDraft ? "AND status IN ('draft', 'published', 'scheduled')" : "AND status = 'published'";
|
|
297
|
+
const statusOrder = allowDraft ? "ORDER BY CASE WHEN status = 'draft' THEN 1 WHEN status = 'scheduled' THEN 2 ELSE 3 END" : "";
|
|
298
|
+
const tenantId = getCMSTenantId(event);
|
|
299
|
+
const tenantClause = tenantId ? "AND (tenant_id = ? OR tenant_id IS NULL)" : "";
|
|
300
|
+
const binds = tenantId ? [collectionId, slugOrId, slugOrId, tenantId] : [collectionId, slugOrId, slugOrId];
|
|
301
|
+
let row = null;
|
|
302
|
+
if (db) {
|
|
303
|
+
try {
|
|
304
|
+
row = await db.prepare(
|
|
305
|
+
`SELECT * FROM ${cmsEntryTbl(event)} WHERE collection_id = ? AND (slug = ? OR id = ?) ${statusClause} ${tenantClause} ${statusOrder} LIMIT 1`
|
|
306
|
+
).bind(...binds).first();
|
|
307
|
+
} catch {
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
if (!row) {
|
|
311
|
+
try {
|
|
312
|
+
const { manifestEntries } = await import("#qarpeo/cms/manifest");
|
|
313
|
+
const candidate = (manifestEntries || []).find(
|
|
314
|
+
(e) => (e.collection_id === collectionId || collectionId === "content") && (e.slug === slugOrId || e.id === slugOrId)
|
|
315
|
+
);
|
|
316
|
+
if (candidate) {
|
|
317
|
+
row = {
|
|
318
|
+
id: candidate.slug || candidate.id,
|
|
319
|
+
collection_id: candidate.collection_id,
|
|
320
|
+
slug: candidate.slug,
|
|
321
|
+
title: candidate.title,
|
|
322
|
+
description: candidate.description,
|
|
323
|
+
cover_image: candidate.cover_image,
|
|
324
|
+
tags: candidate.tags,
|
|
325
|
+
order: candidate.order ?? 0,
|
|
326
|
+
content_md: candidate.content_md || "",
|
|
327
|
+
content_html: candidate.content_html || "",
|
|
328
|
+
metadata_json: typeof candidate.metadata_json === "string" ? candidate.metadata_json : JSON.stringify(candidate.metadata || {}),
|
|
329
|
+
status: candidate.status || "published",
|
|
330
|
+
source: "file",
|
|
331
|
+
path: candidate.path,
|
|
332
|
+
file_path: candidate.file_path,
|
|
333
|
+
content_hash: candidate.content_hash,
|
|
334
|
+
published_at: candidate.published_at || Date.now(),
|
|
335
|
+
created_at: candidate.created_at || Date.now(),
|
|
336
|
+
updated_at: candidate.updated_at || Date.now()
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
} catch {
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
const entry = row ? rowToEntry(row) : null;
|
|
343
|
+
if (entry && (!entry.body || !Array.isArray(entry.body.nodes)) && entry.contentMd) {
|
|
344
|
+
const ast = await parseMarkdownAST(entry.contentMd, event);
|
|
345
|
+
entry.body = {
|
|
346
|
+
...ast,
|
|
347
|
+
value: entry.contentMd,
|
|
348
|
+
content: entry.contentMd,
|
|
349
|
+
toc: entry.toc || { links: [] }
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
if (entry && !allowDraft) {
|
|
353
|
+
await setCachedEntry(event, collectionId, slugOrId, entry);
|
|
354
|
+
if (entry.slug && entry.slug !== slugOrId) {
|
|
355
|
+
await setCachedEntry(event, collectionId, entry.slug, entry);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
let finalEntry = entry;
|
|
359
|
+
if (entry && opts.populate) {
|
|
360
|
+
finalEntry = await populateReferenceFields(event, entry, opts.populate);
|
|
361
|
+
}
|
|
362
|
+
if (finalEntry && opts.fields) {
|
|
363
|
+
return projectCMSEntry(finalEntry, opts.fields);
|
|
364
|
+
}
|
|
365
|
+
return finalEntry;
|
|
366
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type RequestEvent } from "nuxt/server";
|
|
2
|
+
import type { CMSComponentDefinition, CMSEntry, CMSFieldDefinition, CMSReferenceValue } from "../../../../types";
|
|
3
|
+
/** Returns `true` when `v` looks like a stored reference object. */
|
|
4
|
+
export declare function isReferenceValue(v: unknown): v is CMSReferenceValue;
|
|
5
|
+
/**
|
|
6
|
+
* Resolves the effective field definitions for a collection, merging config-seeded fields with any
|
|
7
|
+
* schema stored in D1 (DB-created collections take precedence for overlapping keys).
|
|
8
|
+
*/
|
|
9
|
+
export declare function getCollectionFields(event: RequestEvent, collectionId: string): Promise<Record<string, CMSFieldDefinition>>;
|
|
10
|
+
/**
|
|
11
|
+
* Validates and normalises every `reference` field declared for `collectionId` inside `metadata`.
|
|
12
|
+
* Reference inputs (ids, `collection/slug` strings, or partial objects) are resolved to full `{ id,
|
|
13
|
+
* collectionId, slug, title }` values. Mutates `metadata` in place and returns it.
|
|
14
|
+
*/
|
|
15
|
+
export declare function validateAndNormalizeReferenceFields(event: RequestEvent, collectionId: string, metadata: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
16
|
+
export declare function validateAndNormalizeComponentFields(event: RequestEvent, collectionId: string, metadata: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
17
|
+
/**
|
|
18
|
+
* Returns a typed component definition from the CMS config by name, or null if not found.
|
|
19
|
+
*
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
export declare function defineCMSComponent(def: CMSComponentDefinition): CMSComponentDefinition;
|
|
23
|
+
/**
|
|
24
|
+
* Resolves a stored reference object into the full referenced {@link CMSEntry}. Used to populate
|
|
25
|
+
* references on read.
|
|
26
|
+
*/
|
|
27
|
+
export declare function resolveReference(event: RequestEvent, ref: {
|
|
28
|
+
id?: string;
|
|
29
|
+
collectionId?: string;
|
|
30
|
+
slug?: string;
|
|
31
|
+
}): Promise<CMSEntry | null>;
|
|
32
|
+
/**
|
|
33
|
+
* Populates the reference fields of an entry's `metadata` with the full referenced entry, attached
|
|
34
|
+
* as an `entry` property on each reference value. Only fields matching `populate` are resolved.
|
|
35
|
+
* Returns a new entry object; the input is not mutated.
|
|
36
|
+
*/
|
|
37
|
+
export declare function populateReferenceFields(event: RequestEvent, entry: CMSEntry, populate: boolean | string[]): Promise<CMSEntry>;
|
|
38
|
+
/**
|
|
39
|
+
* Serialises reference values inside `metadata` into the human-readable `collection/slug`
|
|
40
|
+
* frontmatter format (single value → string, multiple → string array). Shape-based so it works
|
|
41
|
+
* without field definitions. Returns a new object; the input is not mutated.
|
|
42
|
+
*/
|
|
43
|
+
export declare function serializeReferencesForFrontmatter(metadata: Record<string, unknown>): Record<string, unknown>;
|
|
44
|
+
/**
|
|
45
|
+
* Resolves `collection/slug` frontmatter strings for declared reference fields into stored
|
|
46
|
+
* reference objects. Field-aware so plain string fields are left untouched. Mutates `fm` in place.
|
|
47
|
+
*/
|
|
48
|
+
export declare function resolveReferenceFieldsFromFrontmatter(event: RequestEvent, collectionId: string, fm: Record<string, unknown>): Promise<void>;
|