qarpeo 0.2.1 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/tools.mjs +993 -31
- package/dist/cli/index.mjs +1071 -31
- package/dist/fate/index.d.ts +9 -1
- package/dist/fate/index.mjs +20 -3
- package/dist/module.mjs +296 -750
- 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
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { createError, defineEventHandler, getRouterParam } from "nuxt/server";
|
|
2
2
|
import { getComment } from "../../utils/comments.mjs";
|
|
3
|
+
import { getAuthContext } from "../../utils/context.mjs";
|
|
4
|
+
import { getTenant } from "../../utils/tenant.mjs";
|
|
3
5
|
export default defineEventHandler(async (event) => {
|
|
4
6
|
const id = getRouterParam(event, "id");
|
|
5
7
|
if (!id) {
|
|
@@ -9,5 +11,16 @@ export default defineEventHandler(async (event) => {
|
|
|
9
11
|
if (!comment) {
|
|
10
12
|
throw createError({ statusCode: 404, statusMessage: "Comment not found" });
|
|
11
13
|
}
|
|
14
|
+
const activeTenant = getTenant(event);
|
|
15
|
+
if (activeTenant && comment.tenantId !== activeTenant.id) {
|
|
16
|
+
throw createError({ statusCode: 404, statusMessage: "Comment not found" });
|
|
17
|
+
}
|
|
18
|
+
const auth = await getAuthContext(event).catch(() => null);
|
|
19
|
+
const role = auth?.user?.role || "";
|
|
20
|
+
const isModerator = role === "admin" || role === "super" || role === "moderator";
|
|
21
|
+
const isAuthor = Boolean(auth?.user?.id && comment.authorId && auth.user.id === comment.authorId);
|
|
22
|
+
if (comment.status !== "approved" && !isModerator && !isAuthor) {
|
|
23
|
+
throw createError({ statusCode: 404, statusMessage: "Comment not found" });
|
|
24
|
+
}
|
|
12
25
|
return { comment };
|
|
13
26
|
});
|
|
@@ -32,7 +32,7 @@ export default defineEventHandler(async (event) => {
|
|
|
32
32
|
throw createError({ statusCode: 404, statusMessage: "Comment not found" });
|
|
33
33
|
}
|
|
34
34
|
const activeTenant = getTenant(event);
|
|
35
|
-
if (activeTenant && existing.tenantId
|
|
35
|
+
if (activeTenant && existing.tenantId !== activeTenant.id) {
|
|
36
36
|
throw createError({ statusCode: 404, statusMessage: "Comment not found" });
|
|
37
37
|
}
|
|
38
38
|
const updated = await updateCommentStatus(id, body.status, event);
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
defineEventHandler,
|
|
3
|
+
readBody,
|
|
4
|
+
getRequestHeaders,
|
|
5
|
+
createError,
|
|
6
|
+
useRuntimeConfig
|
|
7
|
+
} from "nuxt/server";
|
|
8
|
+
import { getAuthSession } from "../utils/session.mjs";
|
|
2
9
|
import { fateViews } from "#qarpeo/fate/views";
|
|
3
10
|
let _fateHandler;
|
|
4
11
|
async function getFateHandler() {
|
|
@@ -8,7 +15,13 @@ async function getFateHandler() {
|
|
|
8
15
|
"@nkzw/fate/server"
|
|
9
16
|
);
|
|
10
17
|
const server = createFateServer({
|
|
11
|
-
context: async ({ adapterContext }) =>
|
|
18
|
+
context: async ({ adapterContext }) => {
|
|
19
|
+
if (adapterContext && "event" in adapterContext) {
|
|
20
|
+
return adapterContext;
|
|
21
|
+
}
|
|
22
|
+
const s = adapterContext ? await getAuthSession(adapterContext) : {};
|
|
23
|
+
return { event: adapterContext, session: s, user: s?.user ?? null };
|
|
24
|
+
},
|
|
12
25
|
roots: fateViews.roots,
|
|
13
26
|
lists: fateViews.lists,
|
|
14
27
|
sources: {
|
|
@@ -20,6 +33,22 @@ async function getFateHandler() {
|
|
|
20
33
|
return _fateHandler;
|
|
21
34
|
}
|
|
22
35
|
export default defineEventHandler(async (event) => {
|
|
36
|
+
const session = await getAuthSession(event);
|
|
37
|
+
const user = session?.user ?? null;
|
|
38
|
+
let requireAuth = true;
|
|
39
|
+
try {
|
|
40
|
+
const cfg = useRuntimeConfig();
|
|
41
|
+
if (cfg?.qarpeoFateAuth === false) {
|
|
42
|
+
requireAuth = false;
|
|
43
|
+
}
|
|
44
|
+
} catch {
|
|
45
|
+
}
|
|
46
|
+
if (requireAuth && !user) {
|
|
47
|
+
throw createError({
|
|
48
|
+
statusCode: 401,
|
|
49
|
+
statusMessage: "Unauthorized: Authentication required for Fate endpoint"
|
|
50
|
+
});
|
|
51
|
+
}
|
|
23
52
|
const handler = await getFateHandler();
|
|
24
53
|
const ev = event;
|
|
25
54
|
const headers = getRequestHeaders(event);
|
|
@@ -28,5 +57,5 @@ export default defineEventHandler(async (event) => {
|
|
|
28
57
|
headers: ev.headers,
|
|
29
58
|
body: ["POST", "PUT", "PATCH"].includes(ev.method) ? JSON.stringify(await readBody(event)) : void 0
|
|
30
59
|
});
|
|
31
|
-
return handler(req, event);
|
|
60
|
+
return handler(req, { event, session, user });
|
|
32
61
|
});
|
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
import { createError, defineEventHandler, getQuery, getRequestHeader, readBody } from "nuxt/server";
|
|
2
2
|
import { getQarpeoConfig } from "../../utils/config.mjs";
|
|
3
|
+
import { timingSafeEqualString } from "../../utils/crypto.mjs";
|
|
3
4
|
import { recordEmailBounce, recordSoftBounce, suppressEmail } from "../../utils/mail.mjs";
|
|
4
5
|
export default defineEventHandler(async (event) => {
|
|
5
6
|
const mailConfig = getQarpeoConfig(event).mail || {};
|
|
6
7
|
const webhookSecret = mailConfig.webhookSecret || globalThis.process?.env?.QARPEO_MAIL_WEBHOOK_SECRET;
|
|
7
8
|
if (webhookSecret) {
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
let providedSecret;
|
|
10
|
+
try {
|
|
11
|
+
providedSecret = getRequestHeader(event, "x-webhook-secret") || getRequestHeader(event, "x-qarpeo-webhook-secret");
|
|
12
|
+
} catch {
|
|
13
|
+
providedSecret = event?.headers?.get?.("x-webhook-secret") || event?.headers?.get?.("x-qarpeo-webhook-secret") || event?.node?.req?.headers?.["x-webhook-secret"];
|
|
14
|
+
}
|
|
15
|
+
if (!providedSecret) {
|
|
16
|
+
try {
|
|
17
|
+
providedSecret = getQuery(event)?.secret;
|
|
18
|
+
} catch {
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (!providedSecret || !timingSafeEqualString(String(providedSecret), String(webhookSecret))) {
|
|
10
22
|
throw createError({ statusCode: 401, message: "Invalid or missing webhook secret" });
|
|
11
23
|
}
|
|
12
24
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createError, defineEventHandler, getQuery, readBody } from "nuxt/server";
|
|
2
2
|
import { suppressEmail, verifyUnsubscribeToken } from "../../utils/mail.mjs";
|
|
3
|
+
import { escapeHtml } from "../../utils/string.mjs";
|
|
3
4
|
export default defineEventHandler(async (event) => {
|
|
4
5
|
const method = (event.method || event.node?.req?.method || "GET").toUpperCase();
|
|
5
6
|
const query = getQuery(event);
|
|
@@ -83,7 +84,7 @@ export default defineEventHandler(async (event) => {
|
|
|
83
84
|
<div class="icon">\u2713</div>
|
|
84
85
|
<h1>You have been unsubscribed</h1>
|
|
85
86
|
<p>You will no longer receive marketing and promotional notifications sent to:</p>
|
|
86
|
-
<div class="email-box">${email}</div>
|
|
87
|
+
<div class="email-box">${escapeHtml(email)}</div>
|
|
87
88
|
<p class="note">Essential transactional emails (such as password resets or receipt confirmations) may still be sent.</p>
|
|
88
89
|
</div>
|
|
89
90
|
</body>
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { createError, defineEventHandler, getQuery, getRequestHeader, readBody } from "nuxt/server";
|
|
2
2
|
import { getQarpeoConfig } from "../../utils/config.mjs";
|
|
3
|
+
import { timingSafeEqualString } from "../../utils/crypto.mjs";
|
|
4
|
+
import { sanitizeUrl } from "../../utils/string.mjs";
|
|
3
5
|
import {
|
|
4
6
|
recordEmailBounce,
|
|
5
7
|
recordEmailClick,
|
|
@@ -11,8 +13,19 @@ export default defineEventHandler(async (event) => {
|
|
|
11
13
|
const mailConfig = getQarpeoConfig(event).mail || {};
|
|
12
14
|
const webhookSecret = mailConfig.webhookSecret || globalThis.process?.env?.QARPEO_MAIL_WEBHOOK_SECRET;
|
|
13
15
|
if (webhookSecret) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
let providedSecret;
|
|
17
|
+
try {
|
|
18
|
+
providedSecret = getRequestHeader(event, "x-webhook-secret") || getRequestHeader(event, "x-qarpeo-webhook-secret");
|
|
19
|
+
} catch {
|
|
20
|
+
providedSecret = event?.headers?.get?.("x-webhook-secret") || event?.headers?.get?.("x-qarpeo-webhook-secret") || event?.node?.req?.headers?.["x-webhook-secret"];
|
|
21
|
+
}
|
|
22
|
+
if (!providedSecret) {
|
|
23
|
+
try {
|
|
24
|
+
providedSecret = getQuery(event)?.secret;
|
|
25
|
+
} catch {
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (!providedSecret || !timingSafeEqualString(String(providedSecret), String(webhookSecret))) {
|
|
16
29
|
throw createError({ statusCode: 401, message: "Invalid or missing webhook secret" });
|
|
17
30
|
}
|
|
18
31
|
}
|
|
@@ -75,8 +88,9 @@ export default defineEventHandler(async (event) => {
|
|
|
75
88
|
continue;
|
|
76
89
|
}
|
|
77
90
|
if (eventType.includes("click")) {
|
|
78
|
-
const
|
|
79
|
-
|
|
91
|
+
const rawTargetUrl = item.url || item.data?.click?.link || item.OriginalLink || "";
|
|
92
|
+
const targetUrl = sanitizeUrl(rawTargetUrl);
|
|
93
|
+
if (messageId && targetUrl && targetUrl !== "#") recordEmailClick(messageId, targetUrl);
|
|
80
94
|
results.push({ event: "click", messageId, processed: true });
|
|
81
95
|
continue;
|
|
82
96
|
}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { createError, defineEventHandler, getRouterParam } from "nuxt/server";
|
|
2
|
-
import {
|
|
2
|
+
import { getNotification } from "../../utils/notifications.mjs";
|
|
3
3
|
import { getAuthSession } from "../../utils/session.mjs";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
5
|
const session = await getAuthSession(event);
|
|
6
|
-
if (!session?.user) {
|
|
6
|
+
if (!session?.user?.id) {
|
|
7
7
|
throw createError({ statusCode: 401, message: "Unauthorized" });
|
|
8
8
|
}
|
|
9
9
|
const id = getRouterParam(event, "id");
|
|
10
10
|
if (!id) throw createError({ statusCode: 400, message: "Missing id" });
|
|
11
|
-
const
|
|
12
|
-
const notification = result.notifications.find((n) => n.id === id);
|
|
11
|
+
const notification = await getNotification(id, session.user.id, event);
|
|
13
12
|
if (!notification) throw createError({ statusCode: 404, message: "Notification not found" });
|
|
14
13
|
return notification;
|
|
15
14
|
});
|
|
@@ -7,8 +7,10 @@ export default defineEventHandler(async (event) => {
|
|
|
7
7
|
throw createError({ statusCode: 401, message: "Unauthorized" });
|
|
8
8
|
}
|
|
9
9
|
const query = getQuery(event);
|
|
10
|
-
const
|
|
11
|
-
const
|
|
10
|
+
const rawLimit = Number(query.limit);
|
|
11
|
+
const limit = Math.min(100, Math.max(1, isNaN(rawLimit) ? 20 : Math.trunc(rawLimit)));
|
|
12
|
+
const rawOffset = Number(query.offset);
|
|
13
|
+
const offset = Math.max(0, isNaN(rawOffset) ? 0 : Math.trunc(rawOffset));
|
|
12
14
|
const unreadOnly = query.unreadOnly === "true" || query.unreadOnly === "1";
|
|
13
15
|
return getNotifications(
|
|
14
16
|
session.user.id,
|
|
@@ -3,7 +3,9 @@ import { z } from "zod";
|
|
|
3
3
|
import { savePushSubscription } from "../../../utils/notifications.mjs";
|
|
4
4
|
import { getAuthSession } from "../../../utils/session.mjs";
|
|
5
5
|
const PushSubscribeSchema = z.object({
|
|
6
|
-
endpoint: z.string().url(),
|
|
6
|
+
endpoint: z.string().url().refine((val) => val.startsWith("https://"), {
|
|
7
|
+
message: "Push endpoint must use HTTPS protocol"
|
|
8
|
+
}),
|
|
7
9
|
keys: z.object({
|
|
8
10
|
p256dh: z.string().min(1),
|
|
9
11
|
auth: z.string().min(1)
|
|
@@ -3,14 +3,16 @@ import { z } from "zod";
|
|
|
3
3
|
import { removePushSubscription } from "../../../utils/notifications.mjs";
|
|
4
4
|
import { getAuthSession } from "../../../utils/session.mjs";
|
|
5
5
|
const PushUnsubscribeSchema = z.object({
|
|
6
|
-
endpoint: z.string().url()
|
|
6
|
+
endpoint: z.string().url().refine((val) => val.startsWith("https://"), {
|
|
7
|
+
message: "Push endpoint must use HTTPS protocol"
|
|
8
|
+
})
|
|
7
9
|
});
|
|
8
10
|
export default defineEventHandler(async (event) => {
|
|
9
11
|
const session = await getAuthSession(event);
|
|
10
|
-
if (!session?.user) {
|
|
12
|
+
if (!session?.user?.id) {
|
|
11
13
|
throw createError({ statusCode: 401, message: "Unauthorized" });
|
|
12
14
|
}
|
|
13
15
|
const body = await readValidatedBody(event, (b) => PushUnsubscribeSchema.parse(b));
|
|
14
|
-
await removePushSubscription(body.endpoint, event);
|
|
16
|
+
await removePushSubscription(body.endpoint, event, session.user.id);
|
|
15
17
|
return { ok: true };
|
|
16
18
|
});
|
|
@@ -3,9 +3,13 @@ import { markAllNotificationsRead } from "../../utils/notifications.mjs";
|
|
|
3
3
|
import { getAuthSession } from "../../utils/session.mjs";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
5
|
const session = await getAuthSession(event);
|
|
6
|
-
if (!session?.user) {
|
|
6
|
+
if (!session?.user?.id) {
|
|
7
7
|
throw createError({ statusCode: 401, message: "Unauthorized" });
|
|
8
8
|
}
|
|
9
|
-
await markAllNotificationsRead(
|
|
9
|
+
await markAllNotificationsRead(
|
|
10
|
+
session.user.id,
|
|
11
|
+
event,
|
|
12
|
+
session.user.tenantId
|
|
13
|
+
);
|
|
10
14
|
return { ok: true };
|
|
11
15
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createError, defineEventHandler, readBody } from "nuxt/server";
|
|
2
2
|
import { getAuthContext } from "../../utils/context.mjs";
|
|
3
3
|
import { sendNotification } from "../../utils/notifications.mjs";
|
|
4
|
+
import { safeRedirect } from "../../utils/string.mjs";
|
|
4
5
|
export default defineEventHandler(async (event) => {
|
|
5
6
|
const auth = await getAuthContext(event).catch(() => null);
|
|
6
7
|
if (!auth?.user?.id) {
|
|
@@ -13,7 +14,8 @@ export default defineEventHandler(async (event) => {
|
|
|
13
14
|
const body = await readBody(event) || {};
|
|
14
15
|
const targetUserId = body.userId || auth.user.id;
|
|
15
16
|
const userRole = auth.user?.role || "user";
|
|
16
|
-
|
|
17
|
+
const isAdmin = auth.isAdmin || userRole === "admin" || userRole === "super";
|
|
18
|
+
if (body.userId && body.userId !== auth.user.id && !isAdmin) {
|
|
17
19
|
throw createError({
|
|
18
20
|
statusCode: 403,
|
|
19
21
|
statusMessage: "Forbidden",
|
|
@@ -26,6 +28,15 @@ export default defineEventHandler(async (event) => {
|
|
|
26
28
|
statusMessage: "Field 'title' is required."
|
|
27
29
|
});
|
|
28
30
|
}
|
|
31
|
+
let safeActionUrl = void 0;
|
|
32
|
+
if (typeof body.actionUrl === "string" && body.actionUrl.trim()) {
|
|
33
|
+
const trimmed = body.actionUrl.trim();
|
|
34
|
+
if (trimmed.startsWith("https://") || trimmed.startsWith("http://")) {
|
|
35
|
+
safeActionUrl = trimmed;
|
|
36
|
+
} else {
|
|
37
|
+
safeActionUrl = safeRedirect(trimmed, "/");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
29
40
|
const channels = Array.isArray(body.channels) ? body.channels : ["in-app"];
|
|
30
41
|
await sendNotification(
|
|
31
42
|
{
|
|
@@ -34,7 +45,7 @@ export default defineEventHandler(async (event) => {
|
|
|
34
45
|
title: body.title,
|
|
35
46
|
body: body.body,
|
|
36
47
|
icon: body.icon,
|
|
37
|
-
actionUrl:
|
|
48
|
+
actionUrl: safeActionUrl,
|
|
38
49
|
channels,
|
|
39
50
|
metadata: body.metadata,
|
|
40
51
|
emailOptions: body.emailOptions
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineEventHandler, readValidatedBody } from "nuxt/server";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import { cancelSubscription } from "../../utils/payments.mjs";
|
|
3
|
+
import { cancelSubscription } from "../../utils/payments/index.mjs";
|
|
4
4
|
const CancelBodySchema = z.object({
|
|
5
5
|
subscriptionId: z.string().min(1, "subscriptionId is required")
|
|
6
6
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineEventHandler, readValidatedBody } from "nuxt/server";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import { changePlan } from "../../utils/payments.mjs";
|
|
3
|
+
import { changePlan } from "../../utils/payments/index.mjs";
|
|
4
4
|
const ChangePlanBodySchema = z.object({
|
|
5
5
|
subscriptionId: z.string().min(1, "subscriptionId is required"),
|
|
6
6
|
newPriceId: z.string().min(1, "newPriceId is required")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineEventHandler, readValidatedBody } from "nuxt/server";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import { createCheckoutSession } from "../../utils/payments.mjs";
|
|
3
|
+
import { createCheckoutSession } from "../../utils/payments/index.mjs";
|
|
4
4
|
const CheckoutBodySchema = z.object({
|
|
5
5
|
planId: z.string().optional(),
|
|
6
6
|
priceId: z.string().optional(),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineEventHandler, readValidatedBody } from "nuxt/server";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import { pauseSubscription } from "../../utils/payments.mjs";
|
|
3
|
+
import { pauseSubscription } from "../../utils/payments/index.mjs";
|
|
4
4
|
const PauseBodySchema = z.object({
|
|
5
5
|
subscriptionId: z.string().min(1, "subscriptionId is required")
|
|
6
6
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineEventHandler, readValidatedBody } from "nuxt/server";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import { createCustomerPortalSession } from "../../utils/payments.mjs";
|
|
3
|
+
import { createCustomerPortalSession } from "../../utils/payments/index.mjs";
|
|
4
4
|
const PortalBodySchema = z.object({
|
|
5
5
|
returnUrl: z.string().optional()
|
|
6
6
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineEventHandler } from "nuxt/server";
|
|
2
|
-
import { getSubscription } from "../../utils/payments.mjs";
|
|
2
|
+
import { getSubscription } from "../../utils/payments/index.mjs";
|
|
3
3
|
export default defineEventHandler(async (event) => {
|
|
4
4
|
const subscription = await getSubscription(event);
|
|
5
5
|
return {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineEventHandler, getQuery } from "nuxt/server";
|
|
2
|
-
import { getUsageSummary } from "../../utils/payments.mjs";
|
|
2
|
+
import { getUsageSummary } from "../../utils/payments/index.mjs";
|
|
3
3
|
export default defineEventHandler(async (event) => {
|
|
4
4
|
const query = getQuery(event);
|
|
5
5
|
const eventName = query.eventName ? String(query.eventName) : void 0;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineEventHandler, readValidatedBody } from "nuxt/server";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import { reportUsage } from "../../utils/payments.mjs";
|
|
3
|
+
import { reportUsage } from "../../utils/payments/index.mjs";
|
|
4
4
|
const UsageBodySchema = z.object({
|
|
5
5
|
eventName: z.string().min(1, "eventName is required"),
|
|
6
6
|
quantity: z.number().int().positive().optional().default(1),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineEventHandler, createError } from "nuxt/server";
|
|
2
|
-
import { processPaymentWebhook } from "../../utils/payments.mjs";
|
|
2
|
+
import { processPaymentWebhook } from "../../utils/payments/index.mjs";
|
|
3
3
|
export default defineEventHandler(async (event) => {
|
|
4
4
|
let rawBody;
|
|
5
5
|
if (event?.req?.text) {
|
|
@@ -17,5 +17,12 @@ export default defineEventHandler(async (event) => {
|
|
|
17
17
|
throw createError({ statusCode: 400, message: "Empty request body" });
|
|
18
18
|
}
|
|
19
19
|
const result = await processPaymentWebhook(event, rawBody);
|
|
20
|
+
if (result.error === "invalid_signature" || result.success === false) {
|
|
21
|
+
throw createError({
|
|
22
|
+
statusCode: 401,
|
|
23
|
+
statusMessage: "Unauthorized",
|
|
24
|
+
message: "Invalid webhook signature"
|
|
25
|
+
});
|
|
26
|
+
}
|
|
20
27
|
return { received: true, ...result };
|
|
21
28
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineEventHandler, readBody, createError } from "nuxt/server";
|
|
2
2
|
import { getAuthContext } from "../../utils/context.mjs";
|
|
3
|
-
import { broadcastToRoom } from "../../utils/realtime.mjs";
|
|
3
|
+
import { broadcastToRoom, assertSafeRoomName } from "../../utils/realtime.mjs";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
5
|
const auth = await getAuthContext(event).catch(() => null);
|
|
6
6
|
if (!auth?.user?.id) {
|
|
@@ -25,8 +25,9 @@ export default defineEventHandler(async (event) => {
|
|
|
25
25
|
statusMessage: "Missing required fields: room and event are required."
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
|
+
const room = assertSafeRoomName(body.room);
|
|
28
29
|
const sender = auth?.user?.name || auth?.user?.email || body.sender || "server";
|
|
29
|
-
await broadcastToRoom(event,
|
|
30
|
+
await broadcastToRoom(event, room, body.event, body.payload, {
|
|
30
31
|
sender,
|
|
31
32
|
excludePeerId: body.excludePeerId
|
|
32
33
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineEventHandler, getQuery, createError } from "nuxt/server";
|
|
2
2
|
import { getAuthContext } from "../../utils/context.mjs";
|
|
3
|
-
import { clearRoomHistory } from "../../utils/realtime.mjs";
|
|
3
|
+
import { clearRoomHistory, assertSafeRoomName } from "../../utils/realtime.mjs";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
5
|
const auth = await getAuthContext(event).catch(() => null);
|
|
6
6
|
if (!auth?.user?.id) {
|
|
@@ -19,7 +19,7 @@ export default defineEventHandler(async (event) => {
|
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
const query = getQuery(event);
|
|
22
|
-
const room = query.room || "general";
|
|
22
|
+
const room = assertSafeRoomName(query.room || "general");
|
|
23
23
|
const ok = await clearRoomHistory(event, room);
|
|
24
24
|
return {
|
|
25
25
|
success: ok,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineEventHandler, getQuery, createError } from "nuxt/server";
|
|
2
2
|
import { getAuthContext } from "../../utils/context.mjs";
|
|
3
|
-
import { getRoomHistory } from "../../utils/realtime.mjs";
|
|
3
|
+
import { getRoomHistory, assertSafeRoomName } from "../../utils/realtime.mjs";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
5
|
const auth = await getAuthContext(event).catch(() => null);
|
|
6
6
|
if (!auth?.user?.id) {
|
|
@@ -11,7 +11,7 @@ export default defineEventHandler(async (event) => {
|
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
13
|
const query = getQuery(event);
|
|
14
|
-
const room = query.room || "general";
|
|
14
|
+
const room = assertSafeRoomName(query.room || "general");
|
|
15
15
|
const limit = query.limit ? parseInt(query.limit, 10) : void 0;
|
|
16
16
|
const sinceSeq = query.sinceSeq ? parseInt(query.sinceSeq, 10) : void 0;
|
|
17
17
|
const since = query.since ? parseInt(query.since, 10) : void 0;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineEventHandler, getQuery, createError } from "nuxt/server";
|
|
2
2
|
import { getAuthContext } from "../../utils/context.mjs";
|
|
3
|
-
import { getRoomPresence } from "../../utils/realtime.mjs";
|
|
3
|
+
import { getRoomPresence, assertSafeRoomName } from "../../utils/realtime.mjs";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
5
|
const auth = await getAuthContext(event).catch(() => null);
|
|
6
6
|
if (!auth?.user?.id) {
|
|
@@ -11,13 +11,13 @@ export default defineEventHandler(async (event) => {
|
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
13
|
const query = getQuery(event);
|
|
14
|
-
|
|
15
|
-
if (!room) {
|
|
14
|
+
if (!query.room) {
|
|
16
15
|
throw createError({
|
|
17
16
|
statusCode: 400,
|
|
18
17
|
statusMessage: "Query parameter 'room' is required."
|
|
19
18
|
});
|
|
20
19
|
}
|
|
20
|
+
const room = assertSafeRoomName(query.room);
|
|
21
21
|
const presence = await getRoomPresence(event, room);
|
|
22
22
|
return {
|
|
23
23
|
room,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineEventHandler, getQuery, createError } from "nuxt/server";
|
|
2
2
|
import { getAuthContext } from "../../utils/context.mjs";
|
|
3
|
-
import { getRoomState } from "../../utils/realtime.mjs";
|
|
3
|
+
import { getRoomState, assertSafeRoomName } from "../../utils/realtime.mjs";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
5
|
const auth = await getAuthContext(event).catch(() => null);
|
|
6
6
|
if (!auth?.user?.id) {
|
|
@@ -11,13 +11,13 @@ export default defineEventHandler(async (event) => {
|
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
13
|
const query = getQuery(event);
|
|
14
|
-
|
|
15
|
-
if (!room) {
|
|
14
|
+
if (!query.room) {
|
|
16
15
|
throw createError({
|
|
17
16
|
statusCode: 400,
|
|
18
17
|
statusMessage: "Query parameter 'room' is required."
|
|
19
18
|
});
|
|
20
19
|
}
|
|
20
|
+
const room = assertSafeRoomName(query.room);
|
|
21
21
|
const state = await getRoomState(event, room);
|
|
22
22
|
return {
|
|
23
23
|
room,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineEventHandler, readBody, createError } from "nuxt/server";
|
|
2
2
|
import { getAuthContext } from "../../utils/context.mjs";
|
|
3
|
-
import { patchRoomState, setRoomState } from "../../utils/realtime.mjs";
|
|
3
|
+
import { patchRoomState, setRoomState, assertSafeRoomName } from "../../utils/realtime.mjs";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
5
|
const auth = await getAuthContext(event).catch(() => null);
|
|
6
6
|
if (!auth?.user?.id) {
|
|
@@ -10,6 +10,14 @@ export default defineEventHandler(async (event) => {
|
|
|
10
10
|
message: "Authentication required to update room state."
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
|
+
const userRole = auth.user.role || "user";
|
|
14
|
+
if (userRole !== "admin") {
|
|
15
|
+
throw createError({
|
|
16
|
+
statusCode: 403,
|
|
17
|
+
statusMessage: "Forbidden",
|
|
18
|
+
message: "Admin role required to use the realtime state control-plane."
|
|
19
|
+
});
|
|
20
|
+
}
|
|
13
21
|
const body = await readBody(event) || {};
|
|
14
22
|
if (!body.room) {
|
|
15
23
|
throw createError({
|
|
@@ -17,6 +25,7 @@ export default defineEventHandler(async (event) => {
|
|
|
17
25
|
statusMessage: "Field 'room' is required."
|
|
18
26
|
});
|
|
19
27
|
}
|
|
28
|
+
const room = assertSafeRoomName(body.room);
|
|
20
29
|
if (!body.state && !body.patch) {
|
|
21
30
|
throw createError({
|
|
22
31
|
statusCode: 400,
|
|
@@ -25,13 +34,13 @@ export default defineEventHandler(async (event) => {
|
|
|
25
34
|
}
|
|
26
35
|
let state;
|
|
27
36
|
if (body.patch) {
|
|
28
|
-
state = await patchRoomState(event,
|
|
37
|
+
state = await patchRoomState(event, room, body.patch);
|
|
29
38
|
} else {
|
|
30
|
-
state = await setRoomState(event,
|
|
39
|
+
state = await setRoomState(event, room, body.state);
|
|
31
40
|
}
|
|
32
41
|
return {
|
|
33
42
|
ok: true,
|
|
34
|
-
room
|
|
43
|
+
room,
|
|
35
44
|
state
|
|
36
45
|
};
|
|
37
46
|
});
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
} from "nuxt/server";
|
|
7
7
|
import { getQarpeoConfig } from "../../utils/config.mjs";
|
|
8
8
|
import { getAuthContext } from "../../utils/context.mjs";
|
|
9
|
-
import { getRoomDurableObject } from "../../utils/realtime.mjs";
|
|
9
|
+
import { getRoomDurableObject, assertSafeRoomName } from "../../utils/realtime.mjs";
|
|
10
10
|
function resolveWebRequest(event) {
|
|
11
11
|
const ev = event;
|
|
12
12
|
if (ev.web?.request) {
|
|
@@ -29,7 +29,7 @@ function resolveWebRequest(event) {
|
|
|
29
29
|
}
|
|
30
30
|
export default defineEventHandler(async (event) => {
|
|
31
31
|
const query = getQuery(event);
|
|
32
|
-
const room = query.room || "general";
|
|
32
|
+
const room = assertSafeRoomName(query.room || "general");
|
|
33
33
|
const realtimeConfig = getQarpeoConfig(event).realtime;
|
|
34
34
|
const requireAuth = realtimeConfig.requireAuth === true || realtimeConfig.auth === true;
|
|
35
35
|
let user = null;
|
|
@@ -30,7 +30,7 @@ export default defineEventHandler(async (event) => {
|
|
|
30
30
|
message: "Storage key is required"
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
|
-
if (key.includes("..") || key.includes("\\")) {
|
|
33
|
+
if (key.includes("..") || key.includes("\\") || key.includes("\0")) {
|
|
34
34
|
throw createError({
|
|
35
35
|
statusCode: 400,
|
|
36
36
|
statusMessage: "Bad Request",
|
|
@@ -20,5 +20,12 @@ export default defineEventHandler(async (event) => {
|
|
|
20
20
|
message: `Storage key is required. Context params: ${JSON.stringify(event.context.params || {})}`
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
|
+
if (key.includes("..") || key.includes("\\") || key.includes("\0")) {
|
|
24
|
+
throw createError({
|
|
25
|
+
statusCode: 400,
|
|
26
|
+
statusMessage: "Bad Request",
|
|
27
|
+
message: "Invalid storage key"
|
|
28
|
+
});
|
|
29
|
+
}
|
|
23
30
|
return await serveStorageFile(event, key);
|
|
24
31
|
});
|
|
@@ -6,7 +6,7 @@ declare const _default: import("nuxt/server").EventHandler<Promise<{
|
|
|
6
6
|
uploaded: string;
|
|
7
7
|
url: string;
|
|
8
8
|
pathname: string;
|
|
9
|
-
access: import("
|
|
9
|
+
access: import("../../../storage-server").BlobAccessTier;
|
|
10
10
|
}>;
|
|
11
11
|
cursor?: string;
|
|
12
12
|
truncated: boolean;
|