@frigear-nu/events 0.5.4 → 0.5.5

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/README.md CHANGED
@@ -31,7 +31,9 @@ export default defineNuxtConfig({
31
31
  Policies on `events:manage` and `events:refund` (`definePolicy`) receive the event row (`typeof schema.events.$inferSelect`)
32
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
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`.
34
+ the policy only with `withoutRecord`, so a record policy does not filter the staff event lists (the admin list, the
35
+ dashboard's upcoming events, the `list-all-events` MCP tool). Give them the same rule in the `events:list:filter` hook,
36
+ which ANDs your conditions on `schema.events` into those queries.
35
37
 
36
38
  ```ts
37
39
  // server/policies.ts: youth coordinators manage the `youth-*` events only
@@ -41,6 +43,18 @@ export default [
41
43
  ]
42
44
  ```
43
45
 
46
+ ```ts [server/plugins/events-list.ts]
47
+ import { like } from 'drizzle-orm'
48
+ import { schema } from '@nuxthub/db'
49
+
50
+ // The same rule on the staff lists, which check without a record and so run no policy.
51
+ export default defineNitroPlugin((nitro) => {
52
+ nitro.hooks.hook('events:list:filter', async ({ event, principal, where }) => {
53
+ if ((await getEffectiveRoles(event, principal.user)).includes('youth')) where.push(like(schema.events.slug, 'youth-%'))
54
+ })
55
+ })
56
+ ```
57
+
44
58
  Tickets (`tickets:read`, `tickets:write`) are self-service: every signed-in user holds them. The named scope `tickets`
45
59
  offers both to API tokens and OAuth clients.
46
60
 
package/dist/module.d.mts CHANGED
@@ -1,5 +1,7 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
2
  import { H3Event } from 'h3';
3
+ import { SQL } from 'drizzle-orm';
4
+ import { AuthPrincipal } from '@frigear-nu/auth/utils';
3
5
  import { Translated } from '@frigear-nu/ui/translated';
4
6
  export { Translated } from '@frigear-nu/ui/translated';
5
7
  import { Schedule } from '@frigear-nu/module-kit/schedule';
@@ -259,6 +261,18 @@ type MembershipOption = {
259
261
  value: string;
260
262
  label: string;
261
263
  };
264
+ /**
265
+ * Context of the `events:list:filter` hook, called by every staff list of events (the admin list, the dashboard's
266
+ * upcoming events and the `list-all-events` MCP tool). Those lists check `events:manage` without a record, so record
267
+ * policies never run for them: a host that narrows `events:manage` with a policy pushes the same rule here.
268
+ */
269
+ type EventsListFilterContext = {
270
+ event: H3Event;
271
+ /** The caller, as `authorize(event, 'events:manage')` returned it. */
272
+ principal: AuthPrincipal;
273
+ /** Conditions on `schema.events`, ANDed into the list query. Push to narrow; never remove another listener's. */
274
+ where: SQL[];
275
+ };
262
276
  /** Context of the `events:membership:check` hook. */
263
277
  type MembershipCheckContext = {
264
278
  userId: number;
@@ -298,6 +312,11 @@ declare module 'nitropack' {
298
312
  'events:membership:check': (ctx: MembershipCheckContext) => void | Promise<void>;
299
313
  /** Membership provider: set `ctx.available = true` and add the selectable memberships to `ctx.options`. */
300
314
  'events:membership:options': (ctx: MembershipOptionsContext) => void | Promise<void>;
315
+ /**
316
+ * Narrow the staff lists of events: push conditions on `schema.events` to `ctx.where`. Mirror here any policy a
317
+ * host adds on `events:manage`, since lists check without a record and so run no record policy.
318
+ */
319
+ 'events:list:filter': (ctx: EventsListFilterContext) => void | Promise<void>;
301
320
  /** Policy hook: throw to deny a purchase. */
302
321
  'events:purchase:before': (ctx: PurchaseBeforeContext) => void | Promise<void>;
303
322
  /** A ticket became `paid` (free tickets immediately, paid ones after the Stripe event). Send confirmations here. */
@@ -309,4 +328,4 @@ declare module 'nitropack' {
309
328
  declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
310
329
 
311
330
  export { _default as default };
312
- 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 };
331
+ export type { AddonDto, AddonGroupDto, AdminAddonDto, AdminAddonGroupDto, AdminEventDetailDto, AdminEventDto, AdminTicketTypeDto, AttendeeDto, CheckInResponse, EventDetailDto, EventStatus, EventSummaryDto, EventsListFilterContext, 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.5.4",
4
+ "version": "0.5.5",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.4",
7
7
  "unbuild": "unknown"
package/dist/module.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { defineNuxtModule, createResolver, hasNuxtModule, addServerImportsDir, addNitroPlugin, addImports, addComponentsDir } from '@nuxt/kit';
2
- import { registerModule, registerTailwindSource, registerLocales, resolvePagePath, resolveDashboardHubPath, joinPagePath, isPathUnder, addPageRedirects, registerDatabaseTable, addModuleRoutes, registerBootstrapProvider, inlineModuleRuntime, addModulePages, addOptionalMenuSource } from '@frigear-nu/module-kit/utils';
3
- import { adminRoute } from '@frigear-nu/admin/utils';
2
+ import { registerModule, registerTailwindSource, registerLocales, resolvePagePath, resolveDashboardHubPath, joinPagePath, isPathUnder, addPageRedirects, registerDatabaseTable, addModuleRoutes, registerPreloadProvider, inlineModuleRuntime, addModulePages, addOptionalMenuSource } from '@frigear-nu/module-kit/utils';
3
+ import { adminRoute, extendAdminDashboard } from '@frigear-nu/admin/utils';
4
4
  import { registerAccess } from '@frigear-nu/auth/utils';
5
5
  import { eventsAccess } from '../dist/runtime/access.js';
6
6
  import { addMcpDefinitions } from '@frigear-nu/mcp/utils';
@@ -67,10 +67,10 @@ const module$1 = defineNuxtModule({
67
67
  { method: "get", path: ":slug", file: "public/event.get" },
68
68
  { method: "post", path: ":slug/purchase", file: "public/purchase.post" }
69
69
  ], { base: "/api/events" });
70
- registerBootstrapProvider(nuxt, {
71
- scope: "account",
70
+ registerPreloadProvider(nuxt, {
71
+ area: "account",
72
72
  key: "events:tickets:mine",
73
- handler: resolver.resolve("./runtime/server/bootstrap/my-tickets")
73
+ handler: resolver.resolve("./runtime/server/preload/my-tickets")
74
74
  });
75
75
  addModuleRoutes(resolver, [
76
76
  { method: "get", path: "", file: "admin/events.get" },
@@ -132,9 +132,22 @@ const module$1 = defineNuxtModule({
132
132
  ]);
133
133
  }
134
134
  if (adminPath && hasNuxtModule("@frigear-nu/widget")) {
135
- const { extendWidgets } = await import('@frigear-nu/widget/utils');
136
- extendWidgets(nuxt, "admin.dashboard.top", { id: "events-upcoming-stat", component: resolver.resolve("./runtime/app/widgets/UpcomingEventsStat.vue"), order: 20 });
137
- extendWidgets(nuxt, "admin.dashboard.side", { id: "events-upcoming", component: resolver.resolve("./runtime/app/widgets/UpcomingEvents.vue"), order: 10 });
135
+ extendAdminDashboard(nuxt, {
136
+ id: "events-upcoming-stat",
137
+ component: resolver.resolve("./runtime/app/widgets/UpcomingEventsStat.vue"),
138
+ title: "Upcoming events",
139
+ titleKey: "events.admin.dashboard.upcomingStat",
140
+ order: 11,
141
+ size: { cols: 1, maxCols: 2 }
142
+ }, "top");
143
+ extendAdminDashboard(nuxt, {
144
+ id: "events-upcoming",
145
+ component: resolver.resolve("./runtime/app/widgets/UpcomingEvents.vue"),
146
+ title: "Next events",
147
+ titleKey: "events.admin.dashboard.upcoming",
148
+ order: 30,
149
+ size: { cols: 2, minCols: 1 }
150
+ }, "side");
138
151
  }
139
152
  addOptionalMenuSource(nuxt, { file: resolver.resolve("./runtime/menus"), menu: "account" });
140
153
  }
@@ -60,12 +60,13 @@ const catalog = useEventCatalogActions({ onChanged: () => emit("refresh") });
60
60
  </p>
61
61
  </div>
62
62
  <div>
63
- <UButton
63
+ <TooltipButton
64
64
  icon="i-lucide-plus"
65
65
  color="neutral"
66
66
  variant="outline"
67
67
  size="xs"
68
68
  :label="t('admin.addGroup', 'Add add-on group')"
69
+ :tooltip="t('admin.addGroupHint', 'Give buyers a set of extras to choose from with this ticket')"
69
70
  @click="catalog.openGroup(ticketType)"
70
71
  />
71
72
  </div>
@@ -58,9 +58,10 @@ const columns = computed(() => [
58
58
  :description="t('admin.listDescription', 'Events, their ticket types and attendees.')"
59
59
  >
60
60
  <template #actions>
61
- <UButton
61
+ <TooltipButton
62
62
  icon="i-lucide-plus"
63
63
  :label="t('admin.create', 'New event')"
64
+ :tooltip="t('admin.createHint', 'Create a draft event; it stays hidden until you publish it')"
64
65
  @click="actions.create()"
65
66
  />
66
67
  </template>
@@ -60,12 +60,13 @@ const typeColumns = computed(() => [
60
60
  <template>
61
61
  <TableCard :title="t('admin.ticketTypes', 'Ticket types')">
62
62
  <template #actions>
63
- <UButton
63
+ <TooltipButton
64
64
  icon="i-lucide-plus"
65
65
  variant="outline"
66
66
  color="neutral"
67
67
  size="xs"
68
68
  :label="t('admin.addType', 'Add ticket type')"
69
+ :tooltip="t('admin.addTypeHint', 'Add a kind of ticket people can get for this event')"
69
70
  @click="catalog.openTicketType()"
70
71
  />
71
72
  </template>
@@ -75,12 +76,13 @@ const typeColumns = computed(() => [
75
76
  :ui="tableUi({ tr: 'data-[expanded=true]:bg-elevated/30' })"
76
77
  >
77
78
  <template #expand-cell="{ row }">
78
- <UButton
79
+ <TooltipButton
79
80
  color="neutral"
80
81
  variant="ghost"
81
82
  size="xs"
82
83
  :icon="row.getIsExpanded() ? 'i-lucide-chevron-down' : 'i-lucide-chevron-right'"
83
84
  :aria-label="t('admin.addonGroups', 'Add-ons')"
85
+ :tooltip="t('admin.addonGroupsHint', 'Show or hide the add-on groups of this ticket type')"
84
86
  :aria-expanded="row.getIsExpanded()"
85
87
  @click="row.toggleExpanded()"
86
88
  />
@@ -1,3 +1,6 @@
1
- declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
1
+ type __VLS_Props = {
2
+ framed?: boolean;
3
+ };
4
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
2
5
  declare const _default: typeof __VLS_export;
3
6
  export default _default;
@@ -2,6 +2,9 @@
2
2
  import { eventsApi } from "../../utils/api";
3
3
  import { useEventLinks, useEventsTranslate, useFormat, useLazyFetch, useModuleT } from "#imports";
4
4
  defineOptions({ name: "EventsUpcomingList" });
5
+ defineProps({
6
+ framed: { type: Boolean, required: false }
7
+ });
5
8
  const t = useModuleT("events");
6
9
  const format = useFormat();
7
10
  const tr = useEventsTranslate();
@@ -11,7 +14,7 @@ const { data, status } = useLazyFetch(eventsApi.admin.upcoming, { key: "admin-ev
11
14
 
12
15
  <template>
13
16
  <ListCard
14
- :title="t('admin.upcoming.title', 'Upcoming events')"
17
+ :title="framed ? void 0 : t('admin.upcoming.title', 'Upcoming events')"
15
18
  :loading="status === 'pending' && !data"
16
19
  :is-empty="!data?.items.length"
17
20
  :empty="t('admin.upcoming.empty', 'No upcoming events.')"
@@ -1,3 +1,6 @@
1
- declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
1
+ type __VLS_Props = {
2
+ framed?: boolean;
3
+ };
4
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
2
5
  declare const _default: typeof __VLS_export;
3
6
  export default _default;
@@ -1,3 +1,6 @@
1
- declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
1
+ type __VLS_Props = {
2
+ framed?: boolean;
3
+ };
4
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
2
5
  declare const _default: typeof __VLS_export;
3
6
  export default _default;
@@ -2,6 +2,9 @@
2
2
  import { eventsApi } from "../../utils/api";
3
3
  import { useEventLinks, useLazyFetch, useModuleT } from "#imports";
4
4
  defineOptions({ name: "EventsUpcomingStat" });
5
+ defineProps({
6
+ framed: { type: Boolean, required: false }
7
+ });
5
8
  const t = useModuleT("events");
6
9
  const links = useEventLinks();
7
10
  const { data, status } = useLazyFetch(eventsApi.admin.upcoming, { key: "admin-events-upcoming" });
@@ -9,7 +12,7 @@ const { data, status } = useLazyFetch(eventsApi.admin.upcoming, { key: "admin-ev
9
12
 
10
13
  <template>
11
14
  <StatCard
12
- :label="t('admin.upcoming.stat', 'Upcoming events')"
15
+ :label="framed ? void 0 : t('admin.upcoming.stat', 'Upcoming events')"
13
16
  icon="i-lucide-calendar-days"
14
17
  :to="links.admin()"
15
18
  :value="data?.total"
@@ -1,3 +1,6 @@
1
- declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
1
+ type __VLS_Props = {
2
+ framed?: boolean;
3
+ };
4
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
2
5
  declare const _default: typeof __VLS_export;
3
6
  export default _default;
@@ -149,6 +149,7 @@
149
149
  "capacity": "Kapacitet",
150
150
  "access": "Adgang",
151
151
  "addonGroups": "Tilvalg",
152
+ "addonGroupsHint": "Vis eller skjul billettypens tilvalgsgrupper",
152
153
  "ruleAny": "Alle medlemskaber",
153
154
  "confirmRemoveType": "Slet {name}?",
154
155
  "confirmRemoveTypeDescription": "Dens tilvalgsgrupper og valg slettes også. En billettype med aktive billetter kan ikke slettes.",
@@ -157,6 +158,7 @@
157
158
  "editType": "Redigér billettype",
158
159
  "ticketTypes": "Billettyper",
159
160
  "addType": "Tilføj billettype",
161
+ "addTypeHint": "Tilføj en slags billet, folk kan få til arrangementet",
160
162
  "requires": "Kræver",
161
163
  "notFor": "Ikke for",
162
164
  "noTypes": "Ingen billettyper endnu: ingen kan købe en billet.",
@@ -172,6 +174,7 @@
172
174
  "excludesHelp": "Medlemmer med disse medlemskaber kan ikke købe denne billet, så medlemmer og ikke-medlemmer kan have hver deres pris.",
173
175
  "created": "Arrangementet er oprettet",
174
176
  "create": "Nyt arrangement",
177
+ "createHint": "Opret et arrangement som kladde; det er skjult, indtil du udgiver det",
175
178
  "createDescription": "Det gemmes som kladde, indtil du udgiver det.",
176
179
  "createAction": "Opret kladde",
177
180
  "slug": "URL-navn",
@@ -199,6 +202,7 @@
199
202
  "included": "Inkluderet",
200
203
  "noAddons": "Ingen valg endnu: købere har intet at vælge imellem.",
201
204
  "addGroup": "Tilføj tilvalgsgruppe",
205
+ "addGroupHint": "Giv købere et sæt tilvalg at vælge imellem til billetten",
202
206
  "groupSaved": "Tilvalgsgruppen er gemt.",
203
207
  "groupTitle": "Titel",
204
208
  "groupTitleHelp": "Vises over valgene, f.eks. Mad.",
@@ -244,7 +248,11 @@
244
248
  "attendeesLoadFailed": "Deltagerne kunne ikke indlæses",
245
249
  "allStatuses": "Alle statusser",
246
250
  "clearFilters": "Ryd filtre",
247
- "searchAttendees": "Søg navn eller e-mail"
251
+ "searchAttendees": "Søg navn eller e-mail",
252
+ "dashboard": {
253
+ "upcomingStat": "Kommende arrangementer",
254
+ "upcoming": "Næste arrangementer"
255
+ }
248
256
  },
249
257
  "listDescription": "Find et arrangement og få din billet.",
250
258
  "noTicketsTitle": "Ingen billetter endnu",
@@ -149,6 +149,7 @@
149
149
  "capacity": "Capacity",
150
150
  "access": "Access",
151
151
  "addonGroups": "Add-ons",
152
+ "addonGroupsHint": "Show or hide the add-on groups of this ticket type",
152
153
  "ruleAny": "Any membership",
153
154
  "confirmRemoveType": "Delete {name}?",
154
155
  "confirmRemoveTypeDescription": "Its add-on groups and choices are deleted too. A ticket type with active tickets cannot be deleted.",
@@ -157,6 +158,7 @@
157
158
  "editType": "Edit ticket type",
158
159
  "ticketTypes": "Ticket types",
159
160
  "addType": "Add ticket type",
161
+ "addTypeHint": "Add a kind of ticket people can get for this event",
160
162
  "requires": "Requires",
161
163
  "notFor": "Not for",
162
164
  "noTypes": "No ticket types yet: nobody can buy a ticket.",
@@ -172,6 +174,7 @@
172
174
  "excludesHelp": "Holders of these memberships cannot buy this ticket, so members and non-members can have separate prices.",
173
175
  "created": "Event created",
174
176
  "create": "New event",
177
+ "createHint": "Create a draft event; it stays hidden until you publish it",
175
178
  "createDescription": "It is saved as a draft until you publish it.",
176
179
  "createAction": "Create draft",
177
180
  "slug": "URL name",
@@ -199,6 +202,7 @@
199
202
  "included": "Included",
200
203
  "noAddons": "No choices yet: buyers will see nothing to pick.",
201
204
  "addGroup": "Add add-on group",
205
+ "addGroupHint": "Give buyers a set of extras to choose from with this ticket",
202
206
  "groupSaved": "Add-on group saved.",
203
207
  "groupTitle": "Title",
204
208
  "groupTitleHelp": "Shown above the choices, e.g. Food.",
@@ -244,7 +248,11 @@
244
248
  "attendeesLoadFailed": "Attendees could not be loaded",
245
249
  "allStatuses": "All statuses",
246
250
  "clearFilters": "Clear filters",
247
- "searchAttendees": "Search name or email"
251
+ "searchAttendees": "Search name or email",
252
+ "dashboard": {
253
+ "upcomingStat": "Upcoming events",
254
+ "upcoming": "Next events"
255
+ }
248
256
  },
249
257
  "listDescription": "Find an event and get your ticket.",
250
258
  "noTicketsTitle": "No tickets yet",
@@ -1,8 +1,9 @@
1
1
  import { db, schema } from "@nuxthub/db";
2
2
  import { desc } from "drizzle-orm";
3
+ import { eventsListFilter } from "../../../utils/admin.js";
3
4
  export default defineScopedMcpTool({
4
5
  description: "List all events including drafts and archived ones (staff).",
5
6
  permission: "events:manage",
6
7
  annotations: { readOnlyHint: true },
7
- handler: () => db.select().from(schema.events).orderBy(desc(schema.events.startsAt))
8
+ handler: async (_args, { event, principal }) => db.select().from(schema.events).where(await eventsListFilter(event, principal)).orderBy(desc(schema.events.startsAt))
8
9
  });
@@ -1,7 +1,7 @@
1
1
  import type { H3Event } from 'h3';
2
2
  import type { TicketDto } from '../../../types.js';
3
3
  /**
4
- * The caller's tickets: the body of `GET /api/events/me/tickets` and the account bootstrap's `events:tickets:mine`
4
+ * The caller's tickets: the body of `GET /api/events/me/tickets` and the account preload's `events:tickets:mine`
5
5
  * (the key `useMyTickets()` reads), so both always return the same thing.
6
6
  */
7
7
  export default function myTickets(event: H3Event): Promise<TicketDto[]>;
@@ -3,6 +3,7 @@ import { and, count, eq, is, or, sql } from "drizzle-orm";
3
3
  import { PgTable } from "drizzle-orm/pg-core";
4
4
  import { z } from "zod";
5
5
  import { escapeLike, likeContains, orderByQuery, pageQuery, pageRange, paginate } from "@frigear-nu/module-kit/server";
6
+ import { eventsListFilter } from "../../utils/admin.js";
6
7
  function translatedContains(column, value) {
7
8
  const pattern = `%${escapeLike(value)}%`;
8
9
  if (is(schema.events, PgTable)) {
@@ -18,12 +19,12 @@ const querySchema = pageQuery({
18
19
  }
19
20
  });
20
21
  export default defineEventHandler(async (event) => {
21
- await authorize(event, "events:manage");
22
+ const principal = await authorize(event, "events:manage");
22
23
  const query = await getValidatedQuery(event, querySchema.parse);
23
- const conditions = [];
24
+ const conditions = [await eventsListFilter(event, principal)];
24
25
  if (query.q) conditions.push(or(translatedContains(schema.events.name, query.q), likeContains(schema.events.slug, query.q)));
25
26
  if (query.status) conditions.push(eq(schema.events.status, query.status));
26
- const where = conditions.length ? and(...conditions) : void 0;
27
+ const where = and(...conditions);
27
28
  const orderBy = orderByQuery({
28
29
  startsAt: schema.events.startsAt,
29
30
  createdAt: schema.events.createdAt,
@@ -1,10 +1,15 @@
1
1
  import { db, schema } from "@nuxthub/db";
2
2
  import { and, asc, count, eq, gte } from "drizzle-orm";
3
3
  import { isoDate } from "@frigear-nu/module-kit/server";
4
+ import { eventsListFilter } from "../../utils/admin.js";
4
5
  const LIMIT = 5;
5
6
  export default defineEventHandler(async (event) => {
6
- await authorize(event, "events:manage");
7
- const upcoming = and(eq(schema.events.status, "published"), gte(schema.events.startsAt, /* @__PURE__ */ new Date()));
7
+ const principal = await authorize(event, "events:manage");
8
+ const upcoming = and(
9
+ eq(schema.events.status, "published"),
10
+ gte(schema.events.startsAt, /* @__PURE__ */ new Date()),
11
+ await eventsListFilter(event, principal)
12
+ );
8
13
  const [[total], rows] = await Promise.all([
9
14
  db.select({ value: count() }).from(schema.events).where(upcoming),
10
15
  db.select({
@@ -1,2 +1,2 @@
1
- import myTickets from "../../bootstrap/my-tickets.js";
1
+ import myTickets from "../../preload/my-tickets.js";
2
2
  export default defineEventHandler(myTickets);
@@ -1,5 +1,7 @@
1
1
  import type { H3Event } from 'h3';
2
2
  import type { z } from 'zod';
3
+ import type { SQL } from 'drizzle-orm';
4
+ import type { AuthPrincipal } from '@frigear-nu/auth/utils';
3
5
  import { eventInput, ticketTypeInput } from './admin-schemas.js';
4
6
  import { eventsAccess } from '../../access.js';
5
7
  import type { addonGroupInput } from './admin-schemas.js';
@@ -7,6 +9,12 @@ type TicketTypeInput = z.output<typeof ticketTypeInput>;
7
9
  type AddonGroupInput = z.output<typeof addonGroupInput>;
8
10
  /** The permissions whose record-level policies run on one event. */
9
11
  export type EventsRecordPermission = typeof eventsAccess.permissions.manage | typeof eventsAccess.permissions.refund;
12
+ /**
13
+ * The host's narrowing of the staff lists of events (`events:list:filter`), as one condition on `schema.events`, or
14
+ * `undefined` when no listener narrows. Every list that checks `events:manage` without a record ANDs it into its query,
15
+ * so a host policy on `events:manage` can be mirrored once for all of them.
16
+ */
17
+ export declare function eventsListFilter(event: H3Event, principal: AuthPrincipal): Promise<SQL | undefined>;
10
18
  /**
11
19
  * Loads the event `eventId` (404 `not_found`) and authorizes `permission` on it. Every record-level check of
12
20
  * `events:manage` and `events:refund` goes through here, so their policies always receive the stored EVENT row
@@ -5,6 +5,11 @@ 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 eventsListFilter(event, principal) {
9
+ const ctx = { event, principal, where: [] };
10
+ await useNitroApp().hooks.callHook("events:list:filter", ctx);
11
+ return ctx.where.length ? and(...ctx.where) : void 0;
12
+ }
8
13
  export async function authorizeEventsRecord(event, eventId, permission = eventsAccess.permissions.manage) {
9
14
  const [row] = await db.select().from(schema.events).where(eq(schema.events.id, eventId)).limit(1);
10
15
  if (!row) throw notFound("Event not found.");
@@ -6,7 +6,7 @@ export declare const eventsApi: {
6
6
  /** `POST` a ticket purchase. */
7
7
  readonly purchase: (slug: string) => string;
8
8
  readonly me: {
9
- /** `GET` the caller's tickets (also the account bootstrap's `events:tickets:mine`). */
9
+ /** `GET` the caller's tickets (also the account preload's `events:tickets:mine`). */
10
10
  readonly tickets: "/api/events/me/tickets";
11
11
  /** `GET` one of the caller's tickets. */
12
12
  readonly ticket: (id: string) => string;
@@ -9,7 +9,7 @@ export const eventsApi = {
9
9
  /** `POST` a ticket purchase. */
10
10
  purchase: (slug) => `${PUBLIC_BASE}/${enc(slug)}/purchase`,
11
11
  me: {
12
- /** `GET` the caller's tickets (also the account bootstrap's `events:tickets:mine`). */
12
+ /** `GET` the caller's tickets (also the account preload's `events:tickets:mine`). */
13
13
  tickets: `${PUBLIC_BASE}/me/tickets`,
14
14
  /** `GET` one of the caller's tickets. */
15
15
  ticket: (id) => `${PUBLIC_BASE}/me/tickets/${enc(id)}`,
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 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 EventsListFilterContext, 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,7 +1,11 @@
1
1
  {
2
2
  "name": "@frigear-nu/events",
3
- "version": "0.5.4",
3
+ "version": "0.5.5",
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
+ "keywords": [
6
+ "frigear-module",
7
+ "nuxt-module"
8
+ ],
5
9
  "homepage": "https://docs.frigear.dev/modules/features/events",
6
10
  "repository": {
7
11
  "type": "git",
@@ -35,15 +39,15 @@
35
39
  "playground"
36
40
  ],
37
41
  "dependencies": {
38
- "@frigear-nu/admin": "^0.5.2",
39
- "@frigear-nu/auth": "^0.6.8",
40
- "@frigear-nu/mcp": "^0.5.2",
41
- "@frigear-nu/module-kit": "^1.3.12",
42
- "@frigear-nu/payments": "^0.5.4",
43
- "@frigear-nu/stripe": "^0.4.3",
44
- "@frigear-nu/subscriptions": "^0.5.3",
45
- "@frigear-nu/ui": "^0.2.11",
46
- "@frigear-nu/users": "^3.1.5",
42
+ "@frigear-nu/admin": "^0.5.3",
43
+ "@frigear-nu/auth": "^0.6.9",
44
+ "@frigear-nu/mcp": "^0.5.3",
45
+ "@frigear-nu/module-kit": "^1.3.13",
46
+ "@frigear-nu/payments": "^0.5.5",
47
+ "@frigear-nu/stripe": "^0.4.4",
48
+ "@frigear-nu/subscriptions": "^0.5.4",
49
+ "@frigear-nu/ui": "^0.2.12",
50
+ "@frigear-nu/users": "^3.1.6",
47
51
  "@libsql/client": "^0.18.0",
48
52
  "@nuxt/kit": "^4.6.4",
49
53
  "@vueuse/core": "^15.0.0",
@@ -55,8 +59,8 @@
55
59
  "zod": "^4.6.7"
56
60
  },
57
61
  "peerDependencies": {
58
- "@frigear-nu/menu": "^0.4.1",
59
- "@frigear-nu/widget": "^0.4.3",
62
+ "@frigear-nu/menu": "^0.4.2",
63
+ "@frigear-nu/widget": "^0.4.4",
60
64
  "@nuxt/ui": "^4.12.0",
61
65
  "@nuxthub/core": "^0.10.12"
62
66
  },
@@ -72,8 +76,8 @@
72
76
  }
73
77
  },
74
78
  "devDependencies": {
75
- "@frigear-nu/menu": "^0.4.1",
76
- "@frigear-nu/widget": "^0.4.3",
79
+ "@frigear-nu/menu": "^0.4.2",
80
+ "@frigear-nu/widget": "^0.4.4",
77
81
  "@nuxt/devtools": "^4.2.0",
78
82
  "@nuxt/eslint-config": "^1.17.0",
79
83
  "@nuxt/module-builder": "^1.0.4",