@openseat/node
v0.1.0
Published
Server client for the OpenSeat Cloud API: hold, book, release and block seats with your secret key, create events from your own platform, and verify OpenSeat webhooks. Zero dependencies.
Maintainers
Readme
@openseat/node
The OpenSeat Cloud API from your server. Hold, book, release and block seats with your secret key, create events from your own ticketing platform, mint embeddable-designer sessions, and verify OpenSeat webhooks.
- Zero dependencies. Global
fetch,crypto.subtleandcrypto.randomUUIDonly. - Runs on Node 20+, Bun, Deno, Cloudflare Workers and edge runtimes.
- Never in a browser. Bundling it for a browser fails, and constructing it in a page throws. Browsers use
@openseat/cloudwith a public key.
import { OpenSeat, OpenSeatError } from "@openseat/node";
const openseat = new OpenSeat({
secretKey: process.env.OPENSEAT_SECRET_KEY!, // os_sk_live_… or os_sk_test_…
baseUrl: "https://openseat.example.com", // your OpenSeat address (the dashboard's "<origin>/api" also works)
});
await openseat.me(); // { ownerId, mode, kind: "secret", scopes, last4, keyName }: "is my key working?"Options: timeoutMs (per attempt, default 15000), maxRetries (default 2), fetch (default the global one).
baseUrl must be https; plain http is accepted for localhost and 127.0.0.1, or anywhere with
allowInsecureHttp: true on a private network you control, because the secret key travels in every request.
Checkout with a browser hold
The buyer picks seats on your page (@openseat/cloud), which gives you a holdToken. Your server then:
// 1. See what is held, and price it yourself.
const hold = await openseat.holds.retrieve(holdToken);
// 2. Attach your order before taking payment. This locks the hold: the browser can no longer change it.
await openseat.holds.attachOrder(holdToken, order.id);
// 3. Optional: more time while the payment page is open (60..3600 s, at most one hour after the first hold).
await openseat.holds.extend(holdToken, { seconds: 900 });
// 4. After payment succeeds, book.
try {
const booking = await openseat.events.book({ eventKey, holdToken, orderId: order.id, amountPaise: order.amount });
} catch (e) {
if (e instanceof OpenSeatError && e.refundRequired)
await refund(order); // the seats are gone for good
else throw e; // retryable, or a bug in the call (e.g. HOLD_MISMATCH): fix and retry
}book uses the idempotency key book:<eventKey>:<orderId> by default (a sha256 form when that would pass 200 characters), so calling it again for the same order
(after a crash or a timeout) replays the same booking with replayed: true instead of booking twice. A paid
buyer is never refused because sales closed or API access was turned off mid-checkout. If the hold expired but
every seat is still free, the booking succeeds with late: true.
To abandon a checkout: await openseat.holds.release(holdToken).
Server holds (no browser token)
Platforms that keep the seat picker on their own servers hold seats directly:
const hold = await openseat.holds.create({
eventKey: "BMS-88213/A",
buyerRef: user.id, // your platform's opaque user ID
seatIds: ["silver:B:1", "silver:B:2"],
areas: [{ inventoryId: "sec-balcony", quantity: 2 }],
});
// hold.holdToken works with attachOrder, extend, release and events.book exactly like a browser token.
// Change the buyer's seats atomically: pass the token back.
await openseat.holds.create({ eventKey, buyerRef: user.id, seatIds: ["gold:A:1"], holdToken: hold.holdToken });buyerRef is an opaque platform user ID: never an email address or a phone number. It is 1 to 128
printable ASCII characters. OpenSeat stores only an HMAC of it and never returns it in responses or webhooks
(match deliveries by orderId or holdToken). It is how the buyer's ticket limit is enforced: everything that
buyerRef holds or has booked for the event, across all orders, counts against the event's
maxTicketsPerBooking. The SDK refuses an email-shaped value before sending anything.
Each holds.create call gets a random idempotency key that its own retries reuse; pass idempotencyKey to
control it yourself.
Events and layouts from your platform
for await (const layout of openseat.layouts.list()) console.log(layout.layoutKey, layout.seatCount);
const layout = await openseat.layouts.retrieve("arena-main"); // includes the layout document
const event = await openseat.events.create({
eventKey: "BMS-88213/A", // your own event ID, 1..128 printable ASCII
layoutKey: "arena-main",
name: "Annual Fest 2026",
startsAt: "2026-12-07T13:30:00.000Z",
holdSeconds: 600,
categoryPriceLabels: { gold: "1499" }, // optional display labels; you own the prices
});
// Calling create again with the same eventKey returns the same event with created: false.
await openseat.events.update(event.eventKey, { saleOpen: false });
await openseat.events.changeLayout(event.eventKey); // latest revision of its layout (or pass { layoutKey })
const categories = await openseat.events.categories(event.eventKey); // ticket types with counts
await openseat.events.archive(event.eventKey);Reading: events.list(), events.retrieve(eventKey) and events.objects(eventKey, { status }) (seat by seat,
the ground truth for reconciliation). Every list-style method is an async iterable that follows the server's
next cursor for you.
Refunds, cancellations and blocks
// Release a whole booking, or some seats and area quantities of it (exactly one of bookingId / orderId).
const result = await openseat.events.release(eventKey, {
orderId: "ORD-1",
seatIds: ["gold:A:3"],
areas: [{ inventoryId: "ga-floor", quantity: 1 }],
});
// result.notReleased lists what wasn't released and why (not_in_booking, already_released, quantity_exceeds).
await openseat.events.block({ eventKey, objectIds: ["gold:A:1"], note: "Sponsor" });
await openseat.events.unblock({ eventKey, objectIds: ["gold:A:1"] });events.release({ eventKey, … }) (one object) is accepted too. Bookings: bookings.list({ eventKey, orderId,
status, source }), bookings.retrieve(id), bookings.byOrder(eventKey, orderId) (the confirmed booking, else
the latest, else null) and bookings.eraseExtraData(id).
Embeddable designer sessions
const session = await openseat.designerSessions.create({
layoutKey: "arena-main", // or create: { name: "Hall B" } for a new layout
origin: "https://admin.your-platform.example", // must be one of your allowed designer origins
user: { id: admin.id, name: admin.name }, // shown in OpenSeat's activity log
});
// Give session.embedUrl to mountDesigner() in that admin page. The token is shown once.
await openseat.designerSessions.retrieve(session.id);
await openseat.designerSessions.revoke(session.id);Webhooks
import { verifyWebhook, OpenSeatWebhookError } from "@openseat/node";
app.post("/webhooks/openseat", express.raw({ type: "application/json" }), async (req, res) => {
let event;
try {
event = await verifyWebhook(req.body, req.header("openseat-signature"), process.env.OPENSEAT_WEBHOOK_SECRET!);
} catch (e) {
return res.status(400).end(); // e is an OpenSeatWebhookError; never act on an unverified body
}
if (await alreadyHandled(event.id)) return res.status(200).end(); // deliveries can repeat
// booking.released with actor "organiser": refund the buyer in your app.
res.status(200).end();
});Verify the raw body bytes, never re-serialised JSON: express.raw(...), or await request.text() in
Next.js route handlers and Workers. During a secret rotation pass both secrets ([newSecret, oldSecret]).
The verifier refuses timestamps more than 300 s away (toleranceSec), headers over 8 KB or with more than 8
v1 signatures (before any HMAC work), anything but exactly one numeric t, and non-hex signatures; it
compares in constant time. Manage endpoints with webhookEndpoints.list/create/retrieve/update/delete/
rotateSecret/test/deliveries/redeliver; the secret from create and rotateSecret is shown once.
Errors
Every failure is an OpenSeatError with code, reason, status, requestId (quote it to support),
retryable, retryAfterMs, unavailableSeatIds, unavailableAreaIds, details and refundRequired.
| code / reason | Meaning | What to do |
| ---------------------------------------------- | -------------------------------------------- | ---------------------------------------- |
| HOLD_EXPIRED / SEATS_TAKEN | Late payment and a seat was resold | Refund (refundRequired) |
| HOLD_EXPIRED / RELEASED | The buyer or your server released the hold | Refund (refundRequired) |
| CONFLICT / HOLD_ALREADY_BOOKED | Another order booked this hold | Refund (refundRequired) |
| CONFLICT / HOLD_MISMATCH | Seats, areas or orderId differ from the hold | A bug in your call: fix it and retry |
| CONFLICT / ORDER_ID_IN_USE | That orderId is on another booking | Use a new order ID |
| LIMIT_EXCEEDED | The buyer's ticket limit (or KEY_HOLD_CAP) | Show the limit to the buyer |
| RATE_LIMITED, SERVER, NETWORK, TIMEOUT | Temporary | Retried automatically; retryable: true |
Retries. Network errors, timeouts, 429 (honouring Retry-After up to 60 s) and 5xx are retried up to
maxRetries times with jittered backoff, always with the same Idempotency-Key. Every write sends one (your
idempotencyKey, the defaults above, or a fresh UUID per call). Calls that would act twice if an answer were
lost (creating a webhook endpoint, rotating its secret, sending a test, redelivering, minting a designer
session) are retried only after a 429 or a 503 BUSY, which prove nothing happened.
Types
All wire types are exported: HoldDetails, ServerHold, Booking, SeatObject, EventSummary,
EventDetails, CreatedEvent, CreateEventInput, CategoryInfo, ReleaseResult, LayoutSummary,
LayoutDetails, AreaQuantity, WebhookEndpoint, WebhookDelivery, DesignerSessionCreated,
DesignerSessionInfo, OpenSeatWebhookEvent, OpenSeatErrorCode and OpenSeatErrorReason.
