npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@synap-core/client

v0.2.0

Published

Type-safe client SDK for Synap Core OS

Readme

@synap/client

Type-safe Client SDK for Synap Core OS

A hybrid 3-layer SDK that provides both high-level convenience methods and low-level RPC access.


🏗️ Architecture

The SDK is built on 3 layers:

  1. Core RPC (Auto-generated): Direct tRPC access via client.rpc.*
  2. Business Facade: High-level methods via client.notes.*, client.chat.*, etc.
  3. Authentication: Agnostic token management via getToken()

📦 Installation

npm install @synap/client
# or
pnpm add @synap/client
# or
yarn add @synap/client

🚀 Quick Start

Basic Usage

import SynapClient from '@synap/client';

const synap = new SynapClient({
  url: 'http://localhost:3000',
  getToken: async () => {
    // Get your auth token (Better Auth, custom auth, etc.)
    return await getSessionToken();
  },
});

// High-level API (recommended)
await synap.notes.create({
  content: '# My Note\n\nContent here',
  title: 'My Note',
});

// Low-level API (for power users)
await synap.rpc.notes.create.mutate({
  content: '# My Note',
});

With Static Token

const synap = new SynapClient({
  url: 'http://localhost:3000',
  token: 'your-static-token',
});

📚 API Reference

High-Level API (Business Facade)

Notes

// Create a note
await synap.notes.create({
  content: '# My Note',
  title: 'My Note',
  tags: ['important'],
});

// List notes
const notes = await synap.notes.list({
  limit: 20,
  offset: 0,
});

// Get a note
const note = await synap.notes.get('note-id');

Chat

// Send a message
const result = await synap.chat.sendMessage({
  content: 'Create a note about AI',
  threadId: 'thread-123',
});

// Get thread
const thread = await synap.chat.getThread('thread-123');

// List threads
const threads = await synap.chat.listThreads();

Tasks

// Complete a task
await synap.tasks.complete('task-id');

Capture

// Capture a thought
await synap.capture.thought('I need to remember to buy milk');

System

// Health check
const health = await synap.system.health();

// System info
const info = await synap.system.info();

Low-Level API (RPC)

For full control, use the RPC client directly:

// Direct tRPC access
await synap.rpc.notes.create.mutate({ content: '...' });
await synap.rpc.notes.list.query({ limit: 20 });
await synap.rpc.chat.sendMessage.mutate({ content: '...' });

🔌 Real-Time (WebSocket)

import { SynapRealtimeClient } from '@synap/client/realtime';

const realtime = new SynapRealtimeClient({
  url: synap.getRealtimeUrl('user-123'),
  userId: 'user-123',
  onMessage: (message) => {
    console.log('Received:', message);
    if (message.type === 'note.creation.completed') {
      // Refresh notes list
    }
  },
});

realtime.connect();

⚛️ React Integration

import { trpc, createSynapReactClient } from '@synap/client/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';

const queryClient = new QueryClient();
const trpcClient = createSynapReactClient({
  url: 'http://localhost:3000',
  getToken: async () => await getSessionToken(),
});

function App() {
  return (
    <trpc.Provider client={trpcClient} queryClient={queryClient}>
      <MyComponent />
    </trpc.Provider>
  );
}

function MyComponent() {
  const { data: notes } = trpc.notes.list.useQuery();
  const createNote = trpc.notes.create.useMutation();

  return (
    <div>
      {notes?.map(note => (
        <div key={note.id}>{note.title}</div>
      ))}
    </div>
  );
}

🔐 Authentication

The SDK supports multiple authentication methods:

Better Auth (PostgreSQL mode)

const synap = new SynapClient({
  url: 'http://localhost:3000',
  getToken: async () => {
    const session = await getSession();
    return session?.token || null;
  },
});

Ory Kratos Session (PostgreSQL mode)

const synap = new SynapClient({
  url: 'http://localhost:3000',
  // Authentication handled via Ory Kratos session cookies
});

Custom Auth

const synap = new SynapClient({
  url: 'http://localhost:3000',
  getToken: async () => {
    // Your custom auth logic
    return await myAuthService.getToken();
  },
});

📖 Documentation


📝 License

MIT