Swift public booking client
A typed public booking client for published pages and private customer capabilities. No workspace credential or native account ceremony.
On this page
Install without a private checkout
AvailKit 0.1.1. Swift 6.4.x and Swift Package Manager; no external package dependencies. See the package runtime policy for declared Apple platforms and actual tested environments. These are hosted distributions; availability on a public registry is not claimed.
Download the package or complete example project. Installation commands come from its shipped README. Verify the relevant entry in SHA256SUMS before use; the archive includes its license, support policy and full instructions.
curl --fail --proto '=https' -O https://availkit.dev/downloads/availkit-swift-0.1.1.zip
curl --fail --proto '=https' -O https://availkit.dev/downloads/SHA256SUMS
sha256sum --check --ignore-missing SHA256SUMS
mkdir -p Vendor/AvailKit
unzip -q availkit-swift-0.1.1.zip -d Vendor/AvailKitConfigure a public page
Follow dashboard setup to publish a test booking page. Copy its public page ID and use a test offering with future availability. The runnable CLI example accepts a private config file containing only public configuration and synthetic contact data; it rejects a live page. Your mobile app holds no workspace key or dashboard session.
The following is taken from Sources/FirstBooking/FirstBooking.swift in the download. Complete the surrounding config and imports using that runnable project; it is not an account-enrollment flow.
let config = try JSONDecoder().decode(
Config.self, from: PrivateFiles.read(from: URL(fileURLWithPath: path), limit: 16_384))
let client = try PublicBookingClient(
pageID: config.pageID, baseURL: config.baseURL ?? "https://api.availkit.com")
let directory = URL(fileURLWithPath: config.intentDirectory, isDirectory: true)
// Every run is a deliberate one-time fixture. Keep the latch after ANY result.
// On rerun this exclusive durable write fails before any network request.
try PrivateFiles.create(
Data("{\"version\":1,\"state\":\"started\"}".utf8),
at: directory.appendingPathComponent("lifecycle-started.json"))Create, read, move and cancel once
The complete example first checks availability, retains an exclusive original intent before each send, and gates every later step on a confirmed acknowledgment. It reads the booking, moves it using the original expectedStart, then cancels that exact booking. Existing intent/latch files prevent a second invocation from creating a fresh booking after an uncertain run. The example creates no catalog data and performs no unrelated cleanup.
let page = try await client.getPage()
guard page.environment == .test else { throw CocoaError(.featureUnsupported) }
var cursor: String?
var found = false
for _ in 0..<100 {
let catalog = try await client.listOfferings(after: cursor)
if catalog.items.contains(where: { $0.id == config.offeringID }) {
found = true
break
}
guard let next = catalog.nextAfter else { break }
cursor = next
}
guard found else { throw CocoaError(.fileNoSuchFile) }
let times = try await client.availability(
offeringID: config.offeringID, from: config.from, to: config.to)
guard times.slots.count >= 2 else { throw CocoaError(.fileNoSuchFile) }
let first = times.slots[0]
let second = times.slots[1]
let bookingToken = AvailKitSecrets.newBookingToken()
let contactToken = AvailKitSecrets.newBookingToken()
let body = PublicBookingInput(
offeringId: config.offeringID, start: first.start,
contact: .init(displayName: config.displayName, email: config.email, phone: config.phone))
let intent = try client.prepareBook(
body, idempotencyKey: AvailKitSecrets.newIdempotencyKey(), bookingToken: bookingToken,
contactToken: contactToken)
try retain(
intent, at: directory.appendingPathComponent("create.json"))
let booking = try await client.execute(intent)
_ = try await client.getBooking(bookingID: booking.id, bookingToken: bookingToken)
let move = try client.prepareReschedule(
bookingID: booking.id,
body: .init(expectedStart: booking.start, start: second.start),
idempotencyKey: AvailKitSecrets.newIdempotencyKey(), bookingToken: bookingToken)
try retain(move, at: directory.appendingPathComponent("move.json"))
let moved = try await client.execute(move)
let cancel = try client.prepareCancel(
bookingID: moved.id, idempotencyKey: AvailKitSecrets.newIdempotencyKey(),
bookingToken: bookingToken)
try retain(
cancel, at: directory.appendingPathComponent("cancel.json"))
_ = try await client.execute(cancel)
try PrivateFiles.create(
Data("{\"version\":1,\"state\":\"completed\"}".utf8),
at: directory.appendingPathComponent("completed.json"))After preparing the private configuration, run the example once from its documented directory:
AVAILKIT_CONFIG_FILE=/absolute/private/config.json swift run --package-path Vendor/AvailKit -j 1 availkit-first-bookingUse a fresh private intent directory for a separately intended test. Never replace the directory or files to recover an unknown request.
Handle rejection and unknown outcomes
After any failure, stop and preserve the original private intent and acknowledged booking IDs. A lost, timed-out or malformed mutation response can follow a committed change. An unrecognized error response is also insufficient to prove rejection. Log only the SDK’s finite safe diagnostic fields; keep raw requests, headers, contact details, capabilities and private intent records out of logs.
A current read can show what exists; it cannot recover a missing acknowledgment or prove an unknown create never happened. Do not generate a replacement key or delete the example’s permanent latch to rerun it. Only booking create/move/cancel operations have an explicit original-intent replay contract, bounded by the server’s 24-hour receipt window and current authority. Loading or importing an intent never sends it. Follow the lost-response guide before a separately authorized identical replay. Catalog, customer, webhook and maintenance writes have no such replay guarantee.
All transports enforce a configured total request deadline and response-size cap, validate TLS, refuse redirects and disable SDK mutation retries. Cancellation after admission is unknown. Read the package policy before supplying a custom transport or platform persistence implementation.
Coverage and runtime policy
All seven published-page operations are implemented: page, offerings, availability, create, view, move and cancel. Pagination is explicit and bounded by your application. Supported calls, minimum permissions, exact versions, tests and platform limits ship in coverage.json, the package README and runtime policy.
Account/passkey/session ceremonies and recovery are excluded. Mobile and browser code must use public capabilities or a narrowly authorized backend. See the authority matrix, backend setup and all SDKs.