Skip to content

If this moment feels too heavy, you don't have to carry it alone.

AustraliaLifeline 13 11 14 Text 0477 13 11 14Beyond Blue 1300 22 4636Emergency 000
All help lines

On air

Kintsugi Hour

Everlight Stories

Everlight Stories, on Base44, is the first client of this platform. The player is an iframe. Dedications and webhooks go through Base44 backend functions so the secret key never reaches the browser. Published Rudo's Corner articles are GET /api/v1/rudos-corner/articles and can be framed at /embed/article/the-slug. Drafts are not included. The same files live in examples/base44.

API reference

README.md

This sample is not in the deployed bundle. It lives in the project under examples/base44.

submitDedication.ts

/**
 * Base44 backend function. Proxy a dedication so EVERLIGHT_SK stays on the server.
 * Enable backend functions, then set the secret EVERLIGHT_SK.
 */
declare const secrets: { get(name: string): Promise<string | undefined> };

const RADIO = Deno.env.get("EVERLIGHT_ORIGIN") ?? "http://127.0.0.1:4317";

Deno.serve(async (request: Request) => {
  if (request.method !== "POST") return new Response("POST a dedication.", { status: 405 });
  const key = await secrets.get("EVERLIGHT_SK");
  if (!key) return Response.json({ error: "EVERLIGHT_SK is not set." }, { status: 500 });

  const body = await request.text();
  const response = await fetch(`${RADIO}/api/v1/stations/everlight/dedications`, {
    method: "POST",
    headers: {
      authorization: `Bearer ${key}`,
      "content-type": "application/json",
    },
    body,
  });
  const text = await response.text();
  return new Response(text, {
    status: response.status,
    headers: { "content-type": "application/json" },
  });
});

everlightWebhook.ts

/**
 * Base44 backend function. Receives Everlight webhooks.
 * dedication.flagged_care never includes the message, email or notes.
 * Signature: Everlight-Signature: t=<unix>,v1=<hmac sha256 of timestamp.body>
 */
declare const secrets: { get(name: string): Promise<string | undefined> };

Deno.serve(async (request: Request) => {
  const secret = await secrets.get("EVERLIGHT_WEBHOOK_SECRET");
  if (!secret) return new Response("Webhook secret is not configured.", { status: 500 });
  const body = await request.text();
  const header = request.headers.get("everlight-signature") ?? "";
  if (!(await verify(secret, header, body))) return new Response("Invalid signature.", { status: 401 });

  const event = JSON.parse(body) as { type?: string; data?: Record<string, unknown> };
  if (event.type === "dedication.flagged_care") {
    console.log("Care flag", event.data?.dedication_id, "Open Studio. The message is not in this payload.");
    return Response.json({ ok: true });
  }
  if (event.type === "dedication.approved" || event.type === "dedication.aired" || event.type === "now_playing.changed") {
    console.log(event.type, event.data?.dedication_id ?? event.data?.title);
  }
  return Response.json({ ok: true });
});

async function verify(secret: string, header: string, body: string): Promise<boolean> {
  const parts = Object.fromEntries(
    header.split(",").map((piece) => {
      const index = piece.indexOf("=");
      return [piece.slice(0, index).trim(), piece.slice(index + 1).trim()];
    }),
  );
  const timestamp = Number(parts.t);
  const given = parts.v1 ?? "";
  if (!Number.isFinite(timestamp) || !given) return false;
  if (Math.abs(Date.now() / 1000 - timestamp) > 300) return false;
  const encoder = new TextEncoder();
  const key = await crypto.subtle.importKey("raw", encoder.encode(secret), { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
  const mac = await crypto.subtle.sign("HMAC", key, encoder.encode(`${timestamp}.${body}`));
  const hex = [...new Uint8Array(mac)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
  if (hex.length !== given.length) return false;
  let mismatch = 0;
  for (let index = 0; index < hex.length; index += 1) mismatch |= hex.charCodeAt(index) ^ given.charCodeAt(index);
  return mismatch === 0;
}

everlightNowPlaying.ts

/**
 * Base44 backend function. Optional. The iframe player already follows the shared clock.
 * Uses the secret key so the call is not limited to a browser origin.
 */
declare const secrets: { get(name: string): Promise<string | undefined> };

const RADIO = Deno.env.get("EVERLIGHT_ORIGIN") ?? "http://127.0.0.1:4317";

Deno.serve(async () => {
  const key = await secrets.get("EVERLIGHT_SK");
  if (!key) return Response.json({ error: "EVERLIGHT_SK is not set." }, { status: 500 });
  const response = await fetch(`${RADIO}/api/v1/stations/everlight/now-playing`, {
    headers: { authorization: `Bearer ${key}` },
  });
  return new Response(await response.text(), {
    status: response.status,
    headers: { "content-type": "application/json", "cache-control": "no-store" },
  });
});

Explore everything Everlight

Kintsugi Noki as provider, Pull Up A Chair Radio as the digital channel.

Pull Up A Chair Radio

Programme · Kintsugi Hour

Kintsugi Corner · Episode 2 · Sit with the pieces · Story

Station audio stays mounted while you move around the site.