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

@switchx/apps-sdk

v1.1.2

Published

Official SwitchX Apps SDK - Simple API for building AI-powered mini apps on SwitchX

Downloads

906

Readme

@switchx/apps-sdk

Official TypeScript SDK for building mini apps on SwitchX - the AI-powered social platform.

Installation

npm install @switchx/apps-sdk

Quick Start

React (with hooks)

import { useAuth, useCommunity } from '@switchx/apps-sdk/react';

function App() {
  const { user, isAuthenticated, client } = useAuth();
  const { data: community } = useCommunity();

  // Direct client usage
  const messages = await client.searchMessages('hello');

  return <div>{community?.name}</div>;
}

Core (Universal - Client + Server)

import { SwitchXCore } from '@switchx/apps-sdk/core';

const client = new SwitchXCore(token, communityId);

// Read operations
const community = await client.getCommunity();
const members = await client.getMembers();
const channels = await client.getChannels();

// AI operations
const response = await client.chatWithAI([
  { role: 'user', content: 'Hello!' }
]);

const imageUrl = await client.generateImage('a beautiful sunset');

// File upload (client-side)
const url = await client.uploadFile(file);

Server (Node.js)

import { switchx } from '@switchx/apps-sdk/server';

switchx.setup(process.env.MINIAPPS_TOKEN, process.env.COMMUNITY_ID);

// All Core methods + server-specific
const community = await switchx.getCommunity();

// Upload from Buffer (Node.js only)
const url = await switchx.uploadFromBuffer(buffer, 'image.png', 'image/png');

// AI operations
const response = await switchx.chatWithAI([
  { role: 'user', content: 'Hello!' }
]);

Key Features

React Hooks - useAuth(), useCommunity(), useMembers(), etc. ✅ AI Operations - Chat with AI and generate images ✅ File Upload - Direct client-side upload support ✅ Universal Core - Works in browser, Node.js, Edge functions ✅ TypeScript - Full type safety and auto-complete ✅ Zero Config - Works with SwitchX Bridge out of the box

Core API Methods

Community & Users:

  • getCommunity(communityId?) - Get community info
  • getMembers(communityId?) - Get all members
  • getUser(userId) - Get user info
  • getCurrentUser() - Get current user

Channels & Groups:

  • getChannels(communityId?) - Get all channels
  • getGroups(communityId?) - Get all groups
  • getChannelMessages(channelId, options?) - Get messages
  • getGroupMessages(groupId, options?) - Get messages

Search & Utility:

  • searchMessages(query, options?) - Search messages
  • isAdmin(userId, communityId?) - Check admin status

AI Operations:

  • chatWithAI(messages, options?) - Chat with Gemini AI
  • generateImage(prompt, options?) - Generate images

File Operations:

  • uploadFile(file, filename?) - Upload file (browser)
  • uploadFromBuffer(buffer, filename, mimeType) - Upload (Node.js only)

React Hooks

All hooks return { data, loading, error, refetch }:

  • useAuth() - Auth state, user, token, client
  • useCommunity(communityId?) - Community info
  • useMembers(communityId?) - Members list
  • useChannels(communityId?) - Channels
  • useGroups(communityId?) - Groups
  • useChannelMessages(channelId, options?) - Channel messages
  • useSearchMessages(query, options?) - Search results
  • useIsAdmin(userId, communityId?) - Admin status

Module Structure

| Module | Environment | Use Case | |--------|-------------|----------| | @switchx/apps-sdk/core | Universal | Works everywhere (client + server) | | @switchx/apps-sdk/react | Client-only | React hooks with AuthContext | | @switchx/apps-sdk/server | Server-only | Node.js Buffer operations |

Examples

File Upload Example

import { useAuth } from '@switchx/apps-sdk/react';

function FileUpload() {
  const { client } = useAuth();

  const handleUpload = async (e) => {
    const file = e.target.files[0];
    const url = await client.uploadFile(file);
    console.log('Uploaded:', url);
  };

  return <input type="file" onChange={handleUpload} />;
}

AI Chat Example

import { useAuth } from '@switchx/apps-sdk/react';

function AIChat() {
  const { client } = useAuth();

  const chat = async () => {
    const response = await client.chatWithAI([
      { role: 'user', content: 'What is SwitchX?' }
    ], {
      model: 'gemini-2.5-flash',
      temperature: 0.7
    });
    console.log(response);
  };

  return <button onClick={chat}>Ask AI</button>;
}

Next.js API Route Example

// app/api/community/route.ts
import { switchx } from '@switchx/apps-sdk/server';

switchx.setup(process.env.MINIAPPS_TOKEN);

export async function GET() {
  const community = await switchx.getCommunity();
  return Response.json(community);
}

Environment Variables

MINIAPPS_TOKEN=your-token
COMMUNITY_ID=your-community-id

TypeScript

Full TypeScript support with auto-complete:

import type { CommunityInfo, Message, UserInfo } from '@switchx/apps-sdk/types';

License

MIT

Links