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

@marlinjai/storage-brain-sdk

v0.9.0

Published

TypeScript SDK for Storage Brain - edge-native file storage service

Readme


title: Storage Brain SDK summary: README for the Storage Brain TypeScript SDK providing file upload, download, listing, signed URLs, workspace management, progress tracking, and automatic retries with zero dependencies. type: readme tags: [storage-brain, sdk, typescript, file-storage, npm] date: 2026-02-20

@marlinjai/storage-brain-sdk

TypeScript SDK for Storage Brain — a multi-tenant file storage service. Works with the managed Cloudflare Workers deployment and self-hosted (Docker + S3 + Postgres) instances.

Features

  • Simple API — Upload, download, list, and delete files with ease
  • Workspaces — Scope files to workspaces with per-workspace quotas
  • Signed URLs — Time-limited public download links without API key
  • Progress tracking — Real-time upload progress callbacks
  • Type-safe — Full TypeScript support with comprehensive types
  • Automatic retries — Built-in retry logic with exponential backoff
  • Zero dependencies — Uses only native browser/Node.js APIs

Installation

pnpm add @marlinjai/storage-brain-sdk

Quick Start

import { StorageBrain } from '@marlinjai/storage-brain-sdk';

const storage = new StorageBrain({
  apiKey: 'sk_live_your_api_key_here',
  // baseUrl: 'http://localhost:3000', // for self-hosted
});

// Upload a file
const file = await storage.upload(fileBlob, {
  context: 'my-app',
  onProgress: (progress) => console.log(`${progress}%`),
});

console.log('File uploaded:', file.url);

API Reference

Constructor

const storage = new StorageBrain({
  apiKey: string;          // Required: Your API key (sk_live_* or sk_test_*)
  baseUrl?: string;        // Optional: API base URL (default: managed cloud)
  timeout?: number;        // Optional: Request timeout in ms (default: 30000)
  maxRetries?: number;     // Optional: Max retry attempts (default: 3)
  workspaceId?: string;    // Optional: Default workspace for all operations
});

File Operations

upload(file, options?)

Upload a file to Storage Brain.

const result = await storage.upload(file, {
  context: 'invoices',                // Optional context label
  tags: { orderId: '123' },           // Optional metadata tags
  onProgress: (p) => {},              // Progress callback (0-100)
  webhookUrl: 'https://...',          // Optional webhook notification
  workspaceId: 'ws-uuid',            // Optional workspace override
  signal: abortController.signal,     // Optional abort signal
});

getFile(fileId)

Get file information by ID.

const file = await storage.getFile('file-uuid');

listFiles(options?)

List files with optional filtering and pagination.

const { files, nextCursor, total } = await storage.listFiles({
  limit: 20,
  cursor: 'abc...',
  context: 'invoices',
  fileType: 'image/png',
  workspaceId: 'ws-uuid',
});

deleteFile(fileId)

Soft-delete a file.

await storage.deleteFile('file-uuid');

getSignedUrl(fileId, expiresIn?)

Get a time-limited signed URL for unauthenticated file download.

const { url, expiresAt } = await storage.getSignedUrl('file-uuid', 3600);
// url can be shared publicly — no API key needed to download

Workspace Operations

withWorkspace(workspaceId)

Create a workspace-scoped client. All uploads and listings default to this workspace.

const wsStorage = storage.withWorkspace('ws-uuid');
await wsStorage.upload(fileBlob, { context: 'campaign-images' });
const { files } = await wsStorage.listFiles();

createWorkspace(input)

const ws = await storage.createWorkspace({
  name: 'Marketing Assets',
  slug: 'marketing-assets',
  quotaBytes: 100 * 1024 * 1024,  // 100 MB
  metadata: { team: 'marketing' },
});

listWorkspaces()

const workspaces = await storage.listWorkspaces();

getWorkspace(workspaceId)

const ws = await storage.getWorkspace('ws-uuid');

updateWorkspace(workspaceId, updates)

await storage.updateWorkspace('ws-uuid', {
  name: 'Rebranded Assets',
  quotaBytes: 200 * 1024 * 1024,
});

deleteWorkspace(workspaceId)

Deletes the workspace and soft-deletes all its files.

await storage.deleteWorkspace('ws-uuid');

Tenant Operations

getQuota()

const quota = await storage.getQuota();
console.log(`Used: ${quota.usedBytes} / ${quota.quotaBytes} bytes`);
console.log(`Usage: ${quota.usagePercent}%`);

getTenantInfo()

const tenant = await storage.getTenantInfo();
console.log(`Tenant: ${tenant.name}`);

Self-Hosting

Storage Brain can be self-hosted with Docker (S3 + Postgres). Point the SDK at your instance:

const storage = new StorageBrain({
  apiKey: 'sk_live_...',
  baseUrl: 'http://localhost:3000',
});

See the self-hosting docs for setup instructions.

Supported File Types

  • Images: JPEG, PNG, WebP, GIF, AVIF
  • Documents: PDF

Error Handling

import {
  StorageBrainError,
  AuthenticationError,
  QuotaExceededError,
  InvalidFileTypeError,
  FileTooLargeError,
  FileNotFoundError,
  NetworkError,
  UploadError,
  ValidationError,
} from '@marlinjai/storage-brain-sdk';

try {
  await storage.upload(file, { context: 'my-app' });
} catch (error) {
  if (error instanceof QuotaExceededError) {
    console.error('Storage quota exceeded');
  } else if (error instanceof InvalidFileTypeError) {
    console.error('File type not allowed');
  } else if (error instanceof AuthenticationError) {
    console.error('Invalid API key');
  }
}

TypeScript Types

import type {
  StorageBrainConfig,
  UploadOptions,
  FileInfo,
  ListFilesOptions,
  ListFilesResult,
  QuotaInfo,
  TenantInfo,
  SignedUrlInfo,
  FileMetadata,
  Workspace,
  CreateWorkspaceInput,
  UpdateWorkspaceInput,
  AllowedMimeType,
  ProcessingStatus,
} from '@marlinjai/storage-brain-sdk';

Constants

import {
  ALLOWED_MIME_TYPES,     // ['image/jpeg', 'image/png', ...]
  PROCESSING_STATUSES,    // ['pending', 'processing', 'completed', 'failed']
  MAX_FILE_SIZE_BYTES,    // 100MB
} from '@marlinjai/storage-brain-sdk';

License

MIT