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

@socialrails/js

v1.0.0

Published

Official JavaScript/TypeScript SDK for the SocialRails API

Readme

@socialrails/js

Official JavaScript/TypeScript SDK for the SocialRails API. Schedule, publish, and manage social media posts across all major platforms from a single, type-safe client.

  • Zero dependencies -- uses native fetch
  • Full TypeScript support with complete type definitions
  • Works in Node.js 18+, Deno, Bun, and modern browsers

Installation

npm install @socialrails/js
yarn add @socialrails/js
pnpm add @socialrails/js

Quick Start

import { SocialRails } from '@socialrails/js';

const sr = new SocialRails({ apiKey: 'sr_live_...' });

// Create a post
const post = await sr.posts.create({
  content: 'Hello from SocialRails!',
  platform: 'twitter',
  scheduled_for: '2026-03-10T14:00:00Z',
});

console.log(post.id, post.status);

Configuration

Constructor Options

| Option | Type | Default | Description | | --------- | -------- | ------------------------------------ | ---------------------- | | apiKey | string | process.env.SOCIALRAILS_API_KEY | Your SocialRails API key (starts with sr_live_) | | baseUrl | string | https://socialrails.com/api/v1 | API base URL |

Environment Variable

Instead of passing the key directly you can set the SOCIALRAILS_API_KEY environment variable:

export SOCIALRAILS_API_KEY=sr_live_your_key_here
// Automatically picks up the env var
const sr = new SocialRails();

API Reference

Posts

// Create a post
const post = await sr.posts.create({
  content: 'Hello world!',
  platform: 'twitter',
  scheduled_for: '2026-03-10T14:00:00Z', // optional
  media: ['media_abc123'],                // optional media IDs
  platform_settings: { reply_settings: 'everyone' }, // optional
});

// Create a thread
const thread = await sr.posts.create({
  content: 'Thread start',
  platform: 'twitter',
  thread: ['Second tweet', 'Third tweet'],
  thread_delay: 60,
});

// List posts with filters
const { data: posts, pagination } = await sr.posts.list({
  status: 'scheduled',
  platform: 'twitter',
  sort: '-scheduled_for',
  limit: 20,
  offset: 0,
});

// Get a single post
const post = await sr.posts.get('post_abc123');

// Update a post
const updated = await sr.posts.update('post_abc123', {
  content: 'Updated content',
});

// Delete a post
const result = await sr.posts.delete('post_abc123');
// { id: 'post_abc123', deleted: true }

// Batch create across platforms
const batch = await sr.posts.batch({
  content: 'Cross-platform post!',
  platforms: ['twitter', 'linkedin', 'bluesky'],
  platform_content: {
    twitter: 'Short version for Twitter',
  },
});
// { batch_id: '...', posts: [...] }

Analytics

const stats = await sr.analytics.get({
  platform: 'twitter', // optional
  period: '30d',       // optional
  post_id: 'post_abc', // optional
});

console.log(stats.total_posts);
console.log(stats.by_platform);
// [{ platform: 'twitter', posts_published: 42 }, ...]

Accounts

// List connected accounts
const accounts = await sr.accounts.list();

// Get account settings & capabilities
const settings = await sr.accounts.getSettings('acc_abc123');
console.log(settings.capabilities.character_limit);
console.log(settings.capabilities.supports_thread);
console.log(settings.available_tools);

// Trigger a platform tool
const result = await sr.accounts.triggerTool('acc_abc123', {
  tool: 'fetch_trending',
});
console.log(result.results);

AI Content Generation

const result = await sr.ai.generate({
  prompt: 'Write a tweet about our new product launch',
  platform: 'twitter',  // optional
  tone: 'professional', // optional
});

console.log(result.content);

Workspace

const workspace = await sr.workspace.get();

console.log(workspace.plan);
console.log(workspace.limits.max_posts_per_month);
console.log(workspace.usage.posts_this_month);

Media

// Upload a file (Blob in browsers, Buffer in Node.js)
const media = await sr.media.upload(fileBlob, 'photo.jpg', 'image/jpeg');
console.log(media.media_id, media.url);

// Upload from a remote URL
const media2 = await sr.media.uploadFromUrl({
  url: 'https://example.com/image.png',
  type: 'image', // optional
});

Webhooks

// List webhooks
const webhooks = await sr.webhooks.list();

// Create a webhook (secret is only returned at creation)
const webhook = await sr.webhooks.create({
  url: 'https://example.com/hooks/socialrails',
  events: ['post.published', 'post.failed'],
});
console.log(webhook.secret); // Save this!

// Delete a webhook
await sr.webhooks.delete('wh_abc123');

Error Handling

All API errors are thrown as SocialRailsError instances with structured error information:

import { SocialRails, SocialRailsError } from '@socialrails/js';

const sr = new SocialRails({ apiKey: 'sr_live_...' });

try {
  await sr.posts.create({
    content: '',
    platform: 'twitter',
  });
} catch (error) {
  if (error instanceof SocialRailsError) {
    console.error(error.message); // Human-readable message
    console.error(error.code);    // Machine-readable code, e.g. "validation_error"
    console.error(error.status);  // HTTP status code, e.g. 422
  }
}

Common error codes:

| Code | Status | Description | | --------------------- | ------ | --------------------------------- | | invalid_api_key | 401 | API key is missing or invalid | | rate_limit_exceeded | 429 | Too many requests | | validation_error | 422 | Request body failed validation | | not_found | 404 | Resource does not exist | | server_error | 500 | Internal server error |

TypeScript

This SDK is written in TypeScript and ships with complete type definitions. All request parameters and response objects are fully typed:

import type {
  Post,
  CreatePostParams,
  Platform,
  AnalyticsData,
  Workspace,
} from '@socialrails/js';

const params: CreatePostParams = {
  content: 'Typed!',
  platform: 'twitter',
};

Supported Platforms

The SDK supports the following platforms via the Platform type:

  • twitter
  • linkedin
  • facebook
  • instagram
  • tiktok
  • bluesky
  • pinterest
  • threads
  • youtube

Requirements

  • Node.js 18+ (uses native fetch)
  • Deno -- works out of the box
  • Bun -- works out of the box
  • Browsers -- any modern browser with fetch support

License

MIT