Skip to guide
AvailKit/ developers
Browse documentation

Build a booking flow with Angular.

A complete public browser example: choose an offering and time, book once, then read, move or cancel with the original private capability.

On this page

Run the standalone example

Download the Angular example 0.1.0 and unzip it into an empty directory. It includes source, an exact dependency lockfile, controller tests and a README. Use Node 24.15 or newer in the Node 24 line and npm 11.19.0.

Shell
npm ci
npm test
npm run build
npm start

Open http://127.0.0.1:43162. For source development use npm run dev. The servers bind loopback. The production build and the development server are local tools; this archive adds no runtime to the AvailKit service.

The lockfile installs @availkit/booking 0.3.0 from the hosted SDK archive. No npm registry availability or public repository access is implied. The app uses standalone Angular 22 with zoneless change detection. Angular 22 is actively supported; its pinned TypeScript 6 compiler follows the official compatibility range.

Publish a page and select a time

  1. Follow dashboard setup. Choose your workspace’s test environment and prepare a resource, weekly hours and an offering. Publish its booking page.
  2. Copy the public page ID from the shareable booking URL. Enter that ID in the example; the loaded page displays its server-returned test/live environment.
  3. Choose an offering. If another page exists, use Load more offerings. The example follows nextAfter explicitly and preserves the loaded items.
  4. Choose a UTC date, find the next seven days of availability and select an exact returned start. The resource timezone is shown separately; all displayed dates, starts and ends are UTC.
  5. Enter the requested contact details, review the offering, duration and UTC time, then explicitly confirm the booking once. Use synthetic contact details with a test page.

The example does not create resources or catalog fixtures. Publication, resource hours and API availability remain server decisions.

Use only the public client

The browser receives a public page ID and per-booking capabilities. Workspace keys, account cookies and CSRF tokens do not belong in this flow. The SDK’s public transport omits cookies, requests no-store and refuses redirects. Published-page CORS does not expose account or dashboard APIs cross-origin.

TypeScript
import {
  PublicBookingClient, newGuestToken, publicBookingInput,
  type PublicBooking, type PublicBookingInput, type PublicOffering, type PublicPage,
} from '@availkit/booking/public';
TypeScript
import { BookingController } from './booking-controller';
export const API_ORIGIN = 'https://api.availkit.com';
export const booking = new BookingController({ baseUrl: API_ORIGIN });

This module creates one controller for the tab. Construction and subscriptions do not send requests. Keep API_ORIGIN as public configuration; never add a workspace credential to a frontend environment variable.

Send only from an explicit customer action

The actual form binding and submit handler below come from the runnable source. The customer confirms the reviewed selection. No render, effect, initialization hook or subscription performs a mutation.

HTML
<form ngNativeValidate (ngSubmit)="confirmBooking()">
TypeScript
async confirmBooking() {
  await booking.book({
    displayName: this.name.trim(),
    ...(this.email.trim() ? { email: this.email.trim() } : {}),
  }, this.bookConfirmed);
  this.bookConfirmed = false;
  this.focusStatus();
}

The standalone component subscribes only to state and removes that subscription on destruction. Signals render the result; mutation methods run only from submit and click handlers.

Retain the exact intent before the send

The shipped controller sets its single-flight guard synchronously before any await. It deep-freezes the request body, method/path, API origin, page/environment, time, key and original independent booking/contact tokens in tab memory before calling the SDK. Duplicate events cannot create another key or capability pair while a request is active.

