Skip to content

Example: numbers from Supabase

An app can show its own metrics on its Periskopos card by implementing the protocol. Periskopos generates the endpoint; you fill in what the numbers are. This is a complete example for an app that keeps its accounts in Supabase Auth and its data in a Supabase table.

In Periskopos: your app → Settings → Protocol → Add the protocol, choose Metrics, Generate code. It writes the endpoint’s secret to your keys file and shows the endpoint file and the two commands to deploy it. Put the file in your app’s repo at supabase/functions/periskopos/index.ts.

Replace the generated getMetrics() with something like this. It counts accounts, sign-ups in the last week, and the rows of a saved_items table (use your own tables):

export async function getMetrics(): Promise<Metric[]> {
const supabase = await admin();
const { count: saved, error: savedError } = await supabase
.from("saved_items")
.select("*", { count: "exact", head: true });
if (savedError) throw savedError;
// Accounts live in Supabase Auth: count them page by page.
const weekAgo = Date.now() - 7 * 24 * 3600 * 1000;
let accounts = 0;
let signupsThisWeek = 0;
for (let page = 1; ; page++) {
const { data, error } = await supabase.auth.admin.listUsers({ page, perPage: 1000 });
if (error) throw error;
accounts += data.users.length;
signupsThisWeek += data.users.filter((u) => Date.parse(u.created_at) >= weekAgo).length;
if (data.users.length < 1000) break;
}
return [
{ id: "users", label: "Accounts", value: accounts },
{ id: "saved_items", label: "Saved items", value: saved ?? 0 },
{ id: "signups_week", label: "Sign-ups this week", value: signupsThisWeek, hint: "last 7 days" },
];
}

Counts only: no emails or names ever leave the function.

Deploy with --no-verify-jwt (the generator’s second command has it), then test the connection in Periskopos with https://<project-ref>.supabase.co/functions/v1/periskopos.

This snippet is type-checked under Deno against the real, current supabase-js by Periskopos’s test suite.