@frigear-nu/events 0.5.5 → 0.6.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 (35) hide show
  1. package/dist/module.d.mts +59 -1
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +33 -4
  4. package/dist/runtime/app/dashboard/MyNextTicket.d.vue.ts +3 -0
  5. package/dist/runtime/app/dashboard/MyNextTicket.vue +110 -0
  6. package/dist/runtime/app/dashboard/MyNextTicket.vue.d.ts +3 -0
  7. package/dist/runtime/app/grants/EventGrantField.d.vue.ts +15 -0
  8. package/dist/runtime/app/grants/EventGrantField.vue +87 -0
  9. package/dist/runtime/app/grants/EventGrantField.vue.d.ts +15 -0
  10. package/dist/runtime/app/pages/admin.vue +2 -0
  11. package/dist/runtime/app/tabs/Attendees.vue +33 -12
  12. package/dist/runtime/app/tabs/Details.vue +2 -1
  13. package/dist/runtime/app/widgets/UpcomingEvents.vue +22 -13
  14. package/dist/runtime/app/widgets/UpcomingEventsStat.vue +7 -2
  15. package/dist/runtime/campaigns-owner.d.ts +38 -0
  16. package/dist/runtime/campaigns-owner.js +123 -0
  17. package/dist/runtime/dashboard.d.ts +6 -0
  18. package/dist/runtime/dashboard.js +19 -0
  19. package/dist/runtime/i18n/lang/da.json +32 -1
  20. package/dist/runtime/i18n/lang/en.json +32 -1
  21. package/dist/runtime/server/grants/event.d.ts +3 -0
  22. package/dist/runtime/server/grants/event.js +38 -0
  23. package/dist/runtime/server/plugins/campaigns-owner.d.ts +2 -0
  24. package/dist/runtime/server/plugins/campaigns-owner.js +39 -0
  25. package/dist/runtime/server/plugins/payment-hooks.js +2 -2
  26. package/dist/runtime/server/routes/admin/attendees.get.js +5 -2
  27. package/dist/runtime/server/routes/admin/check-in.post.js +1 -0
  28. package/dist/runtime/server/routes/admin/event.delete.js +1 -0
  29. package/dist/runtime/server/utils/admin.d.ts +8 -2
  30. package/dist/runtime/server/utils/admin.js +20 -0
  31. package/dist/runtime/server/utils/tickets.js +1 -1
  32. package/dist/runtime/utils/grants.d.ts +18 -0
  33. package/dist/runtime/utils/grants.js +17 -0
  34. package/dist/types.d.mts +1 -1
  35. package/package.json +17 -7
