Skip to content

Sayr Public API & SDK
Created on

Terminal window
npm install @sayrio/public

or

Terminal window
pnpm add @sayrio/public

All SDK methods return a non‑throwing result object:

interface ApiResult<T> {
success: boolean;
data: T | null;
error: string | null;
}

Always check success before accessing data.


Fetch a public organization.

Sayr.org is an alias for the latest API version (v1).

import Sayr from "@sayrio/public";
const res = await Sayr.org.get("acme");
if (!res.success) {
console.error(res.error);
return;
}
console.log(res.data.name);

You can also use the versioned API explicitly:

const res = await Sayr.v1.org.get("acme");

const res = await Sayr.org.get("acme");
if (res.success) {
console.log(res.data);
}

const res = await Sayr.org.tasks.list("acme", {
order: "desc",
limit: 10,
});
if (!res.success) return;
res.data.items.forEach((task) => {
console.log(task.title);
});
console.log(res.data.pagination);

Returned shape:

ApiResult<{
items: Task[];
pagination: Pagination;
}>

const res = await Sayr.org.tasks.get("acme", 42);
if (res.success) {
console.log(res.data.title);
}

const res = await Sayr.org.comments.list("acme", 42);
if (!res.success) return;
res.data.items.forEach((comment) => {
console.log(comment.contentMarkdown);
});

Returned shape:

ApiResult<{
items: Comment[];
pagination: Pagination;
}>

const res = await Sayr.org.labels.list("acme");
if (res.success) {
console.log(res.data);
}
const res = await Sayr.org.categories.list("acme", "desc");
if (res.success) {
console.log(res.data);
}

The /me namespace provides read‑only access to the currently authenticated user.

Authentication is required
Set a token using Sayr.client.setToken(...).


Sayr.client.setToken("********");

const res = await Sayr.me.get();
if (res.success) {
console.log(res.data.email);
}

const res = await Sayr.me.organizations();
if (res.success) {
console.log(res.data);
}

Subscribe to public real‑time events using Server‑Sent Events:

Sayr.sse(org.eventsUrl, {
[Sayr.EVENTS.UPDATE_TASK]: (data) => {
console.log("Task updated", data);
},
});
  • Automatic reconnection (native in browsers)
  • Lightweight, one‑way streaming
  • Typed event constants
  • Public‑safe payloads only

<script type="module">
import Sayr from "https://esm.sh/@sayrio/public";
const res = await Sayr.org.get("acme");
if (res.success) {
console.log(res.data);
}
</script>

Alias for Sayr.v1.org.

MethodDescription
get(slug)Fetch a public organization

MethodDescription
tasks.list(slug, opts?)List tasks (paginated)
tasks.get(slug, shortId)Fetch a single task

MethodDescription
comments.list(slug, shortId, opts?)List task comments

MethodDescription
labels.list(slug)List organization labels

MethodDescription
categories.list(slug, order?)List categories

Authenticated user endpoints.

MethodDescription
get()Fetch the authenticated user
organizations()List organizations the user belongs to

Sayr.sse(url, handlers)

Create an SSE connection for public events:

const conn = Sayr.sse(eventsUrl, {
UPDATE_TASK: () => {},
});
conn.close();

Typed SSE event constants:

Sayr.EVENTS.CREATE_TASK;
Sayr.EVENTS.UPDATE_TASK;
Sayr.EVENTS.UPDATE_TASK_COMMENTS;
Sayr.EVENTS.ERROR;

This package ships with full TypeScript definitions:

import type {
Organization,
Task,
Comment,
Label,
Category,
} from "@sayrio/public";

React bindings are available via:

import {
useOrg,
useTasks,
useTask,
useComments,
} from "@sayrio/public/react";

See @sayrio/public/react README for full hook documentation.