Skip to content

Kestrel Air — an airline on Tessera

Kestrel Air is a concept airline built in a three-hour hackathon. Its loyalty programme, Kestrel Club, runs on two rules — every flown sector earns Kestrel points for its distance, and every complete 100 km block earns status points toward tier — driven entirely by Tessera through @tesseraloyalty/sdk. There is no Shopify, no cart, and no order total: the “purchase” is a flight.

It is here because it shows what the API is actually shaped around: a member you can name and an event you can describe. If your backend can do those two things, Tessera can run the programme.

Moment on the siteSDK callNotes
Search and pick an itinerary—Flights are the airline’s own data; Tessera is not involved yet.
Join Kestrel Club at checkoutcustomers.upsert({ externalId: memberNo, email, name })The member number is the external_id on the kestrel channel. Sign-in reuses the same member.
Confirm the bookingevents.ingest(...) once per sectorEach flown leg is its own signed, idempotent earn event.
Confirmation pagemember(memberNo).history() + .balance() + .status()Polled until every sector has its ledger entries, then shows what landed.
Account pagethe same three reads + rewards.list()Balance, tier progress, activity and the catalogue, all live.

Every call runs on the server. The secret key and signing secret never reach the browser, so there are no NEXT_PUBLIC_ secrets — the same rule as the Getting started quickstart.

Kestrel Club pays into two different currencies from the same fact — a sector’s distance in kilometres — through two independent rules:

currencyratebase
spendable0.5{ kind: 'event_units', unit: 'km' }
qualifying5{ kind: 'event_units', unit: 'km', block: 100 }

The first rule pays Kestrel points — spendable, what a member redeems — half a point per kilometre flown. The second pays status points — qualifying, what drives tier progress — 5 points for every complete 100 km block. A units-based earn base must be a rule’s only effect, so these are genuinely two separate rules, not two lines of one formula: there is no combined “points for this sector,” only a spendable figure and a qualifying figure, and they can differ in what promotes a member versus what they can spend.

Fly London → Singapore → Sydney and each sector posts to both currencies on its own — a one-stop itinerary earns more qualifying credit than a non-stop of the same total distance, because each sector gets its own 100 km block bonus.

export function sectorPoints(distanceKm: number): number {
const km = Math.max(0, Math.floor(distanceKm));
return Math.floor(km * 0.5);
}
export function sectorStatus(distanceKm: number): number {
const km = Math.max(0, Math.floor(distanceKm));
return 5 * Math.floor(km / 100);
}

These are previews only — a display estimate the site can show before the booking is confirmed. The credited amount comes from Tessera once the event lands, and it is the only figure that counts.

The site never computes a point. It sends the one fact the programme needs — the sector’s distance — and lets Tessera’s event_units earn base decide what each rule pays:

units: [{ unit: 'km', value: sector.km }]

Both rules above read that same entry independently. Change a rate in the programme’s configuration and the next event earns at the new rate, on both currencies or either one, with no deploy on the airline’s side.

One server-side client, bound to the airline’s own channel:

import { TesseraClient } from '@tesseraloyalty/sdk';
const kestrel = new TesseraClient({
secretKey: process.env.TESSERA_SECRET_KEY, // server-side only — never a NEXT_PUBLIC_ value
signingSecret: process.env.TESSERA_SIGNING_SECRET, // needed for the signed events.ingest call
channel: 'kestrel', // the website is its own channel; members are keyed by Kestrel Club number
baseUrl: process.env.TESSERA_API_URL,
});

Joining at checkout is an upsert keyed on the member number. The idempotency key makes a retried form submission safe:

export async function enrolMember(memberNo: string, email: string, name: string) {
return kestrel.customers.upsert(
{ externalId: memberNo, email, name },
{ idempotencyKey: `kestrel:enrol:${memberNo}` },
);
}

Each sector is one signed event. sourceRef names the sector, so both of its ledger entries carry it and the account page can join history back to a flight; the idempotency key namespaces the channel, so a replay is a dedupe rather than a double credit:

