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,226 @@
1
+ import { defineEventHandler, useRuntimeConfig } from "nuxt/server";
2
+ export function buildQarpeoManifest(options, qarpeoVersion = "0.0.0") {
3
+ const opts = options;
4
+ const hasDb = Boolean(opts.db || opts.d1);
5
+ const hasKv = Boolean(opts.kv);
6
+ const hasBlob = Boolean(opts.blob || opts.r2);
7
+ const hasAi = Boolean(opts.ai);
8
+ const hasVectorize = Boolean(opts.vectorize);
9
+ const hasQueue = Boolean(opts.queue);
10
+ const hasHyperdrive = Boolean(opts.hyperdrive);
11
+ const hasBrowser = Boolean(opts.browser);
12
+ const hasAnalytics = Boolean(opts.analytics);
13
+ const hasDo = Boolean(opts.do || opts.agents);
14
+ const hasAuth = Boolean(opts.auth);
15
+ const hasEmail = Boolean(opts.email || opts.mail);
16
+ const hasPayments = Boolean(opts.payments);
17
+ const hasNotifications = Boolean(opts.notifications || opts.notify);
18
+ const hasComments = Boolean(opts.comments);
19
+ const hasCms = Boolean(opts.cms);
20
+ const hasStore = Boolean(opts.store);
21
+ const hasAgents = Boolean(opts.agents);
22
+ const hasMultitenant = Boolean(opts.multitenant);
23
+ const hasSite = Boolean(opts.site || opts.seo);
24
+ const hasPwa = Boolean(opts.pwa || typeof opts.site === "object" && opts.site?.pwa);
25
+ const features = {
26
+ db: hasDb,
27
+ kv: hasKv,
28
+ blob: hasBlob,
29
+ ai: hasAi,
30
+ vectorize: hasVectorize,
31
+ queue: hasQueue,
32
+ workflows: Boolean(opts.workflows),
33
+ hyperdrive: hasHyperdrive,
34
+ browser: hasBrowser,
35
+ analytics: hasAnalytics,
36
+ ratelimit: Boolean(opts.ratelimit),
37
+ do: hasDo,
38
+ auth: hasAuth,
39
+ email: hasEmail,
40
+ payments: hasPayments,
41
+ notifications: hasNotifications,
42
+ comments: hasComments,
43
+ cms: hasCms,
44
+ store: hasStore,
45
+ agents: hasAgents,
46
+ multitenant: hasMultitenant,
47
+ site: hasSite,
48
+ pwa: hasPwa
49
+ };
50
+ const expectedBindings = [];
51
+ if (hasDb) {
52
+ expectedBindings.push({
53
+ type: "d1",
54
+ name: typeof opts.db === "object" && opts.db.binding ? opts.db.binding : "DB",
55
+ feature: "db",
56
+ required: true
57
+ });
58
+ }
59
+ if (hasKv) {
60
+ expectedBindings.push({
61
+ type: "kv_namespace",
62
+ name: typeof opts.kv === "object" && opts.kv.binding ? opts.kv.binding : "KV",
63
+ feature: "kv",
64
+ required: true
65
+ });
66
+ }
67
+ if (hasBlob) {
68
+ expectedBindings.push({
69
+ type: "r2_bucket",
70
+ name: typeof opts.blob === "object" && opts.blob.binding ? opts.blob.binding : "BLOB",
71
+ feature: "blob",
72
+ required: true
73
+ });
74
+ }
75
+ if (hasAi) {
76
+ expectedBindings.push({ type: "ai", name: "AI", feature: "ai", required: true });
77
+ }
78
+ if (hasVectorize) {
79
+ expectedBindings.push({
80
+ type: "vectorize",
81
+ name: typeof opts.vectorize === "object" && opts.vectorize.binding ? opts.vectorize.binding : "VECTORIZE",
82
+ feature: "vectorize",
83
+ required: true
84
+ });
85
+ }
86
+ if (hasQueue) {
87
+ expectedBindings.push({
88
+ type: "queue",
89
+ name: typeof opts.queue === "object" && opts.queue.binding ? opts.queue.binding : "QUEUE",
90
+ feature: "queue",
91
+ required: true
92
+ });
93
+ }
94
+ if (hasHyperdrive) {
95
+ expectedBindings.push({
96
+ type: "hyperdrive",
97
+ name: typeof opts.hyperdrive === "object" && opts.hyperdrive.binding ? opts.hyperdrive.binding : "HYPERDRIVE",
98
+ feature: "hyperdrive",
99
+ required: true
100
+ });
101
+ }
102
+ if (hasBrowser) {
103
+ expectedBindings.push({
104
+ type: "browser",
105
+ name: "BROWSER",
106
+ feature: "browser",
107
+ required: false
108
+ });
109
+ }
110
+ if (hasAnalytics) {
111
+ expectedBindings.push({
112
+ type: "analytics_engine",
113
+ name: "ANALYTICS",
114
+ feature: "analytics",
115
+ required: false
116
+ });
117
+ }
118
+ const expectedSecrets = [];
119
+ if (hasAuth || hasBlob || hasStore) {
120
+ expectedSecrets.push({
121
+ key: "NUXT_APP_SECRET",
122
+ feature: hasAuth ? "auth" : hasBlob ? "blob" : "store",
123
+ required: true,
124
+ description: "Signing secret for auth sessions, preview tokens, and signed R2 URLs.",
125
+ generatable: "secret"
126
+ });
127
+ }
128
+ if (hasNotifications) {
129
+ expectedSecrets.push(
130
+ {
131
+ key: "VAPID_PUBLIC_KEY",
132
+ feature: "notifications",
133
+ required: false,
134
+ description: "Web Push VAPID public key.",
135
+ generatable: "vapid"
136
+ },
137
+ {
138
+ key: "VAPID_PRIVATE_KEY",
139
+ feature: "notifications",
140
+ required: false,
141
+ description: "Web Push VAPID private key.",
142
+ generatable: "vapid"
143
+ }
144
+ );
145
+ }
146
+ if (hasPayments) {
147
+ expectedSecrets.push(
148
+ {
149
+ key: "STRIPE_SECRET_KEY",
150
+ feature: "payments",
151
+ required: true,
152
+ description: "Stripe API secret key for checkout & portal."
153
+ },
154
+ {
155
+ key: "STRIPE_WEBHOOK_SECRET",
156
+ feature: "payments",
157
+ required: true,
158
+ description: "Stripe webhook signing secret."
159
+ }
160
+ );
161
+ }
162
+ if (hasEmail) {
163
+ expectedSecrets.push({
164
+ key: "RESEND_API_KEY",
165
+ feature: "email",
166
+ required: false,
167
+ description: "Transactional email provider API key (when not using CF Email Routing)."
168
+ });
169
+ }
170
+ const endpoints = {};
171
+ if (hasSite) {
172
+ endpoints.robots = "/robots.txt";
173
+ endpoints.sitemap = "/sitemap.xml";
174
+ endpoints.og = "/__qarpeo/og";
175
+ }
176
+ if (hasPwa) {
177
+ endpoints.manifest = "/manifest.webmanifest";
178
+ endpoints.sw = "/sw.js";
179
+ }
180
+ return {
181
+ qarpeoVersion,
182
+ workerName: typeof opts.workerName === "string" ? opts.workerName : null,
183
+ features,
184
+ expectedBindings,
185
+ expectedSecrets,
186
+ endpoints
187
+ };
188
+ }
189
+ export default defineEventHandler((event) => {
190
+ const config = useRuntimeConfig();
191
+ const baseManifest = config.qarpeo?.manifest;
192
+ const cfEnv = event.context?.cloudflare?.env;
193
+ const manifest = baseManifest || {
194
+ qarpeoVersion: config.public?.qarpeoVersion || "0.0.0",
195
+ workerName: null,
196
+ features: {},
197
+ expectedBindings: [],
198
+ expectedSecrets: [],
199
+ endpoints: {}
200
+ };
201
+ const bindingPresence = {};
202
+ for (const b of manifest.expectedBindings) {
203
+ bindingPresence[b.name] = Boolean(cfEnv && b.name in cfEnv && cfEnv[b.name] !== void 0);
204
+ }
205
+ const secretPresence = {};
206
+ for (const s of manifest.expectedSecrets) {
207
+ secretPresence[s.key] = Boolean(
208
+ cfEnv && typeof cfEnv[s.key] === "string" && cfEnv[s.key].length > 0 || typeof process !== "undefined" && typeof process.env?.[s.key] === "string" && process.env[s.key].length > 0
209
+ );
210
+ }
211
+ return new Response(
212
+ JSON.stringify({
213
+ ...manifest,
214
+ liveEnvPresence: {
215
+ bindings: bindingPresence,
216
+ secrets: secretPresence
217
+ }
218
+ }),
219
+ {
220
+ headers: {
221
+ "Content-Type": "application/json; charset=UTF-8",
222
+ "Cache-Control": "no-store"
223
+ }
224
+ }
225
+ );
226
+ });
@@ -0,0 +1,15 @@
1
+ export interface BuildOgSvgOptions {
2
+ title: string;
3
+ description?: string;
4
+ siteName?: string;
5
+ theme?: "dark" | "light" | "gradient";
6
+ themeColor?: string;
7
+ author?: string;
8
+ }
9
+ /**
10
+ * Generates a zero-dependency 1200x630 SVG OpenGraph social card.
11
+ * Used as the edge fallback when Cloudflare Browser Rendering (`browser: true`) is not bound.
12
+ */
13
+ export declare function buildOgSvg(opts: BuildOgSvgOptions): string;
14
+ declare const _default: import("nuxt/server").EventHandler<Promise<Response>>;
15
+ export default _default;
@@ -0,0 +1,109 @@
1
+ import { defineEventHandler, getQuery, useRuntimeConfig } from "nuxt/server";
2
+ import { renderOgSocialCard } from "../../utils/browser-utils.mjs";
3
+ function escapeXml(str) {
4
+ return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
5
+ }
6
+ function wrapText(text, maxChars, maxLines) {
7
+ const words = text.trim().split(/\s+/).filter(Boolean);
8
+ const lines = [];
9
+ let current = "";
10
+ for (const word of words) {
11
+ const candidate = current ? `${current} ${word}` : word;
12
+ if (candidate.length <= maxChars) {
13
+ current = candidate;
14
+ } else {
15
+ if (current) lines.push(current);
16
+ current = word;
17
+ if (lines.length >= maxLines) break;
18
+ }
19
+ }
20
+ if (current && lines.length < maxLines) {
21
+ lines.push(current);
22
+ }
23
+ if (lines.length === maxLines && words.join(" ").length > lines.join(" ").length) {
24
+ lines[maxLines - 1] = `${lines[maxLines - 1].slice(0, Math.max(0, maxChars - 1))}\u2026`;
25
+ }
26
+ return lines;
27
+ }
28
+ export function buildOgSvg(opts) {
29
+ const theme = opts.theme || "dark";
30
+ const accent = opts.themeColor || "#3b82f6";
31
+ const bg = theme === "light" ? "#ffffff" : "#090d16";
32
+ const fg = theme === "light" ? "#0f172a" : "#f8fafc";
33
+ const muted = theme === "light" ? "#64748b" : "#94a3b8";
34
+ const border = theme === "light" ? "#e2e8f0" : "rgba(255,255,255,0.12)";
35
+ const titleLines = wrapText(opts.title || "Qarpeo", 32, 3);
36
+ const descLines = opts.description ? wrapText(opts.description, 62, 2) : [];
37
+ const gradientDef = theme === "gradient" ? `<linearGradient id="bg-grad" x1="0%" y1="0%" x2="100%" y2="100%">
38
+ <stop offset="0%" stop-color="#090d16"/>
39
+ <stop offset="50%" stop-color="#1e1b4b"/>
40
+ <stop offset="100%" stop-color="#0f172a"/>
41
+ </linearGradient>` : "";
42
+ const titleSvg = titleLines.map(
43
+ (line, i) => `<text x="72" y="${230 + i * 68}" fill="${fg}" font-size="54" font-weight="800" font-family="-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif">${escapeXml(line)}</text>`
44
+ ).join("\n ");
45
+ const descY = 230 + titleLines.length * 68 + 20;
46
+ const descSvg = descLines.map(
47
+ (line, i) => `<text x="72" y="${descY + i * 36}" fill="${muted}" font-size="26" font-weight="400" font-family="-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif">${escapeXml(line)}</text>`
48
+ ).join("\n ");
49
+ const siteBadge = opts.siteName ? `<rect x="72" y="64" width="${Math.max(120, opts.siteName.length * 14 + 36)}" height="42" rx="21" fill="${accent}" fill-opacity="0.16" stroke="${accent}" stroke-opacity="0.4"/>
50
+ <text x="92" y="92" fill="${accent}" font-size="20" font-weight="700" font-family="-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif">${escapeXml(opts.siteName)}</text>` : "";
51
+ const authorSvg = opts.author ? `<text x="72" y="562" fill="${muted}" font-size="22" font-weight="500" font-family="-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif">${escapeXml(opts.author)}</text>` : "";
52
+ return `<svg xmlns="http://www.w3.org/2000/svg" width="1200" height="630" viewBox="0 0 1200 630">
53
+ <defs>${gradientDef}</defs>
54
+ <rect width="1200" height="630" fill="${theme === "gradient" ? "url(#bg-grad)" : bg}"/>
55
+ <rect x="24" y="24" width="1152" height="582" rx="20" fill="none" stroke="${border}" stroke-width="2"/>
56
+ <circle cx="1100" cy="90" r="180" fill="${accent}" fill-opacity="0.12"/>
57
+ ${siteBadge}
58
+ ${titleSvg}
59
+ ${descSvg}
60
+ ${authorSvg}
61
+ </svg>`;
62
+ }
63
+ export default defineEventHandler(async (event) => {
64
+ const rc = useRuntimeConfig(event) || globalThis.__NUXT_RUNTIME_CONFIG__ || {};
65
+ const site = rc.public?.qarpeo?.site || {};
66
+ const ogCfg = typeof site.ogImage === "object" ? site.ogImage : {};
67
+ const q = getQuery(event);
68
+ const title = q.title || site.name || "Qarpeo";
69
+ const description = q.description ?? site.description ?? "";
70
+ const siteName = q.siteName ?? site.name ?? "";
71
+ const theme = q.theme || ogCfg.theme || "dark";
72
+ const themeColor = q.themeColor || ogCfg.themeColor || "#3b82f6";
73
+ const logoUrl = q.logo || ogCfg.logo;
74
+ const author = q.author;
75
+ const maxAge = ogCfg.cacheMaxAge ?? 86400;
76
+ const cacheHeader = `public, max-age=${maxAge}, s-maxage=604800`;
77
+ try {
78
+ const result = await renderOgSocialCard({
79
+ title,
80
+ description,
81
+ siteName,
82
+ theme,
83
+ themeColor,
84
+ logoUrl,
85
+ author: author ? { name: author } : void 0
86
+ });
87
+ return new Response(result.data, {
88
+ headers: {
89
+ "Content-Type": result.contentType || "image/png",
90
+ "Cache-Control": cacheHeader
91
+ }
92
+ });
93
+ } catch {
94
+ const svg = buildOgSvg({
95
+ title,
96
+ description,
97
+ siteName,
98
+ theme,
99
+ themeColor,
100
+ author
101
+ });
102
+ return new Response(svg, {
103
+ headers: {
104
+ "Content-Type": "image/svg+xml; charset=UTF-8",
105
+ "Cache-Control": cacheHeader
106
+ }
107
+ });
108
+ }
109
+ });
@@ -0,0 +1,26 @@
1
+ /**
2
+ * GET /__qarpeo/rbac/me
3
+ *
4
+ * Returns the current authenticated user's resolved roles, effective role
5
+ * permissions, and per-user `allow` / `deny` overrides for client UI checks (`useCan`).
6
+ */
7
+ declare const _default: import("nuxt/server").EventHandler<Promise<{
8
+ authenticated: boolean;
9
+ userId: null;
10
+ primaryRole: null;
11
+ roles: string[];
12
+ isSuper: boolean;
13
+ rolePermissions: string[];
14
+ allow: string[];
15
+ deny: string[];
16
+ } | {
17
+ userId: string;
18
+ primaryRole: string;
19
+ roles: string[];
20
+ isSuper: boolean;
21
+ rolePermissions: string[];
22
+ allow: string[];
23
+ deny: string[];
24
+ authenticated: boolean;
25
+ }>>;
26
+ export default _default;
@@ -0,0 +1,23 @@
1
+ import { defineEventHandler } from "nuxt/server";
2
+ import { getAuthContext } from "../../../utils/context.mjs";
3
+ import { resolveUserPermissions } from "../../../utils/rbac.mjs";
4
+ export default defineEventHandler(async (event) => {
5
+ const auth = await getAuthContext(event);
6
+ if (!auth?.user?.id) {
7
+ return {
8
+ authenticated: false,
9
+ userId: null,
10
+ primaryRole: null,
11
+ roles: [],
12
+ isSuper: false,
13
+ rolePermissions: [],
14
+ allow: [],
15
+ deny: []
16
+ };
17
+ }
18
+ const resolved = await resolveUserPermissions(auth.user, event);
19
+ return {
20
+ authenticated: true,
21
+ ...resolved
22
+ };
23
+ });
@@ -0,0 +1,12 @@
1
+ /**
2
+ * DELETE /__qarpeo/rbac/roles?id=<roleId>
3
+ *
4
+ * Deletes a custom role or resets an overridden built-in role back to code defaults.
5
+ * Requires `roles:manage` (or `super`).
6
+ */
7
+ declare const _default: import("nuxt/server").EventHandler<Promise<{
8
+ reset: boolean;
9
+ ok: boolean;
10
+ id: string;
11
+ }>>;
12
+ export default _default;
@@ -0,0 +1,12 @@
1
+ import { createError, defineEventHandler, getQuery, readBody } from "nuxt/server";
2
+ import { deleteRole } from "../../../utils/rbac.mjs";
3
+ export default defineEventHandler(async (event) => {
4
+ const qs = getQuery(event);
5
+ const body = await readBody(event).catch(() => ({}));
6
+ const roleId = typeof qs?.id === "string" && qs.id.trim() || typeof body?.id === "string" && body.id.trim() || "";
7
+ if (!roleId) {
8
+ throw createError({ statusCode: 400, statusMessage: "Bad Request", message: "role id is required." });
9
+ }
10
+ const result = await deleteRole(event, roleId);
11
+ return { ok: true, id: roleId, ...result };
12
+ });
@@ -0,0 +1,16 @@
1
+ /**
2
+ * GET /__qarpeo/rbac/roles
3
+ *
4
+ * Lists all built-in + D1-overridden + custom roles and the standard permission catalog.
5
+ * Requires `roles:manage` (or `super`).
6
+ */
7
+ declare const _default: import("nuxt/server").EventHandler<Promise<{
8
+ ok: boolean;
9
+ roles: import("../../../..").RoleDefinition[];
10
+ catalog: readonly {
11
+ key: string;
12
+ module: "console" | "cms" | "store" | "comments" | "media" | "users" | "roles";
13
+ description: string;
14
+ }[];
15
+ }>>;
16
+ export default _default;
@@ -0,0 +1,15 @@
1
+ import { defineEventHandler } from "nuxt/server";
2
+ import {
3
+ listRoles,
4
+ PERMISSION_CATALOG,
5
+ requirePermission
6
+ } from "../../../utils/rbac.mjs";
7
+ export default defineEventHandler(async (event) => {
8
+ await requirePermission(event, "roles:manage");
9
+ const roles = await listRoles(event);
10
+ return {
11
+ ok: true,
12
+ roles,
13
+ catalog: PERMISSION_CATALOG
14
+ };
15
+ });
@@ -0,0 +1,11 @@
1
+ /**
2
+ * POST /__qarpeo/rbac/roles
3
+ *
4
+ * Creates or updates a role's permissions in D1.
5
+ * Requires `roles:manage` (or `super`). `super` itself is immutable.
6
+ */
7
+ declare const _default: import("nuxt/server").EventHandler<Promise<{
8
+ ok: boolean;
9
+ role: import("../../../..").RoleDefinition;
10
+ }>>;
11
+ export default _default;
@@ -0,0 +1,16 @@
1
+ import { createError, defineEventHandler, readBody } from "nuxt/server";
2
+ import { upsertRole } from "../../../utils/rbac.mjs";
3
+ export default defineEventHandler(async (event) => {
4
+ const body = await readBody(event).catch(() => ({}));
5
+ const id = typeof body?.id === "string" ? body.id.trim() : "";
6
+ if (!id) {
7
+ throw createError({ statusCode: 400, statusMessage: "Bad Request", message: "role id is required." });
8
+ }
9
+ const role = await upsertRole(event, {
10
+ id,
11
+ name: typeof body?.name === "string" ? body.name : id,
12
+ description: typeof body?.description === "string" ? body.description : void 0,
13
+ permissions: Array.isArray(body?.permissions) ? body.permissions : []
14
+ });
15
+ return { ok: true, role };
16
+ });
@@ -0,0 +1,14 @@
1
+ /**
2
+ * POST /__qarpeo/rbac/users
3
+ *
4
+ * Updates per-user `extraRoles`, `allow`, and `deny` permission overrides in D1.
5
+ * Requires `roles:manage` (or `super`).
6
+ */
7
+ declare const _default: import("nuxt/server").EventHandler<Promise<{
8
+ userId: string;
9
+ extraRoles: string[];
10
+ allow: string[];
11
+ deny: string[];
12
+ ok: boolean;
13
+ }>>;
14
+ export default _default;
@@ -0,0 +1,19 @@
1
+ import { createError, defineEventHandler, readBody } from "nuxt/server";
2
+ import { setUserPermissions } from "../../../utils/rbac.mjs";
3
+ export default defineEventHandler(async (event) => {
4
+ const body = await readBody(event).catch(() => ({}));
5
+ const userId = typeof body?.userId === "string" ? body.userId.trim() : "";
6
+ if (!userId) {
7
+ throw createError({
8
+ statusCode: 400,
9
+ statusMessage: "Bad Request",
10
+ message: "userId is required."
11
+ });
12
+ }
13
+ const overrides = await setUserPermissions(event, userId, {
14
+ extraRoles: Array.isArray(body?.extraRoles) ? body.extraRoles : [],
15
+ allow: Array.isArray(body?.allow) ? body.allow : [],
16
+ deny: Array.isArray(body?.deny) ? body.deny : []
17
+ });
18
+ return { ok: true, ...overrides };
19
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: import("nuxt/server").EventHandler<Response>;
2
+ export default _default;
@@ -0,0 +1,31 @@
1
+ import { defineEventHandler, useRuntimeConfig } from "nuxt/server";
2
+ export default defineEventHandler((event) => {
3
+ const rc = useRuntimeConfig(event) || globalThis.__NUXT_RUNTIME_CONFIG__ || {};
4
+ const qarpeoPublic = rc.public?.qarpeo || {};
5
+ const site = qarpeoPublic.site || {};
6
+ const pwa = qarpeoPublic.pwa || {};
7
+ const name = pwa.name || site.name || "Qarpeo App";
8
+ const shortName = pwa.shortName || (name.length > 16 ? name.slice(0, 16).trim() : name);
9
+ const manifest = {
10
+ name,
11
+ short_name: shortName,
12
+ description: pwa.description || site.description || void 0,
13
+ start_url: pwa.startUrl || "/",
14
+ scope: pwa.scope || "/",
15
+ display: pwa.display || "standalone",
16
+ theme_color: pwa.themeColor || "#0f172a",
17
+ background_color: pwa.backgroundColor || "#ffffff",
18
+ lang: pwa.lang || site.defaultLocale || "en"
19
+ };
20
+ if (pwa.orientation) manifest.orientation = pwa.orientation;
21
+ if (pwa.dir) manifest.dir = pwa.dir;
22
+ if (pwa.icons?.length) manifest.icons = pwa.icons;
23
+ if (pwa.shortcuts?.length) manifest.shortcuts = pwa.shortcuts;
24
+ if (pwa.categories?.length) manifest.categories = pwa.categories;
25
+ return new Response(JSON.stringify(manifest, null, 2), {
26
+ headers: {
27
+ "Content-Type": "application/manifest+json; charset=UTF-8",
28
+ "Cache-Control": "public, max-age=3600, s-maxage=86400"
29
+ }
30
+ });
31
+ });
@@ -1,6 +1,16 @@
1
- import { defineEventHandler } from "nuxt/server";
2
- export default defineEventHandler((_event) => {
3
- const runtimeConfig = globalThis.__NUXT_RUNTIME_CONFIG__ || {};
1
+ import { defineEventHandler, useRuntimeConfig } from "nuxt/server";
2
+ const AI_CRAWLER_AGENTS = [
3
+ "GPTBot",
4
+ "ChatGPT-User",
5
+ "CCBot",
6
+ "ClaudeBot",
7
+ "anthropic-ai",
8
+ "Google-Extended",
9
+ "Bytespider",
10
+ "PerplexityBot"
11
+ ];
12
+ export default defineEventHandler((event) => {
13
+ const runtimeConfig = useRuntimeConfig(event) || globalThis.__NUXT_RUNTIME_CONFIG__ || {};
4
14
  const site = runtimeConfig.public?.qarpeo?.site || {};
5
15
  const procEnv = globalThis.process?.env || {};
6
16
  const isDev = procEnv.NODE_ENV !== "production";
@@ -25,11 +35,17 @@ Disallow: /
25
35
  for (const rule of disallowRules) {
26
36
  lines.push(`Disallow: ${rule}`);
27
37
  }
38
+ if (robotsConfig.blockAiBots) {
39
+ lines.push("", "# AI Crawler Restrictions");
40
+ for (const agent of AI_CRAWLER_AGENTS) {
41
+ lines.push(`User-agent: ${agent}`, "Disallow: /", "");
42
+ }
43
+ }
28
44
  if (site.url && site.sitemap !== false) {
29
45
  const sitemapUrl = `${site.url.replace(/\/$/, "")}/sitemap.xml`;
30
46
  lines.push("", `Sitemap: ${sitemapUrl}`);
31
47
  }
32
- content = `${lines.join("\n")}
48
+ content = `${lines.join("\n").replace(/\n{3,}/g, "\n\n")}
33
49
  `;
34
50
  }
35
51
  return new Response(content, {