qarpeo 0.3.5 → 0.4.1
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 → manifest.get.mjs} +229 -3
- package/dist/cli/index.mjs +74 -5
- package/dist/features/console.d.ts +4 -0
- package/dist/module.mjs +299 -57
- package/dist/runtime/app/components/{BlobImage.vue → QImg.vue} +5 -4
- package/dist/runtime/app/composables/console.d.ts +60 -0
- package/dist/runtime/app/composables/console.mjs +169 -0
- package/dist/runtime/app/composables/pwa.d.ts +34 -0
- package/dist/runtime/app/composables/pwa.mjs +86 -0
- package/dist/runtime/app/composables/rbac.d.ts +33 -0
- package/dist/runtime/app/composables/rbac.mjs +60 -0
- package/dist/runtime/app/composables/site.d.ts +73 -0
- package/dist/runtime/app/composables/site.mjs +174 -1
- package/dist/runtime/app/middleware/console.global.d.ts +2 -0
- package/dist/runtime/app/middleware/console.global.mjs +37 -0
- package/dist/runtime/app/plugins/pwa.client.d.ts +2 -0
- package/dist/runtime/app/plugins/pwa.client.mjs +28 -0
- package/dist/runtime/app/plugins/pwa.d.ts +2 -0
- package/dist/runtime/app/plugins/pwa.mjs +42 -0
- package/dist/runtime/app/plugins/seo.mjs +39 -10
- package/dist/runtime/schema.d.ts +32 -12
- package/dist/runtime/schema.mjs +47 -125
- package/dist/runtime/server/routes/__qarpeo/cloud/agents/run.post.d.ts +13 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/agents/run.post.mjs +46 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/cms/entry.get.d.ts +22 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/cms/entry.get.mjs +40 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/cms/entry.post.d.ts +20 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/cms/entry.post.mjs +52 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/cms.get.d.ts +26 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/cms.get.mjs +80 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/comments/moderate.post.d.ts +16 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/comments/moderate.post.mjs +30 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/comments.get.d.ts +21 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/comments.get.mjs +49 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/extras.get.d.ts +22 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/extras.get.mjs +65 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/mail/unsuppress.post.d.ts +12 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/mail/unsuppress.post.mjs +17 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/migrate/cms.post.d.ts +22 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/migrate/cms.post.mjs +87 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/migrate/products.post.d.ts +25 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/migrate/products.post.mjs +119 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/migrate/users.post.d.ts +19 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/migrate/users.post.mjs +86 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/migrate.post.d.ts +21 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/migrate.post.mjs +91 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/notifications/test.post.d.ts +13 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/notifications/test.post.mjs +49 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/operations.get.d.ts +43 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/operations.get.mjs +111 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/overview.get.d.ts +22 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/overview.get.mjs +44 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/store/order-status.post.d.ts +9 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/store/order-status.post.mjs +27 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/store/orders.get.d.ts +23 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/store/orders.get.mjs +56 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/store/products.get.d.ts +21 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/store/products.get.mjs +50 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/tasks/run.post.d.ts +12 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/tasks/run.post.mjs +24 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/users/action.post.d.ts +26 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/users/action.post.mjs +40 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/users.get.d.ts +39 -0
- package/dist/runtime/server/routes/__qarpeo/cloud/users.get.mjs +69 -0
- package/dist/runtime/server/routes/__qarpeo/manifest.get.d.ts +39 -0
- package/dist/runtime/server/routes/__qarpeo/manifest.get.mjs +226 -0
- package/dist/runtime/server/routes/__qarpeo/og.get.d.ts +15 -0
- package/dist/runtime/server/routes/__qarpeo/og.get.mjs +109 -0
- package/dist/runtime/server/routes/__qarpeo/rbac/me.get.d.ts +26 -0
- package/dist/runtime/server/routes/__qarpeo/rbac/me.get.mjs +23 -0
- package/dist/runtime/server/routes/__qarpeo/rbac/roles.delete.d.ts +12 -0
- package/dist/runtime/server/routes/__qarpeo/rbac/roles.delete.mjs +12 -0
- package/dist/runtime/server/routes/__qarpeo/rbac/roles.get.d.ts +16 -0
- package/dist/runtime/server/routes/__qarpeo/rbac/roles.get.mjs +15 -0
- package/dist/runtime/server/routes/__qarpeo/rbac/roles.post.d.ts +11 -0
- package/dist/runtime/server/routes/__qarpeo/rbac/roles.post.mjs +16 -0
- package/dist/runtime/server/routes/__qarpeo/rbac/users.post.d.ts +14 -0
- package/dist/runtime/server/routes/__qarpeo/rbac/users.post.mjs +19 -0
- package/dist/runtime/server/routes/manifest.webmanifest.get.d.ts +2 -0
- package/dist/runtime/server/routes/manifest.webmanifest.get.mjs +31 -0
- package/dist/runtime/server/routes/robots.txt.get.mjs +20 -4
- package/dist/runtime/server/routes/sitemap.xml.get.mjs +47 -6
- package/dist/runtime/server/routes/sw.js.get.d.ts +8 -0
- package/dist/runtime/server/routes/sw.js.get.mjs +141 -0
- package/dist/runtime/server/utils/auth.d.ts +2 -14
- package/dist/runtime/server/utils/auth.mjs +32 -36
- package/dist/runtime/server/utils/cloud-auth.d.ts +8 -0
- package/dist/runtime/server/utils/cloud-auth.mjs +23 -0
- package/dist/runtime/server/utils/console.d.ts +19 -0
- package/dist/runtime/server/utils/console.mjs +34 -0
- package/dist/runtime/server/utils/legacy-hash.d.ts +76 -0
- package/dist/runtime/server/utils/legacy-hash.mjs +96 -0
- package/dist/runtime/server/utils/rbac.d.ts +89 -0
- package/dist/runtime/server/utils/rbac.mjs +427 -0
- package/dist/runtime/server/utils/role-env.d.ts +19 -0
- package/dist/runtime/server/utils/role-env.mjs +34 -0
- package/dist/runtime/server.d.ts +2 -0
- package/dist/runtime/server.mjs +2 -0
- package/dist/types/console.d.ts +67 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/options.d.ts +9 -0
- package/dist/types/site.d.ts +102 -0
- package/dist/types/storage.d.ts +5 -11
- package/package.json +1 -1
- package/dist/runtime/providers/qarpeo.d.ts +0 -23
- package/dist/runtime/providers/qarpeo.mjs +0 -46
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface MigrateUserInput {
|
|
2
|
+
email: string;
|
|
3
|
+
name?: string;
|
|
4
|
+
emailVerified?: boolean;
|
|
5
|
+
role?: string;
|
|
6
|
+
passwordHash?: string;
|
|
7
|
+
createdAt?: number;
|
|
8
|
+
}
|
|
9
|
+
declare const _default: import("nuxt/server").EventHandler<Promise<{
|
|
10
|
+
ok: boolean;
|
|
11
|
+
imported: number;
|
|
12
|
+
skipped: number;
|
|
13
|
+
failed: number;
|
|
14
|
+
errors: {
|
|
15
|
+
email: string;
|
|
16
|
+
reason: string;
|
|
17
|
+
}[];
|
|
18
|
+
}>>;
|
|
19
|
+
export default _default;
|
|
@@ -0,0 +1,86 @@
|
|
|
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 users = Array.isArray(body?.users) ? body.users : [];
|
|
10
|
+
if (users.length === 0) {
|
|
11
|
+
throw createError({
|
|
12
|
+
statusCode: 400,
|
|
13
|
+
statusMessage: "Bad Request",
|
|
14
|
+
message: "users array is required and must not be empty."
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
if (users.length > 500) {
|
|
18
|
+
throw createError({
|
|
19
|
+
statusCode: 400,
|
|
20
|
+
statusMessage: "Bad Request",
|
|
21
|
+
message: "Maximum 500 users per migration batch."
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
const d1 = getD1Binding(event);
|
|
25
|
+
if (!d1) {
|
|
26
|
+
throw createError({
|
|
27
|
+
statusCode: 500,
|
|
28
|
+
statusMessage: "Internal Server Error",
|
|
29
|
+
message: "D1 database binding is not available."
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
const userTable = resolveTableName("user").replace(/"/g, "");
|
|
33
|
+
const accountTable = resolveTableName("account").replace(/"/g, "");
|
|
34
|
+
const mode = body?.mode === "upsert" ? "upsert" : "skip";
|
|
35
|
+
let imported = 0;
|
|
36
|
+
let skipped = 0;
|
|
37
|
+
const errors = [];
|
|
38
|
+
for (const item of users) {
|
|
39
|
+
const email = typeof item?.email === "string" ? item.email.trim().toLowerCase() : "";
|
|
40
|
+
if (!email || !email.includes("@")) {
|
|
41
|
+
errors.push({ email: String(item?.email || ""), reason: "Invalid email" });
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
const existing = await d1.prepare(`SELECT id FROM "${userTable}" WHERE email = ?1 LIMIT 1`).bind(email).first();
|
|
46
|
+
const now = item.createdAt || Math.floor(Date.now() / 1e3);
|
|
47
|
+
const name = (item.name || email.split("@")[0] || "User").trim();
|
|
48
|
+
const emailVerified = item.emailVerified ? 1 : 0;
|
|
49
|
+
const role = item.role || "user";
|
|
50
|
+
if (existing) {
|
|
51
|
+
if (mode === "skip") {
|
|
52
|
+
skipped++;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
await d1.prepare(
|
|
56
|
+
`UPDATE "${userTable}" SET name = ?1, email_verified = ?2, role = ?3, updated_at = ?4 WHERE id = ?5`
|
|
57
|
+
).bind(name, emailVerified, role, now, existing.id).run();
|
|
58
|
+
if (item.passwordHash) {
|
|
59
|
+
await d1.prepare(
|
|
60
|
+
`UPDATE "${accountTable}" SET password = ?1, updated_at = ?2 WHERE user_id = ?3 AND provider_id = 'credential'`
|
|
61
|
+
).bind(item.passwordHash, now, existing.id).run();
|
|
62
|
+
}
|
|
63
|
+
imported++;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const userId = nanoid();
|
|
67
|
+
await d1.prepare(
|
|
68
|
+
`INSERT INTO "${userTable}" (id, name, email, email_verified, role, created_at, updated_at) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7)`
|
|
69
|
+
).bind(userId, name, email, emailVerified, role, now, now).run();
|
|
70
|
+
const accountId = nanoid();
|
|
71
|
+
await d1.prepare(
|
|
72
|
+
`INSERT INTO "${accountTable}" (id, account_id, provider_id, user_id, password, created_at, updated_at) VALUES (?1, ?2, 'credential', ?3, ?4, ?5, ?6)`
|
|
73
|
+
).bind(accountId, userId, userId, item.passwordHash || null, now, now).run();
|
|
74
|
+
imported++;
|
|
75
|
+
} catch (err) {
|
|
76
|
+
errors.push({ email, reason: err?.message || "Insert failed" });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
ok: true,
|
|
81
|
+
imported,
|
|
82
|
+
skipped,
|
|
83
|
+
failed: errors.length,
|
|
84
|
+
errors: errors.slice(0, 20)
|
|
85
|
+
};
|
|
86
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* POST /__qarpeo/cloud/migrate
|
|
3
|
+
*
|
|
4
|
+
* Runs idempotent `CREATE TABLE IF NOT EXISTS` migrations for enabled Qarpeo
|
|
5
|
+
* features (or an explicit `features` list) against the bound D1 database.
|
|
6
|
+
* Requires `Authorization: Bearer <QARPEO_CLOUD_SECRET>`.
|
|
7
|
+
*/
|
|
8
|
+
declare const _default: import("nuxt/server").EventHandler<Promise<{
|
|
9
|
+
ok: boolean;
|
|
10
|
+
applied: string[];
|
|
11
|
+
errors: {
|
|
12
|
+
feature: string;
|
|
13
|
+
error: string;
|
|
14
|
+
}[];
|
|
15
|
+
tableCount: number;
|
|
16
|
+
missingTables: {
|
|
17
|
+
feature: string;
|
|
18
|
+
table: string;
|
|
19
|
+
}[];
|
|
20
|
+
}>>;
|
|
21
|
+
export default _default;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { createError, defineEventHandler, readBody, useRuntimeConfig } from "nuxt/server";
|
|
2
|
+
import { getD1Binding } from "../../../../index.mjs";
|
|
3
|
+
import { ensureAuditTables } from "../../../utils/audit.mjs";
|
|
4
|
+
import { ensureAuthTables } from "../../../utils/auth.mjs";
|
|
5
|
+
import { verifyCloudSecret } from "../../../utils/cloud-auth.mjs";
|
|
6
|
+
import { ensureCMSTables } from "../../../utils/cms/sync.mjs";
|
|
7
|
+
import { ensureCommentsTables } from "../../../utils/comments.mjs";
|
|
8
|
+
import { ensureMailSuppressionsTable } from "../../../utils/mail-suppression.mjs";
|
|
9
|
+
import { ensurePaymentsTables } from "../../../utils/payments/common.mjs";
|
|
10
|
+
import { ensureStoreTables } from "../../../utils/store/common.mjs";
|
|
11
|
+
import { resolveTableName } from "../../../utils/table-names.mjs";
|
|
12
|
+
export default defineEventHandler(async (event) => {
|
|
13
|
+
verifyCloudSecret(event);
|
|
14
|
+
let d1 = null;
|
|
15
|
+
try {
|
|
16
|
+
d1 = getD1Binding(event);
|
|
17
|
+
} catch {
|
|
18
|
+
d1 = null;
|
|
19
|
+
}
|
|
20
|
+
if (!d1) {
|
|
21
|
+
throw createError({
|
|
22
|
+
statusCode: 400,
|
|
23
|
+
statusMessage: "Bad Request",
|
|
24
|
+
message: "D1 database binding is not available on this Worker."
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
const body = await readBody(event).catch(() => ({}));
|
|
28
|
+
const config = useRuntimeConfig();
|
|
29
|
+
const manifestFeatures = config.qarpeo?.manifest?.features || {};
|
|
30
|
+
const targetFeatures = new Set(
|
|
31
|
+
Array.isArray(body?.features) && body.features.length > 0 ? body.features.map((f) => String(f).trim()).filter(Boolean) : Object.entries(manifestFeatures).filter(([, enabled]) => Boolean(enabled)).map(([name]) => name)
|
|
32
|
+
);
|
|
33
|
+
const applied = [];
|
|
34
|
+
const errors = [];
|
|
35
|
+
const runners = [
|
|
36
|
+
["auth", () => ensureAuthTables(d1, event)],
|
|
37
|
+
["cms", () => ensureCMSTables(event)],
|
|
38
|
+
["comments", () => ensureCommentsTables(event)],
|
|
39
|
+
["store", () => ensureStoreTables(event)],
|
|
40
|
+
["payments", () => ensurePaymentsTables(event)],
|
|
41
|
+
["mail", () => ensureMailSuppressionsTable(d1)],
|
|
42
|
+
["audit", () => ensureAuditTables(d1)]
|
|
43
|
+
];
|
|
44
|
+
for (const [feature, run] of runners) {
|
|
45
|
+
if (!targetFeatures.has(feature)) continue;
|
|
46
|
+
try {
|
|
47
|
+
await run();
|
|
48
|
+
applied.push(feature);
|
|
49
|
+
} catch (err) {
|
|
50
|
+
errors.push({ feature, error: err?.message || String(err) });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const existingTables = /* @__PURE__ */ new Set();
|
|
54
|
+
try {
|
|
55
|
+
const rows = await d1.prepare(`SELECT name FROM sqlite_master WHERE type = 'table'`).all().then((r) => r.results ?? []);
|
|
56
|
+
for (const r of rows) {
|
|
57
|
+
if (r?.name) existingTables.add(String(r.name));
|
|
58
|
+
}
|
|
59
|
+
} catch {
|
|
60
|
+
}
|
|
61
|
+
const expectedByFeature = [];
|
|
62
|
+
if (manifestFeatures.auth) {
|
|
63
|
+
expectedByFeature.push(
|
|
64
|
+
{ feature: "auth", table: resolveTableName("user").replace(/"/g, "") },
|
|
65
|
+
{ feature: "auth", table: resolveTableName("session").replace(/"/g, "") }
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
if (manifestFeatures.cms) {
|
|
69
|
+
expectedByFeature.push({ feature: "cms", table: resolveTableName("cms_entry").replace(/"/g, "") });
|
|
70
|
+
}
|
|
71
|
+
if (manifestFeatures.comments) {
|
|
72
|
+
expectedByFeature.push({ feature: "comments", table: resolveTableName("comment").replace(/"/g, "") });
|
|
73
|
+
}
|
|
74
|
+
if (manifestFeatures.store) {
|
|
75
|
+
expectedByFeature.push(
|
|
76
|
+
{ feature: "store", table: resolveTableName("store_product").replace(/"/g, "") },
|
|
77
|
+
{ feature: "store", table: resolveTableName("store_order").replace(/"/g, "") }
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
if (manifestFeatures.multitenant) {
|
|
81
|
+
expectedByFeature.push({ feature: "multitenant", table: resolveTableName("tenant").replace(/"/g, "") });
|
|
82
|
+
}
|
|
83
|
+
const missingTables = expectedByFeature.filter((item) => !existingTables.has(item.table));
|
|
84
|
+
return {
|
|
85
|
+
ok: errors.length === 0,
|
|
86
|
+
applied,
|
|
87
|
+
errors,
|
|
88
|
+
tableCount: existingTables.size,
|
|
89
|
+
missingTables
|
|
90
|
+
};
|
|
91
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* POST /__qarpeo/cloud/notifications/test
|
|
3
|
+
*
|
|
4
|
+
* Sends a test in-app and/or Web Push notification from Qarpeo Cloud.
|
|
5
|
+
* Requires `Authorization: Bearer <QARPEO_CLOUD_SECRET>`.
|
|
6
|
+
*/
|
|
7
|
+
declare const _default: import("nuxt/server").EventHandler<Promise<{
|
|
8
|
+
ok: boolean;
|
|
9
|
+
userId: string;
|
|
10
|
+
title: string;
|
|
11
|
+
channels: ("email" | "in-app" | "push")[];
|
|
12
|
+
}>>;
|
|
13
|
+
export default _default;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { createError, defineEventHandler, readBody } from "nuxt/server";
|
|
2
|
+
import { getD1Binding } from "../../../../../index.mjs";
|
|
3
|
+
import { verifyCloudSecret } from "../../../../utils/cloud-auth.mjs";
|
|
4
|
+
import { sendNotification } from "../../../../utils/notifications.mjs";
|
|
5
|
+
import { resolveTableName } from "../../../../utils/table-names.mjs";
|
|
6
|
+
export default defineEventHandler(async (event) => {
|
|
7
|
+
verifyCloudSecret(event);
|
|
8
|
+
const body = await readBody(event).catch(() => ({}));
|
|
9
|
+
let userId = typeof body?.userId === "string" ? body.userId.trim() : "";
|
|
10
|
+
if (!userId) {
|
|
11
|
+
try {
|
|
12
|
+
const d1 = getD1Binding(event);
|
|
13
|
+
if (d1) {
|
|
14
|
+
const pushTbl = resolveTableName("push_subscription").replace(/"/g, "");
|
|
15
|
+
const subRow = await d1.prepare(`SELECT user_id FROM "${pushTbl}" LIMIT 1`).first().catch(() => null);
|
|
16
|
+
if (subRow?.user_id) {
|
|
17
|
+
userId = String(subRow.user_id);
|
|
18
|
+
} else {
|
|
19
|
+
const userTbl = resolveTableName("user").replace(/"/g, "");
|
|
20
|
+
const userRow = await d1.prepare(`SELECT id FROM "${userTbl}" LIMIT 1`).first().catch(() => null);
|
|
21
|
+
if (userRow?.id) userId = String(userRow.id);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
} catch {
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (!userId) userId = "cloud-test";
|
|
28
|
+
const channels = Array.isArray(body?.channels) && body.channels.length > 0 ? body.channels : ["in-app", "push"];
|
|
29
|
+
const title = typeof body?.title === "string" && body.title.trim() ? body.title.trim() : "Test Notification from Qarpeo Cloud";
|
|
30
|
+
const messageBody = typeof body?.body === "string" && body.body.trim() ? body.body.trim() : "Your edge notification & Web Push pipeline is active.";
|
|
31
|
+
try {
|
|
32
|
+
await sendNotification(
|
|
33
|
+
{
|
|
34
|
+
userId,
|
|
35
|
+
title,
|
|
36
|
+
body: messageBody,
|
|
37
|
+
channels
|
|
38
|
+
},
|
|
39
|
+
event
|
|
40
|
+
);
|
|
41
|
+
} catch (err) {
|
|
42
|
+
throw createError({
|
|
43
|
+
statusCode: 500,
|
|
44
|
+
statusMessage: "Internal Server Error",
|
|
45
|
+
message: err?.message || "Failed to dispatch test notification."
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return { ok: true, userId, title, channels };
|
|
49
|
+
});
|
|
@@ -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,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;
|