@@ -0,0 +1,38 @@
1
+ import type { CampaignOwnerDefinition, CampaignOwnerResolved } from '@frigear-nu/campaigns';
2
+ import type { EventStatus } from '../types.js';
3
+ import type { Translated } from '@frigear-nu/ui/translated';
4
+ import type { EventPages } from './utils/links.js';
5
+ /** The owner type of an event's messages, as stored on its campaigns and used in `{{event.name}}`. */
6
+ export declare const EVENTS_CAMPAIGN_OWNER = "event";
7
+ /** The happenings of an event that send a message to the ticket holder they happen to. */
8
+ export declare const EVENTS_CAMPAIGN_TRIGGERS: {
9
+ readonly paid: "ticket.paid";
10
+ readonly refunded: "ticket.refunded";
11
+ readonly checkedIn: "checked-in";
12
+ };
13
+ /** The owner definition of events: anchors, happenings, audiences, variables and presets. */
14
+ export declare function eventsCampaignOwner(): CampaignOwnerDefinition;
15
+ /** The fields of an event row the owner answer needs. */
16
+ export type EventsCampaignOwnerRow = {
17
+ id: string;
18
+ slug: string;
19
+ name: Translated;
20
+ status: EventStatus | string;
21
+ startsAt: Date;
22
+ endsAt: Date | null;
23
+ };
24
+ /** Where the answer's links and texts come from: the module's pages, the site's origin, its zone and language. */
25
+ export type EventsCampaignOwnerOptions = {
26
+ pages?: EventPages;
27
+ /** The public site URL (`runtimeConfig.public.siteUrl`); without it `{{event.url}}` is empty. */
28
+ siteUrl?: string;
29
+ timeZone?: string;
30
+ /** The language the event's name is given in (the app's default locale). */
31
+ locale?: string;
32
+ };
33
+ /**
34
+ * The event as campaigns needs it (`campaigns:owner:resolve`): its name, staff page, dates (an event without an end ends
35
+ * when it starts), the values of `{{event.*}}`, and whether it is live (published: a draft holds its relative messages).
36
+ * The record its permission is checked with is the event row itself, so `events:manage` policies see what they always do.
37
+ */
38
+ export declare function eventsCampaignOwnerResolved<R extends EventsCampaignOwnerRow>(row: R, options?: EventsCampaignOwnerOptions): CampaignOwnerResolved;
@@ -0,0 +1,123 @@
1
+ import { translate } from "@frigear-nu/ui/translated";
2
+ import { fillPath } from "./utils/links.js";
3
+ export const EVENTS_CAMPAIGN_OWNER = "event";
4
+ export const EVENTS_CAMPAIGN_TRIGGERS = {
5
+ paid: "ticket.paid",
6
+ refunded: "ticket.refunded",
7
+ checkedIn: "checked-in"
8
+ };
9
+ const DAY = 24 * 60;
10
+ export function eventsCampaignOwner() {
11
+ const holders = (status) => [{ kind: "event", eventId: "{id}", ...status ? { status } : {} }];
12
+ return {
13
+ type: EVENTS_CAMPAIGN_OWNER,
14
+ label: { en: "Event", da: "Arrangement" },
15
+ topic: {
16
+ key: "events.message",
17
+ label: { en: "Event messages", da: "Beskeder om arrangementer" },
18
+ description: {
19
+ en: "Reminders and news about events you have a ticket to.",
20
+ da: "P\xE5mindelser og nyt om arrangementer, du har billet til."
21
+ }
22
+ },
23
+ permission: "events:manage",
24
+ tabArea: "admin.events",
25
+ contextKey: "event",
26
+ tabOrder: 40,
27
+ anchors: [
28
+ { key: "startsAt", label: { en: "Starts", da: "Starter" } },
29
+ // An event without an end ends when it starts.
30
+ { key: "endsAt", label: { en: "Ends", da: "Slutter" } }
31
+ ],
32
+ triggers: [
33
+ { key: EVENTS_CAMPAIGN_TRIGGERS.paid, label: { en: "Ticket paid", da: "Billet betalt" }, description: { en: "A ticket is paid for, or a free ticket is taken.", da: "En billet bliver betalt, eller en gratis billet bliver taget." } },
34
+ { key: EVENTS_CAMPAIGN_TRIGGERS.refunded, label: { en: "Ticket refunded", da: "Billet refunderet" }, description: { en: "A paid ticket is refunded in full.", da: "En betalt billet bliver refunderet helt." } },
35
+ { key: EVENTS_CAMPAIGN_TRIGGERS.checkedIn, label: { en: "Checked in", da: "Tjekket ind" }, description: { en: "A ticket is scanned at the entrance.", da: "En billet bliver scannet ved indgangen." } }
36
+ ],
37
+ audiences: [
38
+ { key: "holders", label: { en: "Ticket holders", da: "Billetholdere" }, description: { en: "Everyone with a paid ticket.", da: "Alle med en betalt billet." }, grants: holders() },
39
+ { key: "checked-in", label: { en: "Checked in", da: "Tjekket ind" }, description: { en: "Ticket holders who have been checked in.", da: "Billetholdere, der er tjekket ind." }, grants: holders("checked-in") },
40
+ { key: "not-checked-in", label: { en: "Not checked in", da: "Ikke tjekket ind" }, description: { en: "Ticket holders who have not been checked in.", da: "Billetholdere, der ikke er tjekket ind." }, grants: holders("not-checked-in") }
41
+ ],
42
+ variables: [
43
+ { key: "name", label: { en: "Name", da: "Navn" } },
44
+ { key: "startsAt", label: { en: "Starts", da: "Starter" }, type: "date" },
45
+ { key: "url", label: { en: "Event page", da: "Arrangementets side" }, type: "url" }
46
+ ],
47
+ presets: [
48
+ {
49
+ key: "reminder",
50
+ label: { en: "Reminder 1 day before", da: "P\xE5mindelse 1 dag f\xF8r" },
51
+ name: "Reminder 1 day before",
52
+ audience: "holders",
53
+ trigger: { type: "relative", anchor: "startsAt", offsetMinutes: -DAY },
54
+ channels: ["email"],
55
+ content: {
56
+ email: {
57
+ subject: { en: "Tomorrow: {{event.name}}", da: "I morgen: {{event.name}}" },
58
+ body: {
59
+ en: "Hi {{recipient.name}},\n\nSee you at {{event.name}}, {{event.startsAt}}.\n\nRead more: {{event.url}}",
60
+ da: "Hej {{recipient.name}},\n\nVi ses til {{event.name}}, {{event.startsAt}}.\n\nL\xE6s mere: {{event.url}}"
61
+ }
62
+ }
63
+ }
64
+ },
65
+ {
66
+ key: "thanks",
67
+ label: { en: "Thanks after the event", da: "Tak efter arrangementet" },
68
+ name: "Thanks after the event",
69
+ audience: "holders",
70
+ trigger: { type: "relative", anchor: "endsAt", offsetMinutes: DAY },
71
+ channels: ["email"],
72
+ content: {
73
+ email: {
74
+ subject: { en: "Thank you for coming to {{event.name}}", da: "Tak fordi du kom til {{event.name}}" },
75
+ body: {
76
+ en: "Hi {{recipient.name}},\n\nThank you for coming to {{event.name}}. We hope to see you again soon.",
77
+ da: "Hej {{recipient.name}},\n\nTak fordi du kom til {{event.name}}. Vi h\xE5ber at se dig igen snart."
78
+ }
79
+ }
80
+ }
81
+ },
82
+ {
83
+ key: "confirmation",
84
+ label: { en: "Ticket confirmation", da: "Billetbekr\xE6ftelse" },
85
+ name: "Ticket confirmation",
86
+ audience: "holders",
87
+ trigger: { type: "event", key: EVENTS_CAMPAIGN_TRIGGERS.paid },
88
+ channels: ["email"],
89
+ content: {
90
+ email: {
91
+ subject: { en: "Your ticket to {{event.name}}", da: "Din billet til {{event.name}}" },
92
+ body: {
93
+ en: "Hi {{recipient.name}},\n\nYour ticket to {{event.name}}, {{event.startsAt}}, is ready.\n\nSee the event: {{event.url}}",
94
+ da: "Hej {{recipient.name}},\n\nDin billet til {{event.name}}, {{event.startsAt}}, er klar.\n\nSe arrangementet: {{event.url}}"
95
+ }
96
+ }
97
+ }
98
+ }
99
+ ]
100
+ };
101
+ }
102
+ function absoluteUrl(siteUrl, path) {
103
+ if (!siteUrl) return null;
104
+ try {
105
+ const url = new URL(path, siteUrl);
106
+ return /^https?:$/.test(url.protocol) ? url.toString() : null;
107
+ } catch {
108
+ return null;
109
+ }
110
+ }
111
+ export function eventsCampaignOwnerResolved(row, options = {}) {
112
+ const name = translate(row.name, options.locale ?? "en");
113
+ const publicPage = options.pages?.event ? absoluteUrl(options.siteUrl, fillPath(options.pages.event, "slug", row.slug)) : null;
114
+ return {
115
+ name,
116
+ url: options.pages?.adminEvent ? fillPath(options.pages.adminEvent, "id", row.id) : null,
117
+ anchors: { startsAt: row.startsAt, endsAt: row.endsAt ?? row.startsAt },
118
+ variables: { name, startsAt: row.startsAt, url: publicPage },
119
+ live: row.status === "published",
120
+ ...options.timeZone ? { timeZone: options.timeZone } : {},
121
+ record: row
122
+ };
123
+ }
@@ -0,0 +1,6 @@
1
+ import type { DashboardItem } from '@frigear-nu/dashboard/types';
2
+ /**
3
+ * The items events adds to the signed-in hub's dashboard (`extendHubDashboard`). `resolve` turns a path relative to
4
+ * `module.ts` into an absolute one. Kept apart from the module so a test can register them without a Nuxt build.
5
+ */
6
+ export declare function eventsHubDashboardItems(resolve: (path: string) => string): DashboardItem[];
@@ -0,0 +1,19 @@
1
+ import { eventsAccess } from "./access.js";
2
+ export function eventsHubDashboardItems(resolve) {
3
+ return [
4
+ {
5
+ id: "events.next-ticket",
6
+ component: resolve("./runtime/app/dashboard/MyNextTicket.vue"),
7
+ title: "My next ticket",
8
+ titleKey: "events.dashboard.nextTicket",
9
+ icon: "i-lucide-ticket",
10
+ // Beside "My crew status" (10), before the shift items: the two tall cards share a row.
11
+ order: 15,
12
+ // The event's date, name and ticket type, with a button to the ticket (or to pay for it).
13
+ size: { cols: 2, minCols: 1, maxCols: 4 },
14
+ // Most people hold no ticket for an upcoming event: the item only joins the grid when there is one.
15
+ optional: true,
16
+ permission: eventsAccess.permissions["tickets:read"]
17
+ }
18
+ ];
19
+ }
@@ -122,7 +122,10 @@
122
122
  "stat": "Kommende arrangementer",
