SeuraaEdge
v1
Docs/SDKs
SDKs

Issue tokens and publish trusted events from your backend.

Backend SDK

Use the JavaScript backend SDK in trusted code to issue channel tokens, publish events, query presence, and revoke tokens.

Create A Client

ts
import { Client } from "@seuraa/edge/backend";

const edge = new Client({
  appKey: process.env.SEURAA_APP_KEY!,
  appSecret: process.env.SEURAA_APP_SECRET!,
});

Never expose appSecret to browser or mobile clients.

The backend entrypoint requires the standard fetch API and Node's node:crypto module. Node.js is the supported runtime.

Issue A Channel Token

ts
const session = edge.auth.signIn({
  channel: "private:user-123",
  expiresInSeconds: 60,
  permissions: ["subscribe"],
  userId: "user-123",
});

The result contains:

ts
{
  appKey: string;
  channel: string;
  expiresAt: string;
  token: string;
  tokenId: string;
}

Return token to the authenticated client. Store tokenId when the session may need to be revoked before expiry.

Publish An Event

ts
await edge.channels.publish("private:user-123", "notification.created", {
  title: "Your report is ready",
});

Provide a stable client event ID when retrying the same application operation:

ts
await edge.channels.publish(
  "private:user-123",
  "notification.created",
  { title: "Your report is ready" },
  { clientEventId: "notification-456" },
);

Query Presence

ts
const presence = await edge.channels.presence("presence:document-123");

console.log(presence.count);
console.log(presence.members);

Revoke A Token

ts
await edge.auth.revoke(session.tokenId, {
  ttlSeconds: 3600,
});

Set the revocation TTL to cover the token's remaining lifetime.