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,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
+ });
@@ -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
+ });