123
123
  "title": "Kommende arrangementer",
124
124
  "empty": "Ingen kommende arrangementer.",
125
- "all": "Alle arrangementer"
125
+ "all": "Alle arrangementer",
126
+ "next": "Næste: {name}, {date}",
127
+ "none": "Intet planlagt endnu",
128
+ "error": "Kunne ikke hente de kommende arrangementer."
126
129
  },
127
130
  "saved": "Gemt.",
128
131
  "details": "Detaljer",
@@ -246,6 +249,10 @@
246
249
  "forbidden": "Du har ikke adgang til arrangementer",
247
250
  "eventLoadFailed": "Arrangementet kunne ikke indlæses",
248
251
  "attendeesLoadFailed": "Deltagerne kunne ikke indlæses",
252
+ "onlyCheckedIn": "Kun fremmødte",
253
+ "noCheckedInAttendees": "Ingen fremmødte deltagere fundet.",
254
+ "checkInAttendee": "Tjek deltager ind",
255
+ "attendeeCheckedIn": "{name} er tjekket ind.",
249
256
  "allStatuses": "Alle statusser",
250
257
  "clearFilters": "Ryd filtre",
251
258
  "searchAttendees": "Søg navn eller e-mail",
@@ -274,6 +281,30 @@
274
281
  },