TypeScript
async #mutate(kind: Kind, prepare: () => Body): Promise<void> {
  if (!this.#canWrite()) return;
  const operation = this.#begin('Sending this request once. Keep this tab open…', 'write');
  if (operation === null) return;
  let index = -1;
  try {
    const body = prepare();
    const page = this.#state.page!;
    const bookingId = this.#state.current?.id ?? null;
    // Retain exact scope, authority, input and key BEFORE the network call.
    const intent = frozenCopy<SavedIntent>({
      version: 1, origin: this.#options.baseUrl, pageId: page.id,
      environment: page.environment, createdAt: (this.#options.now?.() ?? new Date()).toISOString(),
      kind, method: 'POST',
      path: '/v1/public/pages/' + page.id + '/bookings' +
        (kind === 'book' ? '' : '/' + bookingId + (kind === 'move' ? '/reschedule' : '/cancel')),
      body, key: (this.#options.key ?? (() => crypto.randomUUID()))(),
      bookingId, access: this.#access!,
    });
    index = this.#attempts.push(Object.freeze({ intent, outcome: 'pending', response: null })) - 1;
    this.#update({ retainedCount: this.#attempts.length });
    const current = kind === 'book'
      ? await this.#client!.book(intent.body as PublicBookingInput, intent.key, intent.access)
      : kind === 'move'
        ? await this.#client!.reschedule(intent.bookingId!,
          intent.body as { expectedStart: string; start: string }, intent.key, intent.access.bookingToken)
        : await this.#client!.cancel(intent.bookingId!, intent.key, intent.access.bookingToken);
    this.#attempts[index] = Object.freeze({ intent, outcome: 'confirmed_success', response: current });
    this.#update({
      current, status: kind === 'cancel' ? 'Cancellation confirmed. The time was released.' :
        kind === 'move' ? 'Move confirmed. Your booking now uses the new UTC time.' :
          'Booking confirmed. Save your private request record before leaving.',
      tone: 'success',
    });
  } catch (error) {
    // Preparation is local; anything unclassified after retention is uncertain.
    const outcome = index < 0 ? 'not_sent' : outcomeOf(error);
    if (index >= 0) this.#attempts[index] = Object.freeze({ ...this.#attempts[index], outcome });
    const unknown = outcome === 'unknown';
    this.#update({
      unknown: this.#state.unknown || unknown,
      status: unknown ? 'Outcome unknown. The request may have committed. All further writes are frozen. Keep the original private record and inspect current state.' :
        outcome === 'rejected' ? 'The API rejected this request. Review the selection and current booking before making another explicit decision.' :
          'Request not sent. Check your contact details and selection before confirming again.',
      tone: unknown ? 'warning' : 'error',
    });
  } finally { this.#end(operation); }
}

All attempts remain available through Save private request record, including pending, rejected and uncertain requests. The file contains private capabilities and contact details. Save it outside shared folders and source control. No capability enters browser storage, diagnostics or a URL. Keep the tab open: reloading loses in-memory authority. This example has no import or replay button.

Read, move and cancel deliberately

After a confirmed create, use Read current booking with the original retained booking token. To move, read availability for the original offering, choose a different returned UTC start and confirm the move. The request retains both expectedStart and the new start. Cancellation has a separate confirmation and releases the time only after a validated success.

The booking token authorizes one booking. The distinct contact token proves contact reuse in the original create flow; it grants neither booking management nor workspace access. Keep both private. The public page ID alone cannot read a booking.

Freeze writes when the outcome is unknown

Local validation failures are not_sent; recognized SDK API refusals are rejected. A lost, late, malformed or unclassified response after sending is unknown and may follow a committed booking. The example freezes every later write for the rest of the tab and preserves the original intent and authority. It never automatically retries, generates a replacement key or compensates.

For an uncertain move or cancellation, read the known booking ID with the original retained capability. An uncertain create has no acknowledged ID. Its capability cannot discover one. Ask the page owner to inspect authorized state and provide an ID from an authoritative record, then use the recovery read field. No public booking search or list endpoint is implied. A failed read does not prove absence, and a successful read cannot reconstruct the missing acknowledgment or unlock writes.

Booking replay receipts last 24 hours. Follow the lost-response guide before any separately authorized, deliberate identical replay using the exact still-live original body, key, scope and authority. A new key is a new intent. Do not reload or restart this flow to recover uncertainty.

Verify your integration boundary

npm test exercises the actual shipped controller and installed public SDK: before-send retention, synchronous duplicate events, explicit confirmations, offering pagination, cookie omission and simulated response loss. These are synthetic in-memory transport tests; they do not claim a live API or persistence verification.

The example includes labeled controls, visible keyboard focus, status announcements, loading/empty/error/success states and mobile reflow. For your own service check, use only a published page and contact data you are authorized to test. Keep analytics and error reporting away from private records and capability-bearing state.

Continue with the public frontend architecture, the capability boundaries or a trusted backend integration.