qarpeo 0.2.0 → 0.3.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.
- package/dist/chunks/tools.mjs +993 -31
- package/dist/cli/index.mjs +1102 -31
- package/dist/fate/index.d.ts +9 -1
- package/dist/fate/index.mjs +20 -3
- package/dist/module.mjs +296 -753
- package/dist/runtime/browser.mjs +2 -2
- package/dist/runtime/comments-server.d.ts +3 -0
- package/dist/runtime/comments-server.mjs +2 -0
- package/dist/runtime/comments.d.ts +0 -2
- package/dist/runtime/comments.mjs +0 -2
- package/dist/runtime/db.d.ts +10 -9
- package/dist/runtime/db.mjs +79 -8
- package/dist/runtime/drizzle.mjs +21 -6
- package/dist/runtime/index.d.ts +4 -0
- package/dist/runtime/realtime-server.d.ts +4 -0
- package/dist/runtime/realtime-server.mjs +13 -0
- package/dist/runtime/realtime.d.ts +1 -4
- package/dist/runtime/realtime.mjs +0 -13
- package/dist/runtime/replica.d.ts +27 -0
- package/dist/runtime/replica.mjs +229 -0
- package/dist/runtime/server/durable-objects/agent.mjs +14 -2
- package/dist/runtime/server/durable-objects/room.d.ts +10 -0
- package/dist/runtime/server/durable-objects/room.mjs +119 -28
- package/dist/runtime/server/middleware/devtools.mjs +1 -1
- package/dist/runtime/server/middleware/tenancy.mjs +7 -4
- package/dist/runtime/server/plugins/store.mjs +1 -1
- package/dist/runtime/server/routes/__qarpeo/mail/track/click/[id].get.mjs +57 -17
- package/dist/runtime/server/routes/agents/[agent]/chat.post.mjs +19 -12
- package/dist/runtime/server/routes/agents/[agent]/clear.post.mjs +8 -9
- package/dist/runtime/server/routes/agents/[agent]/history.get.mjs +8 -9
- package/dist/runtime/server/routes/analytics/events.get.mjs +12 -2
- package/dist/runtime/server/routes/analytics/pageviews.get.mjs +10 -1
- package/dist/runtime/server/routes/analytics/summary.get.mjs +10 -1
- package/dist/runtime/server/routes/auth/2fa/disable.post.mjs +11 -2
- package/dist/runtime/server/routes/auth/2fa/setup.post.mjs +7 -0
- package/dist/runtime/server/routes/auth/2fa/verify.post.mjs +11 -2
- package/dist/runtime/server/routes/auth/account.delete.mjs +7 -0
- package/dist/runtime/server/routes/auth/magic-link/verify.get.mjs +5 -3
- package/dist/runtime/server/routes/auth/organization/sso/index.post.mjs +10 -0
- package/dist/runtime/server/routes/auth/otp/verify.post.mjs +5 -3
- package/dist/runtime/server/routes/auth/sso/saml/acs.post.mjs +18 -0
- package/dist/runtime/server/routes/auth/webauthn/login/options.post.d.ts +1 -1
- package/dist/runtime/server/routes/auth/webauthn/login/options.post.mjs +11 -2
- package/dist/runtime/server/routes/auth/webauthn/login/verify.post.mjs +10 -1
- package/dist/runtime/server/routes/auth/webauthn/register/options.post.d.ts +1 -1
- package/dist/runtime/server/routes/auth/webauthn/register/options.post.mjs +10 -1
- package/dist/runtime/server/routes/auth/webauthn/register/verify.post.mjs +10 -1
- package/dist/runtime/server/routes/browser/crawl.post.mjs +13 -0
- package/dist/runtime/server/routes/browser/invoice.post.mjs +15 -1
- package/dist/runtime/server/routes/browser/og-image.post.mjs +13 -0
- package/dist/runtime/server/routes/browser/pdf.post.mjs +15 -1
- package/dist/runtime/server/routes/browser/screenshot.post.mjs +13 -0
- package/dist/runtime/server/routes/cms/[collection]/[id]/preview-token.post.mjs +23 -8
- package/dist/runtime/server/routes/cms/[collection]/[id]/publish.post.mjs +2 -1
- package/dist/runtime/server/routes/cms/[collection]/[id]/review.post.mjs +2 -1
- package/dist/runtime/server/routes/cms/[collection]/[id]/revisions/[revId]/restore.post.mjs +2 -1
- package/dist/runtime/server/routes/cms/[collection]/[id].delete.mjs +2 -1
- package/dist/runtime/server/routes/cms/[collection]/[id].put.mjs +2 -1
- package/dist/runtime/server/routes/cms/[collection]/index.post.mjs +2 -1
- package/dist/runtime/server/routes/cms/categories/[id].delete.mjs +2 -1
- package/dist/runtime/server/routes/cms/categories/[id].put.mjs +2 -1
- package/dist/runtime/server/routes/cms/categories.post.mjs +2 -1
- package/dist/runtime/server/routes/cms/collections/[id].delete.mjs +2 -1
- package/dist/runtime/server/routes/cms/collections/[id].put.mjs +2 -1
- package/dist/runtime/server/routes/cms/collections/index.post.mjs +2 -1
- package/dist/runtime/server/routes/cms/export.post.mjs +1 -1
- package/dist/runtime/server/routes/cms/subscribers/[id].delete.mjs +2 -1
- package/dist/runtime/server/routes/cms/subscribers/[id].patch.mjs +2 -1
- package/dist/runtime/server/routes/cms/tags/[id].delete.mjs +2 -1
- package/dist/runtime/server/routes/cms/tags.post.mjs +2 -1
- package/dist/runtime/server/routes/comments/[id]/react.post.mjs +7 -3
- package/dist/runtime/server/routes/comments/[id]/report.post.mjs +3 -0
- package/dist/runtime/server/routes/comments/[id].delete.mjs +1 -1
- package/dist/runtime/server/routes/comments/[id].get.mjs +13 -0
- package/dist/runtime/server/routes/comments/[id].patch.mjs +1 -1
- package/dist/runtime/server/routes/fate.d.ts +6 -0
- package/dist/runtime/server/routes/fate.mjs +32 -3
- package/dist/runtime/server/routes/mail/bounce.post.mjs +14 -2
- package/dist/runtime/server/routes/mail/unsubscribe.mjs +2 -1
- package/dist/runtime/server/routes/mail/webhooks.post.mjs +18 -4
- package/dist/runtime/server/routes/notifications/[id].get.mjs +3 -4
- package/dist/runtime/server/routes/notifications/index.get.mjs +4 -2
- package/dist/runtime/server/routes/notifications/push/subscribe.post.mjs +3 -1
- package/dist/runtime/server/routes/notifications/push/unsubscribe.post.mjs +5 -3
- package/dist/runtime/server/routes/notifications/read-all.post.mjs +6 -2
- package/dist/runtime/server/routes/notifications/send.post.mjs +13 -2
- package/dist/runtime/server/routes/payments/cancel.post.mjs +1 -1
- package/dist/runtime/server/routes/payments/change-plan.post.mjs +1 -1
- package/dist/runtime/server/routes/payments/checkout.post.mjs +1 -1
- package/dist/runtime/server/routes/payments/pause.post.mjs +1 -1
- package/dist/runtime/server/routes/payments/portal.post.mjs +1 -1
- package/dist/runtime/server/routes/payments/subscription.get.mjs +1 -1
- package/dist/runtime/server/routes/payments/usage.get.mjs +1 -1
- package/dist/runtime/server/routes/payments/usage.post.mjs +1 -1
- package/dist/runtime/server/routes/payments/webhook.post.mjs +8 -1
- package/dist/runtime/server/routes/realtime/broadcast.post.mjs +3 -2
- package/dist/runtime/server/routes/realtime/history.delete.mjs +2 -2
- package/dist/runtime/server/routes/realtime/history.get.mjs +2 -2
- package/dist/runtime/server/routes/realtime/presence.get.mjs +3 -3
- package/dist/runtime/server/routes/realtime/state.get.mjs +3 -3
- package/dist/runtime/server/routes/realtime/state.post.mjs +13 -4
- package/dist/runtime/server/routes/realtime/ws.get.mjs +2 -2
- package/dist/runtime/server/routes/storage/file/[...key].delete.mjs +1 -1
- package/dist/runtime/server/routes/storage/file/[...key].get.mjs +7 -0
- package/dist/runtime/server/routes/storage/files.get.d.ts +1 -1
- package/dist/runtime/server/routes/storage/files.get.mjs +24 -4
- package/dist/runtime/server/routes/storage/multipart/abort.post.mjs +16 -1
- package/dist/runtime/server/routes/storage/multipart/complete.post.d.ts +1 -1
- package/dist/runtime/server/routes/storage/multipart/complete.post.mjs +15 -1
- package/dist/runtime/server/routes/storage/multipart/create.post.mjs +7 -0
- package/dist/runtime/server/routes/storage/multipart/part.put.mjs +15 -1
- package/dist/runtime/server/routes/storage/presigned-r2.post.mjs +8 -1
- package/dist/runtime/server/routes/storage/presigned.post.d.ts +1 -1
- package/dist/runtime/server/routes/storage/presigned.post.mjs +8 -1
- package/dist/runtime/server/routes/storage/sign.post.mjs +7 -0
- package/dist/runtime/server/routes/storage/upload.post.d.ts +2 -2
- package/dist/runtime/server/routes/store/cart/index.delete.mjs +3 -4
- package/dist/runtime/server/routes/store/cart/index.get.mjs +3 -10
- package/dist/runtime/server/routes/store/cart/items/[id].delete.mjs +6 -4
- package/dist/runtime/server/routes/store/cart/items/[id].patch.mjs +12 -4
- package/dist/runtime/server/routes/store/cart/items.post.mjs +9 -10
- package/dist/runtime/server/routes/store/categories/index.get.mjs +4 -2
- package/dist/runtime/server/routes/store/checkout.post.mjs +13 -3
- package/dist/runtime/server/routes/store/coupons/apply.post.mjs +6 -5
- package/dist/runtime/server/routes/store/orders/[id].get.mjs +2 -2
- package/dist/runtime/server/routes/store/orders/download/[token].get.mjs +6 -3
- package/dist/runtime/server/routes/store/orders/index.get.mjs +1 -1
- package/dist/runtime/server/routes/store/products/[slug].get.mjs +2 -2
- package/dist/runtime/server/routes/store/products/index.get.mjs +1 -1
- package/dist/runtime/server/routes/store/tax/calculate.post.mjs +10 -0
- package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/index.delete.mjs +26 -25
- package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/verify.post.mjs +26 -25
- package/dist/runtime/server/utils/ai.d.ts +6 -0
- package/dist/runtime/server/utils/ai.mjs +12 -2
- package/dist/runtime/server/utils/analytics-query.mjs +8 -4
- package/dist/runtime/server/utils/browser-utils.d.ts +9 -0
- package/dist/runtime/server/utils/browser-utils.mjs +135 -0
- package/dist/runtime/server/utils/cms/cache.d.ts +13 -0
- package/dist/runtime/server/utils/cms/cache.mjs +95 -0
- package/dist/runtime/server/utils/cms/common.mjs +1 -1
- package/dist/runtime/server/utils/cms/markdown.mjs +38 -8
- package/dist/runtime/server/utils/cms/mutations.d.ts +26 -0
- package/dist/runtime/server/utils/cms/mutations.mjs +569 -0
- package/dist/runtime/server/utils/cms/path.d.ts +8 -0
- package/dist/runtime/server/utils/cms/path.mjs +23 -0
- package/dist/runtime/server/utils/cms/queries.d.ts +27 -0
- package/dist/runtime/server/utils/cms/queries.mjs +366 -0
- package/dist/runtime/server/utils/cms/references.d.ts +48 -0
- package/dist/runtime/server/utils/cms/references.mjs +309 -0
- package/dist/runtime/server/utils/cms/revisions.d.ts +7 -0
- package/dist/runtime/server/utils/cms/revisions.mjs +60 -0
- package/dist/runtime/server/utils/cms/sync.mjs +3 -3
- package/dist/runtime/server/utils/cms.d.ts +5 -82
- package/dist/runtime/server/utils/cms.mjs +28 -1367
- package/dist/runtime/server/utils/comments.d.ts +11 -0
- package/dist/runtime/server/utils/comments.mjs +65 -17
- package/dist/runtime/server/utils/crypto.mjs +1 -1
- package/dist/runtime/server/utils/domains.mjs +9 -0
- package/dist/runtime/server/utils/drizzle.d.ts +26 -1
- package/dist/runtime/server/utils/drizzle.mjs +78 -19
- package/dist/runtime/server/utils/email-inbound.mjs +9 -1
- package/dist/runtime/server/utils/impersonation.mjs +58 -1
- package/dist/runtime/server/utils/lock.d.ts +11 -0
- package/dist/runtime/server/utils/lock.mjs +4 -0
- package/dist/runtime/server/utils/mail-suppression.mjs +48 -13
- package/dist/runtime/server/utils/mail.d.ts +2 -1
- package/dist/runtime/server/utils/mail.mjs +17 -11
- package/dist/runtime/server/utils/notifications.d.ts +13 -4
- package/dist/runtime/server/utils/notifications.mjs +20 -4
- package/dist/runtime/server/utils/organization.mjs +36 -1
- package/dist/runtime/server/utils/passwordless.mjs +8 -0
- package/dist/runtime/server/utils/payments/checkout.d.ts +34 -0
- package/dist/runtime/server/utils/payments/checkout.mjs +158 -0
- package/dist/runtime/server/utils/payments/common.d.ts +45 -0
- package/dist/runtime/server/utils/payments/common.mjs +234 -0
- package/dist/runtime/server/utils/payments/index.d.ts +9 -0
- package/dist/runtime/server/utils/payments/index.mjs +21 -0
- package/dist/runtime/server/utils/payments/lemonsqueezy.d.ts +7 -0
- package/dist/runtime/server/utils/payments/lemonsqueezy.mjs +55 -0
- package/dist/runtime/server/utils/payments/paddle.d.ts +7 -0
- package/dist/runtime/server/utils/payments/paddle.mjs +92 -0
- package/dist/runtime/server/utils/payments/polar.d.ts +11 -0
- package/dist/runtime/server/utils/payments/polar.mjs +66 -0
- package/dist/runtime/server/utils/payments/stripe.d.ts +7 -0
- package/dist/runtime/server/utils/payments/stripe.mjs +159 -0
- package/dist/runtime/server/utils/payments/subscriptions.d.ts +89 -0
- package/dist/runtime/server/utils/payments/subscriptions.mjs +236 -0
- package/dist/runtime/server/utils/payments/usage.d.ts +12 -0
- package/dist/runtime/server/utils/payments/usage.mjs +143 -0
- package/dist/runtime/server/utils/payments/webhooks.d.ts +10 -0
- package/dist/runtime/server/utils/payments/webhooks.mjs +200 -0
- package/dist/runtime/server/utils/payments.d.ts +1 -158
- package/dist/runtime/server/utils/payments.mjs +1 -1289
- package/dist/runtime/server/utils/queue.d.ts +2 -0
- package/dist/runtime/server/utils/queue.mjs +34 -21
- package/dist/runtime/server/utils/rag.mjs +30 -17
- package/dist/runtime/server/utils/realtime.d.ts +5 -1
- package/dist/runtime/server/utils/realtime.mjs +43 -7
- package/dist/runtime/server/utils/session.mjs +16 -3
- package/dist/runtime/server/utils/sso.d.ts +3 -0
- package/dist/runtime/server/utils/sso.mjs +43 -0
- package/dist/runtime/server/utils/storage.mjs +12 -1
- package/dist/runtime/server/utils/store/cart.d.ts +63 -0
- package/dist/runtime/server/utils/store/cart.mjs +542 -0
- package/dist/runtime/server/utils/store/checkout.d.ts +14 -0
- package/dist/runtime/server/utils/store/checkout.mjs +118 -0
- package/dist/runtime/server/utils/store/common.d.ts +29 -0
- package/dist/runtime/server/utils/store/common.mjs +479 -0
- package/dist/runtime/server/utils/store/index.d.ts +7 -0
- package/dist/runtime/server/utils/store/index.mjs +30 -0
- package/dist/runtime/server/utils/store/inventory.d.ts +25 -0
- package/dist/runtime/server/utils/store/inventory.mjs +190 -0
- package/dist/runtime/server/utils/store/orders.d.ts +60 -0
- package/dist/runtime/server/utils/store/orders.mjs +590 -0
- package/dist/runtime/server/utils/store/products.d.ts +35 -0
- package/dist/runtime/server/utils/store/products.mjs +461 -0
- package/dist/runtime/server/utils/store/vendor.d.ts +18 -0
- package/dist/runtime/server/utils/store/vendor.mjs +68 -0
- package/dist/runtime/server/utils/store.d.ts +1 -207
- package/dist/runtime/server/utils/store.mjs +1 -2227
- package/dist/runtime/server/utils/string.d.ts +1 -1
- package/dist/runtime/server/utils/string.mjs +12 -4
- package/dist/runtime/server/utils/tenant.mjs +19 -5
- package/dist/runtime/server/utils/tracker.mjs +2 -0
- package/dist/runtime/server.d.ts +3 -3
- package/dist/runtime/server.mjs +4 -4
- package/dist/runtime/storage-server.d.ts +2 -0
- package/dist/runtime/storage-server.mjs +1 -0
- package/dist/runtime/storage.d.ts +1 -1
- package/dist/runtime/storage.mjs +0 -1
- package/dist/runtime/store.d.ts +0 -1
- package/dist/runtime/store.mjs +0 -1
- package/dist/runtime/test-utils.d.ts +4 -0
- package/dist/runtime/test-utils.mjs +54 -0
- package/dist/runtime/types/d1.d.ts +43 -0
- package/dist/runtime/types/drizzle.d.ts +6 -0
- package/dist/runtime/types/store.d.ts +1 -1
- package/dist/types/analytics.d.ts +80 -0
- package/dist/types/auth.d.ts +282 -0
- package/dist/types/cache.d.ts +55 -0
- package/dist/types/comments.d.ts +130 -0
- package/dist/types/db.d.ts +29 -0
- package/dist/types/email.d.ts +182 -0
- package/dist/types/index.d.ts +22 -0
- package/dist/types/jobs.d.ts +58 -0
- package/dist/types/notifications.d.ts +77 -0
- package/dist/types/options.d.ts +363 -0
- package/dist/types/payments.d.ts +145 -0
- package/dist/types/ratelimit.d.ts +71 -0
- package/dist/types/realtime.d.ts +136 -0
- package/dist/types/site.d.ts +121 -0
- package/dist/types/storage.d.ts +164 -0
- package/dist/types/store-options.d.ts +199 -0
- package/dist/types/tenant.d.ts +100 -0
- package/dist/types.d.ts +1 -2174
- package/dist/utils/migration-lock.d.ts +139 -0
- package/dist/utils/pkg.d.ts +14 -1
- package/dist/utils/schema-diff.d.ts +39 -0
- package/package.json +55 -17
- package/dist/chunks/auth-schema.mjs +0 -364
|
@@ -9,6 +9,13 @@ export default defineEventHandler(async (event) => {
|
|
|
9
9
|
if (!user || !user.id) {
|
|
10
10
|
throw createError({ statusCode: 401, statusMessage: "Unauthorized" });
|
|
11
11
|
}
|
|
12
|
+
if (session?.impersonator) {
|
|
13
|
+
throw createError({
|
|
14
|
+
statusCode: 403,
|
|
15
|
+
statusMessage: "Forbidden",
|
|
16
|
+
message: "Account deletion cannot be performed while impersonating another user."
|
|
17
|
+
});
|
|
18
|
+
}
|
|
12
19
|
const authConfig = getQarpeoConfig(event).auth || {};
|
|
13
20
|
const deletionConfig = typeof authConfig.accountDeletion === "object" ? authConfig.accountDeletion : {};
|
|
14
21
|
if (deletionConfig.enabled === false) {
|
|
@@ -5,6 +5,7 @@ import { getQarpeoConfig } from "../../../utils/config.mjs";
|
|
|
5
5
|
import { verifyMagicLinkToken } from "../../../utils/passwordless.mjs";
|
|
6
6
|
import { createDeviceSession, setAuthSession } from "../../../utils/session.mjs";
|
|
7
7
|
import { safeRedirect } from "../../../utils/string.mjs";
|
|
8
|
+
import { resolveTableName } from "../../../utils/table-names.mjs";
|
|
8
9
|
export default defineEventHandler(async (event) => {
|
|
9
10
|
const query = getQuery(event);
|
|
10
11
|
const token = query?.token;
|
|
@@ -28,11 +29,12 @@ export default defineEventHandler(async (event) => {
|
|
|
28
29
|
const bindingName = globalThis.process?.env?.QARPEO_DEFAULT_DB_BINDING || "DB";
|
|
29
30
|
const d1 = getD1Binding(bindingName, event);
|
|
30
31
|
await ensureAuthTables(d1);
|
|
31
|
-
|
|
32
|
+
const userTbl = resolveTableName("user", event);
|
|
33
|
+
dbUser = await d1.prepare(`SELECT * FROM ${userTbl} WHERE email = ? LIMIT 1`).bind(cleanEmail).first();
|
|
32
34
|
if (!dbUser) {
|
|
33
35
|
const userId = crypto.randomUUID();
|
|
34
36
|
await d1.prepare(`
|
|
35
|
-
INSERT INTO
|
|
37
|
+
INSERT INTO ${userTbl} (id, email, email_verified, name, image, role, created_at, updated_at)
|
|
36
38
|
VALUES (?, ?, 1, ?, NULL, 'user', ?, ?)
|
|
37
39
|
`).bind(userId, cleanEmail, cleanEmail.split("@")[0], now, now).run();
|
|
38
40
|
dbUser = {
|
|
@@ -43,7 +45,7 @@ export default defineEventHandler(async (event) => {
|
|
|
43
45
|
role: "user"
|
|
44
46
|
};
|
|
45
47
|
} else if (!dbUser.email_verified) {
|
|
46
|
-
await d1.prepare(
|
|
48
|
+
await d1.prepare(`UPDATE ${userTbl} SET email_verified = 1, updated_at = ? WHERE id = ?`).bind(now, dbUser.id).run();
|
|
47
49
|
}
|
|
48
50
|
} catch (err) {
|
|
49
51
|
console.error("[qarpeo:magic-link] Database error resolving user:", err?.message);
|
|
@@ -42,6 +42,16 @@ export default defineEventHandler(async (event) => {
|
|
|
42
42
|
message: "Missing required fields: name, providerType, and ssoUrl are mandatory."
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
|
+
if (body.id) {
|
|
46
|
+
const existing = await d1.prepare("SELECT organization_id FROM sso_connection WHERE id = ? LIMIT 1").bind(body.id).first();
|
|
47
|
+
if (existing && existing.organization_id !== orgId) {
|
|
48
|
+
throw createError({
|
|
49
|
+
statusCode: 403,
|
|
50
|
+
statusMessage: "Forbidden",
|
|
51
|
+
message: "Cannot modify SSO connection belonging to another organization"
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
45
55
|
const id = body.id || crypto.randomUUID();
|
|
46
56
|
const now = Date.now();
|
|
47
57
|
const normalizedDomain = domain ? domain.toLowerCase().trim() : null;
|
|
@@ -4,6 +4,7 @@ import { ensureAuthTables } from "../../../utils/auth.mjs";
|
|
|
4
4
|
import { getQarpeoConfig } from "../../../utils/config.mjs";
|
|
5
5
|
import { verifyOTPCode } from "../../../utils/passwordless.mjs";
|
|
6
6
|
import { createDeviceSession, setAuthSession } from "../../../utils/session.mjs";
|
|
7
|
+
import { resolveTableName } from "../../../utils/table-names.mjs";
|
|
7
8
|
export default defineEventHandler(async (event) => {
|
|
8
9
|
const body = await readBody(event);
|
|
9
10
|
const email = body?.email;
|
|
@@ -37,11 +38,12 @@ export default defineEventHandler(async (event) => {
|
|
|
37
38
|
const bindingName = globalThis.process?.env?.QARPEO_DEFAULT_DB_BINDING || "DB";
|
|
38
39
|
const d1 = getD1Binding(bindingName, event);
|
|
39
40
|
await ensureAuthTables(d1);
|
|
40
|
-
|
|
41
|
+
const userTbl = resolveTableName("user", event);
|
|
42
|
+
dbUser = await d1.prepare(`SELECT * FROM ${userTbl} WHERE email = ? LIMIT 1`).bind(cleanEmail).first();
|
|
41
43
|
if (!dbUser) {
|
|
42
44
|
const userId = crypto.randomUUID();
|
|
43
45
|
await d1.prepare(`
|
|
44
|
-
INSERT INTO
|
|
46
|
+
INSERT INTO ${userTbl} (id, email, email_verified, name, image, role, created_at, updated_at)
|
|
45
47
|
VALUES (?, ?, 1, ?, NULL, 'user', ?, ?)
|
|
46
48
|
`).bind(userId, cleanEmail, cleanEmail.split("@")[0], now, now).run();
|
|
47
49
|
dbUser = {
|
|
@@ -52,7 +54,7 @@ export default defineEventHandler(async (event) => {
|
|
|
52
54
|
role: "user"
|
|
53
55
|
};
|
|
54
56
|
} else if (!dbUser.email_verified) {
|
|
55
|
-
await d1.prepare(
|
|
57
|
+
await d1.prepare(`UPDATE ${userTbl} SET email_verified = 1, updated_at = ? WHERE id = ?`).bind(now, dbUser.id).run();
|
|
56
58
|
}
|
|
57
59
|
} catch {
|
|
58
60
|
}
|
|
@@ -71,6 +71,24 @@ export default defineEventHandler(async (event) => {
|
|
|
71
71
|
message: sigResult === null ? "Unsigned SAML assertions are not permitted. Your IdP must sign assertions or the response." : "SAML response signature verification failed. The response may have been tampered with."
|
|
72
72
|
});
|
|
73
73
|
}
|
|
74
|
+
if (assertion.assertionId) {
|
|
75
|
+
try {
|
|
76
|
+
const kv = getKVBinding("KV", event);
|
|
77
|
+
const replayKey = `sso:saml:assertion:${assertion.assertionId}`;
|
|
78
|
+
const seen = await kv.get(replayKey);
|
|
79
|
+
if (seen) {
|
|
80
|
+
throw createError({
|
|
81
|
+
statusCode: 401,
|
|
82
|
+
statusMessage: "Unauthorized",
|
|
83
|
+
message: "SAML assertion replay detected. This assertion has already been consumed."
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
const ttlSeconds = assertion.notOnOrAfter ? Math.max(60, Math.min(86400, Math.ceil((assertion.notOnOrAfter - now + 3e5) / 1e3))) : 3600;
|
|
87
|
+
await kv.put(replayKey, "1", { expirationTtl: ttlSeconds });
|
|
88
|
+
} catch (err) {
|
|
89
|
+
if (err.statusCode === 401) throw err;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
74
92
|
let user = await d1.prepare("SELECT * FROM user WHERE email = ? LIMIT 1").bind(email).first();
|
|
75
93
|
if (!user) {
|
|
76
94
|
const userId = crypto.randomUUID();
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("nuxt/server").EventHandler<Promise<
|
|
1
|
+
declare const _default: import("nuxt/server").EventHandler<Promise<any>>;
|
|
2
2
|
export default _default;
|
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { defineEventHandler, getRequestURL } from "nuxt/server";
|
|
1
|
+
import { createError, defineEventHandler, getRequestURL } from "nuxt/server";
|
|
3
2
|
import { getKVBinding } from "../../../../../kv.mjs";
|
|
4
3
|
export default defineEventHandler(async (event) => {
|
|
4
|
+
let generateAuthenticationOptions;
|
|
5
|
+
try {
|
|
6
|
+
;
|
|
7
|
+
({ generateAuthenticationOptions } = await import("@simplewebauthn/server"));
|
|
8
|
+
} catch {
|
|
9
|
+
throw createError({
|
|
10
|
+
statusCode: 501,
|
|
11
|
+
message: "WebAuthn requires `@simplewebauthn/server`. Install it with: pnpm add @simplewebauthn/server"
|
|
12
|
+
});
|
|
13
|
+
}
|
|
5
14
|
const reqUrl = getRequestURL(event);
|
|
6
15
|
const rpID = reqUrl.hostname;
|
|
7
16
|
const options = await generateAuthenticationOptions({
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { verifyAuthenticationResponse } from "@simplewebauthn/server";
|
|
2
1
|
import {
|
|
3
2
|
defineEventHandler,
|
|
4
3
|
readBody,
|
|
@@ -10,6 +9,16 @@ import { getKVBinding } from "../../../../../kv.mjs";
|
|
|
10
9
|
import { getQarpeoConfig } from "../../../../utils/config.mjs";
|
|
11
10
|
import { createDeviceSession, setAuthSession } from "../../../../utils/session.mjs";
|
|
12
11
|
export default defineEventHandler(async (event) => {
|
|
12
|
+
let verifyAuthenticationResponse;
|
|
13
|
+
try {
|
|
14
|
+
;
|
|
15
|
+
({ verifyAuthenticationResponse } = await import("@simplewebauthn/server"));
|
|
16
|
+
} catch {
|
|
17
|
+
throw createError({
|
|
18
|
+
statusCode: 501,
|
|
19
|
+
message: "WebAuthn requires `@simplewebauthn/server`. Install it with: pnpm add @simplewebauthn/server"
|
|
20
|
+
});
|
|
21
|
+
}
|
|
13
22
|
const body = await readBody(event);
|
|
14
23
|
const credentialId = body?.id || body?.credentialId;
|
|
15
24
|
if (!credentialId || !body?.response?.clientDataJSON) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("nuxt/server").EventHandler<Promise<
|
|
1
|
+
declare const _default: import("nuxt/server").EventHandler<Promise<any>>;
|
|
2
2
|
export default _default;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { generateRegistrationOptions } from "@simplewebauthn/server";
|
|
2
1
|
import {
|
|
3
2
|
defineEventHandler,
|
|
4
3
|
createError,
|
|
@@ -9,6 +8,16 @@ import { getD1Binding } from "../../../../../db.mjs";
|
|
|
9
8
|
import { getKVBinding } from "../../../../../kv.mjs";
|
|
10
9
|
import { requireAuthSession } from "../../../../utils/session.mjs";
|
|
11
10
|
export default defineEventHandler(async (event) => {
|
|
11
|
+
let generateRegistrationOptions;
|
|
12
|
+
try {
|
|
13
|
+
;
|
|
14
|
+
({ generateRegistrationOptions } = await import("@simplewebauthn/server"));
|
|
15
|
+
} catch {
|
|
16
|
+
throw createError({
|
|
17
|
+
statusCode: 501,
|
|
18
|
+
message: "WebAuthn requires `@simplewebauthn/server`. Install it with: pnpm add @simplewebauthn/server"
|
|
19
|
+
});
|
|
20
|
+
}
|
|
12
21
|
const session = await requireAuthSession(event);
|
|
13
22
|
const user = session?.user;
|
|
14
23
|
if (!user || !user.id) {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { verifyRegistrationResponse } from "@simplewebauthn/server";
|
|
2
1
|
import {
|
|
3
2
|
defineEventHandler,
|
|
4
3
|
readBody,
|
|
@@ -9,6 +8,16 @@ import { getD1Binding } from "../../../../../db.mjs";
|
|
|
9
8
|
import { getKVBinding } from "../../../../../kv.mjs";
|
|
10
9
|
import { requireAuthSession } from "../../../../utils/session.mjs";
|
|
11
10
|
export default defineEventHandler(async (event) => {
|
|
11
|
+
let verifyRegistrationResponse;
|
|
12
|
+
try {
|
|
13
|
+
;
|
|
14
|
+
({ verifyRegistrationResponse } = await import("@simplewebauthn/server"));
|
|
15
|
+
} catch {
|
|
16
|
+
throw createError({
|
|
17
|
+
statusCode: 501,
|
|
18
|
+
message: "WebAuthn requires `@simplewebauthn/server`. Install it with: pnpm add @simplewebauthn/server"
|
|
19
|
+
});
|
|
20
|
+
}
|
|
12
21
|
const session = await requireAuthSession(event);
|
|
13
22
|
const user = session?.user;
|
|
14
23
|
if (!user || !user.id) {
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import { defineEventHandler, readBody, createError } from "nuxt/server";
|
|
2
2
|
import { crawlPage } from "../../utils/browser-utils.mjs";
|
|
3
|
+
import { getQarpeoConfig } from "../../utils/config.mjs";
|
|
4
|
+
import { getAuthContext } from "../../utils/context.mjs";
|
|
3
5
|
export default defineEventHandler(async (event) => {
|
|
6
|
+
const auth = await getAuthContext(event).catch(() => null);
|
|
7
|
+
const config = getQarpeoConfig(event).browser || {};
|
|
8
|
+
const isDev = Boolean(import.meta.dev || process.env.NODE_ENV === "test");
|
|
9
|
+
const allowAnonymous = config.allowAnonymous ?? isDev;
|
|
10
|
+
if (!allowAnonymous && !auth?.user?.id) {
|
|
11
|
+
throw createError({
|
|
12
|
+
statusCode: 401,
|
|
13
|
+
statusMessage: "Unauthorized",
|
|
14
|
+
message: "Authentication required to use browser rendering services."
|
|
15
|
+
});
|
|
16
|
+
}
|
|
4
17
|
let body = {};
|
|
5
18
|
try {
|
|
6
19
|
body = await readBody(event) || {};
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import { defineEventHandler, readBody, createError } from "nuxt/server";
|
|
2
2
|
import { generateInvoicePdf } from "../../utils/browser-utils.mjs";
|
|
3
|
+
import { getQarpeoConfig } from "../../utils/config.mjs";
|
|
4
|
+
import { getAuthContext } from "../../utils/context.mjs";
|
|
3
5
|
export default defineEventHandler(async (event) => {
|
|
6
|
+
const auth = await getAuthContext(event).catch(() => null);
|
|
7
|
+
const config = getQarpeoConfig(event).browser || {};
|
|
8
|
+
const isDev = Boolean(import.meta.dev || process.env.NODE_ENV === "test");
|
|
9
|
+
const allowAnonymous = config.allowAnonymous ?? isDev;
|
|
10
|
+
if (!allowAnonymous && !auth?.user?.id) {
|
|
11
|
+
throw createError({
|
|
12
|
+
statusCode: 401,
|
|
13
|
+
statusMessage: "Unauthorized",
|
|
14
|
+
message: "Authentication required to use browser rendering services."
|
|
15
|
+
});
|
|
16
|
+
}
|
|
4
17
|
let body = {};
|
|
5
18
|
try {
|
|
6
19
|
body = await readBody(event) || {};
|
|
@@ -16,7 +29,8 @@ export default defineEventHandler(async (event) => {
|
|
|
16
29
|
});
|
|
17
30
|
}
|
|
18
31
|
const result = await generateInvoicePdf(body);
|
|
19
|
-
const
|
|
32
|
+
const safeInvoiceNumber = String(invoiceNumber).replace(/[^\w.-]/g, "_").trim();
|
|
33
|
+
const filename = `invoice-${safeInvoiceNumber || "generated"}.pdf`;
|
|
20
34
|
return new Response(result.data, {
|
|
21
35
|
status: 200,
|
|
22
36
|
headers: {
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import { defineEventHandler, readBody, createError } from "nuxt/server";
|
|
2
2
|
import { renderOgSocialCard } from "../../utils/browser-utils.mjs";
|
|
3
|
+
import { getQarpeoConfig } from "../../utils/config.mjs";
|
|
4
|
+
import { getAuthContext } from "../../utils/context.mjs";
|
|
3
5
|
export default defineEventHandler(async (event) => {
|
|
6
|
+
const auth = await getAuthContext(event).catch(() => null);
|
|
7
|
+
const config = getQarpeoConfig(event).browser || {};
|
|
8
|
+
const isDev = Boolean(import.meta.dev || process.env.NODE_ENV === "test");
|
|
9
|
+
const allowAnonymous = config.allowAnonymous ?? isDev;
|
|
10
|
+
if (!allowAnonymous && !auth?.user?.id) {
|
|
11
|
+
throw createError({
|
|
12
|
+
statusCode: 401,
|
|
13
|
+
statusMessage: "Unauthorized",
|
|
14
|
+
message: "Authentication required to use browser rendering services."
|
|
15
|
+
});
|
|
16
|
+
}
|
|
4
17
|
let body = {};
|
|
5
18
|
try {
|
|
6
19
|
body = await readBody(event) || {};
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import { defineEventHandler, readBody, createError } from "nuxt/server";
|
|
2
2
|
import { generatePdf } from "../../utils/browser-utils.mjs";
|
|
3
|
+
import { getQarpeoConfig } from "../../utils/config.mjs";
|
|
4
|
+
import { getAuthContext } from "../../utils/context.mjs";
|
|
3
5
|
export default defineEventHandler(async (event) => {
|
|
6
|
+
const auth = await getAuthContext(event).catch(() => null);
|
|
7
|
+
const config = getQarpeoConfig(event).browser || {};
|
|
8
|
+
const isDev = Boolean(import.meta.dev || process.env.NODE_ENV === "test");
|
|
9
|
+
const allowAnonymous = config.allowAnonymous ?? isDev;
|
|
10
|
+
if (!allowAnonymous && !auth?.user?.id) {
|
|
11
|
+
throw createError({
|
|
12
|
+
statusCode: 401,
|
|
13
|
+
statusMessage: "Unauthorized",
|
|
14
|
+
message: "Authentication required to use browser rendering services."
|
|
15
|
+
});
|
|
16
|
+
}
|
|
4
17
|
let body = {};
|
|
5
18
|
try {
|
|
6
19
|
body = await readBody(event) || {};
|
|
@@ -22,7 +35,8 @@ export default defineEventHandler(async (event) => {
|
|
|
22
35
|
});
|
|
23
36
|
}
|
|
24
37
|
const result = await generatePdf(target, options);
|
|
25
|
-
const
|
|
38
|
+
const safeFilename = filename ? String(filename).replace(/[^\w.-]/g, "_").trim() : "document.pdf";
|
|
39
|
+
const disposition = `attachment; filename="${safeFilename || "document.pdf"}"`;
|
|
26
40
|
return new Response(result.data, {
|
|
27
41
|
status: 200,
|
|
28
42
|
headers: {
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import { defineEventHandler, readBody, createError } from "nuxt/server";
|
|
2
2
|
import { captureScreenshot } from "../../utils/browser-utils.mjs";
|
|
3
|
+
import { getQarpeoConfig } from "../../utils/config.mjs";
|
|
4
|
+
import { getAuthContext } from "../../utils/context.mjs";
|
|
3
5
|
export default defineEventHandler(async (event) => {
|
|
6
|
+
const auth = await getAuthContext(event).catch(() => null);
|
|
7
|
+
const config = getQarpeoConfig(event).browser || {};
|
|
8
|
+
const isDev = Boolean(import.meta.dev || process.env.NODE_ENV === "test");
|
|
9
|
+
const allowAnonymous = config.allowAnonymous ?? isDev;
|
|
10
|
+
if (!allowAnonymous && !auth?.user?.id) {
|
|
11
|
+
throw createError({
|
|
12
|
+
statusCode: 401,
|
|
13
|
+
statusMessage: "Unauthorized",
|
|
14
|
+
message: "Authentication required to use browser rendering services."
|
|
15
|
+
});
|
|
16
|
+
}
|
|
4
17
|
let body = {};
|
|
5
18
|
try {
|
|
6
19
|
body = await readBody(event) || {};
|
|
@@ -1,19 +1,34 @@
|
|
|
1
|
-
import { defineEventHandler, getRouterParam } from "nuxt/server";
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { defineEventHandler, getRouterParam, createError } from "nuxt/server";
|
|
2
|
+
import {
|
|
3
|
+
generatePreviewToken,
|
|
4
|
+
getCMSConfig,
|
|
5
|
+
getCMSDb,
|
|
6
|
+
getCMSTenantId,
|
|
7
|
+
cmsEntryTbl
|
|
8
|
+
} from "../../../../utils/cms.mjs";
|
|
4
9
|
import { requireAuth } from "../../../../utils/context.mjs";
|
|
5
10
|
export default defineEventHandler(async (event) => {
|
|
6
11
|
const config = getCMSConfig(event);
|
|
7
12
|
await requireAuth(event, config.roles ? { role: config.roles } : {});
|
|
8
13
|
const collection = getRouterParam(event, "collection");
|
|
9
14
|
const id = getRouterParam(event, "id");
|
|
10
|
-
const db =
|
|
15
|
+
const db = getCMSDb(event);
|
|
16
|
+
if (!db) {
|
|
17
|
+
throw createError({ statusCode: 500, message: "Database not available" });
|
|
18
|
+
}
|
|
19
|
+
const tenantId = getCMSTenantId(event);
|
|
11
20
|
const entryRow = await db.prepare(
|
|
12
|
-
|
|
13
|
-
).bind(collection, id, id).first();
|
|
14
|
-
|
|
21
|
+
`SELECT id, slug, path FROM ${cmsEntryTbl(event)} WHERE collection_id = ? AND (id = ? OR slug = ?) ${tenantId ? "AND (tenant_id = ? OR tenant_id IS NULL)" : ""} LIMIT 1`
|
|
22
|
+
).bind(...tenantId ? [collection, id, id, tenantId] : [collection, id, id]).first();
|
|
23
|
+
if (!entryRow) {
|
|
24
|
+
throw createError({
|
|
25
|
+
statusCode: 404,
|
|
26
|
+
message: `Entry '${id}' not found in collection '${collection}'`
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
const targetIdentifier = entryRow.slug || id;
|
|
15
30
|
const { token, expires } = await generatePreviewToken(event, collection, targetIdentifier);
|
|
16
|
-
const targetPath = entryRow
|
|
31
|
+
const targetPath = entryRow.path || (collection === "docs" ? `/docs/${entryRow.slug || id}` : `/${collection}/${entryRow.slug || id}`);
|
|
17
32
|
const previewUrl = `${targetPath}?preview=true&preview_token=${encodeURIComponent(token)}&expires=${expires}`;
|
|
18
33
|
const shareUrl = `${config.apiPath}/preview/enable?collection=${encodeURIComponent(collection)}&slug=${encodeURIComponent(targetIdentifier)}&token=${encodeURIComponent(token)}&expires=${expires}&redirect=${encodeURIComponent(targetPath)}`;
|
|
19
34
|
const apiUrl = `${config.apiPath}/${collection}/${targetIdentifier}?preview=true&preview_token=${encodeURIComponent(token)}&expires=${expires}`;
|
|
@@ -3,7 +3,8 @@ import { publishCMSEntry, getCMSConfig } from "../../../../utils/cms.mjs";
|
|
|
3
3
|
import { requireAuth } from "../../../../utils/context.mjs";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
5
|
const config = getCMSConfig(event);
|
|
6
|
-
|
|
6
|
+
const allowedRoles = config.roles?.length ? config.roles : ["admin", "editor"];
|
|
7
|
+
await requireAuth(event, { role: allowedRoles });
|
|
7
8
|
const collection = getRouterParam(event, "collection");
|
|
8
9
|
if (config.collections[collection]?.mode === "file") {
|
|
9
10
|
throw createError({
|
|
@@ -3,7 +3,8 @@ import { submitCMSEntryForReview, rejectCMSEntryReview, getCMSConfig } from "../
|
|
|
3
3
|
import { requireAuth } from "../../../../utils/context.mjs";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
5
|
const config = getCMSConfig(event);
|
|
6
|
-
|
|
6
|
+
const allowedRoles = config.roles?.length ? config.roles : ["admin", "editor"];
|
|
7
|
+
await requireAuth(event, { role: allowedRoles });
|
|
7
8
|
const collection = getRouterParam(event, "collection");
|
|
8
9
|
if (config.collections[collection]?.mode === "file") {
|
|
9
10
|
throw createError({
|
|
@@ -3,7 +3,8 @@ import { restoreCMSRevision, getCMSConfig } from "../../../../../../utils/cms.mj
|
|
|
3
3
|
import { requireAuth } from "../../../../../../utils/context.mjs";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
5
|
const config = getCMSConfig(event);
|
|
6
|
-
|
|
6
|
+
const allowedRoles = config.roles?.length ? config.roles : ["admin", "editor"];
|
|
7
|
+
await requireAuth(event, { role: allowedRoles });
|
|
7
8
|
const collection = getRouterParam(event, "collection");
|
|
8
9
|
if (config.collections[collection]?.mode === "file") {
|
|
9
10
|
throw createError({
|
|
@@ -3,7 +3,8 @@ import { deleteCMSEntry, getCMSConfig } from "../../../utils/cms.mjs";
|
|
|
3
3
|
import { requireAuth } from "../../../utils/context.mjs";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
5
|
const config = getCMSConfig(event);
|
|
6
|
-
|
|
6
|
+
const allowedRoles = config.roles?.length ? config.roles : ["admin", "editor"];
|
|
7
|
+
await requireAuth(event, { role: allowedRoles });
|
|
7
8
|
const collection = getRouterParam(event, "collection");
|
|
8
9
|
if (config.collections[collection]?.mode === "file") {
|
|
9
10
|
throw createError({
|
|
@@ -3,7 +3,8 @@ import { updateCMSEntry, getCMSConfig } from "../../../utils/cms.mjs";
|
|
|
3
3
|
import { requireAuth } from "../../../utils/context.mjs";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
5
|
const config = getCMSConfig(event);
|
|
6
|
-
|
|
6
|
+
const allowedRoles = config.roles?.length ? config.roles : ["admin", "editor"];
|
|
7
|
+
await requireAuth(event, { role: allowedRoles });
|
|
7
8
|
const collection = getRouterParam(event, "collection");
|
|
8
9
|
if (config.collections[collection]?.mode === "file") {
|
|
9
10
|
throw createError({
|
|
@@ -3,7 +3,8 @@ import { createCMSEntry, getCMSConfig } from "../../../utils/cms.mjs";
|
|
|
3
3
|
import { requireAuth } from "../../../utils/context.mjs";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
5
|
const config = getCMSConfig(event);
|
|
6
|
-
const
|
|
6
|
+
const allowedRoles = config.roles?.length ? config.roles : ["admin", "editor"];
|
|
7
|
+
const { user } = await requireAuth(event, { role: allowedRoles });
|
|
7
8
|
const collection = getRouterParam(event, "collection");
|
|
8
9
|
if (config.collections[collection]?.mode === "file") {
|
|
9
10
|
throw createError({
|
|
@@ -3,7 +3,8 @@ import { deleteCMSCategory, getCMSConfig } from "../../../utils/cms.mjs";
|
|
|
3
3
|
import { requireAuth } from "../../../utils/context.mjs";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
5
|
const config = getCMSConfig(event);
|
|
6
|
-
|
|
6
|
+
const allowedRoles = config.roles?.length ? config.roles : ["admin", "editor"];
|
|
7
|
+
await requireAuth(event, { role: allowedRoles });
|
|
7
8
|
const { id } = getRouterParams(event);
|
|
8
9
|
if (!id) {
|
|
9
10
|
throw createError({ statusCode: 400, message: "Category ID is required" });
|
|
@@ -3,7 +3,8 @@ import { updateCMSCategory, getCMSConfig } from "../../../utils/cms.mjs";
|
|
|
3
3
|
import { requireAuth } from "../../../utils/context.mjs";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
5
|
const config = getCMSConfig(event);
|
|
6
|
-
|
|
6
|
+
const allowedRoles = config.roles?.length ? config.roles : ["admin", "editor"];
|
|
7
|
+
await requireAuth(event, { role: allowedRoles });
|
|
7
8
|
const { id } = getRouterParams(event);
|
|
8
9
|
if (!id) {
|
|
9
10
|
throw createError({ statusCode: 400, message: "Category ID is required" });
|
|
@@ -3,7 +3,8 @@ import { createCMSCategory, getCMSConfig } from "../../utils/cms.mjs";
|
|
|
3
3
|
import { requireAuth } from "../../utils/context.mjs";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
5
|
const config = getCMSConfig(event);
|
|
6
|
-
|
|
6
|
+
const allowedRoles = config.roles?.length ? config.roles : ["admin", "editor"];
|
|
7
|
+
await requireAuth(event, { role: allowedRoles });
|
|
7
8
|
const body = await readBody(event);
|
|
8
9
|
if (!body?.name) {
|
|
9
10
|
throw createError({ statusCode: 400, message: "Category name is required" });
|
|
@@ -3,7 +3,8 @@ import { deleteCMSCollection, getCMSConfig } from "../../../utils/cms.mjs";
|
|
|
3
3
|
import { requireAuth } from "../../../utils/context.mjs";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
5
|
const config = getCMSConfig(event);
|
|
6
|
-
|
|
6
|
+
const allowedRoles = config.roles?.length ? config.roles : ["admin", "editor"];
|
|
7
|
+
await requireAuth(event, { role: allowedRoles });
|
|
7
8
|
const id = getRouterParam(event, "id");
|
|
8
9
|
await deleteCMSCollection(event, id);
|
|
9
10
|
return { ok: true };
|
|
@@ -3,7 +3,8 @@ import { updateCMSCollection, getCMSConfig } from "../../../utils/cms.mjs";
|
|
|
3
3
|
import { requireAuth } from "../../../utils/context.mjs";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
5
|
const config = getCMSConfig(event);
|
|
6
|
-
|
|
6
|
+
const allowedRoles = config.roles?.length ? config.roles : ["admin", "editor"];
|
|
7
|
+
await requireAuth(event, { role: allowedRoles });
|
|
7
8
|
const id = getRouterParam(event, "id");
|
|
8
9
|
const body = await readBody(event);
|
|
9
10
|
await updateCMSCollection(event, id, body || {});
|
|
@@ -3,7 +3,8 @@ import { createCMSCollection, getCMSConfig } from "../../../utils/cms.mjs";
|
|
|
3
3
|
import { requireAuth } from "../../../utils/context.mjs";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
5
|
const config = getCMSConfig(event);
|
|
6
|
-
|
|
6
|
+
const allowedRoles = config.roles?.length ? config.roles : ["admin", "editor"];
|
|
7
|
+
await requireAuth(event, { role: allowedRoles });
|
|
7
8
|
const body = await readBody(event);
|
|
8
9
|
if (!body?.id || !body?.name) {
|
|
9
10
|
throw createError({ statusCode: 400, message: "id and name are required" });
|
|
@@ -4,7 +4,7 @@ import { getCMSConfig, formatFrontmatter, computeContentHash, cmsEntryTbl } from
|
|
|
4
4
|
import { requireAuth } from "../../utils/context.mjs";
|
|
5
5
|
export default defineEventHandler(async (event) => {
|
|
6
6
|
const config = getCMSConfig(event);
|
|
7
|
-
await requireAuth(event,
|
|
7
|
+
await requireAuth(event, { role: ["admin", "super"] });
|
|
8
8
|
let writeFile, mkdir, resolvePath, dirname;
|
|
9
9
|
try {
|
|
10
10
|
const fs = await import("node:fs/promises");
|
|
@@ -3,7 +3,8 @@ import { deleteCMSSubscriber, getCMSConfig } from "../../../utils/cms.mjs";
|
|
|
3
3
|
import { requireAuth } from "../../../utils/context.mjs";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
5
|
const config = getCMSConfig(event);
|
|
6
|
-
|
|
6
|
+
const allowedRoles = config.roles?.length ? config.roles : ["admin", "editor"];
|
|
7
|
+
await requireAuth(event, { role: allowedRoles });
|
|
7
8
|
const id = getRouterParam(event, "id");
|
|
8
9
|
if (!id) {
|
|
9
10
|
throw createError({ statusCode: 400, message: "Missing subscriber ID" });
|
|
@@ -3,7 +3,8 @@ import { updateCMSSubscriberStatus, getCMSConfig } from "../../../utils/cms.mjs"
|
|
|
3
3
|
import { requireAuth } from "../../../utils/context.mjs";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
5
|
const config = getCMSConfig(event);
|
|
6
|
-
|
|
6
|
+
const allowedRoles = config.roles?.length ? config.roles : ["admin", "editor"];
|
|
7
|
+
await requireAuth(event, { role: allowedRoles });
|
|
7
8
|
const { id } = getRouterParams(event);
|
|
8
9
|
if (!id) {
|
|
9
10
|
throw createError({ statusCode: 400, message: "Subscriber ID is required" });
|
|
@@ -3,7 +3,8 @@ import { deleteCMSTag, getCMSConfig } from "../../../utils/cms.mjs";
|
|
|
3
3
|
import { requireAuth } from "../../../utils/context.mjs";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
5
|
const config = getCMSConfig(event);
|
|
6
|
-
|
|
6
|
+
const allowedRoles = config.roles?.length ? config.roles : ["admin", "editor"];
|
|
7
|
+
await requireAuth(event, { role: allowedRoles });
|
|
7
8
|
const { id } = getRouterParams(event);
|
|
8
9
|
if (!id) {
|
|
9
10
|
throw createError({ statusCode: 400, message: "Tag ID is required" });
|
|
@@ -3,7 +3,8 @@ import { createCMSTag, getCMSConfig } from "../../utils/cms.mjs";
|
|
|
3
3
|
import { requireAuth } from "../../utils/context.mjs";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
5
|
const config = getCMSConfig(event);
|
|
6
|
-
|
|
6
|
+
const allowedRoles = config.roles?.length ? config.roles : ["admin", "editor"];
|
|
7
|
+
await requireAuth(event, { role: allowedRoles });
|
|
7
8
|
const body = await readBody(event);
|
|
8
9
|
if (!body?.name) {
|
|
9
10
|
throw createError({ statusCode: 400, message: "Tag name is required" });
|
|
@@ -18,13 +18,17 @@ export default defineEventHandler(async (event) => {
|
|
|
18
18
|
throw createError({ statusCode: 404, statusMessage: "Comment not found" });
|
|
19
19
|
}
|
|
20
20
|
const body = await readBody(event) || {};
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
const reaction = String(body.reaction || "").trim();
|
|
22
|
+
if (!reaction || reaction.length > 32 || /[\r\n\0<>]/.test(reaction)) {
|
|
23
|
+
throw createError({
|
|
24
|
+
statusCode: 400,
|
|
25
|
+
statusMessage: "Invalid reaction format. Must be at most 32 characters."
|
|
26
|
+
});
|
|
23
27
|
}
|
|
24
28
|
const auth = await getAuthContext(event).catch(() => null);
|
|
25
29
|
const result = await reactToComment(
|
|
26
30
|
id,
|
|
27
|
-
|
|
31
|
+
reaction,
|
|
28
32
|
{
|
|
29
33
|
userId: auth?.user?.id
|
|
30
34
|
},
|
|
@@ -35,6 +35,9 @@ export default defineEventHandler(async (event) => {
|
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
const auth = await getAuthContext(event).catch(() => null);
|
|
38
|
+
if (auth?.user?.id && existing.authorId && auth.user.id === existing.authorId) {
|
|
39
|
+
throw createError({ statusCode: 400, statusMessage: "You cannot report your own comment." });
|
|
40
|
+
}
|
|
38
41
|
const report = await reportComment(
|
|
39
42
|
id,
|
|
40
43
|
body.reason,
|
|
@@ -12,7 +12,7 @@ export default defineEventHandler(async (event) => {
|
|
|
12
12
|
throw createError({ statusCode: 404, statusMessage: "Comment not found" });
|
|
13
13
|
}
|
|
14
14
|
const activeTenant = getTenant(event);
|
|
15
|
-
if (activeTenant && existing.tenantId
|
|
15
|
+
if (activeTenant && existing.tenantId !== activeTenant.id) {
|
|
16
16
|
throw createError({ statusCode: 404, statusMessage: "Comment not found" });
|
|
17
17
|
}
|
|
18
18
|
const auth = await getAuthContext(event).catch(() => null);
|