@themoonlitcompany/mbevents
v0.1.0
Published
Client SDK for Momentum Events: a white-label RSVP engine. Read events, render your own form, submit RSVPs.
Maintainers
Readme
@themoonlitcompany/mbevents
Client SDK for Momentum Events, a white-label RSVP engine. The backend workflow is prebuilt; this package gives your front end ready-made tools to talk to it. Zero dependencies, works in the browser and Node.
Install
npm install @themoonlitcompany/mbeventsQuick start
Every Momentum event has a slug and a public event key (find both on the event's API tab in the console). The key only grants reading the published event and submitting RSVPs, so it is safe in browser code.
import { createEventClient } from "@themoonlitcompany/mbevents";
const client = createEventClient({
baseUrl: "https://your-momentum-deployment.com",
slug: "spring-launch-dinner",
eventKey: "me_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
});
// 1. Read the event and its question definitions
const event = await client.getEvent();
// 2. Submit an RSVP (idempotency key is generated for you)
const result = await client.accept({
email: "[email protected]",
fullName: "Guest Name",
partySize: 2,
answers: { meal_preference: "Vegetarian" },
});
console.log(result); // { rsvpId: "...", status: "accepted", deduped: false }Tools included
| Tool | What it does |
| --- | --- |
| client.getEvent() | Fetches the published event with questions |
| client.submitRsvp(input) | Submits or updates an RSVP (any status) |
| client.accept(input) / client.decline(input) | Status shorthands |
| toFormFields(event) | Flattens built-in fields + questions into an ordered, renderable field list |
| validateAnswers(event, answers) | Client-side validation mirroring the server, for instant feedback |
| isRsvpClosed(event) | Whether the RSVP deadline has passed |
| MomentumError | Thrown on API errors; carries .status and a human-readable message |
Rendering a form from the event definition
import { createEventClient, toFormFields, validateAnswers } from "@themoonlitcompany/mbevents";
const client = createEventClient({ baseUrl, slug, eventKey });
const event = await client.getEvent();
// Drive your markup from the definition; it stays in sync with the console.
for (const field of toFormFields(event)) {
renderInput(field); // your UI, your brand
}
// Validate before submitting
const errors = validateAnswers(event, collectedAnswers);
if (Object.keys(errors).length === 0) {
await client.accept({ email, fullName, answers: collectedAnswers });
}Error handling
import { MomentumError } from "@themoonlitcompany/mbevents";
try {
await client.accept({ email, fullName });
} catch (error) {
if (error instanceof MomentumError) {
// Server messages are written to be shown to guests,
// e.g. "This event is at capacity." or "Meal preference is required."
showMessage(error.message);
}
}What the engine enforces server-side
Required questions, capacity, party-size limits, RSVP deadlines, one response per email (repeat submissions update the existing RSVP), and idempotent retries. Your front end never reimplements the workflow.
