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 70bace54357d4b57b674108f
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/share.ts
// Shared links: a resume saved to Bounded so anyone with its link can view it and download the PDF.
// Knowing the id lets a device join and read it; presenting the admin key makes a device an owner.
// The editor loads this file only when someone shares, so the landing page does not carry the client.
import { get, set, setMany, serverTimestamp } from "@bounded-sh/client";
import { cleanResume, randomId, MAX_DATA, type Resume } from "../functions/lib/resume";
import { me } from "./lib/bounded";
import { hashOf, rememberMine, type Linked } from "./store";
export interface ResumeDoc { data: string; createdAt: number; updatedAt: number }
function payload(r: Resume): string {
const data = JSON.stringify(cleanResume(r));
if (data.length > MAX_DATA) throw new Error("This resume is too long to share by link. Shorten it a little and try again.");
return data;
}
export function remember(id: string, key: string, r: Resume) {
rememberMine({ id, key, name: r.basics.name.trim(), label: r.basics.label.trim(), at: Date.now() });
}
/** Joins the resume on this device (the id is the permission). False when there is no such resume. */
export async function join(id: string): Promise<boolean> {
const uid = await me();
if (await get(`resumes/${id}/joins/${uid}`)) return true;
try {
await set(`resumes/${id}/joins/${uid}`, { at: serverTimestamp() });
return true;
} catch {
return false;
}
}
/** Makes this device an owner by presenting the admin key (the policy checks it). False for a wrong key. */
export async function claim(id: string, key: string): Promise<boolean> {
const uid = await me();
if (await get(`resumes/${id}/owners/${uid}`)) return true;
try {
await setMany([
{ path: `resumeclaims/${id}/c/${uid}`, document: { key } },
{ path: `resumes/${id}/owners/${uid}`, document: { at: serverTimestamp() } },
]);
return true;
} catch {
return false;
}
}
export async function readShared(id: string): Promise<ResumeDoc | null> {
return (await get(`resumes/${id}`)) as ResumeDoc | null;
}
async function storedAt(id: string): Promise<number> {
return (await readShared(id))?.updatedAt ?? 0;
}
export async function createShared(r: Resume): Promise<Linked> {
const data = payload(r);
const uid = await me();
const id = randomId(20);
const key = randomId(24);
await setMany([
{ path: `resumes/${id}`, document: { data, createdBy: uid, createdAt: serverTimestamp(), updatedAt: serverTimestamp() } },
{ path: `resumes/${id}/joins/${uid}`, document: { at: serverTimestamp() } },
{ path: `resumes/${id}/owners/${uid}`, document: { at: serverTimestamp() } },
{ path: `resumekeys/${id}`, document: { key } },
]);
remember(id, key, r);
return { id, key, savedAt: await storedAt(id), hash: hashOf(r) };
}
/** Saves a new version for an owner; returns the time the server stored for it. */
export async function updateShared(id: string, key: string, r: Resume): Promise<number> {
await set(`resumes/${id}`, { data: payload(r), updatedAt: serverTimestamp() });
remember(id, key, r);
return storedAt(id);
}
/** True when this device can still write to the draft's link (it joins and presents the key if it must). */
export async function canUpdate(linked: Linked): Promise<boolean> {
return (await join(linked.id)) && (await claim(linked.id, linked.key));
}
Change history
Quality pass: several resumes, cover letters, phone-readable shared pages
Bounded source sync
Bounded source sync
Bounded source sync