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.5.0

Published

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

Readme

@marlinjai/storage-brain-sdk

TypeScript SDK for Storage Brain - an edge-native file storage service built on Cloudflare Workers, R2, and D1.

Features

  • Simple API - Upload, download, list, and delete files with ease
  • Progress tracking - Real-time upload progress callbacks
  • Type-safe - Full TypeScript support with comprehensive types
  • Automatic retries - Built-in retry logic with exponential backoff
  • Flexible context - Optional free-form context labels for organizing files
  • Zero dependencies - Uses only native browser/Node.js APIs

Installation

npm install @marlinjai/storage-brain-sdk

Quick Start

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

// Initialize the client
const storage = new StorageBrain({
  apiKey: 'sk_live_your_api_key_here',
});

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

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

API Reference

Constructor

const storage = new StorageBrain({
  apiKey: string;        // Required: Your API key
  baseUrl?: string;      // Optional: API base URL
  timeout?: number;      // Optional: Request timeout in ms (default: 30000)
  maxRetries?: number;   // Optional: Max retry attempts (default: 3)
});

Methods

upload(file, options)

Upload a file to Storage Brain.

const result = await storage.upload(file, {
  context: 'my-app',                // Optional free-form context label
  tags: { orderId: '123' },         // Optional metadata tags
  onProgress: (p) => {},            // Progress callback (0-100)
  webhookUrl: 'https://...',        // Optional webhook for notifications
  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,              // Max results (default: 20)
  cursor: 'abc...',       // Pagination cursor
  context: 'my-app',     // Filter by context (free-form string)
  fileType: 'image/png',  // Filter by MIME type
});

deleteFile(fileId)

Soft delete a file.

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

getQuota()

Get storage quota information.

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

getTenantInfo()

Get tenant information.

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

Supported File Types

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

Error Handling

The SDK throws typed errors for different scenarios:

import {
  StorageBrainError,
  AuthenticationError,
  QuotaExceededError,
  InvalidFileTypeError,
  FileTooLargeError,
  FileNotFoundError,
  NetworkError,
  UploadError,
} 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

All types are exported for your convenience:

import type {
  StorageBrainConfig,
  UploadOptions,
  FileInfo,
  ListFilesOptions,
  ListFilesResult,
  QuotaInfo,
  TenantInfo,
  FileMetadata,
  AllowedMimeType,
} 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