275
282
  "roles": {
276
283
  "eventmanager": "Eventansvarlig"
284
+ },
285
+ "grants": {
286
+ "event": "Arrangement",
287
+ "choose": "Vælg et arrangement",
288
+ "search": "Søg i arrangementer",
289
+ "status": "Hvilke billetholdere",
290
+ "allTicketTypes": "Alle billettyper",
291
+ "statuses": {
292
+ "paid": "Alle billetholdere",
293
+ "checkedIn": "Tjekket ind",
294
+ "notCheckedIn": "Ikke tjekket ind"
295
+ }
296
+ },
297
+ "dashboard": {
298
+ "nextTicket": "Min næste billet",
299
+ "allTickets": "Alle billetter",
300
+ "ticketToday": "I dag",
301
+ "ticketTomorrow": "I morgen",
302
+ "ticketInDays": "Om {count} dage",
303
+ "ticketUnpaid": "Billetten er ikke betalt endnu",
304
+ "ticketUnpaidHint": "Betal for den for at beholde din plads.",
305
+ "payTicket": "Betal for billetten",
306
+ "showTicket": "Vis min billet",
307
+ "moreTickets": "{count} mere på vej"
277
308
  }
278
309
  }
279
310
  }
@@ -122,7 +122,10 @@
122
122
  "stat": "Upcoming events",
123
123
  "title": "Upcoming events",
124
124
  "empty": "No upcoming events.",
125
- "all": "All events"
125
+ "all": "All events",
126
+ "next": "Next: {name}, {date}",
127
+ "none": "Nothing planned yet",
128
+ "error": "Could not load the upcoming events."
126
129
  },
127
130
  "saved": "Saved.",
128
131
  "details": "Details",
@@ -246,6 +249,10 @@
246
249
  "forbidden": "You do not have access to events",
247
250
  "eventLoadFailed": "The event could not be loaded",
248
251
  "attendeesLoadFailed": "Attendees could not be loaded",
252
+ "onlyCheckedIn": "Checked in only",
253
+ "noCheckedInAttendees": "No checked-in attendees found.",
254
+ "checkInAttendee": "Check in attendee",
255
+ "attendeeCheckedIn": "{name} checked in.",
249
256
  "allStatuses": "All statuses",
250
257
  "clearFilters": "Clear filters",
251
258
  "searchAttendees": "Search name or email",
@@ -274,6 +281,30 @@
274
281
  },
275
282
  "roles": {
276
283
  "eventmanager": "Event manager"
284
+ },
285
+ "grants": {
286
+ "event": "Event",
287
+ "choose": "Choose an event",
288
+ "search": "Search events",
289
+ "status": "Which ticket holders",
290
+ "allTicketTypes": "Every ticket type",
291
+ "statuses": {
292
+ "paid": "Every ticket holder",
293
+ "checkedIn": "Checked in",
294
+ "notCheckedIn": "Not checked in"
295
+ }
296
+ },
297
+ "dashboard": {
298
+ "nextTicket": "My next ticket",
299
+ "allTickets": "All tickets",
300
+ "ticketToday": "Today",
301
+ "ticketTomorrow": "Tomorrow",
302
+ "ticketInDays": "In {count} days",
303
+ "ticketUnpaid": "This ticket is not paid yet",
304
+ "ticketUnpaidHint": "Pay for it to keep your place.",
305
+ "payTicket": "Pay for the ticket",
306
+ "showTicket": "Show my ticket",
307
+ "moreTickets": "{count} more upcoming"
277
308
  }
278
309
  }
279
310
  }
