Sayr Public API & SDK
Installation
Section titled “Installation”npm install @sayrio/publicor
pnpm add @sayrio/publicCore Concepts
Section titled “Core Concepts”✅ ApiResult<T>
Section titled “✅ ApiResult<T>”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.
Basic Usage (REST)
Section titled “Basic Usage (REST)”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");Organizations
Section titled “Organizations”Fetch an Organization
Section titled “Fetch an Organization”const res = await Sayr.org.get("acme");
if (res.success) { console.log(res.data);}List Tasks (Paginated)
Section titled “List Tasks (Paginated)”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;}>Fetch a Single Task
Section titled “Fetch a Single Task”const res = await Sayr.org.tasks.get("acme", 42);
if (res.success) { console.log(res.data.title);}Comments
Section titled “Comments”List Task Comments (Paginated)
Section titled “List Task Comments (Paginated)”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;}>Labels & Categories
Section titled “Labels & Categories”Labels
Section titled “Labels”const res = await Sayr.org.labels.list("acme");
if (res.success) { console.log(res.data);}Categories
Section titled “Categories”const res = await Sayr.org.categories.list("acme", "desc");
if (res.success) { console.log(res.data);}Authenticated User (/me)
Section titled “Authenticated User (/me)”The /me namespace provides read‑only access to the currently
authenticated user.
Authentication is required
Set a token usingSayr.client.setToken(...).
Set Token
Section titled “Set Token”Sayr.client.setToken("********");Fetch Current User
Section titled “Fetch Current User”const res = await Sayr.me.get();
if (res.success) { console.log(res.data.email);}List Your Organizations
Section titled “List Your Organizations”const res = await Sayr.me.organizations();
if (res.success) { console.log(res.data);}Real‑Time Updates (WebSocket)
Section titled “Real‑Time Updates (WebSocket)”Subscribe to public real‑time events using WebSockets:
Sayr.ws(org.wsUrl, { [Sayr.WS_EVENTS.UPDATE_TASK]: (data) => { console.log("Task updated", data); },});WebSocket Features
Section titled “WebSocket Features”- Automatic reconnection
- Heartbeat support (PING / PONG)
- Typed event constants
- Public‑safe payloads only
Browser Usage (No Bundler)
Section titled “Browser Usage (No Bundler)”<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>API Overview
Section titled “API Overview”Sayr.org (latest)
Section titled “Sayr.org (latest)”Alias for Sayr.v1.org.
Organization
Section titled “Organization”| Method | Description |
|---|---|
get(slug) | Fetch a public organization |
| Method | Description |
|---|---|
tasks.list(slug, opts?) | List tasks (paginated) |
tasks.get(slug, shortId) | Fetch a single task |
Comments
Section titled “Comments”| Method | Description |
|---|---|
comments.list(slug, shortId, opts?) | List task comments |
Labels
Section titled “Labels”| Method | Description |
|---|---|
labels.list(slug) | List organization labels |
Categories
Section titled “Categories”| Method | Description |
|---|---|
categories.list(slug, order?) | List categories |
Sayr.me
Section titled “Sayr.me”Authenticated user endpoints.
| Method | Description |
|---|---|
get() | Fetch the authenticated user |
organizations() | List organizations the user belongs to |
Sayr.ws(url, handlers)
Section titled “Sayr.ws(url, handlers)”Create a WebSocket connection for public events:
const conn = Sayr.ws(wsUrl, { UPDATE_TASK: () => {},});
conn.close();WS_EVENTS
Section titled “WS_EVENTS”Typed WebSocket event constants:
Sayr.WS_EVENTS.CREATE_TASK;Sayr.WS_EVENTS.UPDATE_TASK;Sayr.WS_EVENTS.UPDATE_TASK_COMMENTS;Sayr.WS_EVENTS.ERROR;TypeScript
Section titled “TypeScript”This package ships with full TypeScript definitions:
import type { Organization, Task, Comment, Label, Category,} from "@sayrio/public";React Hooks
Section titled “React Hooks”React bindings are available via:
import { useOrg, useTasks, useTask, useComments,} from "@sayrio/public/react";See @sayrio/public/react README for full hook documentation.