export async function creditSector(memberNo: string, bookingRef: string, sector: Sector) {
const sourceRef = `${bookingRef}-S${sector.seq}`;
return kestrel.events.ingest({
type: 'purchase',
channel: 'kestrel',
externalId: memberNo,
sourceRef,
orderRef: bookingRef,
idempotencyKey: `kestrel:${sourceRef}:purchase`, // a retry is a dedupe, never a double credit
occurredAt: new Date(),
trigger: 'order_placed', // must match the tenant rule's earn trigger
units: [{ unit: 'km', value: sector.km }], // the fact; the programme owns the arithmetic
});
}

The confirmation and account pages keep nothing of their own — they read the member live:

export async function memberSnapshot(memberNo: string) {
const member = kestrel.member(memberNo);
const [balance, status, history, rewards] = await Promise.all([
member.balance(), // spendable / pending / qualifying / available, plus the points label
member.status(), // current tier, multiplier, progress to the next tier
member.history({ limit: 50 }), // the ledger, newest first
kestrel.rewards.list(), // the catalogue, with tier gates and point costs
]);
return { balance, status, history: history.data, rewards };
}

And “what did this booking actually earn?” is a fold over history, per currency — a sector’s spendable and qualifying entries share a sourceRef, so folding without splitting by currency would add spend to status:

export function creditedForBooking(history: HistoryEntry[], bookingRef: string) {
const forBooking = (h: HistoryEntry) =>
h.type === 'earn' && h.sourceRef?.startsWith(`${bookingRef}-S`);
const sum = (currency: string) =>
history
.filter((h) => forBooking(h) && h.currency === currency)
.reduce((total, h) => total + h.amount, 0);
return { spendable: sum('spendable'), qualifying: sum('qualifying') };
}

Earn is processed asynchronously by Tessera’s worker, so the confirmation page polls this fold until every sector has both its entries — a second or two on a local stack.

A real booking made the split concrete. A brand-new member’s LHR → JFK direct flight — one sector, 5,540 km — credited:

CurrencyFormulaCredited
Spendable (Kestrel points)⌊5540 × 0.5⌋2,770
Qualifying (status points)5 × ⌊5540 ÷ 100⌋275

Two entries, one sourceRef, two currencies. The member — new, so still Blue — ends the booking at 275 of the 500 qualifying points needed for Silver; this sector alone doesn’t promote them. A shorter sector shows the same split at a smaller scale: 1,000 km credits 500 spendable and 50 qualifying.

Nothing in the airline’s code decided either number — creditSector sent one fact, { unit: 'km', value: 5540 }, and the two rules read it independently. The member’s tier multiplier still applies live, the same as before the migration: it multiplies the spendable rate only, never qualifying, so a sector that promotes a member changes what the next sector earns — the status track itself is never multiplied.

The programme is ordinary configuration — the same knobs a retail tenant uses, set from the management plane rather than the API:

SettingValue
Channel allow-listkestrel — so events from the site are not flagged as an unknown channel
Earn rulestwo event_units rules on km, trigger order_placed, each its own effect: 0.5 spendable per km, 5 qualifying per full 100 km block — floor rounding, immediate maturation
TiersBlue (0, ×1) → Silver (500 qualifying, ×1.25) → Gold (1,500, ×1.5) → Platinum (4,000, ×2) — hold thresholds 400 / 1,200 / 3,200, calendar-year status with a 30-day grace
Brandingprogramme “Kestrel Club”, points label “Kestrel points” — the label the SDK returns on balance() and rewards.list()
Catalogueflight discounts, a lounge pass, an extra-legroom seat, and a Gold-gated upgrade voucher — the account page marks each as available, N more points, or tier-gated
The airline keepsTessera keeps
Accounts (email, password hash, member number)The member on the kestrel channel and its PII
Bookings and their sectors (flight, date, km)Every ledger entry, with the sector’s sourceRef as provenance
The event_id and status Tessera returned per sectorBalances, pending lots, tier, period and progress, in both currencies
—The catalogue and which options this member can afford

The site never stores a point total. When it needs one, it asks.