Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
17 KiB
Design
Context
See proposal.md for the motivation. The product design is docs/superpowers/specs/2026-12-01-event-invitations-attendance-design.md. This change builds on add-qr-self-registration (archived 2026-12-01), which already provides:
- services-counter:
RegistrationService.registerruns matching, the never-edit rule and the already-captured rule in one transaction with one retry.EventLeadService.captureis the staff path, andEventLeadService.updateis the staff edit. - mobile-api:
PublicRegistrationServiceholds the token-shape check,open()checks, rate limits (limit(key, max)), last-hop IP, honeypot and consent.AdminEventLeadServiceholds the validation helpers. - gateway:
JWTAuthFilter.PUBLIC_REGISTRATIONis a list of method and anchored-pattern pairs, and the public flow gets through only on those. - portal:
/r/[token]uses a non-redirecting fetch helper (app/lib/services/publicRegistration.ts);routeGuard.isPublicPathand the reset-pending exemption control access;QrCodeItemandRegistrationQrCardrender codes;/my-qrlists a salesperson's codes.
Emails are built in mobile-api as escaped HTML and sent with EmailService.send(Email) over Pub/Sub, as PublicFormController does. services-email saves every email, and super admins read them under Emails. Email has a companyId.
The services run with TZ=Asia/Kuala_Lumpur, so every stored time is Malaysian local time.
Goals / Non-Goals
Goals:
- One shared rule for "during the event days" and one shared rule for linking a guest. Every capture route uses both, so the numbers agree everywhere.
- Reuse the QR registration capture for invite and check-in registrations, rather than a third matching path.
- Keep the module-based access model: one new module, and no read-only flags.
Non-Goals:
- A redesign of the existing screens. The visual revamp is a separate change. The portal tasks of this change start after its foundation (PRODUCT.md, DESIGN.md and tokens) lands, so the new screens are built in the new look.
- WhatsApp sending, reminders, RSVP declines.
- Backfilling attendance for existing event leads.
Decisions
1. Data (SQL in sql/)
-
service-counter.event_guestcolumns:idbigint PK auto;company_idbigint NOT NULL;event_uuidbigint NOT NULL;namevarchar(100) NOT NULL;mobile_e164varchar(20) NULL;emailvarchar(254) NULL;company_namevarchar(150) NULL;salesperson_user_idbigint NULL;tokenvarchar(32) NOT NULL UNIQUE;invited_atdatetime NULL;invite_sent_countint NOT NULL DEFAULT 0;registered_atdatetime NULL;event_lead_idbigint NULL;created_by,created_at,updated_by,updated_at.
Keys:
uk_event_guest_mobile (event_uuid, mobile_e164)anduk_event_guest_email (event_uuid, email). MySQL allows several NULLs in a unique key, so a guest with only one of the two is fine. These keys enforce "no duplicate on the list" against races.idx_event_guest_lead (event_lead_id).
-
event: addcapacityint NULL;invitation_capint NULL;checkin_tokenvarchar(32) NULL UNIQUE. It is created on first use, like registration links.
Check-in codes live on the event row because there is exactly one per event. This is simpler than a kind column on
registration_link, whose event-code lookups would then all need a filter. -
event_lead: addattended_atdatetime NULL.sourcestays varchar(8), andINVITEfits. -
service-system.module: add(41150000, 'BO_EVENT_GUESTS', 'Event guests', 'BO', 'M', 40000000, NULL, NULL). A NULL url keeps it out of the sidebar, likeBO_LEADS_EDITandBO_LEADS_EXPORT. No role gets it by default. -
Seed:
local/seed/03-colite.sqlmirrors 01 and 02.99-rollback.sqldrops the table and columns and deletes the module row and itsmodules_rolesrows.
2. Shared rules in services-counter
EventDays.isDuring(event, now): true whennow.toLocalDate()(Malaysian time) is betweendateStart.toLocalDate()anddateEnd.toLocalDate()inclusive. WhendateStartis null, only the end counts. WhendateEndis null, it is false. This one static helper is used by:- staff capture, QR register and check-in capture, to set
attended_at(an invite registration never does: the link can be opened anywhere, so the guest checks in); - the capacity rule;
- the check-in window.
- staff capture, QR register and check-in capture, to set
GuestLinker.link(eventUuid, eventLead, lead): called in the same transaction after any capture creates or finds an event lead. It finds an unlinked guest of the event by the lead'smobile_e164, else byemail_normalised. It setsevent_lead_idandregistered_at(if empty). It is a no-op when the event lead is already linked to a guest.- Called from
EventLeadService.capture(staff),RegistrationService.register(QR, invite and check-in walk-in) and the invite register. - The match is by the person's lead, not the submitted values, so a guest who corrected their mobile on the invite page is still linked by the invite token (see decision 3).
- Called from
- Attendance at capture:
- a new event lead gets
attended_at = nowwhenEventDays.isDuring; - an existing event lead found by the already-captured rule gets
attended_atset only by an explicit check-in, never by a repeat registration.
- a new event lead gets
3. services-counter endpoints
All bodies are JSON. companyId is always a concrete company, set by mobile-api.
- Guests:
POST /counter/eventGuest/list {companyId, eventUuid}returns[{id, name, mobileE164, email, companyName, salespersonUserId, token, invitedAt, inviteSentCount, registeredAt, attended, eventLeadUuid}].attendedis derived from the linked event lead'sattended_at. The list is ordered by name.POST /counter/eventGuest/add {companyId, eventUuid, guests:[{name, mobileE164, email, companyName, salespersonUserId}], doneBy}returns{added:[...], rejected:[{index, code, field, message}]}. Values arrive normalised by mobile-api.- Rejection codes:
DUPLICATE(names the existing guest),CAP_REACHED,NOT_ON_TEAM. - It saves the valid guests in input order up to the cap.
- It returns 404 when the event is not in the company.
- Rejection codes:
POST /counter/eventGuest/remove {companyId, eventUuid, guestId, doneBy}returns 409GUEST_REGISTEREDwhen the guest is linked.POST /counter/eventGuest/markSent {companyId, eventUuid, guestIds, doneBy}setsinvited_atif empty and incrementsinvite_sent_count.GET /counter/eventGuest/findByToken/{token}returns{companyId, eventUuid, guestId, name, mobileE164, email, companyName, salespersonUserId, registered, attended}, or 404.
- Event settings:
POST /counter/event/saveacceptscapacityandinvitationCap, each null or ≥ 1. It returns 409CAP_BELOW_GUESTSwhen the cap is below the current guest count. - Invite registration:
POST /counter/eventGuest/register {companyId, guestToken, name, mobileE164, email, companyName, jobTitle, interestIds, consentNoticeId, consentAt}returns{outcome, eventLeadUuid}.- Capacity: before the event days, it returns 409
EVENT_FULLwhen the guest is not yet registered and registered guests plus walk-ins ≥ capacity. - Capture: it runs
RegistrationService.registerwith sourceINVITEand the guest's salesperson, then links this guest row to the resulting event lead directly by token, not by matching. - Already registered: a guest who is already registered gets
ALREADY_REGISTEREDand nothing changes.
- Capacity: before the event days, it returns 409
- Check-in:
GET /counter/checkin/findEvent/{token}returns{companyId, eventUuid}, or 404.POST /counter/checkin/ensureToken {companyId, eventUuid}returns{token}, creating it once.POST /counter/checkin/lookup {companyId, eventUuid, mobileE164, email}(exactly one of the two) returns{result: CHECKED_IN | FORM, firstName}.firstNameis only present for CHECKED_IN.- It matches an event lead of this event by the lead's mobile, else email. That covers registered guests and earlier registrants.
- When it matches, it sets
attended_atif empty and returns CHECKED_IN. - Otherwise (an invited-not-registered guest, or nobody) it returns FORM.
POST /counter/checkin/byGuest {companyId, guestToken}covers the "Check in" button on/i/. It requires the guest to be registered and today to be an event day, setsattended_atand returns{firstName}.- The walk-in form on
/c/posts toPOST /counter/registration/registerwith sourceQR, a new fieldattend: true, and no salesperson.attendsetsattended_ateven on an already-captured event lead.
- Attendance edit:
POST /counter/eventLead/updateacceptsattended(boolean). True setsattended_at = nowif empty; false clears it. - Numbers:
POST /counter/event/attendance {companyId, eventUuid}returns{invited, cap, registered, attended, walkIns, total, capacity}, using the counts defined in the spec. - New codes:
POST /counter/registrationLink/mineaddsaddedAt(the team row'screate_date_time) to each entry.
4. mobile-api contracts
- Admin, gated
BO_EVENTSfor reads andBO_EVENT_GUESTSfor writes, with the company scope vialoadEventas today:GET /api/admin/events/{uuid}/guestsreturns the list, with eachsalespersonNameresolved.POST /api/admin/events/{uuid}/guestswith{guests:[{name, mobile, email, companyName, salespersonUserId}]}returns{added, rejected}.- The same endpoint serves single add and paste. The portal parses pasted lines into this shape and shows the preview from a dry-run flag,
?preview=true, which validates and returns the result without saving. - Validation and normalisation use the
AdminEventLeadServicehelpers.rejected[].fieldnames the field.
- The same endpoint serves single add and paste. The portal parses pasted lines into this shape and shows the preview from a dry-run flag,
DELETE /api/admin/events/{uuid}/guests/{guestId}POST /api/admin/events/{uuid}/guests/sendwith{guestIds}or{allUnsent: true}returns{sent, skippedNoEmail}.- It builds one email per guest: escaped values, English then Bahasa Malaysia, and the link
<ADMIN_PORTAL_BASE_URL>/i/<token>. - It sends with
companyId= the event's company, then calls countermarkSentfor the sent ones. ADMIN_PORTAL_BASE_URLis a new mobile-api setting. Emails have no browser origin, unlike the QR card. Only the local profile has a default (http://localhost:3001); elsewhere it is required.
- It builds one email per guest: escaped values, English then Bahasa Malaysia, and the link
GET /api/admin/events/{uuid}/checkinreturns{token}, ensured.GET /api/admin/events/{uuid}/attendancereturns the numbers.- Event GET and PUT gain
capacityandinvitationCap. The PUT only changes them when the caller hasBO_EVENT_GUESTS; otherwise it ignores them. - The event-lead PUT accepts
attended. - The audit target is the event uuid for every guest endpoint.
@Audited(targetVariable = "uuid")is used where a later path variable exists.
- Public endpoints,
@AppAuth(skipValidate = true), with token shape[A-Za-z0-9_-]{22}checked before any backend call:- Invite pages:
GET /api/public/invite/{token}returns{eventName, startDate, endDate, location, companyName, notice, interests, guest:{name, mobile, email, companyName}, state: OPEN | REGISTERED | CHECKIN | CHECKED_IN}.CHECKINmeans registered on an event day.CHECKED_INmeans registered and attended.- Inactive gives 404
INVITE_INACTIVE("This invitation is no longer active."). - The guest's own details go only to their own token.
POST /api/public/invite/{token}registers. It uses the same body, consent and honeypot as/registration. It returns 409EVENT_FULL("This event is full") and 200{eventName}otherwise.POST /api/public/invite/{token}/checkinreturns 200{firstName}.- Check-in pages:
GET /api/public/checkin/{token}returns{eventName, startDate, endDate, location, companyName, notice, interests, state: OPEN | NOT_YET | ENDED}.NOT_YETandENDEDcarry onlystartDate, not the other details. An unknown token gives 404CODE_INACTIVE.
POST /api/public/checkin/{token}/lookupwith{value}(mobile or email, detected by the presence of@) returns{result, firstName}.POST /api/public/checkin/{token}/registertakes the walk-in form and returns 200{eventName}(counter register withattend: true).- Only the check-in register sets
attend. The QR/api/public/registrationand the invite POST never pass it, whatever the client sends.
- Invite pages:
- Limits (Redis keys, 10 minutes):
inv:load:<ip>120 andinv:submit:<eventUuid>:<ip>60 for invites;chk:<eventUuid>:<ip>300 for every check-in call. The check-in page does not countreg:load.- Over the limit: 429
TOO_MANY.
5. Gateway (decision 6 of the QR change, extended)
Add these anchored method and path pairs:
- GET
/counter/eventGuest/findByToken/[A-Za-z0-9_-]{22} - POST
/counter/eventGuest/register - GET
/counter/checkin/findEvent/[A-Za-z0-9_-]{22} - POST
/counter/checkin/lookup - POST
/counter/checkin/byGuest
/counter/registration/register is already open. The public pages load the event, company, notice and interests through the paths the QR change already opened. Everything else stays closed, including /counter/event/attendance: the capacity check runs inside eventGuest/register.
6. Portal
- Public pages:
/i/[token]and/c/[token]are public inrouteGuard, including the reset-pending exemption, using one shared pattern for/r/,/i/and/c/. Their proxies areapp/api/public/invite/[token]/**andapp/api/public/checkin/[token]/**, which send only the last X-Forwarded-For hop. They reuse the/r/form component (extract the form fromapp/r/[token]/page.tsxinto a shared component, so the three pages share fields, consent, errors and thank-you). - Event page:
- Guests section: a table with status badges, an Add guest dialog, a Paste list dialog with preview, send to one or to all unsent, copy link, and remove for Invited guests. Actions show only with
BO_EVENT_GUESTS. - Numbers strip.
- Capacity and cap fields: disabled without
BO_EVENT_GUESTS. - Check-in code: shown in the Registration QR card.
- Print cards and Copy all links.
- Guests section: a table with status badges, an Add guest dialog, a Paste list dialog with preview, send to one or to all unsent, copy link, and remove for Invited guests. Actions show only with
- Print page:
/events/[uuid]/printuses print CSS (A4, 2×4 cards). Its "Print" button callswindow.print(), so no PDF library is needed. - My QR codes:
- Share uses
navigator.share, falling back to the clipboard. - The full-screen view is a dialog with the QR sized to
min(90vw, 90vh)on white. - The notice is a banner in the shell after sign-in when any code's
addedAtis within 7 days. It is dismissible, and the dismissal is stored inlocalStorageper code.
- Share uses
- Event leads: the listing gains an Attended column and filter and a Source column. The edit form gains an Attended checkbox.
ROUTE_MODULES:/events/[uuid]/printmaps toBO_EVENTS.
7. Rejected
- Guests as event leads with status Invited. It inflates captures and conversion (product design, approach 2).
- A
kindcolumn onregistration_linkfor check-in codes. Every event-code query would need the filter; one column on the event is enough. - Server-side PDF generation for cards. It adds a dependency; browser print to PDF covers it.
- Storing
attended_aton the guest. Two sources of truth; it is derived from the event lead instead.
Risks / Trade-offs
- [Check-in reveals membership] It reveals whether a mobile or email is registered for the event (welcome versus form). It is limited to the event days, one event and 300 per 10 minutes per IP, and shows a first name only.
- [Wrong attendance] A staff capture typed in later during the event days, for example from a business card, counts as attended. Staff can untick.
- [Email delivery] Until SMTP exists, invite emails are saved, not delivered. The Guests section states it, and Copy link always works.
- [Gateway exposure] New open paths let a holder of a gateway api-key read a guest by token and register or check in without a user token. Same accepted risk as QR decision 6: the gateway is internal only.
- [Capacity race] Two last-seat invite registrations at the same moment can both pass. This is accepted; capacity is a planning number, and it is never enforced on the day.
- [ADMIN_PORTAL_BASE_URL] A wrong value sends broken invite links. The deployment notes list it with the other required settings, and a startup log line prints it.
Migration Plan
- Run
sql/01-event-guests.sql(DDL: table and columns) andsql/02-event-guests-module.sqlbefore the new images. The new services-counter reads the new columns on every event and event-lead query. - Set
ADMIN_PORTAL_BASE_URLon mobile-api. - Deploy services-counter, mobile-api, api-gateway and admin-portal together.
- A super admin grants Event guests to the admin roles under Roles.
Rollback: sql/99-rollback.sql drops the table and columns and deletes the module, losing guests and attendance marks. Redeploy the previous images.