@frigear-nu/events 0.3.1 → 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.
Files changed (54) hide show
  1. package/README.md +21 -3
  2. package/dist/module.d.mts +4 -12
  3. package/dist/module.json +1 -1
  4. package/dist/module.mjs +3 -12
  5. package/dist/runtime/access.d.ts +1 -0
  6. package/dist/runtime/access.js +39 -0
  7. package/dist/runtime/i18n/lang/da.json +17 -1
  8. package/dist/runtime/i18n/lang/en.json +17 -1
  9. package/dist/runtime/menus.js +2 -0
  10. package/dist/runtime/server/bootstrap/my-tickets.js +1 -1
  11. package/dist/runtime/server/mcp/schemas.d.ts +2 -2
  12. package/dist/runtime/server/mcp/tools/admin/create-event.js +1 -2
  13. package/dist/runtime/server/mcp/tools/admin/get-event-definition.js +6 -4
  14. package/dist/runtime/server/mcp/tools/admin/list-all-events.js +1 -2
  15. package/dist/runtime/server/mcp/tools/admin/list-attendees.js +5 -4
  16. package/dist/runtime/server/mcp/tools/admin/update-event.js +6 -4
  17. package/dist/runtime/server/mcp/tools/admin/update-ticket-type.js +4 -4
  18. package/dist/runtime/server/mcp/tools/get-event.js +1 -1
  19. package/dist/runtime/server/mcp/tools/list-events.js +1 -1
  20. package/dist/runtime/server/mcp/tools/my-tickets.js +1 -1
  21. package/dist/runtime/server/routes/admin/addon-group.delete.js +3 -1
  22. package/dist/runtime/server/routes/admin/addon-group.patch.js +3 -1
  23. package/dist/runtime/server/routes/admin/addon-groups.post.js +4 -7
  24. package/dist/runtime/server/routes/admin/addon.delete.js +3 -1
  25. package/dist/runtime/server/routes/admin/addon.patch.js +3 -1
  26. package/dist/runtime/server/routes/admin/addons.post.js +4 -5
  27. package/dist/runtime/server/routes/admin/attendees.get.js +3 -2
  28. package/dist/runtime/server/routes/admin/check-in.post.js +4 -1
  29. package/dist/runtime/server/routes/admin/event-clone.post.js +2 -1
  30. package/dist/runtime/server/routes/admin/event.delete.js +3 -2
  31. package/dist/runtime/server/routes/admin/event.get.js +4 -2
  32. package/dist/runtime/server/routes/admin/event.patch.js +7 -2
  33. package/dist/runtime/server/routes/admin/events.get.js +1 -1
  34. package/dist/runtime/server/routes/admin/events.post.js +1 -1
  35. package/dist/runtime/server/routes/admin/membership-options.get.js +1 -1
  36. package/dist/runtime/server/routes/admin/ticket-cancel.post.js +3 -1
  37. package/dist/runtime/server/routes/admin/ticket-refund.post.js +4 -1
  38. package/dist/runtime/server/routes/admin/ticket-type.delete.js +4 -4
  39. package/dist/runtime/server/routes/admin/ticket-type.patch.js +3 -2
  40. package/dist/runtime/server/routes/admin/ticket-types.post.js +4 -7
  41. package/dist/runtime/server/routes/admin/upcoming.get.js +1 -1
  42. package/dist/runtime/server/routes/me/ticket-pay.post.js +3 -1
  43. package/dist/runtime/server/routes/me/ticket.get.js +1 -1
  44. package/dist/runtime/server/routes/public/event.get.js +2 -2
  45. package/dist/runtime/server/routes/public/purchase.post.js +1 -1
  46. package/dist/runtime/server/utils/admin.d.ts +22 -4
  47. package/dist/runtime/server/utils/admin.js +22 -0
  48. package/dist/runtime/utils/index.d.ts +1 -1
  49. package/dist/types.d.mts +1 -1
  50. package/package.json +12 -12
  51. package/dist/runtime/server/plugins/staff-scopes.d.ts +0 -2
  52. package/dist/runtime/server/plugins/staff-scopes.js +0 -1
  53. package/dist/runtime/server/utils/auth.d.ts +0 -12
  54. package/dist/runtime/server/utils/auth.js +0 -6
