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 🙏

© 2024 – Pkg Stats / Ryan Hefner

smashroad

v0.2.5

Published

An advanced Gumroad API client by @smashah.

Downloads

17

Readme

Gumroad API Client

A TypeScript/JavaScript client for interacting with the Gumroad API. This library provides a simple and intuitive way to interact with the Gumroad API, supporting all major endpoints. It includes interfaces for various data types returned by the API, as well as classes for managing licenses and subscriptions.

Installation

To install the library, use the following command:

> npm install smashroad

Usage

First, import the GumroadClient class from the library:

import { GumroadClient } from 'smashroad';

Then, create a new instance of the client, passing your Gumroad API access token, product id, and cookie as parameters to the constructor:

const client = new GumroadClient('YOUR_ACCESS_TOKEN', 'YOUR_PRODUCT_ID', 'YOUR_GUMROAD_COOKIE');

You can now use the client to interact with the Gumroad API. For example, to get a license:

const license = await client.getLicense('LICENSE_KEY', 'PRODUCT_ID');

API

GumroadClient

The main class for interacting with the Gumroad API. It provides methods for making requests to the API, managing resource subscriptions, and working with licenses and subscriptions.

Constructor

new GumroadClient(access_token: string, product_id?: string, cookie?: string)
  • access_token: Gumroad API access token
  • product_id: (Optional) Gumroad product id
  • cookie: (Optional) Gumroad cookie. You can get this from the browser when you're logged in to Gumroad.

Methods

public async getResourceSubscriptions(resource_name : ResourceSubscriptionType) : Promise<ResourceSubscription[]>
public async createResourceSubscription(resource_name: ResourceSubscriptionType, post_url: string) : Promise<ResourceSubscription>
public async getLicense(license_key: string, product_id: string): Promise<GumroadLicense>
public async getSubscriptionPurchases(subscription_id: string): Promise<Purchase[]>
public async searchPurchases(query: string): Promise<Purchase[]>
public async getSubscriptions(email?: string, product_id?: string): Promise<Subscription[]>
public async emailIsSubscriber(email: string, product_id ?: string): Promise<boolean>
public async getSubscription(subscription_id: string): Promise<Subscription>

GumroadLicense

A class for managing a Gumroad license. It provides methods for getting charges, purchases, and subscription information, as well as checking the validity and status of the license.

Constructor

new GumroadLicense(initiatingPurchase: Purchase, client: GumroadClient)

Methods

async getCharges(): Promise<Purchase[]>
async getPurchases(): Promise<Purchase[]>
async getSubscription(): Promise<Subscription>
async isValid(invalidCases?: InvalidCases): Promise<boolean>
async getStatus(): Promise<string>
async getTotalRevenue(): Promise<number>

Examples

Here's an example of how to use the GumroadClient to get a license:

const client = new GumroadClient('YOUR_ACCESS_TOKEN', 'YOUR_PRODUCT_ID', 'YOUR_GUMROAD_COOKIE');
const license = await client.getLicense('LICENSE_KEY', 'PRODUCT_ID');
console.log(await license.getStatus());

And here's an example of how to use the GumroadLicense to check if a license is valid:

const client = new GumroadClient('YOUR_ACCESS_TOKEN', 'YOUR_PRODUCT_ID', 'YOUR_GUMROAD_COOKIE');
const license = await client.getLicense('LICENSE_KEY', 'PRODUCT_ID');
try {
const isValid = await license.isValid();
console.log('License is valid');
} catch (error) {
console.error('License is invalid:', error.message);
}

Types

The library includes TypeScript definitions for various Gumroad API response types, including:

  • Purchase
  • Subscription
  • ResourceSubscription
  • GumroadSaleData
  • GumroadSubscriptionData
  • SubscriptionUpdateData
  • SubscriptionEndedData
  • SubscriptionRestartedData

These types can be imported and used in your TypeScript projects for better type checking and autocompletion.

Error Handling

The library throws errors for invalid API responses or when a license is invalid. Make sure to wrap your API calls in try-catch blocks to handle these errors gracefully.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License.