santa-free.openapps.xyz

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.
Owned app · rev b8b257a837b1
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 c7891873549c9ca1004894b3
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.
← All files
src/lib/bounded.ts
// One Bounded session per tab: a guest account, created on first use. No sign-up, ever.
import { init, getCurrentUser, signInAnonymously } from "@bounded-sh/client";
import { APP_ID } from "../../functions/lib/config";

/** The app this page is served for: the host injects it, so a preview talks to its own data. Local dev falls back to config. */
export const SERVED_APP_ID =
  (typeof document !== "undefined" && document.getElementById("__bounded-first-live-bridge")?.getAttribute("data-app-id")) || APP_ID;

/** The public API of the app this page is served for. Only it can draw names. */
export const API_URL = `https://functions.openapps.xyz/apps/${SERVED_APP_ID}/api`;

let session: Promise<string> | null = null;

/** Resolves to this browser's guest user id, signing in once. */
export function me(): Promise<string> {
  session ??= (async () => {
    await init({ appId: SERVED_APP_ID });
    const user = getCurrentUser() || (await signInAnonymously());
    if (!user?.id) throw new Error("Could not start a guest session.");
    return user.id as string;
  })().catch((err) => {
    session = null;
    throw err;
  });
  return session;
}

/** Calls the app's API (with the owner key when given); throws the API's own sentence on failure. */
export async function callApi<T>(path: string, ownerKey?: string, method = "GET", body?: unknown): Promise<T> {
  let res: Response;
  try {
    res = await fetch(API_URL + path, {
      method,
      headers: { ...(ownerKey ? { "x-owner-key": ownerKey } : {}), ...(body ? { "content-type": "application/json" } : {}) },
      body: body ? JSON.stringify(body) : undefined,
    });
  } catch {
    throw new Error("You seem to be offline. Try again in a moment.");
  }
  const data = await res.json().catch(() => ({}));
  if (!res.ok) throw new Error(data?.error || "Something went wrong. Try again.");
  return data as T;
}

/** A sentence a person can read for a failed write or read. */
export function explain(err: unknown): string {
  const e = err as { message?: string; status?: number; decline?: { message?: string } };
  if (e?.decline?.message) return e.decline.message;
  const msg = String(e?.message || err || "");
  if (/network|fetch|Failed to fetch/i.test(msg)) return "You seem to be offline. Try again in a moment.";
  if (/denied|403|forbidden|constraint/i.test(msg)) return "That change was not allowed.";
  return msg || "Something went wrong. Try again.";
}

Change history

Point OpenApps links to openapps.free
b8b257a837 · 18 hours ago
Bind agent address in policy constants
9a72d0200b · 20 hours ago
Use functions.openapps.xyz alias, add OpenApp contribution strip
60038fa63d · 20 hours ago
Bounded source sync
a2e0247232 · 1 day ago
Bounded source sync
c84c736f8b · 1 day ago
Bounded source sync
3a54a80cdc · 1 day ago
Bounded source sync
2eed41b4de · 1 day ago