qarpeo 0.3.5 → 0.4.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.
Files changed (104) hide show
  1. package/dist/chunks/{tools.mjs → manifest.get.mjs} +229 -3
  2. package/dist/cli/index.mjs +74 -5
  3. package/dist/features/console.d.ts +4 -0
  4. package/dist/module.mjs +287 -56
  5. package/dist/runtime/app/components/{BlobImage.vue → QImg.vue} +5 -4
  6. package/dist/runtime/app/composables/console.d.ts +60 -0
  7. package/dist/runtime/app/composables/console.mjs +169 -0
  8. package/dist/runtime/app/composables/pwa.d.ts +34 -0
  9. package/dist/runtime/app/composables/pwa.mjs +86 -0
  10. package/dist/runtime/app/composables/rbac.d.ts +33 -0
  11. package/dist/runtime/app/composables/rbac.mjs +60 -0
  12. package/dist/runtime/app/composables/site.d.ts +73 -0
  13. package/dist/runtime/app/composables/site.mjs +174 -1
  14. package/dist/runtime/app/middleware/console.global.d.ts +2 -0
  15. package/dist/runtime/app/middleware/console.global.mjs +37 -0
  16. package/dist/runtime/app/plugins/pwa.client.d.ts +2 -0
  17. package/dist/runtime/app/plugins/pwa.client.mjs +28 -0
  18. package/dist/runtime/app/plugins/pwa.d.ts +2 -0
  19. package/dist/runtime/app/plugins/pwa.mjs +42 -0
  20. package/dist/runtime/app/plugins/seo.mjs +39 -10
  21. package/dist/runtime/server/routes/__qarpeo/cloud/agents/run.post.d.ts +13 -0
  22. package/dist/runtime/server/routes/__qarpeo/cloud/agents/run.post.mjs +46 -0
  23. package/dist/runtime/server/routes/__qarpeo/cloud/cms/entry.get.d.ts +22 -0
  24. package/dist/runtime/server/routes/__qarpeo/cloud/cms/entry.get.mjs +40 -0
  25. package/dist/runtime/server/routes/__qarpeo/cloud/cms/entry.post.d.ts +20 -0
  26. package/dist/runtime/server/routes/__qarpeo/cloud/cms/entry.post.mjs +52 -0
  27. package/dist/runtime/server/routes/__qarpeo/cloud/cms.get.d.ts +26 -0
  28. package/dist/runtime/server/routes/__qarpeo/cloud/cms.get.mjs +80 -0
  29. package/dist/runtime/server/routes/__qarpeo/cloud/comments/moderate.post.d.ts +16 -0
  30. package/dist/runtime/server/routes/__qarpeo/cloud/comments/moderate.post.mjs +30 -0
  31. package/dist/runtime/server/routes/__qarpeo/cloud/comments.get.d.ts +21 -0
  32. package/dist/runtime/server/routes/__qarpeo/cloud/comments.get.mjs +49 -0
  33. package/dist/runtime/server/routes/__qarpeo/cloud/extras.get.d.ts +22 -0
  34. package/dist/runtime/server/routes/__qarpeo/cloud/extras.get.mjs +65 -0
  35. package/dist/runtime/server/routes/__qarpeo/cloud/mail/unsuppress.post.d.ts +12 -0
  36. package/dist/runtime/server/routes/__qarpeo/cloud/mail/unsuppress.post.mjs +17 -0
  37. package/dist/runtime/server/routes/__qarpeo/cloud/migrate/cms.post.d.ts +22 -0
  38. package/dist/runtime/server/routes/__qarpeo/cloud/migrate/cms.post.mjs +87 -0
  39. package/dist/runtime/server/routes/__qarpeo/cloud/migrate/products.post.d.ts +25 -0
  40. package/dist/runtime/server/routes/__qarpeo/cloud/migrate/products.post.mjs +119 -0
  41. package/dist/runtime/server/routes/__qarpeo/cloud/migrate/users.post.d.ts +19 -0
  42. package/dist/runtime/server/routes/__qarpeo/cloud/migrate/users.post.mjs +86 -0
  43. package/dist/runtime/server/routes/__qarpeo/cloud/migrate.post.d.ts +21 -0
  44. package/dist/runtime/server/routes/__qarpeo/cloud/migrate.post.mjs +91 -0
  45. package/dist/runtime/server/routes/__qarpeo/cloud/notifications/test.post.d.ts +13 -0
  46. package/dist/runtime/server/routes/__qarpeo/cloud/notifications/test.post.mjs +49 -0
  47. package/dist/runtime/server/routes/__qarpeo/cloud/operations.get.d.ts +43 -0
  48. package/dist/runtime/server/routes/__qarpeo/cloud/operations.get.mjs +111 -0
  49. package/dist/runtime/server/routes/__qarpeo/cloud/overview.get.d.ts +22 -0
  50. package/dist/runtime/server/routes/__qarpeo/cloud/overview.get.mjs +44 -0
  51. package/dist/runtime/server/routes/__qarpeo/cloud/store/order-status.post.d.ts +9 -0
  52. package/dist/runtime/server/routes/__qarpeo/cloud/store/order-status.post.mjs +27 -0
  53. package/dist/runtime/server/routes/__qarpeo/cloud/store/orders.get.d.ts +23 -0
  54. package/dist/runtime/server/routes/__qarpeo/cloud/store/orders.get.mjs +56 -0
  55. package/dist/runtime/server/routes/__qarpeo/cloud/store/products.get.d.ts +21 -0
  56. package/dist/runtime/server/routes/__qarpeo/cloud/store/products.get.mjs +50 -0
  57. package/dist/runtime/server/routes/__qarpeo/cloud/tasks/run.post.d.ts +12 -0
  58. package/dist/runtime/server/routes/__qarpeo/cloud/tasks/run.post.mjs +24 -0
  59. package/dist/runtime/server/routes/__qarpeo/cloud/users/action.post.d.ts +26 -0
  60. package/dist/runtime/server/routes/__qarpeo/cloud/users/action.post.mjs +40 -0
  61. package/dist/runtime/server/routes/__qarpeo/cloud/users.get.d.ts +39 -0
  62. package/dist/runtime/server/routes/__qarpeo/cloud/users.get.mjs +69 -0
  63. package/dist/runtime/server/routes/__qarpeo/manifest.get.d.ts +39 -0
  64. package/dist/runtime/server/routes/__qarpeo/manifest.get.mjs +226 -0
  65. package/dist/runtime/server/routes/__qarpeo/og.get.d.ts +15 -0
  66. package/dist/runtime/server/routes/__qarpeo/og.get.mjs +109 -0
  67. package/dist/runtime/server/routes/__qarpeo/rbac/me.get.d.ts +26 -0
  68. package/dist/runtime/server/routes/__qarpeo/rbac/me.get.mjs +23 -0
  69. package/dist/runtime/server/routes/__qarpeo/rbac/roles.delete.d.ts +12 -0
  70. package/dist/runtime/server/routes/__qarpeo/rbac/roles.delete.mjs +12 -0
  71. package/dist/runtime/server/routes/__qarpeo/rbac/roles.get.d.ts +16 -0
  72. package/dist/runtime/server/routes/__qarpeo/rbac/roles.get.mjs +15 -0
  73. package/dist/runtime/server/routes/__qarpeo/rbac/roles.post.d.ts +11 -0
  74. package/dist/runtime/server/routes/__qarpeo/rbac/roles.post.mjs +16 -0
  75. package/dist/runtime/server/routes/__qarpeo/rbac/users.post.d.ts +14 -0
  76. package/dist/runtime/server/routes/__qarpeo/rbac/users.post.mjs +19 -0
  77. package/dist/runtime/server/routes/manifest.webmanifest.get.d.ts +2 -0
  78. package/dist/runtime/server/routes/manifest.webmanifest.get.mjs +31 -0
  79. package/dist/runtime/server/routes/robots.txt.get.mjs +20 -4
  80. package/dist/runtime/server/routes/sitemap.xml.get.mjs +47 -6
  81. package/dist/runtime/server/routes/sw.js.get.d.ts +8 -0
  82. package/dist/runtime/server/routes/sw.js.get.mjs +141 -0
  83. package/dist/runtime/server/utils/auth.d.ts +2 -14
  84. package/dist/runtime/server/utils/auth.mjs +32 -36
  85. package/dist/runtime/server/utils/cloud-auth.d.ts +8 -0
  86. package/dist/runtime/server/utils/cloud-auth.mjs +23 -0
  87. package/dist/runtime/server/utils/console.d.ts +19 -0
  88. package/dist/runtime/server/utils/console.mjs +34 -0
  89. package/dist/runtime/server/utils/legacy-hash.d.ts +76 -0
  90. package/dist/runtime/server/utils/legacy-hash.mjs +96 -0
  91. package/dist/runtime/server/utils/rbac.d.ts +89 -0
  92. package/dist/runtime/server/utils/rbac.mjs +427 -0
  93. package/dist/runtime/server/utils/role-env.d.ts +19 -0
  94. package/dist/runtime/server/utils/role-env.mjs +34 -0
  95. package/dist/runtime/server.d.ts +2 -0
  96. package/dist/runtime/server.mjs +2 -0
  97. package/dist/types/console.d.ts +67 -0
  98. package/dist/types/index.d.ts +1 -0
  99. package/dist/types/options.d.ts +9 -0
  100. package/dist/types/site.d.ts +102 -0
  101. package/dist/types/storage.d.ts +5 -11
  102. package/package.json +1 -1
  103. package/dist/runtime/providers/qarpeo.d.ts +0 -23
  104. package/dist/runtime/providers/qarpeo.mjs +0 -46
