SDKOverview

SDK overview

@junjo/sdk is the TypeScript client. Same package runs in Node and the browser; tree-shakeable; zero runtime dependencies beyond fetch (a built-in everywhere we ship to).

Construct a client

import { Junjo } from "@junjo/sdk";
 
const junjo = new Junjo({
  apiKey: process.env.JUNJO_API_KEY!,
  // baseUrl: "https://api.junjo.io", // default
});
OptionRequiredNotes
apiKeyyesThe full prefix.secret string issued in the dashboard or by npm run db:seed.
baseUrlnoOverride the API root. Trailing slashes are stripped. Defaults to the cloud endpoint.
authAdapternoAn AuthAdapter (Clerk, Supabase, JWT, or BYO). Used by the permission-resolution path; not required for server-to-server calls.
fetchnoOverride the fetch implementation. Useful in environments without a global fetch, and to mock requests in tests.

Errors

Every method that talks to the server throws JunjoError for any non-2xx response. The instance preserves the server’s envelope:

import { JunjoError } from "@junjo/sdk";
 
try {
  await junjo.groups.create({ kind: "guild", name: "" });
} catch (e) {
  if (e instanceof JunjoError) {
    e.code;    // "bad_request"
    e.status;  // 400
    e.message; // "name: too short"
  }
}

Branch on error.code, not on error.message. Codes are stable; messages are not.

Sub-namespaces

The Junjo instance exposes typed namespaces for each resource. See the per-namespace pages for the methods inside each.

NamespaceMethods
junjo.groupsCRUD, invites, membership lifecycle, group relationships, sub-group setParent / listChildren, subscribe (SSE).
junjo.rolescreate, get, update, delete, list, grantPermission, revokePermission.
junjo.membersRead (get, getById, list, listForUser), metadata / notes (setMetadata, setNotes), role assignment (assignRole, removeRole), permission overrides (overridePermission, clearPermissionOverride, listPermissionOverrides).
junjo.invitationslist, get, revoke. Accept and decline live on junjo.groups (acceptInvitation, declineInvitation).
junjo.auditlist.
junjo.webhooksverify, middleware; endpoints.{create,list,update,delete}.

Top-level methods

In addition to the resource namespaces, Junjo exposes a small set of cross-cutting methods directly on the instance.

MethodNotes
junjo.can(userId, groupId, permission)Boolean wrapper around check.
junjo.check(userId, groupId, permission)Returns the full PermissionCheckResult.
junjo.whoami(token)Delegates to the configured authAdapter.verifyToken; returns { userId } | null. Throws JunjoError({ code: "invalid_config" }) if no authAdapter was passed to the constructor.