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

@salable/js

v4.0.0

Published

A set of functions to simplify building Salable applications with JS

Downloads

11

Readme

A set of functions to simplify building Salable applications in JavaScript/Node.js.

Installation

# npm
npm install @salable/js

# yarn
yarn add @salable/js

# pnpm
pnpm install @salable/js

Functions

The library features exports for both ECMAScript Modules (ESM) and CommonJS (CJS).

import salableJs from '@salable/js'
// or
const salableJs = require('@salable/js')

For convenience, the functions documented are also added to the window object on the web under the salable object. So, getGrantee can be accessed via window.salable.getGrantee.

getGrantee({ apiKey: string, productUuid: string, granteeId?: string })

Returns a list of capabilities for the current user. This function is scoped to a grantee (through the provided granteeId) and a product (through the provided productUuid).

Also returns a hasCapability utility function that simplifies the checking of the provided user's capabilities.

Example

import { getGrantee } from '@salable/js'

const { hasCapability, licenses, capabilities, isTest } = await getGrantee({
  apiKey: 'your-api-key',
  productUuid: 'your-product-uuid',
  granteeId: 'your-users-grantee-id',
})

if (hasCapability('edit')) {
  console.log('You have the edit capability!')
}

getProduct({ apiKey: string, productUuid: string, withDeprecated?: boolean})

Returns useful data about the current product. Can be used for many things including the creation of custom pricing tables.

By default, plans and features that are marked as DEPRECATED will be excluded from the response. If you would like these returned, you can pass in an optional options object with { withDeprecated: true }.

Example

import { getProduct } from '@salable/js'

const { name, plans } = await getProduct({
  apiKey: 'your-api-key',
  productUuid: 'your-product-uuid',
  withDeprecated: true,
})

getCheckoutLink({ apiKey: string, planUuid: string, successUrl: string, cancelUrl: string, granteeId: string, member: string })

Returns a checkout link for the specified planUuid.

Example

import { getCheckoutLink } from '@salable/js'

const checkoutLink = await getCheckoutLink({
  planUuid: 'your-plan-uuid',
  apiKey: 'your-api-key',
  successUrl: 'https://your.apps/success',
  cancelUrl: 'https://your.apps/cancel',
  granteeId: 'your-users-id',
  member: 'your-users-id',
  checkoutEmail: '', // optional, pre-fills email field in Stripe checkout
  quantity: 5, // optional, the number of seats purchased on checkout (if using per-seat plan, default is minimum number set on plan)
  currency: 'EUR', // optional, defaults to the product's default currency in Salable
})

createScope({ apiKey: string, productUuid: string })

Creates scoped versions of all other functions exposed by this package where the productUuid and apiKey are already provided. This allows you to pass these values in one time, rather than with each call if that's what you'd prefer.

This function isn't available on the window.salable object in the browser.

Example

import { createScope } from '@salable/js'

const { getGrantee, getProduct } = createScope({
  apiKey: 'your-api-key',
  productUuid: 'your-product-uuid',
})

// This function now only takes the `granteeId`, the other values are already
// passed in by the `createScope` call.
const grantee = await getGrantee({ granteeId: 'the-users-grantee-id' })