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 🙏

© 2026 – Pkg Stats / Ryan Hefner

social-stock-sdk

v1.1.0

Published

TypeScript SDK for Social Stock Exchange - shared business logic for web and mobile

Downloads

29

Readme

Social Stock Exchange SDK

TypeScript SDK for Social Stock Exchange - shared business logic for web and mobile applications.

Installation

npm install social-stock-sdk

Features

  • 🏗️ Cross-platform compatible - Works in React Native, Next.js, and Node.js
  • 🔒 Type-safe - Full TypeScript support with comprehensive type definitions
  • 📊 Portfolio Management - Real-time portfolio calculations and metrics
  • 💹 Exchange Integration - Direct communication with trading APIs
  • 👥 User Management - Supabase integration for user profiles and social features

Quick Start

Exchange Client

import { createExchangeClient, ExchangeConfig } from 'social-stock-sdk';

const config: ExchangeConfig = {
  baseURL: 'https://your-exchange-api.com',
  readApiKey: 'your-read-key',
  tradingApiKey: 'your-trading-key',
  timeout: 10000
};

const exchangeClient = createExchangeClient(config);

// Get stock data
const stockData = await exchangeClient.getStockData('AAPL');

// Submit an order
const orderResult = await exchangeClient.submitOrder({
  order_type: 'BUY',
  stock_ticker: 'AAPL',
  stock_amount: 10,
  stock_price: 150.00
});

Portfolio Calculator

import { createPortfolioCalculator, createSocialStockSupabaseClient } from 'social-stock-sdk';

// Create Supabase client
const supabaseClient = createSocialStockSupabaseClient({
  url: 'your-supabase-url',
  anonKey: 'your-supabase-anon-key'
});

// Create portfolio calculator
const portfolioCalculator = createPortfolioCalculator(supabaseClient.supabase);

// Calculate real-time portfolio metrics
const metrics = await portfolioCalculator.calculatePortfolioMetrics('user-uuid');

User Management

import { createSocialStockSupabaseClient } from 'social-stock-sdk';

const client = createSocialStockSupabaseClient({
  url: 'your-supabase-url',
  anonKey: 'your-supabase-anon-key'
});

// Get user profile
const profile = await client.getUserProfile('user-uuid');

// Update profile
await client.updateUserProfile('user-uuid', {
  bio_description: 'Updated bio'
});

// Friend management
await client.sendFriendRequest('user-id', 'target-username');
await client.acceptFriendRequest('user-id', 'requester-username');
const followers = await client.getFollowersList('user-id');

// Notifications
const notifications = await client.getNotifications('user-id');
await client.markNotificationRead('user-id', 0);
await client.markAllNotificationsRead('user-id');

// Search
const stockResults = await client.searchStocks('AAPL');
const userResults = await client.searchUsers('john');

Architecture

The SDK is organized into modules:

Clients

  • ExchangeClient - Direct API communication with trading systems
  • SocialStockSupabaseClient - Database operations and user management

Utils

  • PortfolioCalculator - Portfolio metrics and calculations
  • Pending order utilities - Share availability and validation

Types

  • Exchange Types - Stock data, orders, trade executions
  • Portfolio Types - Positions, metrics, snapshots
  • User Types - Profiles, notifications, social features

Usage in Different Environments

Web Application (Next.js)

// Replace your existing imports with SDK imports
import { 
  createExchangeClient, 
  createPortfolioCalculator,
  ExchangeConfig 
} from 'social-stock-sdk';

// Use environment variables
const exchangeConfig: ExchangeConfig = {
  baseURL: process.env.EXCHANGE_API_URL!,
  readApiKey: process.env.EXCHANGE_API_READ_KEY!,
  tradingApiKey: process.env.EXCHANGE_API_TRADING_KEY!,
  timeout: 10000
};

Mobile Application (React Native)

import { 
  createExchangeClient,
  createSocialStockSupabaseClient,
  ExchangeConfig,
  SupabaseConfig 
} from 'social-stock-sdk';

// Configure clients
const exchangeConfig: ExchangeConfig = {
  baseURL: 'https://your-api.com',
  readApiKey: 'your-key',
  tradingApiKey: 'your-trading-key',
  timeout: 10000
};

const supabaseConfig: SupabaseConfig = {
  url: 'your-supabase-url',
  anonKey: 'your-anon-key'
};

// Create clients
const exchangeClient = createExchangeClient(exchangeConfig);
const dbClient = createSocialStockSupabaseClient(supabaseConfig);

API Reference

ExchangeClient Methods

  • getStockData(ticker?: string) - Get stock market data
  • getMultipleStocks(tickers: string[]) - Get data for multiple stocks
  • getOrderBook(ticker: string) - Get order book data
  • submitOrder(orderData) - Submit trading order
  • cancelOrder(orderId: string) - Cancel pending order
  • healthCheck() - Check API health

PortfolioCalculator Methods

  • calculatePortfolioMetrics(userUuid: string) - Real-time portfolio calculations
  • createPortfolioSnapshot(userUuid: string) - Create portfolio snapshot
  • getPortfolioHistory(userUuid: string) - Get historical snapshots
  • updateStockPriceCache(webhookData) - Update price cache from webhooks

SocialStockSupabaseClient Methods

User Management

  • createUserProfile(clerkUser) - Create user profile from Clerk data
  • getUserProfile(userId) - Get user profile by ID
  • updateUserProfile(userId, updates) - Update user profile
  • updateLastLogin(userId) - Update last login timestamp
  • userExists(userId) - Check if user exists

Friend/Follower Management

  • getUserByUsername(username) - Find user by username
  • sendFriendRequest(fromUserId, toUsername) - Send follow request
  • acceptFriendRequest(userId, fromUsername) - Accept friend request
  • rejectFriendRequest(userId, fromUsername) - Reject friend request
  • getUsersByUsernames(usernames) - Get multiple users by username
  • getFollowersList(userId) - Get user's followers list
  • getFollowingList(userId) - Get user's following list

Notification Management

  • getNotifications(userId) - Get user notifications with unread count
  • markNotificationRead(userId, index) - Mark specific notification as read
  • markAllNotificationsRead(userId) - Mark all notifications as read

Search & Discovery

  • searchStocks(query) - Search for stocks by ticker or company name
  • searchUsers(query) - Search for users by username or name

Utility Functions

  • getPendingSellShares(dbClient, userUuid, ticker) - Get pending sell orders
  • getAvailableSharesForSelling(dbClient, userUuid, ticker, currentShares) - Calculate available shares

Development

# Install dependencies
npm install

# Build the package
npm run build

# Watch for changes
npm run dev

Version

Current version: 1.1.0

What's New in 1.1.0

  • Complete Friend/Follower Management: Accept/reject friend requests, get followers/following lists
  • Notification System: Full notification management with read/unread status
  • User Discovery: Search for users and stocks within the SDK
  • Enhanced Types: Comprehensive TypeScript interfaces for all new features

License

MIT