Source
This app’s code and revision history are public. Download a copy or explore the files below.
Public
The app’s code and revision history are public.
Run it yourself
Take the whole tree and run it on your own machine. The download needs no account. Cloning needs a sign-in.
Download .zip
bounded clone 9383f719c9b37ff76411858f
A copy you download is not bounded. The guarantees this app runs under - declared egress, proven invariants, writes that fail closed - live in the runtime serving this page, not in the files. What you get is auditable source you can read and run, with no runtime guarantees attached.
src/pair.ts
// Pairing a parent device with a baby station: a 6-digit code resolves to the station's room id
// (one rate-limited try per code), or a QR code carries the room id itself.
import { get, set, serverTimestamp } from "@bounded-sh/client";
import { me, explain } from "./lib/bounded";
import { randomId } from "./lib/rtc";
import { pairings, type Pairing } from "./lib/store";
export async function resolveCode(code: string): Promise<string> {
const uid = await me();
const tryPath = `codetries/${uid}/t/${code}`;
if (!(await get(tryPath))) {
try {
await set(tryPath, { n: 1 });
} catch (err) {
const e = err as { decline?: { boundary?: { cause?: string } }; message?: string };
if (e?.decline?.boundary?.cause === "cap_exceeded" || /code_tries|invariant|409/.test(String(e?.message))) {
throw new Error("Too many codes tried. Wait a few minutes, or scan the QR code instead.");
}
throw new Error(explain(err));
}
}
const doc = await get(`codes/${code}`);
if (!doc?.room) throw new Error("That code did not work. Check the code on the baby station. Each code lasts 10 minutes.");
return String(doc.room);
}
export async function joinRoom(room: string, deviceName: string): Promise<Pairing> {
const uid = await me();
const path = `rooms/${room}/joins/${uid}`;
const joined = await get(path);
if (joined?.role === "baby") throw new Error("This device is that baby station. Pair from another phone or laptop.");
if (joined) {
if (joined.name !== deviceName) await set(path, { name: deviceName });
} else {
try {
await set(path, { role: "parent", name: deviceName, at: serverTimestamp() });
} catch {
const banned = await get(`rooms/${room}/bans/${uid}`).catch(() => null);
throw new Error(banned ? "This baby station removed this device, so it cannot pair again." : "That baby station could not be found. Ask for a new code.");
}
}
const station = await get(`rooms/${room}`);
return pairings.save(room, String(station?.name || "Baby station"), randomId(8));
}
Change history
Move store links to openapps.free
Release with preview
Bind agent address in policy
Use OpenApps service URLs and add contribution strip (retry)
Bounded source sync
Bounded source sync
Bounded source sync
Bounded source sync