package/README.md CHANGED
@@ -18,14 +18,32 @@ export default defineNuxtConfig({
18
18
 
19
19
  Generate and commit a migration for the events tables in your app (see the repository `AGENTS.md`).
20
20
 
21
- Staff routes (event management, check-in) are denied until the host implements the `events:authorize` Nitro hook:
21
+ Staff routes (event management, check-in) need the `events:manage` permission (attendee details over MCP need `events:pii`,
22
+ refunds the session-only `events:refund`). Grant them to a role, either the module's `eventmanager` role
23
+ (`events: { settings: { roles: true } }`) or your own:
22
24
 
23
25
  ```ts
24
- export default defineNitroPlugin((nitro) => {
25
- nitro.hooks.hook('events:authorize', (ctx) => { ctx.allowed = isStaff(ctx.userId) })
26
+ export default defineNuxtConfig({
27
+ authorization: { roles: { coordinator: { label: 'Coordinator', grant: ['events:manage', 'events:refund', 'events:pii'] } } },
26
28
  })
27
29
  ```
28
30
 
31
+ Policies on `events:manage` and `events:refund` (`definePolicy`) receive the event row (`typeof schema.events.$inferSelect`)
32
+ as their `record`, on every route and MCP tool: also when the action is on a ticket type, add-on group, add-on or ticket,
33
+ the policy gets the event it belongs to (never the child row). Checks without a record (listing, creating an event) run
34
+ the policy only with `withoutRecord`.
35
+
36
+ ```ts
37
+ // server/policies.ts: youth coordinators manage the `youth-*` events only
38
+ export default [
39
+ definePolicy<typeof schema.events.$inferSelect>('events:manage', async ({ event, user, record }) =>
40
+ (await getEffectiveRoles(event, user)).includes('youth') ? record?.slug.startsWith('youth-') : undefined),
41
+ ]
42
+ ```
43
+
44
+ Tickets (`tickets:read`, `tickets:write`) are self-service: every signed-in user holds them. The named scope `tickets`
45
+ offers both to API tokens and OAuth clients.
46
+
29
47
  Full documentation: `apps/docs/content/3.modules/3.features/1.events/index.md`.
30
48
 
31
49
  ## Development
package/dist/module.d.mts CHANGED
@@ -11,8 +11,8 @@ type TicketStatus = 'pending' | 'paid' | 'cancelled' | 'refunded' | 'expired';
11
11
  type ModuleOptions = {
12
12
  settings?: {
13
13
  /**
14
- * Ship an `eventmanager` role (role-based access control, `@frigear-nu/authorization`): every user's permissions
15
- * plus `events:manage` and `events:pii`, just below `admin`. Defaults to `false`.
14
+ * Ship an `eventmanager` role (role-based access control): `events:manage`, `events:refund` and `events:pii`. `admin` holds both
15
+ * either way. Defaults to `false`.
16
16
  */
17
17
  roles?: boolean;
18
18
  mcp?: boolean;
@@ -23,7 +23,7 @@ type ModuleOptions = {
23
23
  event?: string | boolean;
24
24
  /** The signed-in user's tickets. `true` = `/account/tickets`. */
25
25
  tickets?: string | boolean;
26
- /** Staff event list (needs the `events:authorize` hook to allow staff). `true` = `/admin/events`. Off by default. */
26
+ /** Staff event list (needs the `events:manage` permission). `true` = `/admin/events`. Off by default. */
27
27
  admin?: string | boolean;
28
28
  /** Staff event page (details, ticket types, attendees); must contain an `:id` param. `true` = `/admin/events/:id`. Off by default. */
29
29
  adminEvent?: string | boolean;
@@ -249,12 +249,6 @@ type PurchaseBeforeContext = {
249
249
  ticketTypeId: string;
250
250
  addonIds: string[];
251
251
  };
252
- type AuthorizeContext = {
253
- event: H3Event;
254
- userId: number;
255
- /** Set `ctx.allowed = true` to let the user manage events / check tickets in. Denied by default. */
256
- allowed: boolean;
257
- };
258
252
  /** A selectable membership (plan) offered by a membership provider. */
259
253
  type MembershipOption = {
260
254
  value: string;
@@ -292,8 +286,6 @@ declare module '@nuxt/schema' {
292
286
  }
293
287
  declare module 'nitropack' {
294
288
  interface NitroRuntimeHooks {
295
- /** Staff gate (event management, check-in): set `ctx.allowed = true` to let the user in. Denied by default. */
296
- 'events:authorize': (ctx: AuthorizeContext) => void | Promise<void>;
297
289
  /**
298
290
  * Membership provider (e.g. `@frigear-nu/subscriptions`): set `ctx.satisfied = true` when the user holds a
299
291
  * membership matching `ctx.requirement`. With no provider a requirement can never be met, so it fails closed.
@@ -312,4 +304,4 @@ declare module 'nitropack' {
312
304
  declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
313
305
 
314
306
  export { _default as default };
315
- export type { AddonDto, AddonGroupDto, AdminAddonDto, AdminAddonGroupDto, AdminEventDetailDto, AdminEventDto, AdminTicketTypeDto, AttendeeDto, AuthorizeContext, CheckInResponse, EventDetailDto, EventStatus, EventSummaryDto, EventsRuntimeConfig, MembershipCheckContext, MembershipOption, MembershipOptionsContext, MembershipOptionsDto, MembershipRequirement, ModuleOptions, PublicModuleOptions, PurchaseBeforeContext, PurchaseBody, PurchaseResponse, TicketDto, TicketHookContext, TicketStatus, TicketTypeDto, UpcomingEventsDto };
307
+ export type { AddonDto, AddonGroupDto, AdminAddonDto, AdminAddonGroupDto, AdminEventDetailDto, AdminEventDto, AdminTicketTypeDto, AttendeeDto, CheckInResponse, EventDetailDto, EventStatus, EventSummaryDto, EventsRuntimeConfig, MembershipCheckContext, MembershipOption, MembershipOptionsContext, MembershipOptionsDto, MembershipRequirement, ModuleOptions, PublicModuleOptions, PurchaseBeforeContext, PurchaseBody, PurchaseResponse, TicketDto, TicketHookContext, TicketStatus, TicketTypeDto, UpcomingEventsDto };
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@frigear-nu/events",
3
3
  "configKey": "events",
4
- "version": "0.3.1",
4
+ "version": "0.5.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.3",
7
7
  "unbuild": "unknown"
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 { addAuthScope, addAuthRole } from '@frigear-nu/auth/utils';
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,16 +31,7 @@ const module$1 = defineNuxtModule({
30
31
  },
31
32
  async setup(options, nuxt) {
32
33
  registerModule(MODULE_NAME, nuxt);
33
- addAuthScope(
34
- nuxt,
35
- { name: "events:manage", description: "Manage events, tickets and check-in (staff)", aggregateTo: ["eventmanager"] },
36
- { name: "tickets:read", description: "Read your tickets and event details", aggregateTo: ["user"] },
37
- { name: "tickets:write", description: "Buy tickets and pay for them", aggregateTo: ["user"] },
38
- { name: "events:pii", description: "See attendee names and emails through MCP tools (also needs events:manage)", aggregateTo: ["eventmanager"] }
39
- );
40
- if (options.settings?.roles) {
41
- addAuthRole(nuxt, { name: "eventmanager", label: "Event manager", description: "Manages events, tickets and check-in.", inherits: ["user"], inheritedBy: ["admin"] });
42
- }
34
+ registerAccess(nuxt, eventsAccess, { roles: !!options.settings?.roles, from: MODULE_NAME });
43
35
  const resolver = createResolver(import.meta.url);
44
36
  registerTailwindSource(nuxt, resolver.resolve("./runtime/app"));
45
37
  registerLocales(nuxt, resolver.resolve("./runtime/i18n/lang"));
@@ -100,7 +92,6 @@ const module$1 = defineNuxtModule({
100
92
  inlineModuleRuntime(nuxt, resolver);
101
93
  if (settings.mcp === true) addMcpDefinitions(nuxt, resolver.resolve("./runtime/server/mcp"));
102
94
  addServerPlugin(resolver.resolve("./runtime/server/plugins/payment-hooks"));
103
- addServerPlugin(resolver.resolve("./runtime/server/plugins/staff-scopes"));
104
95
  nuxt.hook("modules:done", () => {
105
96
  if (hasNuxtModule("@frigear-nu/subscriptions", nuxt)) {
106
97
  addServerPlugin(resolver.resolve("./runtime/server/plugins/subscriptions-membership"));
@@ -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
+ });
@@ -250,6 +250,22 @@
250
250
  "noTicketsTitle": "Ingen billetter endnu",
251
251
  "ticketsLoadFailed": "Dine billetter kunne ikke indlæses",
252
252
  "tryAgain": "Prøv igen",
253
- "browseEvents": "Se arrangementer"
253
+ "browseEvents": "Se arrangementer",
254
+ "permissions": {
255
+ "manage": "Administrer begivenheder",
256
+ "manageDescription": "Opret og redigér begivenheder, billettyper og tilvalg, og tjek billetter ind.",
257
+ "pii": "Se deltageroplysninger",
258
+ "piiDescription": "Se deltageres navne og e-mails (MCP-værktøjer). Dækkes aldrig af jokertegn.",
259
+ "refund": "Refundér billetter",
260
+ "refundDescription": "Refundér en betalt billet. Kun cookie-sessioner.",
261
+ "ticketsRead": "Læs dine billetter",
262
+ "ticketsWrite": "Køb billetter"
263
+ },
264
+ "scopes": {
265
+ "tickets": "Dine billetter"
266
+ },
267
+ "roles": {
268
+ "eventmanager": "Eventansvarlig"
269
+ }
254
270
  }
255
271
  }
@@ -250,6 +250,22 @@
250
250
  "noTicketsTitle": "No tickets yet",
251
251
  "ticketsLoadFailed": "Your tickets could not be loaded",
252
252
  "tryAgain": "Try again",
253
- "browseEvents": "Browse events"
253
+ "browseEvents": "Browse events",
254
+ "permissions": {
255
+ "manage": "Manage events",
256
+ "manageDescription": "Create and edit events, ticket types and add-ons, and check tickets in.",
257
+ "pii": "See attendee details",
258
+ "piiDescription": "See attendee names and emails (MCP tools). Never covered by a wildcard.",
259
+ "refund": "Refund tickets",
260
+ "refundDescription": "Refund a paid ticket. Cookie sessions only.",
261
+ "ticketsRead": "Read your tickets",
262
+ "ticketsWrite": "Buy tickets"
263
+ },
264
+ "scopes": {
265
+ "tickets": "Your tickets"
266
+ },
267
+ "roles": {
268
+ "eventmanager": "Event manager"
269
+ }
254
270
  }
255
271
  }
@@ -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,6 +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,
27
+ permission: eventsAccess.permissions.manage,
26
28
  order: 20
27
29
  }));
28
30
  }
@@ -1,4 +1,4 @@
1
1
  export default async function myTickets(event) {
2
- const user = await requireUser(event, { scopes: ["tickets:read"] });
2
+ const { user } = await authorize(event, "tickets:read");
3
3
  return listUserTickets(user.id);
4
4
  }
@@ -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>>;
@@ -4,8 +4,7 @@ import { createEventShape } from "../../schemas.js";
4
4
  import { ticketTypeToMinor } from "../../money.js";
5
5
  export default defineScopedMcpTool({
6
6
  description: "Create an event, optionally with ticket types, addon groups and addons (staff). Prices are in whole currency units (52.2 = 52.20), not cents.",
7
- scopes: ["events:manage"],
8
- gate: canManageEvents,
7
+ permission: "events:manage",
9
8
  annotations: { destructiveHint: false },
10
9
  inputSchema: createEventShape,
11
10
  handler: (args) => createEventWithCatalog(eventInput.parse({ ...args, ticketTypes: args.ticketTypes?.map((type) => ticketTypeToMinor(type)) }))
@@ -1,11 +1,13 @@
1
1
  import { z } from "zod";
2
- import { getEventWithTicketTypes } from "../../../utils/admin.js";
2
+ import { authorizeEventsRecord, getEventWithTicketTypes } from "../../../utils/admin.js";
3
3
  import { eventToMajor } from "../../money.js";
4
4
  export default defineScopedMcpTool({
5
5
  description: "Get one event with all its ticket types and their ids, whatever its status (staff). Use the ids with update-ticket-type. Prices are in whole currency units (52.2 = 52.20), not cents.",
6
- scopes: ["events:manage"],
7
- gate: canManageEvents,
6
+ permission: "events:manage",
8
7
  annotations: { readOnlyHint: true },
9
8
  inputSchema: { id: z.string().describe("The event id.") },
10
- handler: async ({ id }) => eventToMajor(await getEventWithTicketTypes(id))
9
+ handler: async ({ id }, ctx) => {
10
+ await authorizeEventsRecord(ctx.event, id);
11
+ return eventToMajor(await getEventWithTicketTypes(id));
12
+ }
11
13
  });
@@ -2,8 +2,7 @@ import { db, schema } from "@nuxthub/db";
2
2
  import { desc } from "drizzle-orm";
3
3
  export default defineScopedMcpTool({
4
4
  description: "List all events including drafts and archived ones (staff).",
5
- scopes: ["events:manage"],
6
- gate: canManageEvents,
5
+ permission: "events:manage",
7
6
  annotations: { readOnlyHint: true },
8
7
  handler: () => db.select().from(schema.events).orderBy(desc(schema.events.startsAt))
9
8
  });
@@ -2,19 +2,20 @@ import { z } from "zod";
2
2
  import { db, schema } from "@nuxthub/db";
3
3
  import { asc, eq } from "drizzle-orm";
4
4
  import { ticketToMajor } from "../../money.js";
5
+ import { authorizeEventsRecord } from "../../../utils/admin.js";
5
6
  export default defineScopedMcpTool({
6
- description: "List the tickets of an event (staff). Attendee names and emails are only included with the events:pii scope. Amounts are in whole currency units (52.2 = 52.20), not cents.",
7
- scopes: ["events:manage"],
8
- gate: canManageEvents,
7
+ description: "List the tickets of an event (staff). Attendee names and emails are only included with the events:pii permission. Amounts are in whole currency units (52.2 = 52.20), not cents.",
8
+ permission: "events:manage",
9
9
  annotations: { readOnlyHint: true },
10
10
  inputSchema: { eventId: z.string().describe("The event id.") },
11
11
  handler: async ({ eventId }, ctx) => {
12
+ await authorizeEventsRecord(ctx.event, eventId);
12
13
  const rows = await db.select({
13
14
  ticket: schema.eventTickets,
14
15
  userName: schema.users.name,
15
16
  userEmail: schema.users.email
16
17
  }).from(schema.eventTickets).leftJoin(schema.users, eq(schema.eventTickets.userId, schema.users.id)).where(eq(schema.eventTickets.eventId, eventId)).orderBy(asc(schema.eventTickets.createdAt));
17
- const allow = ctx.hasScope("events:pii");
18
+ const allow = await ctx.can("events:pii");
18
19
  const attendees = rows.map(({ ticket, userName, userEmail }) => redactPii({
19
20
  ...ticketToMajor(pick(ticket, ["id", "ticketTypeId", "status", "amount", "currency", "checkedInAt", "createdAt"])),
20
21
  addons: ticket.addons.length,
@@ -1,10 +1,12 @@
1
- import { eventPatchSchema, patchEventRow } from "../../../utils/admin.js";
1
+ import { authorizeEventsRecord, eventPatchSchema, patchEventRow } from "../../../utils/admin.js";
2
2
  import { updateEventShape } from "../../schemas.js";
3
3
  export default defineScopedMcpTool({
4
4
  description: "Update fields of an event (staff). Only the given fields change.",
5
- scopes: ["events:manage"],
6
- gate: canManageEvents,
5
+ permission: "events:manage",
7
6
  annotations: { idempotentHint: true },
8
7
  inputSchema: updateEventShape,
9
- handler: ({ id, patch }) => patchEventRow(id, eventPatchSchema.parse(patch))
8
+ handler: async ({ id, patch }, ctx) => {
9
+ await authorizeEventsRecord(ctx.event, id);
10
+ return patchEventRow(id, eventPatchSchema.parse(patch));
11
+ }
10
12
  });
@@ -1,15 +1,15 @@
1
1
  import { db, schema } from "@nuxthub/db";
2
2
  import { eq } from "drizzle-orm";
3
- import { patchTicketTypeRow, ticketTypePatchSchema } from "../../../utils/admin.js";
3
+ import { authorizeEventsRecord, eventsIdOfTicketType, patchTicketTypeRow, ticketTypePatchSchema } from "../../../utils/admin.js";
4
4
  import { ticketTypeToMajor, ticketTypeToMinor } from "../../money.js";
5
5
  import { updateTicketTypeShape } from "../../schemas.js";
6
6
  export default defineScopedMcpTool({
7
7
  description: "Update fields of an event's ticket type, such as price, capacity or sale dates (staff). Only the given fields change. The price is in whole currency units (52.2 = 52.20), not cents, in the given or the ticket type's current currency.",
8
- scopes: ["events:manage"],
9
- gate: canManageEvents,
8
+ permission: "events:manage",
10
9
  annotations: { idempotentHint: true },
11
10
  inputSchema: updateTicketTypeShape,
12
- handler: async ({ id, patch }) => {
11
+ handler: async ({ id, patch }, ctx) => {
12
+ await authorizeEventsRecord(ctx.event, await eventsIdOfTicketType(id));
13
13
  const [existing] = patch.price === void 0 || patch.currency ? [void 0] : await db.select({ currency: schema.eventTicketTypes.currency }).from(schema.eventTicketTypes).where(eq(schema.eventTicketTypes.id, id)).limit(1);
14
14
  const row = await patchTicketTypeRow(id, ticketTypePatchSchema.parse(ticketTypeToMinor(patch, existing?.currency)));
15
15
  return ticketTypeToMajor(row);
@@ -2,7 +2,7 @@ import { z } from "zod";
2
2
  import { eventToMajor } from "../money.js";
3
3
  export default defineScopedMcpTool({
4
4
  description: "Get a published event with its ticket types and what you can buy. Prices are in whole currency units (52.2 = 52.20), not cents.",
5
- scopes: ["tickets:read"],
5
+ permission: "tickets:read",
6
6
  annotations: { readOnlyHint: true },
7
7
  inputSchema: { slug: z.string().describe("The event slug.") },
8
8
  handler: async ({ slug }, { user }) => {
@@ -1,6 +1,6 @@
1
1
  export default defineScopedMcpTool({
2
2
  description: "List the published events.",
3
- scopes: ["tickets:read"],
3
+ permission: "tickets:read",
4
4
  annotations: { readOnlyHint: true },
5
5
  handler: () => listPublishedEvents()
6
6
  });
@@ -1,7 +1,7 @@
1
1
  import { ticketToMajor } from "../money.js";
2
2
  export default defineScopedMcpTool({
3
3
  description: "List your own tickets. Amounts and prices are in whole currency units (52.2 = 52.20), not cents.",
4
- scopes: ["tickets:read"],
4
+ permission: "tickets:read",
5
5
  annotations: { readOnlyHint: true },
6
6
  handler: async (_args, { user }) => (await listUserTickets(user.id)).map(ticketToMajor)
7
7
  });
@@ -1,9 +1,11 @@
1
1
  import { db, schema } from "@nuxthub/db";
2
2
  import { eq } from "drizzle-orm";
3
3
  import { idParams, noContent, notFound } from "@frigear-nu/module-kit/server";
4
+ import { authorizeEventsRecord, eventsIdOfAddonGroup } from "../../utils/admin.js";
4
5
  export default defineEventHandler(async (event) => {
5
- await eventsStaff.require(event);
6
+ await authorize(event, "events:manage");
6
7
  const { id } = await getValidatedRouterParams(event, idParams().parse);
8
+ await authorizeEventsRecord(event, await eventsIdOfAddonGroup(id));
7
9
  const [row] = await db.delete(schema.eventAddonGroups).where(eq(schema.eventAddonGroups.id, id)).returning({ id: schema.eventAddonGroups.id });
8
10
  if (!row) throw notFound("Addon group not found.");
9
11
  return noContent(event);
@@ -1,11 +1,13 @@
1
1
  import { db, schema } from "@nuxthub/db";
2
2
  import { eq } from "drizzle-orm";
3
3
  import { idParams, notFound } from "@frigear-nu/module-kit/server";
4
+ import { authorizeEventsRecord, eventsIdOfAddonGroup } from "../../utils/admin.js";
4
5
  import { addonGroupInput } from "../../utils/admin-schemas.js";
5
6
  const patchSchema = addonGroupInput.omit({ addons: true }).partial();
6
7
  export default defineEventHandler(async (event) => {
7
- await eventsStaff.require(event);
8
+ await authorize(event, "events:manage");
8
9
  const { id } = await getValidatedRouterParams(event, idParams().parse);
10
+ await authorizeEventsRecord(event, await eventsIdOfAddonGroup(id));
9
11
  const patch = await readValidatedBody(event, patchSchema.parse);
10
12
  const [row] = await db.update(schema.eventAddonGroups).set(patch).where(eq(schema.eventAddonGroups.id, id)).returning();
11
13
  if (!row) throw notFound("Addon group not found.");
@@ -1,13 +1,10 @@
1
- import { db, schema } from "@nuxthub/db";
2
- import { eq } from "drizzle-orm";
3
- import { created, idParams, notFound } from "@frigear-nu/module-kit/server";
4
- import { insertAddonGroup } from "../../utils/admin.js";
1
+ import { created, idParams } from "@frigear-nu/module-kit/server";
2
+ import { authorizeEventsRecord, eventsIdOfTicketType, insertAddonGroup } from "../../utils/admin.js";
5
3
  import { addonGroupInput } from "../../utils/admin-schemas.js";
6
4
  export default defineEventHandler(async (event) => {
7
- await eventsStaff.require(event);
5
+ await authorize(event, "events:manage");
8
6
  const { id } = await getValidatedRouterParams(event, idParams().parse);
9
7
  const input = await readValidatedBody(event, addonGroupInput.parse);
10
- const [parent] = await db.select({ id: schema.eventTicketTypes.id }).from(schema.eventTicketTypes).where(eq(schema.eventTicketTypes.id, id)).limit(1);
11
- if (!parent) throw notFound("Ticket type not found.");
8
+ await authorizeEventsRecord(event, await eventsIdOfTicketType(id));
12
9
  return created(event, toAdminAddonGroupDto(await insertAddonGroup(id, input)));
13
10
  });
@@ -1,9 +1,11 @@
1
1
  import { db, schema } from "@nuxthub/db";
2
2
  import { eq } from "drizzle-orm";
3
3
  import { idParams, noContent, notFound } from "@frigear-nu/module-kit/server";
4
+ import { authorizeEventsRecord, eventsIdOfAddon } from "../../utils/admin.js";
4
5
  export default defineEventHandler(async (event) => {
5
- await eventsStaff.require(event);
6
+ await authorize(event, "events:manage");
6
7
  const { id } = await getValidatedRouterParams(event, idParams().parse);
8
+ await authorizeEventsRecord(event, await eventsIdOfAddon(id));
7
9
  const [row] = await db.delete(schema.eventAddons).where(eq(schema.eventAddons.id, id)).returning({ id: schema.eventAddons.id });
8
10
  if (!row) throw notFound("Addon not found.");
9
11
  return noContent(event);
@@ -1,11 +1,13 @@
1
1
  import { db, schema } from "@nuxthub/db";
2
2
  import { eq } from "drizzle-orm";
3
3
  import { idParams, notFound } from "@frigear-nu/module-kit/server";
4
+ import { authorizeEventsRecord, eventsIdOfAddon } from "../../utils/admin.js";
4
5
  import { addonInput } from "../../utils/admin-schemas.js";
5
6
  const patchSchema = addonInput.partial();
6
7
  export default defineEventHandler(async (event) => {
7
- await eventsStaff.require(event);
8
+ await authorize(event, "events:manage");
8
9
  const { id } = await getValidatedRouterParams(event, idParams().parse);
10
+ await authorizeEventsRecord(event, await eventsIdOfAddon(id));
9
11
  const patch = await readValidatedBody(event, patchSchema.parse);
10
12
  const [row] = await db.update(schema.eventAddons).set(patch).where(eq(schema.eventAddons.id, id)).returning();
11
13
  if (!row) throw notFound("Addon not found.");
@@ -1,14 +1,13 @@
1
1
  import { db, schema } from "@nuxthub/db";
2
- import { eq } from "drizzle-orm";
3
- import { created, idParams, notFound } from "@frigear-nu/module-kit/server";
2
+ import { created, idParams } from "@frigear-nu/module-kit/server";
4
3
  import { newId } from "../../../utils/index.js";
4
+ import { authorizeEventsRecord, eventsIdOfAddonGroup } from "../../utils/admin.js";
5
5
  import { addonInput } from "../../utils/admin-schemas.js";
6
6
  export default defineEventHandler(async (event) => {
7
- await eventsStaff.require(event);
7
+ await authorize(event, "events:manage");
8
8
  const { id } = await getValidatedRouterParams(event, idParams().parse);
9
9
  const input = await readValidatedBody(event, addonInput.parse);
10
- const [parent] = await db.select({ id: schema.eventAddonGroups.id }).from(schema.eventAddonGroups).where(eq(schema.eventAddonGroups.id, id)).limit(1);
11
- if (!parent) throw notFound("Addon group not found.");
10
+ await authorizeEventsRecord(event, await eventsIdOfAddonGroup(id));
12
11
  const [row] = await db.insert(schema.eventAddons).values({ id: newId("adn"), groupId: id, ...input, description: input.description ?? null, capacity: input.capacity ?? null }).returning();
13
12
  return created(event, toAdminAddonDto(row));
14
13
  });
@@ -12,11 +12,12 @@ const querySchema = pageQuery({
12
12
  }
13
13
  });
14
14
  export default defineEventHandler(async (event) => {
15
- await eventsStaff.require(event);
15
+ await authorize(event, "events:manage");
16
16
  const { id } = await getValidatedRouterParams(event, idParams().parse);
17
17
  const query = await getValidatedQuery(event, querySchema.parse);
18
- const [parent] = await db.select({ id: schema.events.id }).from(schema.events).where(eq(schema.events.id, id)).limit(1);
18
+ const [parent] = await db.select().from(schema.events).where(eq(schema.events.id, id)).limit(1);
19
19
  if (!parent) throw notFound("Event not found.");
20
+ await authorize(event, "events:manage", parent);
20
21
  const conditions = [eq(schema.eventTickets.eventId, id)];
21
22
  if (query.q) conditions.push(or(likeContains(schema.users.name, query.q), likeContains(schema.users.email, query.q)));
22
23
  if (query.status) conditions.push(eq(schema.eventTickets.status, query.status));
@@ -2,12 +2,15 @@ import { db, schema } from "@nuxthub/db";
2
2
  import { and, eq, isNull } from "drizzle-orm";
3
3
  import { z } from "zod";
4
4
  import { conflict, notFound } from "@frigear-nu/module-kit/server";
5
+ import { authorizeEventsRecord } from "../../utils/admin.js";
5
6
  const bodySchema = z.object({ code: z.string().min(1) });
6
7
  export default defineEventHandler(async (event) => {
7
- const { userId } = await eventsStaff.require(event);
8
+ const { user } = await authorize(event, "events:manage");
9
+ const userId = user.id;
8
10
  const { code } = await readValidatedBody(event, bodySchema.parse);
9
11
  const [ticket] = await db.select().from(schema.eventTickets).where(eq(schema.eventTickets.code, code)).limit(1);
10
12
  if (!ticket) throw notFound("Unknown ticket code.");
13
+ await authorizeEventsRecord(event, ticket.eventId);
11
14
  if (ticket.status !== "paid") throw conflict(`This ticket is ${ticket.status}, not valid for entry.`, { status: ticket.status });
12
15
  const [claimed] = await db.update(schema.eventTickets).set({ checkedInAt: /* @__PURE__ */ new Date(), checkedInBy: userId }).where(and(eq(schema.eventTickets.id, ticket.id), isNull(schema.eventTickets.checkedInAt))).returning();
13
16
  const row = claimed ?? (await db.select().from(schema.eventTickets).where(eq(schema.eventTickets.id, ticket.id)).limit(1))[0];
@@ -3,10 +3,11 @@ import { db, schema } from "@nuxthub/db";
3
3
  import { created, idParams, notFound, uniqueCopySlug } from "@frigear-nu/module-kit/server";
4
4
  import { newId } from "../../../utils/index.js";
5
5
  export default defineEventHandler(async (event) => {
6
- await eventsStaff.require(event);
6
+ await authorize(event, "events:manage");
7
7
  const { id } = await getValidatedRouterParams(event, idParams().parse);
8
8
  const [source] = await db.select().from(schema.events).where(eq(schema.events.id, id)).limit(1);
9
9
  if (!source) throw notFound("Event not found.");
10
+ await authorize(event, "events:manage", source);
10
11
  const slug = await uniqueCopySlug(source.slug, async (candidate) => (await db.select({ id: schema.events.id }).from(schema.events).where(eq(schema.events.slug, candidate)).limit(1)).length > 0);
11
12
  const types = await db.select().from(schema.eventTicketTypes).where(eq(schema.eventTicketTypes.eventId, id)).orderBy(asc(schema.eventTicketTypes.sortOrder));
12
13
  const groups = types.length ? await db.select().from(schema.eventAddonGroups).where(inArray(schema.eventAddonGroups.ticketTypeId, types.map((t) => t.id))).orderBy(asc(schema.eventAddonGroups.sortOrder)) : [];
@@ -2,10 +2,11 @@ import { db, schema } from "@nuxthub/db";
2
2
  import { and, eq, sql } from "drizzle-orm";
3
3
  import { conflict, idParams, noContent, notFound } from "@frigear-nu/module-kit/server";
4
4
  export default defineEventHandler(async (event) => {
5
- await eventsStaff.require(event);
5
+ await authorize(event, "events:manage");
6
6
  const { id } = await getValidatedRouterParams(event, idParams().parse);
7
- const [existing] = await db.select({ id: schema.events.id }).from(schema.events).where(eq(schema.events.id, id)).limit(1);
7
+ const [existing] = await db.select().from(schema.events).where(eq(schema.events.id, id)).limit(1);
8
8
  if (!existing) throw notFound("Event not found.");
9
+ await authorize(event, "events:manage", existing);
9
10
  const [sold] = await db.select({ count: sql`count(*)` }).from(schema.eventTickets).where(and(eq(schema.eventTickets.eventId, id), eq(schema.eventTickets.status, "paid")));
10
11
  if (Number(sold?.count ?? 0) > 0) throw conflict("This event has paid tickets. Archive it instead.");
11
12
  await db.delete(schema.events).where(eq(schema.events.id, id));
@@ -1,7 +1,9 @@
1
1
  import { idParams } from "@frigear-nu/module-kit/server";
2
- import { getEventWithTicketTypes } from "../../utils/admin.js";
2
+ import { authorizeEventsRecord, getEventWithTicketTypes } from "../../utils/admin.js";
3
+ import { eventsAccess } from "../../../access.js";
3
4
  export default defineEventHandler(async (event) => {
4
- await eventsStaff.require(event);
5
+ await authorize(event, eventsAccess.permissions.manage);
5
6
  const { id } = await getValidatedRouterParams(event, idParams().parse);
7
+ await authorizeEventsRecord(event, id);
6
8
  return toAdminEventDetailDto(await getEventWithTicketTypes(id));
7
9
  });
@@ -1,8 +1,13 @@
1
- import { idParams } from "@frigear-nu/module-kit/server";
1
+ import { db, schema } from "@nuxthub/db";
2
+ import { eq } from "drizzle-orm";
3
+ import { idParams, notFound } from "@frigear-nu/module-kit/server";
2
4
  import { eventPatchSchema, patchEventRow } from "../../utils/admin.js";
3
5
  export default defineEventHandler(async (event) => {
4
- await eventsStaff.require(event);
6
+ await authorize(event, "events:manage");
5
7
  const { id } = await getValidatedRouterParams(event, idParams().parse);
8
+ const [existing] = await db.select().from(schema.events).where(eq(schema.events.id, id)).limit(1);
9
+ if (!existing) throw notFound("Event not found.");
10
+ await authorize(event, "events:manage", existing);
6
11
  const patch = await readValidatedBody(event, eventPatchSchema.parse);
7
12
  return toAdminEventDto(await patchEventRow(id, patch));
8
13
  });
@@ -18,7 +18,7 @@ const querySchema = pageQuery({
18
18
  }
19
19
  });
20
20
  export default defineEventHandler(async (event) => {
21
- await eventsStaff.require(event);
21
+ await authorize(event, "events:manage");
22
22
  const query = await getValidatedQuery(event, querySchema.parse);
23
23
  const conditions = [];
24
24
  if (query.q) conditions.push(or(translatedContains(schema.events.name, query.q), likeContains(schema.events.slug, query.q)));
@@ -2,7 +2,7 @@ import { created } from "@frigear-nu/module-kit/server";
2
2
  import { createEventWithCatalog } from "../../utils/admin.js";
3
3
  import { eventInput } from "../../utils/admin-schemas.js";
4
4
  export default defineEventHandler(async (event) => {
5
- await eventsStaff.require(event);
5
+ await authorize(event, "events:manage");
6
6
  const input = await readValidatedBody(event, eventInput.parse);
7
7
  return created(event, toAdminEventDto(await createEventWithCatalog(input)));
8
8
  });
@@ -1,5 +1,5 @@
1
1
  export default defineEventHandler(async (event) => {
2
- await eventsStaff.require(event);
2
+ await authorize(event, "events:manage");
3
3
  const { available, options } = await getMembershipOptions();
4
4
  return { available, options: options.map((option) => ({ value: option.value, label: option.label })) };
5
5
  });
@@ -1,11 +1,13 @@
1
1
  import { db, schema } from "@nuxthub/db";
2
2
  import { and, eq, inArray } from "drizzle-orm";
3
3
  import { conflict, idParams, notFound } from "@frigear-nu/module-kit/server";
4
+ import { authorizeEventsRecord } from "../../utils/admin.js";
4
5
  export default defineEventHandler(async (event) => {
5
- await eventsStaff.require(event);
6
+ await authorize(event, "events:manage");
6
7
  const { id } = await getValidatedRouterParams(event, idParams().parse);
7
8
  const [ticket] = await db.select().from(schema.eventTickets).where(eq(schema.eventTickets.id, id)).limit(1);
8
9
  if (!ticket) throw notFound("Ticket not found.");
10
+ await authorizeEventsRecord(event, ticket.eventId);
9
11
  if (ticket.status === "paid" && ticket.amount > 0) throw conflict("This ticket was paid for. Refund it instead.");
10
12
  const [updated] = await db.update(schema.eventTickets).set({ status: "cancelled" }).where(and(eq(schema.eventTickets.id, id), inArray(schema.eventTickets.status, ["pending", "paid"]))).returning();
11
13
  if (!updated) throw conflict(`Ticket is already ${ticket.status}.`, { status: ticket.status });
@@ -1,11 +1,14 @@
1
1
  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
+ import { authorizeEventsRecord } from "../../utils/admin.js";
5
+ import { eventsAccess } from "../../../access.js";
4
6
  export default defineEventHandler(async (event) => {
5
- await eventsStaff.require(event, { sessionOnly: true });
7
+ await authorize(event, eventsAccess.permissions.refund);
6
8
  const { id } = await getValidatedRouterParams(event, idParams().parse);
7
9
  const [ticket] = await db.select().from(schema.eventTickets).where(eq(schema.eventTickets.id, id)).limit(1);
8
10
  if (!ticket) throw notFound("Ticket not found.");
11
+ await authorizeEventsRecord(event, ticket.eventId, eventsAccess.permissions.refund);
9
12
  if (ticket.status !== "paid" || !ticket.paymentId) throw conflict("Only paid tickets with a payment can be refunded.", { status: ticket.status });
10
13
  await refundPayment(ticket.paymentId);
11
14
  return toAttendeeDto(ticket, await ticketHolder(ticket.userId));
@@ -1,11 +1,11 @@
1
1
  import { db, schema } from "@nuxthub/db";
2
2
  import { and, eq, inArray, sql } from "drizzle-orm";
3
- import { conflict, idParams, noContent, notFound } from "@frigear-nu/module-kit/server";
3
+ import { conflict, idParams, noContent } from "@frigear-nu/module-kit/server";
4
+ import { authorizeEventsRecord, eventsIdOfTicketType } from "../../utils/admin.js";
4
5
  export default defineEventHandler(async (event) => {
5
- await eventsStaff.require(event);
6
+ await authorize(event, "events:manage");
6
7
  const { id } = await getValidatedRouterParams(event, idParams().parse);
7
- const [existing] = await db.select({ id: schema.eventTicketTypes.id }).from(schema.eventTicketTypes).where(eq(schema.eventTicketTypes.id, id)).limit(1);
8
- if (!existing) throw notFound("Ticket type not found.");
8
+ await authorizeEventsRecord(event, await eventsIdOfTicketType(id));
9
9
  const [sold] = await db.select({ count: sql`count(*)` }).from(schema.eventTickets).where(and(eq(schema.eventTickets.ticketTypeId, id), inArray(schema.eventTickets.status, ["paid", "pending"])));
10
10
  if (Number(sold?.count ?? 0) > 0) throw conflict("This ticket type has tickets. Cancel them first.");
11
11
  await db.delete(schema.eventTicketTypes).where(eq(schema.eventTicketTypes.id, id));
@@ -1,8 +1,9 @@
1
1
  import { idParams } from "@frigear-nu/module-kit/server";
2
- import { patchTicketTypeRow, ticketTypePatchSchema } from "../../utils/admin.js";
2
+ import { authorizeEventsRecord, eventsIdOfTicketType, patchTicketTypeRow, ticketTypePatchSchema } from "../../utils/admin.js";
3
3
  export default defineEventHandler(async (event) => {
4
- await eventsStaff.require(event);
4
+ await authorize(event, "events:manage");
5
5
  const { id } = await getValidatedRouterParams(event, idParams().parse);
6
+ await authorizeEventsRecord(event, await eventsIdOfTicketType(id));
6
7
  const patch = await readValidatedBody(event, ticketTypePatchSchema.parse);
7
8
  return toAdminTicketTypeDto(await patchTicketTypeRow(id, patch));
8
9
  });
@@ -1,14 +1,11 @@
1
- import { db, schema } from "@nuxthub/db";
2
- import { eq } from "drizzle-orm";
3
- import { created, idParams, notFound } from "@frigear-nu/module-kit/server";
4
- import { assertMembershipAvailable, assertTicketTypeKeyFree, insertTicketType } from "../../utils/admin.js";
1
+ import { created, idParams } from "@frigear-nu/module-kit/server";
2
+ import { assertMembershipAvailable, assertTicketTypeKeyFree, authorizeEventsRecord, insertTicketType } from "../../utils/admin.js";
5
3
  import { ticketTypeInput } from "../../utils/admin-schemas.js";
6
4
  export default defineEventHandler(async (event) => {
7
- await eventsStaff.require(event);
5
+ await authorize(event, "events:manage");
8
6
  const { id } = await getValidatedRouterParams(event, idParams().parse);
9
7
  const input = await readValidatedBody(event, ticketTypeInput.parse);
10
- const [parent] = await db.select({ id: schema.events.id }).from(schema.events).where(eq(schema.events.id, id)).limit(1);
11
- if (!parent) throw notFound("Event not found.");
8
+ await authorizeEventsRecord(event, id);
12
9
  await assertMembershipAvailable(input);
13
10
  await assertTicketTypeKeyFree(id, input.key);
14
11
  return created(event, toAdminTicketTypeDto(await insertTicketType(id, input)));
@@ -3,7 +3,7 @@ import { and, asc, count, eq, gte } from "drizzle-orm";
3
3
  import { isoDate } from "@frigear-nu/module-kit/server";
4
4
  const LIMIT = 5;
5
5
  export default defineEventHandler(async (event) => {
6
- await eventsStaff.require(event);
6
+ await authorize(event, "events:manage");
7
7
  const upcoming = and(eq(schema.events.status, "published"), gte(schema.events.startsAt, /* @__PURE__ */ new Date()));
8
8
  const [[total], rows] = await Promise.all([
9
9
  db.select({ value: count() }).from(schema.events).where(upcoming),
@@ -1,11 +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 requireUser(event, { scopes: ["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.");
10
+ await authorize(event, eventsAccess.permissions["tickets:write"], ticket);
9
11
  if (ticket.status === "paid") throw conflict("This ticket is already paid.", { status: ticket.status });
10
12
  if (ticket.status !== "pending" || !ticket.paymentId) throw conflict("This ticket can no longer be paid. Buy a new one.", { status: ticket.status });
11
13
  const { url } = await resumePayment(ticket.paymentId, user.id, event);
@@ -1,6 +1,6 @@
1
1
  import { idParams } from "@frigear-nu/module-kit/server";
2
2
  export default defineEventHandler(async (event) => {
3
- const user = await requireUser(event, { scopes: ["tickets:read"] });
3
+ const { user } = await authorize(event, "tickets:read");
4
4
  const { id } = await getValidatedRouterParams(event, idParams().parse);
5
5
  return getUserTicket(user.id, id);
6
6
  });
@@ -5,6 +5,6 @@ export default defineEventHandler(async (event) => {
5
5
  const { slug } = await getValidatedRouterParams(event, paramsSchema.parse);
6
6
  const row = await getPublishedEventRow(slug);
7
7
  if (!row) throw notFound("Event not found.");
8
- const user = await getUser(event, { scopes: ["tickets:read"] });
9
- return getEventDetail(row, user?.id);
8
+ const principal = await allows(event, "tickets:read") ? await getAuth(event) : null;
9
+ return getEventDetail(row, principal?.user.id);
10
10
  });
@@ -8,7 +8,7 @@ const bodySchema = z.object({
8
8
  locale: z.string().regex(/^[a-z]{2,3}(?:[-_][a-z0-9]{2,8})*$/i).max(16).optional()
9
9
  });
10
10
  export default defineEventHandler(async (event) => {
11
- const user = await requireUser(event, { scopes: ["tickets:write"] });
11
+ const { user } = await authorize(event, "tickets:write");
12
12
  const { slug } = await getValidatedRouterParams(event, paramsSchema.parse);
13
13
  const body = await readValidatedBody(event, bodySchema.parse);
14
14
  return purchaseTicket(event, user.id, slug, body);
@@ -1,8 +1,26 @@
1
+ import type { H3Event } from 'h3';
1
2
  import type { z } from 'zod';
2
3
  import { eventInput, ticketTypeInput } from './admin-schemas.js';
4
+ import { eventsAccess } from '../../access.js';
3
5
  import type { addonGroupInput } from './admin-schemas.js';
4
6
  type TicketTypeInput = z.output<typeof ticketTypeInput>;
5
7
  type AddonGroupInput = z.output<typeof addonGroupInput>;
8
+ /** The permissions whose record-level policies run on one event. */
9
+ export type EventsRecordPermission = typeof eventsAccess.permissions.manage | typeof eventsAccess.permissions.refund;
10
+ /**
11
+ * Loads the event `eventId` (404 `not_found`) and authorizes `permission` on it. Every record-level check of
12
+ * `events:manage` and `events:refund` goes through here, so their policies always receive the stored EVENT row
13
+ * (`typeof schema.events.$inferSelect`), never a ticket type, addon or ticket: a route acting on a child record passes
14
+ * the event it belongs to. Call it after `authorize(event, permission)` without a record, so a caller who may not do the
15
+ * action at all gets 401/403 before any 404. Returns the event row.
16
+ */
17
+ export declare function authorizeEventsRecord(event: H3Event, eventId: string, permission?: EventsRecordPermission): Promise<any>;
18
+ /** The event a ticket type belongs to (404 `not_found` for an unknown ticket type). */
19
+ export declare function eventsIdOfTicketType(ticketTypeId: string): Promise<string>;
20
+ /** The event an addon group belongs to, through its ticket type (404 `not_found` for an unknown addon group). */
21
+ export declare function eventsIdOfAddonGroup(groupId: string): Promise<string>;
22
+ /** The event an addon belongs to, through its group and ticket type (404 `not_found` for an unknown addon). */
23
+ export declare function eventsIdOfAddon(addonId: string): Promise<string>;
6
24
  export declare function insertAddonGroup(ticketTypeId: string, input: AddonGroupInput): Promise<any>;
7
25
  /** 409 when another ticket type of `eventId` already uses `key` (keys are unique per event). */
8
26
  export declare function assertTicketTypeKeyFree(eventId: string, key: string, exceptId?: string): Promise<void>;
@@ -22,14 +40,14 @@ export declare const eventPatchSchema: z.ZodObject<{
22
40
  name: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodRecord<z.ZodString, z.ZodString>, z.ZodTransform<{
23
41
  [k: string]: string;
24
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>>>]>>>>;
25
46
  status: z.ZodOptional<z.ZodOptional<z.ZodEnum<{
26
47
  draft: "draft";
27
48
  published: "published";
28
49
  archived: "archived";
29
50
  }>>>;
30
- description: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodRecord<z.ZodString, z.ZodString>, z.ZodTransform<{
31
- [k: string]: string;
32
- }, Record<string, string>>>]>>>>;
33
51
  image: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
34
52
  slug: z.ZodOptional<z.ZodString>;
35
53
  body: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodRecord<z.ZodString, z.ZodString>, z.ZodTransform<{
@@ -48,10 +66,10 @@ export declare const ticketTypePatchSchema: z.ZodObject<{
48
66
  name: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodRecord<z.ZodString, z.ZodString>, z.ZodTransform<{
49
67
  [k: string]: string;
50
68
  }, Record<string, string>>>]>>;
51
- key: z.ZodOptional<z.ZodString>;
52
69
  description: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodRecord<z.ZodString, z.ZodString>, z.ZodTransform<{
53
70
  [k: string]: string;
54
71
  }, Record<string, string>>>]>>>>;
72
+ key: z.ZodOptional<z.ZodString>;
55
73
  currency: z.ZodOptional<z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>>;
56
74
  price: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
57
75
  hidePrice: z.ZodOptional<z.ZodOptional<z.ZodBoolean>>;
@@ -4,6 +4,28 @@ 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
+ import { eventsAccess } from "../../access.js";
8
+ export async function authorizeEventsRecord(event, eventId, permission = eventsAccess.permissions.manage) {
9
+ const [row] = await db.select().from(schema.events).where(eq(schema.events.id, eventId)).limit(1);
10
+ if (!row) throw notFound("Event not found.");
11
+ await authorize(event, permission, row);
12
+ return row;
13
+ }
14
+ export async function eventsIdOfTicketType(ticketTypeId) {
15
+ const [row] = await db.select({ eventId: schema.eventTicketTypes.eventId }).from(schema.eventTicketTypes).where(eq(schema.eventTicketTypes.id, ticketTypeId)).limit(1);
16
+ if (!row) throw notFound("Ticket type not found.");
17
+ return row.eventId;
18
+ }
19
+ export async function eventsIdOfAddonGroup(groupId) {
20
+ const [row] = await db.select({ eventId: schema.eventTicketTypes.eventId }).from(schema.eventAddonGroups).innerJoin(schema.eventTicketTypes, eq(schema.eventAddonGroups.ticketTypeId, schema.eventTicketTypes.id)).where(eq(schema.eventAddonGroups.id, groupId)).limit(1);
21
+ if (!row) throw notFound("Addon group not found.");
22
+ return row.eventId;
23
+ }
24
+ export async function eventsIdOfAddon(addonId) {
25
+ const [row] = await db.select({ eventId: schema.eventTicketTypes.eventId }).from(schema.eventAddons).innerJoin(schema.eventAddonGroups, eq(schema.eventAddons.groupId, schema.eventAddonGroups.id)).innerJoin(schema.eventTicketTypes, eq(schema.eventAddonGroups.ticketTypeId, schema.eventTicketTypes.id)).where(eq(schema.eventAddons.id, addonId)).limit(1);
26
+ if (!row) throw notFound("Addon not found.");
27
+ return row.eventId;
28
+ }
7
29
  export async function insertAddonGroup(ticketTypeId, input) {
8
30
  const { addons, ...group } = input;
9
31
  const [row] = await db.insert(schema.eventAddonGroups).values({ id: newId("agr"), ticketTypeId, ...group }).returning();
@@ -3,7 +3,7 @@ import type { MembershipRequirement } from '../types.js';
3
3
  export { translate };
4
4
  export * from './links.js';
5
5
  export * from './api.js';
6
- export type { AddonDto, AdminAddonDto, AdminAddonGroupDto, AdminEventDetailDto, AdminEventDto, AdminTicketTypeDto, AttendeeDto, AddonGroupDto, AuthorizeContext, CheckInResponse, EventDetailDto, EventStatus, EventSummaryDto, MembershipOptionsDto, MembershipRequirement, ModuleOptions, PurchaseBeforeContext, PurchaseBody, PurchaseResponse, TicketDto, TicketHookContext, TicketStatus, TicketTypeDto, Translated, UpcomingEventsDto, } from '../types.js';
6
+ export type { AddonDto, AdminAddonDto, AdminAddonGroupDto, AdminEventDetailDto, AdminEventDto, AdminTicketTypeDto, AttendeeDto, AddonGroupDto, CheckInResponse, EventDetailDto, EventStatus, EventSummaryDto, MembershipOptionsDto, MembershipRequirement, ModuleOptions, PurchaseBeforeContext, PurchaseBody, PurchaseResponse, TicketDto, TicketHookContext, TicketStatus, TicketTypeDto, Translated, UpcomingEventsDto, } from '../types.js';
7
7
  /** The currency tickets and add-ons are sold in unless they say otherwise (the column default). */
8
8
  export declare const DEFAULT_CURRENCY = "DKK";
9
9
  /** Normalises a stored requirement: empty plan lists mean "any active subscription". */
package/dist/types.d.mts CHANGED
@@ -2,4 +2,4 @@ export { type Translated } from '@frigear-nu/ui/translated'
2
2
 
3
3
  export { default } from './module.mjs'
4
4
 
5
- export { type AddonDto, type AddonGroupDto, type AdminAddonDto, type AdminAddonGroupDto, type AdminEventDetailDto, type AdminEventDto, type AdminTicketTypeDto, type AttendeeDto, type AuthorizeContext, type CheckInResponse, type EventDetailDto, type EventStatus, type EventSummaryDto, type EventsRuntimeConfig, type MembershipCheckContext, type MembershipOption, type MembershipOptionsContext, type MembershipOptionsDto, type MembershipRequirement, type ModuleOptions, type PublicModuleOptions, type PurchaseBeforeContext, type PurchaseBody, type PurchaseResponse, type TicketDto, type TicketHookContext, type TicketStatus, type TicketTypeDto, type UpcomingEventsDto } from './module.mjs'
5
+ export { type AddonDto, type AddonGroupDto, type AdminAddonDto, type AdminAddonGroupDto, type AdminEventDetailDto, type AdminEventDto, type AdminTicketTypeDto, type AttendeeDto, type CheckInResponse, type EventDetailDto, type EventStatus, type EventSummaryDto, type EventsRuntimeConfig, type MembershipCheckContext, type MembershipOption, type MembershipOptionsContext, type MembershipOptionsDto, type MembershipRequirement, type ModuleOptions, type PublicModuleOptions, type PurchaseBeforeContext, type PurchaseBody, type PurchaseResponse, type TicketDto, type TicketHookContext, type TicketStatus, type TicketTypeDto, type UpcomingEventsDto } from './module.mjs'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frigear-nu/events",
3
- "version": "0.3.1",
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.3.0",
39
- "@frigear-nu/auth": "^0.4.0",
40
- "@frigear-nu/mcp": "^0.3.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.3.1",
43
- "@frigear-nu/stripe": "^0.3.1",
44
- "@frigear-nu/subscriptions": "^0.3.1",
42
+ "@frigear-nu/payments": "^0.5.0",
43
+ "@frigear-nu/stripe": "^0.4.0",
44
+ "@frigear-nu/subscriptions": "^0.5.0",
45
45
  "@frigear-nu/ui": "^0.2.6",
46
- "@frigear-nu/users": "^2.0.0",
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.2.5",
59
- "@frigear-nu/widget": "^0.2.5",
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.2.5",
76
- "@frigear-nu/widget": "^0.2.5",
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",
@@ -1,2 +0,0 @@
1
- declare const _default: any;
2
- export default _default;
@@ -1 +0,0 @@
1
- export default defineStaffScopes(["events:manage", "events:pii"], (event, userId) => canManageEvents(event, { user: { id: userId } }));
@@ -1,12 +0,0 @@
1
- import type { H3Event } from 'h3';
2
- /**
3
- * The staff gate of every `/api/admin/events` route (event and ticket management, check-in). The host decides who is
4
- * staff through the `events:authorize` Nitro hook; denied by default. Bearer tokens need the `events:manage` scope.
5
- */
6
- export declare const eventsStaff: any;
7
- /** Non-throwing form of the `events:authorize` policy for the caller of an already-authenticated request (MCP). */
8
- export declare const canManageEvents: (event: H3Event, principal: {
9
- user: {
10
- id: number;
11
- };
12
- }) => any;
@@ -1,6 +0,0 @@
1
- export const eventsStaff = defineStaffGuard({
2
- hook: "events:authorize",
3
- scope: "events:manage",
4
- message: "You are not allowed to manage events."
5
- });
6
- export const canManageEvents = (event, principal) => eventsStaff.can(event, principal.user.id);