@@ -0,0 +1,28 @@
1
+ import { defineNuxtPlugin, useRuntimeConfig } from "nuxt/app";
2
+ import { usePwa } from "../composables/pwa.mjs";
3
+ export default defineNuxtPlugin(() => {
4
+ if (typeof window === "undefined") return;
5
+ const runtimeConfig = useRuntimeConfig();
6
+ const pwaConfig = runtimeConfig.public?.qarpeo?.pwa || {};
7
+ if (pwaConfig.enabled === false) return;
8
+ const { _bindClientEvents, _setRegistration, _setNeedRefresh } = usePwa();
9
+ _bindClientEvents();
10
+ if (pwaConfig.register !== false && "serviceWorker" in navigator) {
11
+ navigator.serviceWorker.register("/sw.js", { scope: pwaConfig.scope || "/" }).then((reg) => {
12
+ _setRegistration(reg);
13
+ if (reg.waiting) {
14
+ _setNeedRefresh(true);
15
+ }
16
+ reg.addEventListener("updatefound", () => {
17
+ const installing = reg.installing;
18
+ if (!installing) return;
19
+ installing.addEventListener("statechange", () => {
20
+ if (installing.state === "installed" && navigator.serviceWorker.controller) {
21
+ _setNeedRefresh(true);
22
+ }
23
+ });
24
+ });
25
+ }).catch(() => {
26
+ });
27
+ }
28
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: import("nuxt/app").Plugin<Record<string, unknown>> & import("nuxt/app").ObjectPlugin<Record<string, unknown>>;
2
+ export default _default;
@@ -0,0 +1,42 @@
1
+ import { defineNuxtPlugin, useHead, useRuntimeConfig } from "nuxt/app";
2
+ export default defineNuxtPlugin(() => {
3
+ const runtimeConfig = useRuntimeConfig();
4
+ const qarpeo = runtimeConfig.public?.qarpeo || {};
5
+ const pwa = qarpeo.pwa || {};
6
+ const site = qarpeo.site || {};
7
+ if (pwa.enabled === false) return;
8
+ const links = [
9
+ { rel: "manifest", href: "/manifest.webmanifest" }
10
+ ];
11
+ const appleTouchIcon = pwa.appleTouchIcon || pwa.icons?.find((i) => i.sizes.includes("180") || i.sizes.includes("192"))?.src || pwa.icons?.[0]?.src;
12
+ if (appleTouchIcon) {
13
+ links.push({ rel: "apple-touch-icon", href: appleTouchIcon });
14
+ }
15
+ const meta = [
16
+ { name: "apple-mobile-web-app-capable", content: "yes" },
17
+ { name: "apple-mobile-web-app-status-bar-style", content: "default" },
18
+ {
19
+ name: "apple-mobile-web-app-title",
20
+ content: pwa.shortName || pwa.name || site.name || "App"
21
+ }
22
+ ];
23
+ const themeColor = pwa.themeColor || "#0f172a";
24
+ if (pwa.themeColorDark) {
25
+ meta.push({
26
+ name: "theme-color",
27
+ content: themeColor,
28
+ media: "(prefers-color-scheme: light)"
29
+ });
30
+ meta.push({
31
+ name: "theme-color",
32
+ content: pwa.themeColorDark,
33
+ media: "(prefers-color-scheme: dark)"
34
+ });
35
+ } else {
36
+ meta.push({ name: "theme-color", content: themeColor });
37
+ }
38
+ useHead({
39
+ link: links,
40
+ meta
41
+ });
42
+ });
@@ -20,7 +20,8 @@ export default defineNuxtPlugin(() => {
20
20
  });
21
21
  const baseSeo = {
22
22
  ogSiteName: siteName,
23
- ogLocale: site.defaultLocale || "en"
23
+ ogLocale: site.defaultLocale || "en",
24
+ ogType: "website"
24
25
  };
25
26
  if (site.name) {
26
27
  baseSeo.title = site.name;
@@ -33,6 +34,17 @@ export default defineNuxtPlugin(() => {
33
34
  if (site.image) {
34
35
  const imageUrl = site.image.startsWith("http") ? site.image : site.url ? `${site.url.replace(/\/$/, "")}/${site.image.replace(/^\//, "")}` : site.image;
35
36
  baseSeo.ogImage = imageUrl;
37
+ } else if (site.ogImage && (site.ogImage === true || site.ogImage.enabled !== false)) {
38
+ const ogCfg = typeof site.ogImage === "object" ? site.ogImage : {};
39
+ const params = new URLSearchParams();
40
+ if (site.name) params.set("title", site.name);
41
+ if (site.description) params.set("description", site.description);
42
+ if (ogCfg.theme) params.set("theme", ogCfg.theme);
43
+ if (ogCfg.themeColor) params.set("themeColor", ogCfg.themeColor);
44
+ const path = `/__qarpeo/og?${params.toString()}`;
45
+ baseSeo.ogImage = site.url ? `${site.url.replace(/\/$/, "")}${path}` : path;
46
+ baseSeo.ogImageWidth = 1200;
47
+ baseSeo.ogImageHeight = 630;
36
48
  }
37
49
  if (site.twitter) {
38
50
  baseSeo.twitterSite = site.twitter;
@@ -48,8 +60,13 @@ export default defineNuxtPlugin(() => {
48
60
  const route = useRoute();
49
61
  const baseUrl = site.url.replace(/\/$/, "");
50
62
  const canonicalHref = computed(() => {
51
- const cleanPath = route.path === "/" ? "" : route.path;
52
- return `${baseUrl}${cleanPath}`;
63
+ let cleanPath = route.path === "/" ? "" : route.path;
64
+ if (site.trailingSlash && cleanPath && !cleanPath.endsWith("/")) {
65
+ cleanPath = `${cleanPath}/`;
66
+ } else if (!site.trailingSlash && cleanPath.endsWith("/")) {
67
+ cleanPath = cleanPath.slice(0, -1);
68
+ }
69
+ return `${baseUrl}${cleanPath || (site.trailingSlash ? "/" : "")}`;
53
70
  });
54
71
  useHead({
55
72
  link: computed(() => {
@@ -83,16 +100,28 @@ export default defineNuxtPlugin(() => {
83
100
  useHead({
84
101
  script: computed(() => {
85
102
  if (route.path !== "/") return [];
103
+ const websiteSchema = {
104
+ "@context": "https://schema.org",
105
+ "@type": "WebSite",
106
+ name: siteName,
107
+ url: baseUrl,
108
+ description: site.description || void 0
109
+ };
110
+ if (site.searchUrl) {
111
+ const target = site.searchUrl.startsWith("http") ? site.searchUrl : `${baseUrl}${site.searchUrl.startsWith("/") ? "" : "/"}${site.searchUrl}`;
112
+ websiteSchema.potentialAction = {
113
+ "@type": "SearchAction",
114
+ target: {
115
+ "@type": "EntryPoint",
116
+ urlTemplate: target
117
+ },
118
+ "query-input": "required name=search_term_string"
119
+ };
120
+ }
86
121
  return [
87
122
  {
88
123
  type: "application/ld+json",
89
- innerHTML: JSON.stringify({
90
- "@context": "https://schema.org",
91
- "@type": "WebSite",
92
- name: siteName,
93
- url: baseUrl,
94
- description: site.description || void 0
95
- })
124
+ innerHTML: JSON.stringify(websiteSchema).replace(/</g, "\\u003c")
96
125
  }
97
126
  ];
98
127
  })
@@ -0,0 +1,13 @@
1
+ /**
2
+ * POST /__qarpeo/cloud/agents/run
3
+ *
4
+ * Invokes a registered AI agent with a test prompt from Qarpeo Cloud.
5
+ * Requires `Authorization: Bearer <QARPEO_CLOUD_SECRET>`.
6
+ */
7
+ declare const _default: import("nuxt/server").EventHandler<Promise<{
8
+ ok: boolean;
9
+ agent: string;
10
+ model: string | undefined;
11
+ reply: any;
12
+ }>>;
13
+ export default _default;
@@ -0,0 +1,46 @@
1
+ import { createError, defineEventHandler, readBody } from "nuxt/server";
2
+ import { getAgentDefinition, useAgent } from "../../../../utils/ai.mjs";
3
+ import { verifyCloudSecret } from "../../../../utils/cloud-auth.mjs";
4
+ export default defineEventHandler(async (event) => {
5
+ verifyCloudSecret(event);
6
+ const body = await readBody(event).catch(() => ({}));
7
+ const agentName = typeof body?.agent === "string" ? body.agent.trim() : "";
8
+ const message = typeof body?.message === "string" ? body.message.trim() : "";
9
+ if (!agentName) {
10
+ throw createError({
11
+ statusCode: 400,
12
+ statusMessage: "Bad Request",
13
+ message: "agent name is required."
14
+ });
15
+ }
16
+ if (!message) {
17
+ throw createError({
18
+ statusCode: 400,
19
+ statusMessage: "Bad Request",
20
+ message: "message is required."
21
+ });
22
+ }
23
+ const def = getAgentDefinition(agentName);
24
+ if (!def) {
25
+ throw createError({
26
+ statusCode: 404,
27
+ statusMessage: "Not Found",
28
+ message: `Agent "${agentName}" is not registered on this Worker.`
29
+ });
30
+ }
31
+ const model = typeof body?.model === "string" && body.model.trim() ? body.model.trim() : def.model;
32
+ const client = useAgent(agentName, "cloud-console", event);
33
+ const res = await client.chat(message, {
34
+ stream: false,
35
+ model,
36
+ system: def.system
37
+ });
38
+ const data = await res.json();
39
+ const reply = data.reply || data.message?.content || data.response || "";
40
+ return {
41
+ ok: true,
42
+ agent: agentName,
43
+ model,
44
+ reply
45
+ };
46
+ });
@@ -0,0 +1,22 @@
1
+ /**
2
+ * GET /__qarpeo/cloud/cms/entry?id=<entryId>
3
+ *
4
+ * Fetches a single CMS entry with full `contentMd`, `description`, and `metadataJson`.
5
+ */
6
+ declare const _default: import("nuxt/server").EventHandler<Promise<{
7
+ ok: boolean;
8
+ entry: {
9
+ id: any;
10
+ collection: any;
11
+ slug: any;
12
+ title: any;
13
+ description: any;
14
+ body: any;
15
+ status: any;
16
+ metadataJson: any;
17
+ createdAt: any;
18
+ updatedAt: any;
19
+ publishedAt: any;
20
+ };
21
+ }>>;
22
+ export default _default;
@@ -0,0 +1,40 @@
1
+ import { createError, defineEventHandler, getQuery } from "nuxt/server";
2
+ import { getD1Binding } from "../../../../../index.mjs";
3
+ import { verifyCloudSecret } from "../../../../utils/cloud-auth.mjs";
4
+ import { resolveTableName } from "../../../../utils/table-names.mjs";
5
+ export default defineEventHandler(async (event) => {
6
+ verifyCloudSecret(event);
7
+ const qs = getQuery(event);
8
+ const id = typeof qs.id === "string" ? qs.id.trim() : "";
9
+ if (!id) {
10
+ throw createError({ statusCode: 400, statusMessage: "Bad Request", message: "id is required" });
11
+ }
12
+ const d1 = getD1Binding(event);
13
+ if (!d1) {
14
+ throw createError({ statusCode: 500, statusMessage: "Internal Server Error", message: "D1 unavailable" });
15
+ }
16
+ const entryTable = resolveTableName("cms_entry").replace(/"/g, "");
17
+ const row = await d1.prepare(
18
+ `SELECT id, collection_id, slug, title, description, content_md, status, metadata_json, created_at, updated_at, published_at
19
+ FROM "${entryTable}" WHERE id = ?1 LIMIT 1`
20
+ ).bind(id).first();
21
+ if (!row) {
22
+ throw createError({ statusCode: 404, statusMessage: "Not Found", message: "CMS entry not found" });
23
+ }
24
+ return {
25
+ ok: true,
26
+ entry: {
27
+ id: row.id,
28
+ collection: row.collection_id,
29
+ slug: row.slug,
30
+ title: row.title,
31
+ description: row.description || "",
32
+ body: row.content_md || "",
33
+ status: row.status,
34
+ metadataJson: row.metadata_json || "{}",
35
+ createdAt: row.created_at,
36
+ updatedAt: row.updated_at,
37
+ publishedAt: row.published_at
38
+ }
39
+ };
40
+ });
@@ -0,0 +1,20 @@
1
+ /**
2
+ * POST /__qarpeo/cloud/cms/entry
3
+ *
4
+ * Create, update, or delete a CMS entry directly from Qarpeo Cloud.
5
+ * Body: `{ action?: "save" | "delete", id?, collection, title, slug?, description?, body?, status? }`
6
+ */
7
+ declare const _default: import("nuxt/server").EventHandler<Promise<{
8
+ ok: boolean;
9
+ deleted: string;
10
+ id?: undefined;
11
+ slug?: undefined;
12
+ status?: undefined;
13
+ } | {
14
+ ok: boolean;
15
+ id: string;
16
+ slug: string;
17
+ status: "published" | "draft" | "archived";
18
+ deleted?: undefined;
19
+ }>>;
20
+ export default _default;
@@ -0,0 +1,52 @@
1
+ import { createError, defineEventHandler, readBody } from "nuxt/server";
2
+ import { getD1Binding } from "../../../../../index.mjs";
3
+ import { verifyCloudSecret } from "../../../../utils/cloud-auth.mjs";
4
+ import { nanoid } from "../../../../utils/crypto.mjs";
5
+ import { resolveTableName } from "../../../../utils/table-names.mjs";
6
+ export default defineEventHandler(async (event) => {
7
+ verifyCloudSecret(event);
8
+ const body = await readBody(event);
9
+ const d1 = getD1Binding(event);
10
+ if (!d1) {
11
+ throw createError({ statusCode: 500, statusMessage: "Internal Server Error", message: "D1 unavailable" });
12
+ }
13
+ const entryTable = resolveTableName("cms_entry").replace(/"/g, "");
14
+ if (body?.action === "delete") {
15
+ if (!body.id) {
16
+ throw createError({ statusCode: 400, statusMessage: "Bad Request", message: "id is required for delete" });
17
+ }
18
+ await d1.prepare(`DELETE FROM "${entryTable}" WHERE id = ?1`).bind(body.id).run();
19
+ return { ok: true, deleted: body.id };
20
+ }
21
+ const collection = typeof body?.collection === "string" ? body.collection.trim() : "";
22
+ const title = typeof body?.title === "string" ? body.title.trim() : "";
23
+ if (!collection || !title) {
24
+ throw createError({
25
+ statusCode: 400,
26
+ statusMessage: "Bad Request",
27
+ message: "collection and title are required"
28
+ });
29
+ }
30
+ const slug = typeof body?.slug === "string" && body.slug.trim() ? body.slug.trim() : title.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 120);
31
+ const status = ["published", "draft", "archived"].includes(body?.status ?? "") ? body.status : "draft";
32
+ const now = Math.floor(Date.now() / 1e3);
33
+ const publishedAt = status === "published" ? now : null;
34
+ const contentMd = body?.body || "";
35
+ const description = body?.description || null;
36
+ if (body?.id) {
37
+ await d1.prepare(
38
+ `UPDATE "${entryTable}"
39
+ SET collection_id = ?1, slug = ?2, title = ?3, description = ?4, content_md = ?5,
40
+ status = ?6, published_at = COALESCE(published_at, ?7), updated_at = ?8
41
+ WHERE id = ?9`
42
+ ).bind(collection, slug, title, description, contentMd, status, publishedAt, now, body.id).run();
43
+ return { ok: true, id: body.id, slug, status };
44
+ }
45
+ const id = nanoid();
46
+ await d1.prepare(
47
+ `INSERT INTO "${entryTable}"
48
+ (id, collection_id, slug, title, description, content_md, content_html, metadata_json, status, source, created_at, updated_at, published_at)
49
+ VALUES (?1, ?2, ?3, ?4, ?5, ?6, '', '{}', ?7, 'db', ?8, ?8, ?9)`
50
+ ).bind(id, collection, slug, title, description, contentMd, status, now, publishedAt).run();
51
+ return { ok: true, id, slug, status };
52
+ });
@@ -0,0 +1,26 @@
1
+ /**
2
+ * GET /__qarpeo/cloud/cms
3
+ *
4
+ * Returns a paginated list of CMS entries for the Qarpeo Cloud CMS Dashboard.
5
+ * Requires `Authorization: Bearer <QARPEO_CLOUD_SECRET>`.
6
+ */
7
+ declare const _default: import("nuxt/server").EventHandler<Promise<{
8
+ ok: boolean;
9
+ entries: any;
10
+ collections: any;
11
+ total: number;
12
+ page: number;
13
+ limit: number;
14
+ pages: number;
15
+ error?: undefined;
16
+ } | {
17
+ ok: boolean;
18
+ error: any;
19
+ entries: never[];
20
+ collections: never[];
21
+ total: number;
22
+ page?: undefined;
23
+ limit?: undefined;
24
+ pages?: undefined;
25
+ }>>;
26
+ export default _default;
@@ -0,0 +1,80 @@
1
+ import { defineEventHandler, getQuery } from "nuxt/server";
2
+ import { getD1Binding } from "../../../../index.mjs";
3
+ import { verifyCloudSecret } from "../../../utils/cloud-auth.mjs";
4
+ import { resolveTableName } from "../../../utils/table-names.mjs";
5
+ export default defineEventHandler(async (event) => {
6
+ verifyCloudSecret(event);
7
+ const d1 = getD1Binding(event);
8
+ if (!d1) {
9
+ return { ok: false, error: "D1 binding not available", entries: [], collections: [], total: 0 };
10
+ }
11
+ const qs = getQuery(event);
12
+ const page = Math.max(1, parseInt(String(qs.page || "1"), 10));
13
+ const limit = Math.min(100, Math.max(1, parseInt(String(qs.limit || "25"), 10)));
14
+ const q = typeof qs.q === "string" ? qs.q.trim() : "";
15
+ const collection = typeof qs.collection === "string" ? qs.collection.trim() : "";
16
+ const status = typeof qs.status === "string" ? qs.status.trim() : "";
17
+ const offset = (page - 1) * limit;
18
+ const entryTable = resolveTableName("cms_entry").replace(/"/g, "");
19
+ const conditions = [];
20
+ const bindings = [];
21
+ let bindIdx = 1;
22
+ if (q) {
23
+ conditions.push(`(title LIKE ?${bindIdx} OR slug LIKE ?${bindIdx})`);
24
+ bindings.push(`%${q}%`);
25
+ bindIdx++;
26
+ }
27
+ if (collection) {
28
+ conditions.push(`collection_id = ?${bindIdx}`);
29
+ bindings.push(collection);
30
+ bindIdx++;
31
+ }
32
+ if (status) {
33
+ conditions.push(`status = ?${bindIdx}`);
34
+ bindings.push(status);
35
+ bindIdx++;
36
+ }
37
+ const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
38
+ try {
39
+ const countRow = await d1.prepare(`SELECT COUNT(*) as total FROM "${entryTable}" ${whereClause}`).bind(...bindings).first();
40
+ const rows = await d1.prepare(
41
+ `SELECT id, collection_id, title, slug, status, description, created_at, updated_at, published_at
42
+ FROM "${entryTable}"
43
+ ${whereClause}
44
+ ORDER BY updated_at DESC
45
+ LIMIT ?${bindIdx} OFFSET ?${bindIdx + 1}`
46
+ ).bind(...bindings, limit, offset).all().then((r) => r.results ?? []);
47
+ const collectionRows = await d1.prepare(
48
+ `SELECT collection_id, COUNT(*) as count, SUM(CASE WHEN status='published' THEN 1 ELSE 0 END) as published
49
+ FROM "${entryTable}"
50
+ GROUP BY collection_id
51
+ ORDER BY count DESC`
52
+ ).all().then((r) => r.results ?? []);
53
+ const total = typeof countRow?.total === "number" ? countRow.total : Number(countRow?.total ?? 0);
54
+ return {
55
+ ok: true,
56
+ entries: rows.map((e) => ({
57
+ id: e.id,
58
+ collection: e.collection_id,
59
+ title: e.title,
60
+ slug: e.slug,
61
+ status: e.status,
62
+ description: e.description || "",
63
+ createdAt: e.created_at,
64
+ updatedAt: e.updated_at,
65
+ publishedAt: e.published_at
66
+ })),
67
+ collections: collectionRows.map((c) => ({
68
+ name: c.collection_id,
69
+ total: Number(c.count),
70
+ published: Number(c.published ?? 0)
71
+ })),
72
+ total,
73
+ page,
74
+ limit,
75
+ pages: Math.ceil(total / limit)
76
+ };
77
+ } catch (err) {
78
+ return { ok: false, error: err?.message || "Query failed", entries: [], collections: [], total: 0 };
79
+ }
80
+ });
@@ -0,0 +1,16 @@
1
+ /**
2
+ * POST /__qarpeo/cloud/comments/moderate
3
+ * Body: `{ commentId: string, action: "approve" | "spam" | "reject" | "delete" }`
4
+ */
5
+ declare const _default: import("nuxt/server").EventHandler<Promise<{
6
+ ok: boolean;
7
+ commentId: string;
8
+ action: "delete";
9
+ status?: undefined;
10
+ } | {
11
+ ok: boolean;
12
+ commentId: string;
13
+ status: string;
14
+ action?: undefined;
15
+ }>>;
16
+ export default _default;
@@ -0,0 +1,30 @@
1
+ import { createError, defineEventHandler, readBody } from "nuxt/server";
2
+ import { getD1Binding } from "../../../../../index.mjs";
3
+ import { verifyCloudSecret } from "../../../../utils/cloud-auth.mjs";
4
+ import { resolveTableName } from "../../../../utils/table-names.mjs";
5
+ export default defineEventHandler(async (event) => {
6
+ verifyCloudSecret(event);
7
+ const body = await readBody(event);
8
+ const commentId = typeof body?.commentId === "string" ? body.commentId.trim() : "";
9
+ const action = body?.action;
10
+ if (!commentId || !["approve", "spam", "reject", "delete"].includes(action ?? "")) {
11
+ throw createError({
12
+ statusCode: 400,
13
+ statusMessage: "Bad Request",
14
+ message: "commentId and action (approve | spam | reject | delete) are required."
15
+ });
16
+ }
17
+ const d1 = getD1Binding(event);
18
+ if (!d1) {
19
+ throw createError({ statusCode: 500, statusMessage: "Internal Server Error", message: "D1 unavailable" });
20
+ }
21
+ const commentTable = resolveTableName("comment").replace(/"/g, "");
22
+ const now = Math.floor(Date.now() / 1e3);
23
+ if (action === "delete") {
24
+ await d1.prepare(`UPDATE "${commentTable}" SET deleted_at = ?1, updated_at = ?1 WHERE id = ?2`).bind(now, commentId).run();
25
+ return { ok: true, commentId, action };
26
+ }
27
+ const newStatus = action === "approve" ? "approved" : action === "spam" ? "spam" : "rejected";
28
+ await d1.prepare(`UPDATE "${commentTable}" SET status = ?1, updated_at = ?2 WHERE id = ?3`).bind(newStatus, now, commentId).run();
29
+ return { ok: true, commentId, status: newStatus };
30
+ });
@@ -0,0 +1,21 @@
1
+ /**
2
+ * GET /__qarpeo/cloud/comments
3
+ */
4
+ declare const _default: import("nuxt/server").EventHandler<Promise<{
5
+ ok: boolean;
6
+ comments: any;
7
+ total: number;
8
+ page: number;
9
+ limit: number;
10
+ pages: number;
11
+ error?: undefined;
12
+ } | {
13
+ ok: boolean;
14
+ error: any;
15
+ comments: never[];
16
+ total: number;
17
+ page?: undefined;
18
+ limit?: undefined;
19
+ pages?: undefined;
20
+ }>>;
21
+ export default _default;
@@ -0,0 +1,49 @@
1
+ import { defineEventHandler, getQuery } from "nuxt/server";
2
+ import { getD1Binding } from "../../../../index.mjs";
3
+ import { verifyCloudSecret } from "../../../utils/cloud-auth.mjs";
4
+ import { resolveTableName } from "../../../utils/table-names.mjs";
5
+ export default defineEventHandler(async (event) => {
6
+ verifyCloudSecret(event);
7
+ const d1 = getD1Binding(event);
8
+ if (!d1) {
9
+ return { ok: false, error: "D1 unavailable", comments: [], total: 0 };
10
+ }
11
+ const qs = getQuery(event);
12
+ const page = Math.max(1, parseInt(String(qs.page || "1"), 10));
13
+ const limit = Math.min(100, Math.max(1, parseInt(String(qs.limit || "25"), 10)));
14
+ const statusFilter = typeof qs.status === "string" ? qs.status.trim() : "";
15
+ const offset = (page - 1) * limit;
16
+ const commentTable = resolveTableName("comment").replace(/"/g, "");
17
+ try {
18
+ const whereClause = statusFilter ? `WHERE status = ?1 AND deleted_at IS NULL` : `WHERE deleted_at IS NULL`;
19
+ const bindings = statusFilter ? [statusFilter] : [];
20
+ const countRow = await d1.prepare(`SELECT COUNT(*) as total FROM "${commentTable}" ${whereClause}`).bind(...bindings).first();
21
+ const rows = await d1.prepare(
22
+ `SELECT id, target_urn, author_name, author_email, content, status, report_count, created_at
23
+ FROM "${commentTable}"
24
+ ${whereClause}
25
+ ORDER BY created_at DESC
26
+ LIMIT ?${bindings.length + 1} OFFSET ?${bindings.length + 2}`
27
+ ).bind(...bindings, limit, offset).all().then((r) => r.results ?? []);
28
+ const total = typeof countRow?.total === "number" ? countRow.total : Number(countRow?.total ?? 0);
29
+ return {
30
+ ok: true,
31
+ comments: rows.map((c) => ({
32
+ id: c.id,
33
+ targetUrn: c.target_urn,
34
+ authorName: c.author_name,
35
+ authorEmail: c.author_email || "",
36
+ content: c.content,
37
+ status: c.status,
38
+ reportCount: Number(c.report_count ?? 0),
39
+ createdAt: c.created_at
40
+ })),
41
+ total,
42
+ page,
43
+ limit,
44
+ pages: Math.ceil(total / limit)
45
+ };
46
+ } catch (err) {
47
+ return { ok: false, error: err?.message || "Query failed", comments: [], total: 0 };
48
+ }
49
+ });
@@ -0,0 +1,22 @@
1
+ /**
2
+ * GET /__qarpeo/cloud/extras
3
+ *
4
+ * Returns D1 schema health (missing expected tables per enabled feature),
5
+ * active tenants (if multitenant), and mail/push stats.
6
+ */
7
+ declare const _default: import("nuxt/server").EventHandler<Promise<{
8
+ ok: boolean;
9
+ d1Available: boolean;
10
+ tableCount: number;
11
+ missingTables: {
12
+ feature: string;
13
+ table: string;
14
+ }[];
15
+ tenants: {
16
+ id: string;
17
+ slug: string;
18
+ name: string;
19
+ plan?: string;
20
+ }[];
21
+ }>>;
22
+ export default _default;