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,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;
|
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
export default defineEventHandler(async (event) => {
|
|
6
|
+
verifyCloudSecret(event);
|
|
7
|
+
const config = useRuntimeConfig();
|
|
8
|
+
const manifest = config.qarpeo?.manifest || {};
|
|
9
|
+
const features = manifest.features || {};
|
|
10
|
+
let d1 = null;
|
|
11
|
+
try {
|
|
12
|
+
d1 = getD1Binding(event);
|
|
13
|
+
} catch {
|
|
14
|
+
d1 = null;
|
|
15
|
+
}
|
|
16
|
+
const existingTables = /* @__PURE__ */ new Set();
|
|
17
|
+
if (d1) {
|
|
18
|
+
try {
|
|
19
|
+
const rows = await d1.prepare(`SELECT name FROM sqlite_master WHERE type = 'table'`).all().then((r) => r.results ?? []);
|
|
20
|
+
for (const r of rows) {
|
|
21
|
+
if (r?.name) existingTables.add(String(r.name));
|
|
22
|
+
}
|
|
23
|
+
} catch {
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const expectedByFeature = [];
|
|
27
|
+
if (features.auth) {
|
|
28
|
+
expectedByFeature.push(
|
|
29
|
+
{ feature: "auth", table: resolveTableName("user").replace(/"/g, "") },
|
|
30
|
+
{ feature: "auth", table: resolveTableName("session").replace(/"/g, "") }
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
if (features.cms) {
|
|
34
|
+
expectedByFeature.push({ feature: "cms", table: resolveTableName("cms_entry").replace(/"/g, "") });
|
|
35
|
+
}
|
|
36
|
+
if (features.comments) {
|
|
37
|
+
expectedByFeature.push({ feature: "comments", table: resolveTableName("comment").replace(/"/g, "") });
|
|
38
|
+
}
|
|
39
|
+
if (features.store) {
|
|
40
|
+
expectedByFeature.push(
|
|
41
|
+
{ feature: "store", table: resolveTableName("store_product").replace(/"/g, "") },
|
|
42
|
+
{ feature: "store", table: resolveTableName("store_order").replace(/"/g, "") }
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
if (features.multitenant) {
|
|
46
|
+
expectedByFeature.push({ feature: "multitenant", table: resolveTableName("tenant").replace(/"/g, "") });
|
|
47
|
+
}
|
|
48
|
+
const missingTables = d1 ? expectedByFeature.filter((item) => !existingTables.has(item.table)) : [];
|
|
49
|
+
let tenants = [];
|
|
50
|
+
if (features.multitenant && d1 && existingTables.has(resolveTableName("tenant").replace(/"/g, ""))) {
|
|
51
|
+
try {
|
|
52
|
+
const tenantTbl = resolveTableName("tenant").replace(/"/g, "");
|
|
53
|
+
tenants = await d1.prepare(`SELECT id, slug, name, plan FROM "${tenantTbl}" ORDER BY created_at DESC LIMIT 25`).all().then((r) => r.results ?? []);
|
|
54
|
+
} catch {
|
|
55
|
+
tenants = [];
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
ok: true,
|
|
60
|
+
d1Available: Boolean(d1),
|
|
61
|
+
tableCount: existingTables.size,
|
|
62
|
+
missingTables,
|
|
63
|
+
tenants
|
|
64
|
+
};
|
|
65
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* POST /__qarpeo/cloud/mail/unsuppress
|
|
3
|
+
*
|
|
4
|
+
* Removes an email address from the D1 `mail_suppression` table.
|
|
5
|
+
* Requires `Authorization: Bearer <QARPEO_CLOUD_SECRET>`.
|
|
6
|
+
*/
|
|
7
|
+
declare const _default: import("nuxt/server").EventHandler<Promise<{
|
|
8
|
+
ok: boolean;
|
|
9
|
+
email: string;
|
|
10
|
+
removed: boolean;
|
|
11
|
+
}>>;
|
|
12
|
+
export default _default;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createError, defineEventHandler, readBody } from "nuxt/server";
|
|
2
|
+
import { verifyCloudSecret } from "../../../../utils/cloud-auth.mjs";
|
|
3
|
+
import { unsuppressEmail } from "../../../../utils/mail-suppression.mjs";
|
|
4
|
+
export default defineEventHandler(async (event) => {
|
|
5
|
+
verifyCloudSecret(event);
|
|
6
|
+
const body = await readBody(event).catch(() => ({}));
|
|
7
|
+
const email = typeof body?.email === "string" ? body.email.trim().toLowerCase() : "";
|
|
8
|
+
if (!email || !email.includes("@")) {
|
|
9
|
+
throw createError({
|
|
10
|
+
statusCode: 400,
|
|
11
|
+
statusMessage: "Bad Request",
|
|
12
|
+
message: "Valid email is required."
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
const removed = await unsuppressEmail(event, email);
|
|
16
|
+
return { ok: true, email, removed };
|
|
17
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface MigrateCmsInput {
|
|
2
|
+
collection: string;
|
|
3
|
+
title: string;
|
|
4
|
+
slug?: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
body?: string;
|
|
7
|
+
status?: "published" | "draft" | "archived";
|
|
8
|
+
createdAt?: number;
|
|
9
|
+
publishedAt?: number;
|
|
10
|
+
meta?: Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
declare const _default: import("nuxt/server").EventHandler<Promise<{
|
|
13
|
+
ok: boolean;
|
|
14
|
+
imported: number;
|
|
15
|
+
skipped: number;
|
|
16
|
+
failed: number;
|
|
17
|
+
errors: {
|
|
18
|
+
slug: string;
|
|
19
|
+
reason: string;
|
|
20
|
+
}[];
|
|
21
|
+
}>>;
|
|
22
|
+
export default _default;
|
|
@@ -0,0 +1,87 @@
|
|
|
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 entries = Array.isArray(body?.entries) ? body.entries : [];
|
|
10
|
+
if (entries.length === 0) {
|
|
11
|
+
throw createError({
|
|
12
|
+
statusCode: 400,
|
|
13
|
+
statusMessage: "Bad Request",
|
|
14
|
+
message: "entries array is required and must not be empty."
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
if (entries.length > 200) {
|
|
18
|
+
throw createError({
|
|
19
|
+
statusCode: 400,
|
|
20
|
+
statusMessage: "Bad Request",
|
|
21
|
+
message: "Maximum 200 CMS entries 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 entryTable = resolveTableName("cms_entry").replace(/"/g, "");
|
|
33
|
+
const mode = body?.mode === "upsert" ? "upsert" : "skip";
|
|
34
|
+
let imported = 0;
|
|
35
|
+
let skipped = 0;
|
|
36
|
+
const errors = [];
|
|
37
|
+
for (const item of entries) {
|
|
38
|
+
const collection = typeof item?.collection === "string" ? item.collection.trim() : "";
|
|
39
|
+
const title = typeof item?.title === "string" ? item.title.trim() : "";
|
|
40
|
+
if (!collection || !title) {
|
|
41
|
+
errors.push({ slug: String(item?.slug || ""), reason: "collection and title are required" });
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const slug = typeof item.slug === "string" && item.slug.trim() ? item.slug.trim() : title.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 120);
|
|
45
|
+
try {
|
|
46
|
+
const existing = await d1.prepare(
|
|
47
|
+
`SELECT id FROM "${entryTable}" WHERE collection_id = ?1 AND slug = ?2 LIMIT 1`
|
|
48
|
+
).bind(collection, slug).first();
|
|
49
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
50
|
+
const createdAt = item.createdAt || now;
|
|
51
|
+
const publishedAt = item.publishedAt || (item.status === "published" ? createdAt : null);
|
|
52
|
+
const status = ["published", "draft", "archived"].includes(item.status ?? "") ? item.status : "draft";
|
|
53
|
+
const metaStr = item.meta ? JSON.stringify(item.meta) : "{}";
|
|
54
|
+
const contentMd = item.body || "";
|
|
55
|
+
const description = item.description || null;
|
|
56
|
+
if (existing) {
|
|
57
|
+
if (mode === "skip") {
|
|
58
|
+
skipped++;
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
await d1.prepare(
|
|
62
|
+
`UPDATE "${entryTable}"
|
|
63
|
+
SET title = ?1, description = ?2, content_md = ?3, status = ?4, metadata_json = ?5, published_at = ?6, updated_at = ?7
|
|
64
|
+
WHERE id = ?8`
|
|
65
|
+
).bind(title, description, contentMd, status, metaStr, publishedAt, now, existing.id).run();
|
|
66
|
+
imported++;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
const id = nanoid();
|
|
70
|
+
await d1.prepare(
|
|
71
|
+
`INSERT INTO "${entryTable}"
|
|
72
|
+
(id, collection_id, slug, title, description, content_md, content_html, metadata_json, status, source, created_at, updated_at, published_at)
|
|
73
|
+
VALUES (?1, ?2, ?3, ?4, ?5, ?6, '', ?7, ?8, 'db', ?9, ?9, ?10)`
|
|
74
|
+
).bind(id, collection, slug, title, description, contentMd, metaStr, status, createdAt, publishedAt).run();
|
|
75
|
+
imported++;
|
|
76
|
+
} catch (err) {
|
|
77
|
+
errors.push({ slug, reason: err?.message || "Insert failed" });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
ok: true,
|
|
82
|
+
imported,
|
|
83
|
+
skipped,
|
|
84
|
+
failed: errors.length,
|
|
85
|
+
errors: errors.slice(0, 20)
|
|
86
|
+
};
|
|
87
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface MigrateProductInput {
|
|
2
|
+
externalId?: string;
|
|
3
|
+
name?: string;
|
|
4
|
+
title?: string;
|
|
5
|
+
slug?: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
price: number;
|
|
8
|
+
currency?: string;
|
|
9
|
+
status?: "active" | "draft" | "archived";
|
|
10
|
+
type?: "physical" | "digital";
|
|
11
|
+
image?: string;
|
|
12
|
+
meta?: Record<string, unknown>;
|
|
13
|
+
createdAt?: number;
|
|
14
|
+
}
|
|
15
|
+
declare const _default: import("nuxt/server").EventHandler<Promise<{
|
|
16
|
+
ok: boolean;
|
|
17
|
+
imported: number;
|
|
18
|
+
skipped: number;
|
|
19
|
+
failed: number;
|
|
20
|
+
errors: {
|
|
21
|
+
name: string;
|
|
22
|
+
reason: string;
|
|
23
|
+
}[];
|
|
24
|
+
}>>;
|
|
25
|
+
export default _default;
|
|
@@ -0,0 +1,119 @@
|
|
|
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 products = Array.isArray(body?.products) ? body.products : [];
|
|
10
|
+
if (products.length === 0) {
|
|
11
|
+
throw createError({
|
|
12
|
+
statusCode: 400,
|
|
13
|
+
statusMessage: "Bad Request",
|
|
14
|
+
message: "products array is required and must not be empty."
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
if (products.length > 500) {
|
|
18
|
+
throw createError({
|
|
19
|
+
statusCode: 400,
|
|
20
|
+
statusMessage: "Bad Request",
|
|
21
|
+
message: "Maximum 500 products 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 productTable = resolveTableName("store_product").replace(/"/g, "");
|
|
33
|
+
const mode = body?.mode === "upsert" ? "upsert" : "skip";
|
|
34
|
+
let imported = 0;
|
|
35
|
+
let skipped = 0;
|
|
36
|
+
const errors = [];
|
|
37
|
+
for (const item of products) {
|
|
38
|
+
const title = String(item?.title || item?.name || "").trim();
|
|
39
|
+
if (!title) {
|
|
40
|
+
errors.push({ name: "", reason: "title or name is required" });
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
const rawPrice = typeof item.price === "number" ? item.price : parseFloat(String(item.price));
|
|
44
|
+
if (isNaN(rawPrice) || rawPrice < 0) {
|
|
45
|
+
errors.push({ name: title, reason: "price must be a non-negative number" });
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const basePrice = Number.isInteger(rawPrice) ? rawPrice : Math.round(rawPrice * 100);
|
|
49
|
+
const slug = typeof item.slug === "string" && item.slug.trim() ? item.slug.trim() : title.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 120);
|
|
50
|
+
try {
|
|
51
|
+
const existing = await d1.prepare(`SELECT id FROM "${productTable}" WHERE slug = ?1 LIMIT 1`).bind(slug).first();
|
|
52
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
53
|
+
const createdAt = item.createdAt || now;
|
|
54
|
+
const status = ["active", "draft", "archived"].includes(item.status ?? "") ? item.status : "draft";
|
|
55
|
+
const currency = item.currency || "USD";
|
|
56
|
+
const type = item.type === "digital" ? "digital" : "physical";
|
|
57
|
+
const description = item.description || "";
|
|
58
|
+
const imagesJson = item.image ? JSON.stringify([item.image]) : "[]";
|
|
59
|
+
const metadataObj = {
|
|
60
|
+
...item.meta || {},
|
|
61
|
+
...item.externalId ? { externalId: item.externalId } : {}
|
|
62
|
+
};
|
|
63
|
+
const metadataJson = JSON.stringify(metadataObj);
|
|
64
|
+
if (existing) {
|
|
65
|
+
if (mode === "skip") {
|
|
66
|
+
skipped++;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
await d1.prepare(
|
|
70
|
+
`UPDATE "${productTable}"
|
|
71
|
+
SET title = ?1, description = ?2, base_price = ?3, currency = ?4, status = ?5,
|
|
72
|
+
type = ?6, images_json = ?7, metadata_json = ?8, updated_at = ?9
|
|
73
|
+
WHERE id = ?10`
|
|
74
|
+
).bind(
|
|
75
|
+
title,
|
|
76
|
+
description,
|
|
77
|
+
basePrice,
|
|
78
|
+
currency,
|
|
79
|
+
status,
|
|
80
|
+
type,
|
|
81
|
+
imagesJson,
|
|
82
|
+
metadataJson,
|
|
83
|
+
now,
|
|
84
|
+
existing.id
|
|
85
|
+
).run();
|
|
86
|
+
imported++;
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
const id = nanoid();
|
|
90
|
+
await d1.prepare(
|
|
91
|
+
`INSERT INTO "${productTable}"
|
|
92
|
+
(id, slug, title, description, status, type, base_price, currency, images_json, metadata_json, created_at, updated_at)
|
|
93
|
+
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?11)`
|
|
94
|
+
).bind(
|
|
95
|
+
id,
|
|
96
|
+
slug,
|
|
97
|
+
title,
|
|
98
|
+
description,
|
|
99
|
+
status,
|
|
100
|
+
type,
|
|
101
|
+
basePrice,
|
|
102
|
+
currency,
|
|
103
|
+
imagesJson,
|
|
104
|
+
metadataJson,
|
|
105
|
+
createdAt
|
|
106
|
+
).run();
|
|
107
|
+
imported++;
|
|
108
|
+
} catch (err) {
|
|
109
|
+
errors.push({ name: title, reason: err?.message || "Insert failed" });
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
ok: true,
|
|
114
|
+
imported,
|
|
115
|
+
skipped,
|
|
116
|
+
failed: errors.length,
|
|
117
|
+
errors: errors.slice(0, 20)
|
|
118
|
+
};
|
|
119
|
+
});
|