@@ -0,0 +1,3 @@
1
+ import type { EventGrant } from '../../../types.js';
2
+ declare const _default: import("@frigear-nu/auth/grants").GrantKindDefinition<EventGrant>;
3
+ export default _default;
@@ -0,0 +1,38 @@
1
+ import { db, schema } from "@nuxthub/db";
2
+ import { and, eq, inArray } from "drizzle-orm";
3
+ import { defineGrantKind } from "@frigear-nu/auth/grants";
4
+ import { inChunks } from "@frigear-nu/module-kit/server";
5
+ import { eventGrantAdmits, eventGrantSchema } from "../../utils/grants.js";
6
+ const ticketColumns = {
7
+ userId: schema.eventTickets.userId,
8
+ eventId: schema.eventTickets.eventId,
9
+ ticketTypeId: schema.eventTickets.ticketTypeId,
10
+ status: schema.eventTickets.status,
11
+ checkedInAt: schema.eventTickets.checkedInAt
12
+ };
13
+ export default defineGrantKind("event", {
14
+ schema: eventGrantSchema,
15
+ async matches({ user, grant }) {
16
+ const userId = Number(user?.id);
17
+ if (!user || !Number.isInteger(userId)) return false;
18
+ const tickets = await db.select(ticketColumns).from(schema.eventTickets).where(and(eq(schema.eventTickets.userId, userId), eq(schema.eventTickets.eventId, grant.eventId), eq(schema.eventTickets.status, "paid")));
19
+ return tickets.some((ticket) => eventGrantAdmits(grant, ticket));
20
+ },
21
+ async members({ grants }) {
22
+ const eventIds = [...new Set(grants.map((grant) => grant.eventId))];
23
+ const tickets = await inChunks(eventIds, (chunk) => db.select(ticketColumns).from(schema.eventTickets).where(and(inArray(schema.eventTickets.eventId, chunk), eq(schema.eventTickets.status, "paid"))));
24
+ const ids = /* @__PURE__ */ new Set();
25
+ for (const ticket of tickets) {
26
+ if (grants.some((grant) => eventGrantAdmits(grant, ticket))) ids.add(ticket.userId);
27
+ }
28
+ return ids;
29
+ },
30
+ async validate({ grant }) {
31
+ const [event] = await db.select({ id: schema.events.id }).from(schema.events).where(eq(schema.events.id, grant.eventId)).limit(1);
32
+ if (!event) return "This event does not exist.";
33
+ if (!grant.ticketTypeIds?.length) return void 0;
34
+ const types = await db.select({ id: schema.eventTicketTypes.id }).from(schema.eventTicketTypes).where(eq(schema.eventTicketTypes.eventId, grant.eventId));
35
+ const known = new Set(types.map((type) => type.id));
36
+ return grant.ticketTypeIds.every((id) => known.has(id)) ? void 0 : "A ticket type is not one of this event's.";
37
+ }
38
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,39 @@
1
+ import { db, schema } from "@nuxthub/db";
2
+ import { eq } from "drizzle-orm";
3
+ import { appTimeZoneOf } from "@frigear-nu/ui/utils";
4
+ import { EVENTS_CAMPAIGN_OWNER, EVENTS_CAMPAIGN_TRIGGERS, eventsCampaignOwnerResolved } from "../../campaigns-owner.js";
5
+ export default defineNitroPlugin((nitro) => {
6
+ const safely = (what, eventId, run) => run().catch((error) => {
7
+ console.error(`[events] campaigns could not follow ${what} of event ${eventId}`, error);
8
+ });
9
+ nitro.hooks.hook("campaigns:owner:resolve", async (ctx) => {
10
+ if (ctx.type !== EVENTS_CAMPAIGN_OWNER) return;
11
+ const [row] = await db.select().from(schema.events).where(eq(schema.events.id, ctx.id)).limit(1);
12
+ if (!row) return;
13
+ const config = useRuntimeConfig();
14
+ const publicConfig = config.public;
15
+ ctx.owner = eventsCampaignOwnerResolved(row, {
16
+ pages: publicConfig.events?.pages,
17
+ siteUrl: typeof publicConfig.siteUrl === "string" ? publicConfig.siteUrl : void 0,
18
+ // The module's own zone, else the app's (`appConfig.frigearUi.timeZone`), else UTC.
19
+ timeZone: config.events?.timeZone || appTimeZoneOf(useAppConfig()),
20
+ locale: typeof publicConfig.i18n?.defaultLocale === "string" ? publicConfig.i18n.defaultLocale : void 0
21
+ });
22
+ });
23
+ nitro.hooks.hook("events:updated", async ({ event, changedDates }) => {
24
+ if (!changedDates.startsAt && !changedDates.endsAt) return;
25
+ await safely("a date change", event.id, () => campaignsOwnerChanged(EVENTS_CAMPAIGN_OWNER, event.id));
26
+ });
27
+ nitro.hooks.hook("events:status-changed", async ({ event, to }) => {
28
+ await safely("a status change", event.id, () => to === "archived" ? campaignsOwnerRemoved(EVENTS_CAMPAIGN_OWNER, event.id) : campaignsOwnerChanged(EVENTS_CAMPAIGN_OWNER, event.id));
29
+ });
30
+ nitro.hooks.hook("events:deleted", async ({ event }) => {
31
+ await safely("the deletion", event.id, () => campaignsOwnerRemoved(EVENTS_CAMPAIGN_OWNER, event.id));
32
+ });
33
+ const trigger = (key) => async ({ ticket, userId }) => {
34
+ await safely(`"${key}"`, ticket.eventId, () => campaignsTrigger(EVENTS_CAMPAIGN_OWNER, ticket.eventId, key, { userIds: [userId] }));
35
+ };
36
+ nitro.hooks.hook("events:ticket:paid", trigger(EVENTS_CAMPAIGN_TRIGGERS.paid));
37
+ nitro.hooks.hook("events:ticket:refunded", trigger(EVENTS_CAMPAIGN_TRIGGERS.refunded));
38
+ nitro.hooks.hook("events:ticket:checked-in", trigger(EVENTS_CAMPAIGN_TRIGGERS.checkedIn));
39
+ });
@@ -13,7 +13,7 @@ export default defineNitroPlugin((nitro) => {
13
13
  const [updated] = await db.update(schema.eventTickets).set({ status: "paid", paymentId: ctx.payment.id }).where(and(eq(schema.eventTickets.id, ticket.id), inArray(schema.eventTickets.status, ["pending", "expired", "cancelled"]))).returning();
14
14
  if (!updated) return;
15
15
  const [dto] = await toTicketDtos([updated]);
16
- await nitro.hooks.callHook("events:ticket:paid", { ticket: dto });
16
+ await nitro.hooks.callHook("events:ticket:paid", { ticket: dto, userId: updated.userId });
17
17
  });
18
18
  const release = (status) => async (ctx) => {
19
19
  const ticket = await ticketOf(ctx);
@@ -29,6 +29,6 @@ export default defineNitroPlugin((nitro) => {
29
29
  const [updated] = await db.update(schema.eventTickets).set({ status: "refunded" }).where(eq(schema.eventTickets.id, ticket.id)).returning();
30
30
  if (!updated) return;
31
31
  const [dto] = await toTicketDtos([updated]);
32
- await nitro.hooks.callHook("events:ticket:refunded", { ticket: dto });
32
+ await nitro.hooks.callHook("events:ticket:refunded", { ticket: dto, userId: updated.userId });
33
33
  });
34
34
  });
@@ -1,5 +1,5 @@
1
1
  import { db, schema } from "@nuxthub/db";
2
- import { and, count, eq, or } from "drizzle-orm";
2
+ import { and, count, eq, isNotNull, isNull, or } from "drizzle-orm";
3
3
  import { z } from "zod";
4
4
  import { idParams, likeContains, notFound, orderByQuery, pageQuery, pageRange, paginate } from "@frigear-nu/module-kit/server";
5
5
  const querySchema = pageQuery({
@@ -8,7 +8,8 @@ const querySchema = pageQuery({
8
8
  defaultOrder: "asc",
9
9
  defaultPageSize: 50,
10
10
  filters: {
11
- status: z.enum(["pending", "paid", "cancelled", "refunded", "expired"]).optional()
11
+ status: z.enum(["pending", "paid", "cancelled", "refunded", "expired"]).optional(),
12
+ checkedIn: z.enum(["true", "false"]).optional()
12
13
  }
13
14
  });
14
15
  export default defineEventHandler(async (event) => {
@@ -21,6 +22,8 @@ export default defineEventHandler(async (event) => {
21
22
  const conditions = [eq(schema.eventTickets.eventId, id)];
22
23
  if (query.q) conditions.push(or(likeContains(schema.users.name, query.q), likeContains(schema.users.email, query.q)));
23
24
  if (query.status) conditions.push(eq(schema.eventTickets.status, query.status));
25
+ if (query.checkedIn === "true") conditions.push(isNotNull(schema.eventTickets.checkedInAt));
26
+ if (query.checkedIn === "false") conditions.push(isNull(schema.eventTickets.checkedInAt));
24
27
  const where = and(...conditions);
25
28
  const orderBy = orderByQuery({
26
29
  createdAt: schema.eventTickets.createdAt,
@@ -15,5 +15,6 @@ export default defineEventHandler(async (event) => {
15
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();
16
16
  const row = claimed ?? (await db.select().from(schema.eventTickets).where(eq(schema.eventTickets.id, ticket.id)).limit(1))[0];
17
17
  const [dto] = await toTicketDtos([row]);
18
+ if (claimed) await useNitroApp().hooks.callHook("events:ticket:checked-in", { ticket: dto, userId: row.userId, checkedInBy: userId });
18
19
  return { ok: true, alreadyCheckedIn: !claimed, checkedInAt: row.checkedInAt.toISOString(), ticket: { ...dto, code: null } };
19
20
  });
@@ -10,5 +10,6 @@ export default defineEventHandler(async (event) => {
10
10
  const [sold] = await db.select({ count: sql`count(*)` }).from(schema.eventTickets).where(and(eq(schema.eventTickets.eventId, id), eq(schema.eventTickets.status, "paid")));
11
11
  if (Number(sold?.count ?? 0) > 0) throw conflict("This event has paid tickets. Archive it instead.");
12
12
  await db.delete(schema.events).where(eq(schema.events.id, id));
13
+ await useNitroApp().hooks.callHook("events:deleted", { event: toAdminEventDto(existing) });
13
14
  return noContent(event);
14
15
  });
@@ -1,4 +1,5 @@
1
1
  import type { H3Event } from 'h3';
2
+ import { schema } from '@nuxthub/db';
2
3
  import type { z } from 'zod';
3
4
  import type { SQL } from 'drizzle-orm';
4
5
  import type { AuthPrincipal } from '@frigear-nu/auth/utils';
@@ -57,19 +58,24 @@ export declare const eventPatchSchema: z.ZodObject<{
57
58
  archived: "archived";
58
59
  }>>>;
59
60
  image: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
61
+ startsAt: z.ZodOptional<z.ZodCoercedDate<unknown>>;
62
+ endsAt: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodCoercedDate<unknown>>>>;
60
63
  slug: z.ZodOptional<z.ZodString>;
61
64
  body: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodRecord<z.ZodString, z.ZodString>, z.ZodTransform<{
62
65
  [k: string]: string;
63
66
  }, Record<string, string>>>]>>>>;
64
- startsAt: z.ZodOptional<z.ZodCoercedDate<unknown>>;
65
67
  location: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodRecord<z.ZodString, z.ZodString>, z.ZodTransform<{
66
68
  [k: string]: string;
67
69
  }, Record<string, string>>>]>>>>;
68
70
  locationUrl: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
69
- endsAt: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodCoercedDate<unknown>>>>;
70
71
  requiresMembership: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodLiteral<"any">, z.ZodArray<z.ZodString>]>>>>;
71
72
  }, z.core.$strip>;
72
73
  export declare function patchEventRow(id: string, patch: z.output<typeof eventPatchSchema>): Promise<any>;
74
+ /**
75
+ * The hooks of a changed event: `events:updated` (with the dates that changed) after every update, then
76
+ * `events:status-changed` when its status did. Owners of the event's other data (campaigns' messages) follow from them.
77
+ */
78
+ export declare function eventsEmitUpdate(previous: typeof schema.events.$inferSelect, row: typeof schema.events.$inferSelect): Promise<void>;
73
79
  export declare const ticketTypePatchSchema: z.ZodObject<{
74
80
  name: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodRecord<z.ZodString, z.ZodString>, z.ZodTransform<{
75
81
  [k: string]: string;
@@ -5,6 +5,7 @@ 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
+ import { toAdminEventDto } from "./admin-dto.js";
8
9
  export async function eventsListFilter(event, principal) {
9
10
  const ctx = { event, principal, where: [] };
10
11
  await useNitroApp().hooks.callHook("events:list:filter", ctx);
@@ -84,10 +85,29 @@ export async function patchEventRow(id, patch) {
84
85
  const [taken] = await db.select({ id: schema.events.id }).from(schema.events).where(eq(schema.events.slug, patch.slug)).limit(1);
85
86
  if (taken && taken.id !== id) throw conflict("An event with this slug already exists.", { field: "slug" });
86
87
  }
88
+ const [previous] = await db.select().from(schema.events).where(eq(schema.events.id, id)).limit(1);
89
+ if (!previous) throw notFound("Event not found.");
87
90
  const [row] = await db.update(schema.events).set(patch).where(eq(schema.events.id, id)).returning();
88
91
  if (!row) throw notFound("Event not found.");
92
+ await eventsEmitUpdate(previous, row);
89
93
  return row;
90
94
  }
95
+ const dateOf = (value) => value ? value.toISOString() : null;
96
+ export async function eventsEmitUpdate(previous, row) {
97
+ const hooks = useNitroApp().hooks;
98
+ const event = toAdminEventDto(row);
99
+ const before = toAdminEventDto(previous);
100
+ const changedDates = {};
101
+ for (const key of ["startsAt", "endsAt"]) {
102
+ const from = dateOf(previous[key]);
103
+ const to = dateOf(row[key]);
104
+ if (from !== to) changedDates[key] = { from, to };
105
+ }
106
+ await hooks.callHook("events:updated", { event, previous: before, changedDates });
107
+ if (previous.status !== row.status) {
108
+ await hooks.callHook("events:status-changed", { event, from: before.status, to: event.status });
109
+ }
110
+ }
91
111
  export const ticketTypePatchSchema = ticketTypeInput.omit({ addonGroups: true }).partial();
92
112
  export async function patchTicketTypeRow(id, patch) {
93
113
  await assertMembershipAvailable(patch);
@@ -84,7 +84,7 @@ export async function purchaseTicket(event, userId, slug, body) {
84
84
  }
85
85
  const [dto] = await toTicketDtos([inserted]);
86
86
  if (amount === 0) {
87
- await useNitroApp().hooks.callHook("events:ticket:paid", { ticket: dto });
87
+ await useNitroApp().hooks.callHook("events:ticket:paid", { ticket: dto, userId });
88
88
  return { ticket: dto };
89
89
  }
90
90
  try {
@@ -0,0 +1,18 @@
1
+ import { z } from 'zod';
2
+ import type { EventGrant } from '../../types.js';
3
+ export declare const EVENT_GRANT_STATUSES: readonly ["paid", "checked-in", "not-checked-in"];
4
+ /** The most ticket types one grant may name. */
5
+ export declare const EVENT_GRANT_MAX_TICKET_TYPES = 50;
6
+ export declare const eventGrantSchema: z.ZodType<EventGrant>;
7
+ /** The fields of a ticket the grant looks at. */
8
+ export type EventGrantTicket = {
9
+ eventId: string;
10
+ ticketTypeId: string;
11
+ status: string;
12
+ checkedInAt: Date | string | null;
13
+ };
14
+ /**
15
+ * Whether `ticket` admits its holder under `grant`: a paid ticket to the grant's event, of one of its ticket types (all
16
+ * when none or an empty list is named), checked in or not as `status` asks (`paid`, the default, takes both).
17
+ */
18
+ export declare function eventGrantAdmits(grant: EventGrant, ticket: EventGrantTicket): boolean;
@@ -0,0 +1,17 @@
1
+ import { z } from "zod";
2
+ export const EVENT_GRANT_STATUSES = ["paid", "checked-in", "not-checked-in"];
3
+ export const EVENT_GRANT_MAX_TICKET_TYPES = 50;
4
+ export const eventGrantSchema = z.strictObject({
5
+ kind: z.literal("event"),
6
+ eventId: z.string().trim().min(1).max(64),
7
+ status: z.enum(EVENT_GRANT_STATUSES).optional(),
8
+ ticketTypeIds: z.array(z.string().trim().min(1).max(64)).max(EVENT_GRANT_MAX_TICKET_TYPES).optional()
9
+ });
10
+ export function eventGrantAdmits(grant, ticket) {
11
+ if (ticket.eventId !== grant.eventId || ticket.status !== "paid") return false;
12
+ if (grant.ticketTypeIds?.length && !grant.ticketTypeIds.includes(ticket.ticketTypeId)) return false;
13
+ const checkedIn = ticket.checkedInAt !== null && ticket.checkedInAt !== void 0;
14
+ if (grant.status === "checked-in") return checkedIn;
15
+ if (grant.status === "not-checked-in") return !checkedIn;
16
+ return true;
17
+ }
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 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'
5
+ export { type AddonDto, type AddonGroupDto, type AdminAddonDto, type AdminAddonGroupDto, type AdminEventDetailDto, type AdminEventDto, type AdminTicketTypeDto, type AttendeeDto, type CheckInResponse, type EventDateChange, type EventDeletedContext, type EventDetailDto, type EventGrant, type EventGrantStatus, type EventStatus, type EventStatusChangedContext, type EventSummaryDto, type EventUpdatedContext, 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 TicketCheckedInContext, 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.5.5",
3
+ "version": "0.6.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
  "keywords": [
6
6
  "frigear-module",
@@ -39,15 +39,15 @@
39
39
  "playground"
40
40
  ],
41
41
  "dependencies": {
42
- "@frigear-nu/admin": "^0.5.3",
43
- "@frigear-nu/auth": "^0.6.9",
42
+ "@frigear-nu/admin": "^0.6.0",
43
+ "@frigear-nu/auth": "^0.7.0",
44
44
  "@frigear-nu/mcp": "^0.5.3",
45
45
  "@frigear-nu/module-kit": "^1.3.13",
46
- "@frigear-nu/payments": "^0.5.5",
46
+ "@frigear-nu/payments": "^0.6.0",
47
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",
48
+ "@frigear-nu/subscriptions": "^0.6.0",
49
+ "@frigear-nu/ui": "^0.3.0",
50
+ "@frigear-nu/users": "^3.2.0",
51
51
  "@libsql/client": "^0.18.0",
52
52
  "@nuxt/kit": "^4.6.4",
53
53
  "@vueuse/core": "^15.0.0",
@@ -59,12 +59,20 @@
59
59
  "zod": "^4.6.7"
60
60
  },
61
61
  "peerDependencies": {
62
+ "@frigear-nu/campaigns": "^0.1.0",
63
+ "@frigear-nu/dashboard": "^0.2.0",
62
64
  "@frigear-nu/menu": "^0.4.2",
63
65
  "@frigear-nu/widget": "^0.4.4",
64
66
  "@nuxt/ui": "^4.12.0",
65
67
  "@nuxthub/core": "^0.10.12"
66
68
  },
67
69
  "peerDependenciesMeta": {
70
+ "@frigear-nu/campaigns": {
71
+ "optional": true
72
+ },
73
+ "@frigear-nu/dashboard": {
74
+ "optional": true
75
+ },
68
76
  "@frigear-nu/menu": {
69
77
  "optional": true
70
78
  },
@@ -76,6 +84,8 @@
76
84
  }
77
85
  },
78
86
  "devDependencies": {
87
+ "@frigear-nu/campaigns": "^0.1.0",
88
+ "@frigear-nu/dashboard": "^0.2.0",
79
89
  "@frigear-nu/menu": "^0.4.2",
80
90
  "@frigear-nu/widget": "^0.4.4",
81
91
  "@nuxt/devtools": "^4.2.0",