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,43 @@
1
+ /**
2
+ * GET /__qarpeo/cloud/operations
3
+ *
4
+ * Returns runtime operational state for Qarpeo Cloud:
5
+ * - Discovered & active AI Agents + Tools
6
+ * - Discovered MCP Servers
7
+ * - Nitro Scheduled Tasks & Cron schedules
8
+ * - Mail suppression stats + recent suppressed addresses
9
+ * - Web Push subscriptions & Notifications stats
10
+ */
11
+ declare const _default: import("nuxt/server").EventHandler<Promise<{
12
+ ok: boolean;
13
+ agents: {
14
+ name: string;
15
+ model: string;
16
+ tools: string[];
17
+ active: boolean;
18
+ }[];
19
+ tools: string[];
20
+ mcp: {
21
+ basePath: string;
22
+ servers: string[];
23
+ };
24
+ tasks: {
25
+ name: string;
26
+ description?: string;
27
+ cron?: string;
28
+ }[];
29
+ mail: {
30
+ suppressedCount: number | null;
31
+ recentSuppressions: {
32
+ email: string;
33
+ reason: string;
34
+ createdAt: number;
35
+ }[];
36
+ };
37
+ notifications: {
38
+ pushSubscriptions: number | null;
39
+ total: number | null;
40
+ unread: number | null;
41
+ };
42
+ }>>;
43
+ export default _default;
@@ -0,0 +1,111 @@
1
+ import { defineEventHandler, useRuntimeConfig } from "nuxt/server";
2
+ import { getD1Binding } from "../../../../index.mjs";
3
+ import { getAllAgentDefinitions } from "../../../utils/ai.mjs";
4
+ import { verifyCloudSecret } from "../../../utils/cloud-auth.mjs";
5
+ import { resolveTableName } from "../../../utils/table-names.mjs";
6
+ async function safeCount(d1, tableName, where = "") {
7
+ if (!d1) return null;
8
+ try {
9
+ const clean = tableName.replace(/"/g, "");
10
+ const row = await d1.prepare(`SELECT COUNT(*) as total FROM "${clean}" ${where}`).first();
11
+ return typeof row?.total === "number" ? row.total : Number(row?.total ?? 0);
12
+ } catch {
13
+ return null;
14
+ }
15
+ }
16
+ export default defineEventHandler(async (event) => {
17
+ verifyCloudSecret(event);
18
+ const rc = useRuntimeConfig();
19
+ const qrc = rc.qarpeo || {};
20
+ const discoveredAgents = Array.isArray(qrc.agents?.discovered) ? qrc.agents.discovered : [];
21
+ const discoveredTools = Array.isArray(qrc.tools?.discovered) ? qrc.tools.discovered : [];
22
+ const realDefs = getAllAgentDefinitions();
23
+ const agentMap = /* @__PURE__ */ new Map();
24
+ for (const name of discoveredAgents) {
25
+ agentMap.set(name, {
26
+ name,
27
+ model: qrc.agents?.defaultModel || "@cf/meta/llama-3.3-70b-instruct",
28
+ tools: [],
29
+ active: false
30
+ });
31
+ }
32
+ for (const def of realDefs) {
33
+ const toolNames = def.tools ? Array.isArray(def.tools) ? def.tools.map((t) => t.name || "tool") : Object.keys(def.tools) : [];
34
+ agentMap.set(def.name, {
35
+ name: def.name,
36
+ model: def.model || qrc.agents?.defaultModel || "@cf/meta/llama-3.3-70b-instruct",
37
+ tools: toolNames,
38
+ active: true
39
+ });
40
+ }
41
+ const discoveredMcp = Array.isArray(qrc.mcp?.discovered) ? qrc.mcp.discovered : [];
42
+ const mcpPath = qrc.mcp?.path || "/mcp";
43
+ const tasks = [];
44
+ try {
45
+ const nitro = event.context?.nitro;
46
+ const nitroTasks = nitro?.tasks || globalThis.__nitro?.tasks || {};
47
+ const scheduledTasks = nitro?.scheduledTasks || globalThis.__nitro?.scheduledTasks || {};
48
+ const taskCronMap = /* @__PURE__ */ new Map();
49
+ for (const [cron, names] of Object.entries(scheduledTasks)) {
50
+ for (const n of names) {
51
+ taskCronMap.set(n, [...taskCronMap.get(n) || [], cron]);
52
+ }
53
+ }
54
+ for (const [name, def] of Object.entries(nitroTasks)) {
55
+ tasks.push({
56
+ name,
57
+ description: def?.description,
58
+ cron: taskCronMap.get(name)?.[0]
59
+ });
60
+ }
61
+ } catch {
62
+ }
63
+ let d1 = null;
64
+ try {
65
+ d1 = getD1Binding(event);
66
+ } catch {
67
+ d1 = null;
68
+ }
69
+ const suppressedCount = await safeCount(d1, "mail_suppression");
70
+ let recentSuppressions = [];
71
+ if (d1 && suppressedCount && suppressedCount > 0) {
72
+ try {
73
+ const rows = await d1.prepare(
74
+ `SELECT email, reason, created_at FROM "mail_suppression" ORDER BY created_at DESC LIMIT 10`
75
+ ).all().then((r) => r.results ?? []);
76
+ recentSuppressions = rows.map((r) => ({
77
+ email: r.email,
78
+ reason: r.reason,
79
+ createdAt: r.created_at
80
+ }));
81
+ } catch {
82
+ recentSuppressions = [];
83
+ }
84
+ }
85
+ const pushSubTable = resolveTableName("push_subscription").replace(/"/g, "");
86
+ const notifTable = resolveTableName("notification").replace(/"/g, "");
87
+ const [pushSubscriptions, notificationsTotal, notificationsUnread] = await Promise.all([
88
+ safeCount(d1, pushSubTable),
89
+ safeCount(d1, notifTable),
90
+ safeCount(d1, notifTable, "WHERE read_at IS NULL")
91
+ ]);
92
+ return {
93
+ ok: true,
94
+ agents: Array.from(agentMap.values()),
95
+ tools: discoveredTools,
96
+ mcp: {
97
+ basePath: mcpPath,
98
+ servers: discoveredMcp
99
+ },
100
+ tasks,
101
+ mail: {
102
+ suppressedCount,
103
+ recentSuppressions
104
+ },
105
+ notifications: {
106
+ pushSubscriptions,
107
+ total: notificationsTotal,
108
+ unread: notificationsUnread
109
+ }
110
+ };
111
+ });
@@ -0,0 +1,22 @@
1
+ declare const _default: import("nuxt/server").EventHandler<Promise<{
2
+ ok: boolean;
3
+ qarpeoVersion: any;
4
+ features: Record<string, boolean>;
5
+ stats: {
6
+ auth: {
7
+ users: number | null;
8
+ sessions: number | null;
9
+ } | null;
10
+ cms: {
11
+ entries: number | null;
12
+ } | null;
13
+ comments: {
14
+ total: number | null;
15
+ } | null;
16
+ store: {
17
+ products: number | null;
18
+ orders: number | null;
19
+ } | null;
20
+ };
21
+ }>>;
22
+ export default _default;
@@ -0,0 +1,44 @@
1
+ import { defineEventHandler, useRuntimeConfig } 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
+ async function safeCount(d1, tableName) {
6
+ if (!d1) return null;
7
+ try {
8
+ const row = await d1.prepare(`SELECT COUNT(*) as total FROM "${tableName.replace(/"/g, "")}"`).first();
9
+ return typeof row?.total === "number" ? row.total : Number(row?.total ?? 0);
10
+ } catch {
11
+ return null;
12
+ }
13
+ }
14
+ export default defineEventHandler(async (event) => {
15
+ verifyCloudSecret(event);
16
+ const config = useRuntimeConfig();
17
+ const manifest = config.qarpeo?.manifest || {};
18
+ const features = manifest.features || {};
19
+ let d1 = null;
20
+ try {
21
+ d1 = getD1Binding(event);
22
+ } catch {
23
+ d1 = null;
24
+ }
25
+ const [usersCount, sessionsCount, cmsCount, commentsCount, productsCount, ordersCount] = await Promise.all([
26
+ features.auth ? safeCount(d1, resolveTableName("user")) : Promise.resolve(null),
27
+ features.auth ? safeCount(d1, resolveTableName("session")) : Promise.resolve(null),
28
+ features.cms ? safeCount(d1, resolveTableName("cms_entry")) : Promise.resolve(null),
29
+ features.comments ? safeCount(d1, resolveTableName("comment")) : Promise.resolve(null),
30
+ features.store ? safeCount(d1, resolveTableName("store_product")) : Promise.resolve(null),
31
+ features.store ? safeCount(d1, resolveTableName("store_order")) : Promise.resolve(null)
32
+ ]);
33
+ return {
34
+ ok: true,
35
+ qarpeoVersion: manifest.qarpeoVersion || config.public?.qarpeoVersion || null,
36
+ features,
37
+ stats: {
38
+ auth: features.auth ? { users: usersCount, sessions: sessionsCount } : null,
39
+ cms: features.cms ? { entries: cmsCount } : null,
40
+ comments: features.comments ? { total: commentsCount } : null,
41
+ store: features.store ? { products: productsCount, orders: ordersCount } : null
42
+ }
43
+ };
44
+ });
@@ -0,0 +1,9 @@
1
+ /**
2
+ * POST /__qarpeo/cloud/store/order-status
3
+ */
4
+ declare const _default: import("nuxt/server").EventHandler<Promise<{
5
+ ok: boolean;
6
+ orderId: string;
7
+ status: string;
8
+ }>>;
9
+ export default _default;
@@ -0,0 +1,27 @@
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
+ const ALLOWED_STATUSES = ["pending", "paid", "processing", "shipped", "delivered", "cancelled", "refunded"];
6
+ export default defineEventHandler(async (event) => {
7
+ verifyCloudSecret(event);
8
+ const body = await readBody(event);
9
+ const orderId = typeof body?.orderId === "string" ? body.orderId.trim() : "";
10
+ const status = typeof body?.status === "string" ? body.status.trim() : "";
11
+ if (!orderId || !ALLOWED_STATUSES.includes(status)) {
12
+ throw createError({
13
+ statusCode: 400,
14
+ statusMessage: "Bad Request",
15
+ message: `Valid orderId and status (${ALLOWED_STATUSES.join(", ")}) are required.`
16
+ });
17
+ }
18
+ const d1 = getD1Binding(event);
19
+ if (!d1) {
20
+ throw createError({ statusCode: 500, statusMessage: "Internal Server Error", message: "D1 unavailable" });
21
+ }
22
+ const orderTable = resolveTableName("store_order").replace(/"/g, "");
23
+ const now = Math.floor(Date.now() / 1e3);
24
+ const tsCol = status === "paid" ? ", paid_at = COALESCE(paid_at, ?2)" : status === "shipped" ? ", shipped_at = COALESCE(shipped_at, ?2)" : status === "delivered" ? ", delivered_at = COALESCE(delivered_at, ?2)" : status === "cancelled" ? ", cancelled_at = COALESCE(cancelled_at, ?2)" : status === "refunded" ? ", refunded_at = COALESCE(refunded_at, ?2)" : "";
25
+ await d1.prepare(`UPDATE "${orderTable}" SET status = ?1, updated_at = ?2${tsCol} WHERE id = ?3`).bind(status, now, orderId).run();
26
+ return { ok: true, orderId, status };
27
+ });
@@ -0,0 +1,23 @@
1
+ /**
2
+ * GET /__qarpeo/cloud/store/orders
3
+ */
4
+ declare const _default: import("nuxt/server").EventHandler<Promise<{
5
+ ok: boolean;
6
+ orders: any;
7
+ total: number;
8
+ totalRevenue: number;
9
+ page: number;
10
+ limit: number;
11
+ pages: number;
12
+ error?: undefined;
13
+ } | {
14
+ ok: boolean;
15
+ error: any;
16
+ orders: never[];
17
+ total: number;
18
+ totalRevenue: number;
19
+ page?: undefined;
20
+ limit?: undefined;
21
+ pages?: undefined;
22
+ }>>;
23
+ export default _default;
@@ -0,0 +1,56 @@
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", orders: [], total: 0, totalRevenue: 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 orderTable = resolveTableName("store_order").replace(/"/g, "");
17
+ try {
18
+ const whereClause = statusFilter ? `WHERE status = ?1` : "";
19
+ const bindings = statusFilter ? [statusFilter] : [];
20
+ const aggRow = await d1.prepare(
21
+ `SELECT COUNT(*) as total, COALESCE(SUM(CASE WHEN status NOT IN ('cancelled', 'refunded') THEN total ELSE 0 END), 0) as revenue
22
+ FROM "${orderTable}" ${whereClause}`
23
+ ).bind(...bindings).first();
24
+ const rows = await d1.prepare(
25
+ `SELECT id, order_number, customer_email, customer_name, status, currency, total, payment_provider, created_at, updated_at
26
+ FROM "${orderTable}"
27
+ ${whereClause}
28
+ ORDER BY created_at DESC
29
+ LIMIT ?${bindings.length + 1} OFFSET ?${bindings.length + 2}`
30
+ ).bind(...bindings, limit, offset).all().then((r) => r.results ?? []);
31
+ const total = Number(aggRow?.total ?? 0);
32
+ const totalRevenue = Number(aggRow?.revenue ?? 0);
33
+ return {
34
+ ok: true,
35
+ orders: rows.map((o) => ({
36
+ id: o.id,
37
+ orderNumber: o.order_number,
38
+ customerEmail: o.customer_email,
39
+ customerName: o.customer_name || "",
40
+ status: o.status,
41
+ currency: o.currency || "USD",
42
+ total: Number(o.total ?? 0),
43
+ paymentProvider: o.payment_provider || "",
44
+ createdAt: o.created_at,
45
+ updatedAt: o.updated_at
46
+ })),
47
+ total,
48
+ totalRevenue,
49
+ page,
50
+ limit,
51
+ pages: Math.ceil(total / limit)
52
+ };
53
+ } catch (err) {
54
+ return { ok: false, error: err?.message || "Query failed", orders: [], total: 0, totalRevenue: 0 };
55
+ }
56
+ });
@@ -0,0 +1,21 @@
1
+ /**
2
+ * GET /__qarpeo/cloud/store/products
3
+ */
4
+ declare const _default: import("nuxt/server").EventHandler<Promise<{
5
+ ok: boolean;
6
+ products: any;
7
+ total: number;
8
+ page: number;
9
+ limit: number;
10
+ pages: number;
11
+ error?: undefined;
12
+ } | {
13
+ ok: boolean;
14
+ error: any;
15
+ products: never[];
16
+ total: number;
17
+ page?: undefined;
18
+ limit?: undefined;
19
+ pages?: undefined;
20
+ }>>;
21
+ export default _default;
@@ -0,0 +1,50 @@
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", products: [], 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 offset = (page - 1) * limit;
16
+ const productTable = resolveTableName("store_product").replace(/"/g, "");
17
+ try {
18
+ const whereClause = q ? `WHERE title LIKE ?1 OR slug LIKE ?1` : "";
19
+ const bindings = q ? [`%${q}%`] : [];
20
+ const countRow = await d1.prepare(`SELECT COUNT(*) as total FROM "${productTable}" ${whereClause}`).bind(...bindings).first();
21
+ const rows = await d1.prepare(
22
+ `SELECT id, slug, title, status, type, base_price, currency, created_at, updated_at
23
+ FROM "${productTable}"
24
+ ${whereClause}
25
+ ORDER BY updated_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
+ products: rows.map((p) => ({
32
+ id: p.id,
33
+ slug: p.slug,
34
+ title: p.title,
35
+ status: p.status,
36
+ type: p.type,
37
+ basePrice: Number(p.base_price ?? 0),
38
+ currency: p.currency || "USD",
39
+ createdAt: p.created_at,
40
+ updatedAt: p.updated_at
41
+ })),
42
+ total,
43
+ page,
44
+ limit,
45
+ pages: Math.ceil(total / limit)
46
+ };
47
+ } catch (err) {
48
+ return { ok: false, error: err?.message || "Query failed", products: [], total: 0 };
49
+ }
50
+ });
@@ -0,0 +1,12 @@
1
+ /**
2
+ * POST /__qarpeo/cloud/tasks/run
3
+ *
4
+ * Manually triggers a Nitro scheduled task by name from Qarpeo Cloud.
5
+ * Requires `Authorization: Bearer <QARPEO_CLOUD_SECRET>`.
6
+ */
7
+ declare const _default: import("nuxt/server").EventHandler<Promise<{
8
+ ok: boolean;
9
+ task: string;
10
+ result: any;
11
+ }>>;
12
+ export default _default;
@@ -0,0 +1,24 @@
1
+ import { createError, defineEventHandler, readBody } from "nuxt/server";
2
+ import { verifyCloudSecret } from "../../../../utils/cloud-auth.mjs";
3
+ export default defineEventHandler(async (event) => {
4
+ verifyCloudSecret(event);
5
+ const body = await readBody(event);
6
+ const taskName = typeof body?.task === "string" ? body.task.trim() : "";
7
+ if (!taskName) {
8
+ throw createError({
9
+ statusCode: 400,
10
+ statusMessage: "Bad Request",
11
+ message: "task name is required."
12
+ });
13
+ }
14
+ const runTask = event.$runTask || event.context?.nitro?.runTask || globalThis.__nitro?.runTask;
15
+ if (typeof runTask !== "function") {
16
+ throw createError({
17
+ statusCode: 501,
18
+ statusMessage: "Not Implemented",
19
+ message: "Nitro task runner is not available on this Worker."
20
+ });
21
+ }
22
+ const result = await runTask(taskName, { payload: body?.payload ?? {} });
23
+ return { ok: true, task: taskName, result };
24
+ });
@@ -0,0 +1,26 @@
1
+ /**
2
+ * POST /__qarpeo/cloud/users/action
3
+ * Body: `{ userId: string, action: "set-role" | "ban" | "unban" | "revoke-sessions", role?: string }`
4
+ */
5
+ declare const _default: import("nuxt/server").EventHandler<Promise<{
6
+ ok: boolean;
7
+ userId: string;
8
+ action: "revoke-sessions";
9
+ role?: undefined;
10
+ } | {
11
+ ok: boolean;
12
+ userId: string;
13
+ action: "ban";
14
+ role: string;
15
+ } | {
16
+ ok: boolean;
17
+ userId: string;
18
+ action: "unban";
19
+ role: string;
20
+ } | {
21
+ ok: boolean;
22
+ userId: string;
23
+ action: "set-role" | undefined;
24
+ role: string;
25
+ }>>;
26
+ export default _default;
@@ -0,0 +1,40 @@
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 userId = typeof body?.userId === "string" ? body.userId.trim() : "";
9
+ const action = body?.action;
10
+ if (!userId || !["set-role", "ban", "unban", "revoke-sessions"].includes(action ?? "")) {
11
+ throw createError({
12
+ statusCode: 400,
13
+ statusMessage: "Bad Request",
14
+ message: "userId and action (set-role | ban | unban | revoke-sessions) 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 userTable = resolveTableName("user").replace(/"/g, "");
22
+ const sessionTable = resolveTableName("session").replace(/"/g, "");
23
+ const now = Math.floor(Date.now() / 1e3);
24
+ if (action === "revoke-sessions") {
25
+ await d1.prepare(`DELETE FROM "${sessionTable}" WHERE user_id = ?1`).bind(userId).run();
26
+ return { ok: true, userId, action };
27
+ }
28
+ if (action === "ban") {
29
+ await d1.prepare(`UPDATE "${userTable}" SET role = 'banned', updated_at = ?1 WHERE id = ?2`).bind(now, userId).run();
30
+ await d1.prepare(`DELETE FROM "${sessionTable}" WHERE user_id = ?1`).bind(userId).run();
31
+ return { ok: true, userId, action, role: "banned" };
32
+ }
33
+ if (action === "unban") {
34
+ await d1.prepare(`UPDATE "${userTable}" SET role = 'user', updated_at = ?1 WHERE id = ?2`).bind(now, userId).run();
35
+ return { ok: true, userId, action, role: "user" };
36
+ }
37
+ const role = typeof body?.role === "string" && body.role.trim() ? body.role.trim() : "user";
38
+ await d1.prepare(`UPDATE "${userTable}" SET role = ?1, updated_at = ?2 WHERE id = ?3`).bind(role, now, userId).run();
39
+ return { ok: true, userId, action, role };
40
+ });
@@ -0,0 +1,39 @@
1
+ /**
2
+ * GET /__qarpeo/cloud/users
3
+ *
4
+ * Returns a paginated list of auth users for the Qarpeo Cloud Auth Dashboard.
5
+ * Requires `Authorization: Bearer <QARPEO_CLOUD_SECRET>`.
6
+ *
7
+ * Query params:
8
+ * - page (default 1)
9
+ * - limit (default 25, max 100)
10
+ * - q (optional email/name search substring)
11
+ */
12
+ declare const _default: import("nuxt/server").EventHandler<Promise<{
13
+ ok: boolean;
14
+ users: {
15
+ id: any;
16
+ name: any;
17
+ email: any;
18
+ emailVerified: boolean;
19
+ role: any;
20
+ provider: any;
21
+ sessionCount: number;
22
+ createdAt: any;
23
+ updatedAt: any;
24
+ }[];
25
+ total: any;
26
+ page: number;
27
+ limit: number;
28
+ pages: number;
29
+ error?: undefined;
30
+ } | {
31
+ ok: boolean;
32
+ error: any;
33
+ users: never[];
34
+ total: number;
35
+ page?: undefined;
36
+ limit?: undefined;
37
+ pages?: undefined;
38
+ }>>;
39
+ export default _default;
@@ -0,0 +1,69 @@
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", users: [], 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 offset = (page - 1) * limit;
16
+ const userTable = resolveTableName("user").replace(/"/g, "");
17
+ const sessionTable = resolveTableName("session").replace(/"/g, "");
18
+ const accountTable = resolveTableName("account").replace(/"/g, "");
19
+ try {
20
+ let countRow;
21
+ let rows;
22
+ if (q) {
23
+ const pattern = `%${q}%`;
24
+ countRow = await d1.prepare(
25
+ `SELECT COUNT(*) as total FROM "${userTable}" WHERE email LIKE ?1 OR name LIKE ?1`
26
+ ).bind(pattern).first();
27
+ rows = await d1.prepare(
28
+ `SELECT u.id, u.name, u.email, u.email_verified, u.role, u.created_at, u.updated_at,
29
+ (SELECT COUNT(*) FROM "${sessionTable}" s WHERE s.user_id = u.id) as session_count,
30
+ (SELECT provider_id FROM "${accountTable}" a WHERE a.user_id = u.id LIMIT 1) as provider
31
+ FROM "${userTable}" u
32
+ WHERE u.email LIKE ?1 OR u.name LIKE ?1
33
+ ORDER BY u.created_at DESC
34
+ LIMIT ?2 OFFSET ?3`
35
+ ).bind(pattern, limit, offset).all().then((r) => r.results ?? []);
36
+ } else {
37
+ countRow = await d1.prepare(`SELECT COUNT(*) as total FROM "${userTable}"`).first();
38
+ rows = await d1.prepare(
39
+ `SELECT u.id, u.name, u.email, u.email_verified, u.role, u.created_at, u.updated_at,
40
+ (SELECT COUNT(*) FROM "${sessionTable}" s WHERE s.user_id = u.id) as session_count,
41
+ (SELECT provider_id FROM "${accountTable}" a WHERE a.user_id = u.id LIMIT 1) as provider
42
+ FROM "${userTable}" u
43
+ ORDER BY u.created_at DESC
44
+ LIMIT ?1 OFFSET ?2`
45
+ ).bind(limit, offset).all().then((r) => r.results ?? []);
46
+ }
47
+ const total = typeof countRow?.total === "number" ? countRow.total : Number(countRow?.total ?? 0);
48
+ return {
49
+ ok: true,
50
+ users: rows.map((u) => ({
51
+ id: u.id,
52
+ name: u.name,
53
+ email: u.email,
54
+ emailVerified: Boolean(u.email_verified),
55
+ role: u.role,
56
+ provider: u.provider || "credential",
57
+ sessionCount: Number(u.session_count ?? 0),
58
+ createdAt: u.created_at,
59
+ updatedAt: u.updated_at
60
+ })),
61
+ total,
62
+ page,
63
+ limit,
64
+ pages: Math.ceil(total / limit)
65
+ };
66
+ } catch (err) {
67
+ return { ok: false, error: err?.message || "Query failed", users: [], total: 0 };
68
+ }
69
+ });
@@ -0,0 +1,39 @@
1
+ import type { QarpeoOptions } from "../../../../types";
2
+ export interface ManifestBindingSpec {
3
+ type: "d1" | "kv_namespace" | "r2_bucket" | "ai" | "vectorize" | "queue" | "hyperdrive" | "durable_object_namespace" | "browser" | "analytics_engine";
4
+ name: string;
5
+ feature: string;
6
+ required: boolean;
7
+ }
8
+ export interface ManifestSecretSpec {
9
+ key: string;
10
+ feature: string;
11
+ required: boolean;
12
+ description: string;
13
+ generatable?: "secret" | "vapid";
14
+ }
15
+ export interface QarpeoCloudManifest {
16
+ qarpeoVersion: string;
17
+ workerName: string | null;
18
+ features: Record<string, boolean>;
19
+ expectedBindings: ManifestBindingSpec[];
20
+ expectedSecrets: ManifestSecretSpec[];
21
+ endpoints: {
22
+ robots?: string;
23
+ sitemap?: string;
24
+ manifest?: string;
25
+ sw?: string;
26
+ og?: string;
27
+ };
28
+ liveEnvPresence?: {
29
+ bindings: Record<string, boolean>;
30
+ secrets: Record<string, boolean>;
31
+ };
32
+ }
33
+ /**
34
+ * Builds a safe, secret-free structural manifest of Qarpeo features, expected Cloudflare
35
+ * bindings, expected secret keys, and well-known endpoints for Qarpeo Cloud inspection.
36
+ */
37
+ export declare function buildQarpeoManifest(options: QarpeoOptions, qarpeoVersion?: string): QarpeoCloudManifest;
38
+ declare const _default: import("nuxt/server").EventHandler<Response>;
39
+ export default _default;