@frigear-nu/events 0.4.0 → 0.5.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/module.json +1 -1
- package/dist/module.mjs +3 -41
- package/dist/runtime/access.d.ts +1 -0
- package/dist/runtime/access.js +39 -0
- package/dist/runtime/menus.js +2 -1
- package/dist/runtime/server/mcp/schemas.d.ts +2 -2
- package/dist/runtime/server/routes/admin/event.get.js +2 -1
- package/dist/runtime/server/routes/admin/ticket-refund.post.js +3 -2
- package/dist/runtime/server/routes/me/ticket-pay.post.js +3 -2
- package/dist/runtime/server/utils/admin.d.ts +6 -5
- package/dist/runtime/server/utils/admin.js +2 -1
- package/package.json +11 -11
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { defineNuxtModule, createResolver, hasNuxtModule, addServerImportsDir, addServerPlugin, addImports, addComponentsDir } from '@nuxt/kit';
|
|
2
2
|
import { registerModule, registerTailwindSource, registerLocales, resolvePagePath, registerDatabaseTable, addModuleRoutes, registerBootstrapProvider, inlineModuleRuntime, addModulePages, addOptionalMenuSource } from '@frigear-nu/module-kit/utils';
|
|
3
3
|
import { adminRoute } from '@frigear-nu/admin/utils';
|
|
4
|
-
import {
|
|
4
|
+
import { registerAccess } from '@frigear-nu/auth/utils';
|
|
5
|
+
import { eventsAccess } from '../dist/runtime/access.js';
|
|
5
6
|
import { addMcpDefinitions } from '@frigear-nu/mcp/utils';
|
|
6
7
|
|
|
7
8
|
const MODULE_NAME = "@frigear-nu/events";
|
|
@@ -30,46 +31,7 @@ const module$1 = defineNuxtModule({
|
|
|
30
31
|
},
|
|
31
32
|
async setup(options, nuxt) {
|
|
32
33
|
registerModule(MODULE_NAME, nuxt);
|
|
33
|
-
|
|
34
|
-
addPermission(
|
|
35
|
-
nuxt,
|
|
36
|
-
{ name: "events:manage", label: "Manage events", labelKey: "events.permissions.manage", description: "Create and edit events, ticket types and add-ons, and check tickets in.", descriptionKey: "events.permissions.manageDescription", group: "events", grantTo: staffRoles },
|
|
37
|
-
{
|
|
38
|
-
name: "events:pii",
|
|
39
|
-
label: "See attendee details",
|
|
40
|
-
labelKey: "events.permissions.pii",
|
|
41
|
-
description: "See attendee names and emails (MCP tools). Never covered by a wildcard.",
|
|
42
|
-
descriptionKey: "events.permissions.piiDescription",
|
|
43
|
-
group: "events",
|
|
44
|
-
sensitive: true,
|
|
45
|
-
grantTo: staffRoles
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
// Money moves: only a signed-in session may refund, never an API or OAuth token (`sessionOnly`). Roles that
|
|
49
|
-
// grant `events:manage` by name need to grant this too (`events:*` covers it).
|
|
50
|
-
name: "events:refund",
|
|
51
|
-
label: "Refund tickets",
|
|
52
|
-
labelKey: "events.permissions.refund",
|
|
53
|
-
description: "Refund a paid ticket. Cookie sessions only.",
|
|
54
|
-
descriptionKey: "events.permissions.refundDescription",
|
|
55
|
-
group: "events",
|
|
56
|
-
sessionOnly: true,
|
|
57
|
-
grantTo: staffRoles
|
|
58
|
-
},
|
|
59
|
-
{ name: "tickets:read", label: "Read your tickets", labelKey: "events.permissions.ticketsRead", description: "Read your tickets and event details.", group: "tickets", implicit: true },
|
|
60
|
-
{ name: "tickets:write", label: "Buy tickets", labelKey: "events.permissions.ticketsWrite", description: "Buy tickets and pay for them.", group: "tickets", implicit: true }
|
|
61
|
-
);
|
|
62
|
-
addScope(nuxt, {
|
|
63
|
-
name: "tickets",
|
|
64
|
-
label: "Your tickets",
|
|
65
|
-
labelKey: "events.scopes.tickets",
|
|
66
|
-
description: "Read your tickets and event details, and buy tickets.",
|
|
67
|
-
icon: "i-lucide-ticket",
|
|
68
|
-
permissions: ["tickets:read", "tickets:write"]
|
|
69
|
-
});
|
|
70
|
-
if (options.settings?.roles) {
|
|
71
|
-
addRole(nuxt, { name: "eventmanager", label: "Event manager", labelKey: "events.roles.eventmanager", grant: ["events:manage", "events:refund", "events:pii"], from: MODULE_NAME });
|
|
72
|
-
}
|
|
34
|
+
registerAccess(nuxt, eventsAccess, { roles: !!options.settings?.roles, from: MODULE_NAME });
|
|
73
35
|
const resolver = createResolver(import.meta.url);
|
|
74
36
|
registerTailwindSource(nuxt, resolver.resolve("./runtime/app"));
|
|
75
37
|
registerLocales(nuxt, resolver.resolve("./runtime/i18n/lang"));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const eventsAccess: import("@frigear-nu/auth/access").Access<"events", "manage" | "pii" | "refund" | "tickets:read" | "tickets:write", "tickets", "eventmanager">;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { defineAccess } from "@frigear-nu/auth/access";
|
|
2
|
+
export const eventsAccess = defineAccess("events", {
|
|
3
|
+
permissions: {
|
|
4
|
+
"manage": {
|
|
5
|
+
label: "Manage events",
|
|
6
|
+
description: "Create and edit events, ticket types and add-ons, and check tickets in.",
|
|
7
|
+
grantTo: ["admin", "eventmanager"]
|
|
8
|
+
},
|
|
9
|
+
"pii": {
|
|
10
|
+
label: "See attendee details",
|
|
11
|
+
description: "See attendee names and emails (MCP tools). Never covered by a wildcard.",
|
|
12
|
+
sensitive: true,
|
|
13
|
+
grantTo: ["admin", "eventmanager"]
|
|
14
|
+
},
|
|
15
|
+
// Money moves: only a signed-in session may refund, never an API or OAuth token (`sessionOnly`). Roles that grant
|
|
16
|
+
// `events:manage` by name need to grant this too (`events:*` covers it).
|
|
17
|
+
"refund": {
|
|
18
|
+
label: "Refund tickets",
|
|
19
|
+
description: "Refund a paid ticket. Cookie sessions only.",
|
|
20
|
+
sessionOnly: true,
|
|
21
|
+
grantTo: ["admin", "eventmanager"]
|
|
22
|
+
},
|
|
23
|
+
// Self-service: every signed-in user holds these, also without `@frigear-nu/authorization`.
|
|
24
|
+
"tickets:read": { label: "Read your tickets", description: "Read your tickets and event details.", implicit: true },
|
|
25
|
+
"tickets:write": { label: "Buy tickets", description: "Buy tickets and pay for them.", implicit: true }
|
|
26
|
+
},
|
|
27
|
+
scopes: {
|
|
28
|
+
tickets: {
|
|
29
|
+
label: "Your tickets",
|
|
30
|
+
description: "Read your tickets and event details, and buy tickets.",
|
|
31
|
+
icon: "i-lucide-ticket",
|
|
32
|
+
permissions: ["tickets:read", "tickets:write"]
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
roles: {
|
|
36
|
+
// Opt-in (`events.settings.roles`): registered only then, and the permissions' `grantTo` skips it otherwise.
|
|
37
|
+
eventmanager: { label: "Event manager", grant: ["events:manage", "events:refund", "events:pii"] }
|
|
38
|
+
}
|
|
39
|
+
});
|
package/dist/runtime/menus.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { defineMenuItem, defineMenuSource, extendMenuItem } from "@frigear-nu/menu/utils";
|
|
2
2
|
import { useRuntimeConfig } from "#imports";
|
|
3
|
+
import { eventsAccess } from "./access.js";
|
|
3
4
|
export default defineMenuSource(() => {
|
|
4
5
|
const config = useRuntimeConfig().public.events;
|
|
5
6
|
if (config?.pages?.tickets) {
|
|
@@ -23,7 +24,7 @@ export default defineMenuSource(() => {
|
|
|
23
24
|
descriptionKey: "events.menu.admin.description",
|
|
24
25
|
icon: "i-lucide-calendar-days",
|
|
25
26
|
to: config.pages.admin,
|
|
26
|
-
permission:
|
|
27
|
+
permission: eventsAccess.permissions.manage,
|
|
27
28
|
order: 20
|
|
28
29
|
}));
|
|
29
30
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
export declare const ticketTypeFields: z.ZodObject<{
|
|
3
3
|
name: z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>;
|
|
4
|
-
key: z.ZodString;
|
|
5
4
|
description: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>>;
|
|
5
|
+
key: z.ZodString;
|
|
6
6
|
currency: z.ZodOptional<z.ZodString>;
|
|
7
7
|
price: z.ZodOptional<z.ZodNumber>;
|
|
8
8
|
hidePrice: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -102,8 +102,8 @@ export declare const updateTicketTypeShape: {
|
|
|
102
102
|
id: z.ZodString;
|
|
103
103
|
patch: z.ZodObject<{
|
|
104
104
|
name: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>;
|
|
105
|
-
key: z.ZodOptional<z.ZodString>;
|
|
106
105
|
description: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>>>>;
|
|
106
|
+
key: z.ZodOptional<z.ZodString>;
|
|
107
107
|
currency: z.ZodOptional<z.ZodOptional<z.ZodString>>;
|
|
108
108
|
price: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
|
|
109
109
|
hidePrice: z.ZodOptional<z.ZodOptional<z.ZodBoolean>>;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { idParams } from "@frigear-nu/module-kit/server";
|
|
2
2
|
import { authorizeEventsRecord, getEventWithTicketTypes } from "../../utils/admin.js";
|
|
3
|
+
import { eventsAccess } from "../../../access.js";
|
|
3
4
|
export default defineEventHandler(async (event) => {
|
|
4
|
-
await authorize(event,
|
|
5
|
+
await authorize(event, eventsAccess.permissions.manage);
|
|
5
6
|
const { id } = await getValidatedRouterParams(event, idParams().parse);
|
|
6
7
|
await authorizeEventsRecord(event, id);
|
|
7
8
|
return toAdminEventDetailDto(await getEventWithTicketTypes(id));
|
|
@@ -2,12 +2,13 @@ import { db, schema } from "@nuxthub/db";
|
|
|
2
2
|
import { eq } from "drizzle-orm";
|
|
3
3
|
import { conflict, idParams, notFound } from "@frigear-nu/module-kit/server";
|
|
4
4
|
import { authorizeEventsRecord } from "../../utils/admin.js";
|
|
5
|
+
import { eventsAccess } from "../../../access.js";
|
|
5
6
|
export default defineEventHandler(async (event) => {
|
|
6
|
-
await authorize(event,
|
|
7
|
+
await authorize(event, eventsAccess.permissions.refund);
|
|
7
8
|
const { id } = await getValidatedRouterParams(event, idParams().parse);
|
|
8
9
|
const [ticket] = await db.select().from(schema.eventTickets).where(eq(schema.eventTickets.id, id)).limit(1);
|
|
9
10
|
if (!ticket) throw notFound("Ticket not found.");
|
|
10
|
-
await authorizeEventsRecord(event, ticket.eventId,
|
|
11
|
+
await authorizeEventsRecord(event, ticket.eventId, eventsAccess.permissions.refund);
|
|
11
12
|
if (ticket.status !== "paid" || !ticket.paymentId) throw conflict("Only paid tickets with a payment can be refunded.", { status: ticket.status });
|
|
12
13
|
await refundPayment(ticket.paymentId);
|
|
13
14
|
return toAttendeeDto(ticket, await ticketHolder(ticket.userId));
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { db, schema } from "@nuxthub/db";
|
|
2
2
|
import { and, eq } from "drizzle-orm";
|
|
3
3
|
import { conflict, idParams, notFound } from "@frigear-nu/module-kit/server";
|
|
4
|
+
import { eventsAccess } from "../../../access.js";
|
|
4
5
|
export default defineEventHandler(async (event) => {
|
|
5
|
-
const { user } = await authorize(event, "tickets:write");
|
|
6
|
+
const { user } = await authorize(event, eventsAccess.permissions["tickets:write"]);
|
|
6
7
|
const { id } = await getValidatedRouterParams(event, idParams().parse);
|
|
7
8
|
const [ticket] = await db.select().from(schema.eventTickets).where(and(eq(schema.eventTickets.id, id), eq(schema.eventTickets.userId, user.id))).limit(1);
|
|
8
9
|
if (!ticket) throw notFound("Ticket not found.");
|
|
9
|
-
await authorize(event, "tickets:write", ticket);
|
|
10
|
+
await authorize(event, eventsAccess.permissions["tickets:write"], ticket);
|
|
10
11
|
if (ticket.status === "paid") throw conflict("This ticket is already paid.", { status: ticket.status });
|
|
11
12
|
if (ticket.status !== "pending" || !ticket.paymentId) throw conflict("This ticket can no longer be paid. Buy a new one.", { status: ticket.status });
|
|
12
13
|
const { url } = await resumePayment(ticket.paymentId, user.id, event);
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { H3Event } from 'h3';
|
|
2
2
|
import type { z } from 'zod';
|
|
3
3
|
import { eventInput, ticketTypeInput } from './admin-schemas.js';
|
|
4
|
+
import { eventsAccess } from '../../access.js';
|
|
4
5
|
import type { addonGroupInput } from './admin-schemas.js';
|
|
5
6
|
type TicketTypeInput = z.output<typeof ticketTypeInput>;
|
|
6
7
|
type AddonGroupInput = z.output<typeof addonGroupInput>;
|
|
7
8
|
/** The permissions whose record-level policies run on one event. */
|
|
8
|
-
export type EventsRecordPermission =
|
|
9
|
+
export type EventsRecordPermission = typeof eventsAccess.permissions.manage | typeof eventsAccess.permissions.refund;
|
|
9
10
|
/**
|
|
10
11
|
* Loads the event `eventId` (404 `not_found`) and authorizes `permission` on it. Every record-level check of
|
|
11
12
|
* `events:manage` and `events:refund` goes through here, so their policies always receive the stored EVENT row
|
|
@@ -39,14 +40,14 @@ export declare const eventPatchSchema: z.ZodObject<{
|
|
|
39
40
|
name: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodRecord<z.ZodString, z.ZodString>, z.ZodTransform<{
|
|
40
41
|
[k: string]: string;
|
|
41
42
|
}, Record<string, string>>>]>>;
|
|
43
|
+
description: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodRecord<z.ZodString, z.ZodString>, z.ZodTransform<{
|
|
44
|
+
[k: string]: string;
|
|
45
|
+
}, Record<string, string>>>]>>>>;
|
|
42
46
|
status: z.ZodOptional<z.ZodOptional<z.ZodEnum<{
|
|
43
47
|
draft: "draft";
|
|
44
48
|
published: "published";
|
|
45
49
|
archived: "archived";
|
|
46
50
|
}>>>;
|
|
47
|
-
description: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodRecord<z.ZodString, z.ZodString>, z.ZodTransform<{
|
|
48
|
-
[k: string]: string;
|
|
49
|
-
}, Record<string, string>>>]>>>>;
|
|
50
51
|
image: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
|
|
51
52
|
slug: z.ZodOptional<z.ZodString>;
|
|
52
53
|
body: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodRecord<z.ZodString, z.ZodString>, z.ZodTransform<{
|
|
@@ -65,10 +66,10 @@ export declare const ticketTypePatchSchema: z.ZodObject<{
|
|
|
65
66
|
name: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodRecord<z.ZodString, z.ZodString>, z.ZodTransform<{
|
|
66
67
|
[k: string]: string;
|
|
67
68
|
}, Record<string, string>>>]>>;
|
|
68
|
-
key: z.ZodOptional<z.ZodString>;
|
|
69
69
|
description: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodRecord<z.ZodString, z.ZodString>, z.ZodTransform<{
|
|
70
70
|
[k: string]: string;
|
|
71
71
|
}, Record<string, string>>>]>>>>;
|
|
72
|
+
key: z.ZodOptional<z.ZodString>;
|
|
72
73
|
currency: z.ZodOptional<z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>>;
|
|
73
74
|
price: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
|
|
74
75
|
hidePrice: z.ZodOptional<z.ZodOptional<z.ZodBoolean>>;
|
|
@@ -4,7 +4,8 @@ import { and, asc, eq } from "drizzle-orm";
|
|
|
4
4
|
import { badRequest, conflict, notFound } from "@frigear-nu/module-kit/server";
|
|
5
5
|
import { loadCatalog } from "./catalog.js";
|
|
6
6
|
import { eventInput, ticketTypeInput } from "./admin-schemas.js";
|
|
7
|
-
|
|
7
|
+
import { eventsAccess } from "../../access.js";
|
|
8
|
+
export async function authorizeEventsRecord(event, eventId, permission = eventsAccess.permissions.manage) {
|
|
8
9
|
const [row] = await db.select().from(schema.events).where(eq(schema.events.id, eventId)).limit(1);
|
|
9
10
|
if (!row) throw notFound("Event not found.");
|
|
10
11
|
await authorize(event, permission, row);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frigear-nu/events",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Events with ticket types, addons, capacity, membership requirements, Stripe payments and QR check-in for the frigear ecosystem, built on @frigear-nu/payments.",
|
|
5
5
|
"homepage": "https://docs.frigear.dev/modules/features/events",
|
|
6
6
|
"repository": {
|
|
@@ -35,15 +35,15 @@
|
|
|
35
35
|
"playground"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@frigear-nu/admin": "^0.
|
|
39
|
-
"@frigear-nu/auth": "^0.
|
|
40
|
-
"@frigear-nu/mcp": "^0.
|
|
38
|
+
"@frigear-nu/admin": "^0.5.0",
|
|
39
|
+
"@frigear-nu/auth": "^0.6.0",
|
|
40
|
+
"@frigear-nu/mcp": "^0.5.0",
|
|
41
41
|
"@frigear-nu/module-kit": "^1.3.5",
|
|
42
|
-
"@frigear-nu/payments": "^0.
|
|
42
|
+
"@frigear-nu/payments": "^0.5.0",
|
|
43
43
|
"@frigear-nu/stripe": "^0.4.0",
|
|
44
|
-
"@frigear-nu/subscriptions": "^0.
|
|
44
|
+
"@frigear-nu/subscriptions": "^0.5.0",
|
|
45
45
|
"@frigear-nu/ui": "^0.2.6",
|
|
46
|
-
"@frigear-nu/users": "^3.
|
|
46
|
+
"@frigear-nu/users": "^3.1.0",
|
|
47
47
|
"@libsql/client": "^0.18.0",
|
|
48
48
|
"@nuxt/kit": "^4.6.4",
|
|
49
49
|
"@vueuse/core": "^15.0.0",
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
"zod": "^4.6.7"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
|
-
"@frigear-nu/menu": "^0.
|
|
59
|
-
"@frigear-nu/widget": "^0.
|
|
58
|
+
"@frigear-nu/menu": "^0.4.0",
|
|
59
|
+
"@frigear-nu/widget": "^0.4.0",
|
|
60
60
|
"@nuxt/ui": "^4.12.0",
|
|
61
61
|
"@nuxthub/core": "^0.10.12"
|
|
62
62
|
},
|
|
@@ -72,8 +72,8 @@
|
|
|
72
72
|
}
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
|
-
"@frigear-nu/menu": "^0.
|
|
76
|
-
"@frigear-nu/widget": "^0.
|
|
75
|
+
"@frigear-nu/menu": "^0.4.0",
|
|
76
|
+
"@frigear-nu/widget": "^0.4.0",
|
|
77
77
|
"@nuxt/devtools": "^4.1.0",
|
|
78
78
|
"@nuxt/eslint-config": "^1.17.0",
|
|
79
79
|
"@nuxt/module-builder": "^1.0.3",
|