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

@crate.ai/discogs-sdk

v2.4.1

Published

an SDK for the Discogs API

Readme

@crate.ai/discogs-sdk

A TypeScript SDK for the Discogs API with dependency injection support.

Features

  • Full TypeScript support
  • OAuth authentication with interactive flow
  • Dependency injection for better testability
  • Customizable storage adapters
  • Comprehensive test coverage
  • Collection management
  • Search functionality

Installation

npm install @crate.ai/discogs-sdk
# or
pnpm add @crate.ai/discogs-sdk
# or
yarn add @crate.ai/discogs-sdk

Setup

  1. Sign in to Discogs and go to developer settings
  2. Create a new application
  3. Note your consumer key and secret

Basic Usage

import { DiscogsSDK } from '@crate.ai/discogs-sdk';

const sdk = new DiscogsSDK({
  DiscogsConsumerKey: 'your_consumer_key',
  DiscogsConsumerSecret: 'your_consumer_secret',
  callbackUrl: 'http://localhost:4567/callback',
  userAgent: 'YourApp/1.0 +https://github.com/yourusername/your-app',
});

// Get authorization URL
const authUrl = await sdk.auth.getAuthorizationUrl();
console.log('Please visit:', authUrl);

// After user authorizes, handle the callback with verifier
await sdk.auth.handleCallback({
  oauthVerifier: 'verifier_from_callback',
  oauthToken: 'token_from_callback',
});

// Get user identity
const identity = await sdk.auth.getUserIdentity();
console.log('Logged in as:', identity.username);

// Search for releases
const searchResults = await sdk.search.getSearchResults({
  query: 'Dark Side of the Moon',
  type: 'release',
});

// Get user's collection
const collection = await sdk.collection.getCollection({
  username: identity.username,
  page: 1,
  perPage: 50,
});

Custom Storage

By default, the SDK uses in-memory storage. You can implement your own storage adapter:

import { DiscogsSDK, StorageAdapter } from '@crate.ai/discogs-sdk';

class CustomStorage implements StorageAdapter {
  async getItem(key: string): Promise<string | null> {
    // Your implementation
  }

  async setItem(key: string, value: string): Promise<void> {
    // Your implementation
  }

  async removeItem(key: string): Promise<void> {
    // Your implementation
  }
}

const sdk = DiscogsSDK.withCustomStorage(
  {
    DiscogsConsumerKey: 'your_key',
    DiscogsConsumerSecret: 'your_secret',
    callbackUrl: 'your_callback',
    userAgent: 'YourApp/1.0',
  },
  new CustomStorage(),
);

API Reference

Authentication

// Get authorization URL
const authUrl = await sdk.auth.getAuthorizationUrl();

// Handle OAuth callback
await sdk.auth.handleCallback({
  oauthVerifier: 'verifier',
  oauthToken: 'token',
});

// Get user identity
const identity = await sdk.auth.getUserIdentity();

Collection

// Get user's collection
const collection = await sdk.collection.getCollection({
  username: 'username',
  page: 1,
  perPage: 50,
});

// Get collection folders
const folders = await sdk.collection.getFolders('username');

// Add release to collection
await sdk.collection.addToCollection(releaseId, folderId);

Search

// Basic search
const results = await sdk.search.getSearchResults({
  query: 'Artist Name',
  type: 'release',
});

// Advanced search
const results = await sdk.search.getSearchResults({
  query: 'Album Name',
  type: 'release',
  year: '1977',
  format: 'album',
});

Examples

For complete examples, check out our example project.

Contributing

Please see CONTRIBUTING.md for contribution guidelines.

License

MIT

Authentication Flow

The SDK uses OAuth 1.0a for authentication. Here's a complete example:

import { DiscogsSDK } from '@crate.ai/discogs-sdk';

const sdk = new DiscogsSDK({
    DiscogsConsumerKey: 'your_key',
    DiscogsConsumerSecret: 'your_secret',
    callbackUrl: 'http://localhost:4567/callback',
    userAgent: 'YourApp/1.0'
});

// 1. Get authorization URL
const authUrl = await sdk.auth.getAuthorizationUrl();
console.log('Visit:', authUrl);

// 2. Extract oauth_token from the URL
const oauthToken = new URL(authUrl).searchParams.get('oauth_token');

// 3. After user authorizes, they'll be redirected to your callback URL with:
// http://localhost:4567/callback?oauth_token=TOKEN&oauth_verifier=VERIFIER

// 4. Complete authentication with the verifier and token
await sdk.auth.handleCallback({
    oauthVerifier: 'verifier_from_callback_url',
    oauthToken: oauthToken
});

// 5. Get user identity
const identity = await sdk.auth.getUserIdentity();
console.log('Logged in as:', identity.username);

The callback URL will receive two parameters:

  • oauth_token: Matches the token from step 2
  • oauth_verifier: The verification code needed to complete authentication