New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

lemonsqueezy.js

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lemonsqueezy.js

The official Javascript wrapper for the Lemon Squeezy API.

  • 1.0.0
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

The official Javascript wrapper for the Lemon Squeezy API

Introduction

Please read the API reference introduction page to understand how the API works.

Installation

TODO

Usage

Basic usage

import LemonSqueezy from 'lemonsqueezy.js'
const ls = new LemonSqueezy(API_KEY);

const products = await ls.getProducts()

Parameters for requests should be passed in an object. For list methods, these parameters are used for filtering and for list pagination. For create and update methods, these parameters contain the values for the request.

const subscriptions = await ls.getSubscriptions({ storeId: 123, perPage: 50 })

const subscription = await ls.getSubscription({ id: 123, include: 'subscription-invoices' })

const subscription = await ls.cancelSubscription({ id: 123 })

You can use include in every "read" method to pull in related resources (works for both individual and list methods).

const product = await ls.getProduct({ id: 123 include: 'variants' })

Pagination

There are pagination parameters for every list method: page, perPage. If perPage is omitted, the API returns 10 records per page.

// Querying a list of orders for store #3, 50 records per page, page 2, including store and customer related resoueces
const order = await ls.getOrders({ storeId: 3, perPage: 50, page: 2, include: 'store,customer' })

Handling errors

Each method will throw an exception if there are issues with the request. JSON will be returned containing error details.

Use try { ... } catch { ... } to access this object. Error messages will be available in a list in errors.

// "something" is not a valid value for `include`
try {
  const subscriptions = await ls.getSubscriptions({ include: 'something' })
} catch (err) {
  // `err` is an object like this:
  //  {
  //   "jsonapi": {
  //     "version": "1.0"
  //   }
  //   "errors": [
  //     {
  //       "detail": "Include path something is not allowed.",
  //       "source": {
  //         "parameter": "include"
  //       },
  //       "status": "400",
  //       "title": "Invalid Query Parameter"
  //     }
  //   ]
  // }
}

Looping lists

Endpoints that return a list of results can be paged using optional page and perPage values. If perPage is omitted, the API returns the default of 10 results per page. perPage should be a value between 1 and 100. You can use the lastPage value in the meta.page object to check if you are on the last page of results.

let hasNextPage = true
let perPage = 100
let page = 1
let variants = []
while (hasNextPage) {
  const resp = await ls.getVariants({ perPage, page });
  
  variants = variants.concat(resp['data'])

  if (resp.meta.page.lastPage > page) {
    page += 1
  } else {
    hasNextPage = false
  }
}

Notes

Don't use this package directly in the browser as this will expose your API key, which would provide access to your full store.

Methods


getUser()

Get the current user.

Returns a User object.

API reference.

Parameters

None.

Example
const user = await ls.getUser()

getStores(parameters)

Get the current user's stores.

Returns a list of Store objects.

API reference.

Parameters
ParameterTypeDefaultNotes
perPagenumber10
pagenumber1
includestringComma-separated list of object names:
  • products
  • discounts
  • license-keys
  • subscriptions
  • webhooks
Example
const stores = await ls.getStores()

const stores = await ls.getStores({ include: 'products' })

getStore(parameters)

Get a store.

Returns a Store object.

API reference.

Parameters
ParameterTypeRequiredDefaultNotes
idnumberRequired
includestringNoComma-separated list of object names:
  • products
  • discounts
  • license-keys
  • subscriptions
  • webhooks
Example
const store = await ls.getStore({ id: 123 })

getProducts(parameters)

Get a list of products.

Returns a list of Product objects.

API reference.

Parameters
ParameterTypeRequiredDefaultNotes
storeIdnumberNo
perPagenumberNo10
pagenumberNo1
includestringNoComma-separated list of object names:
  • store
  • variants
Example
const products = await ls.getProducts({ storeId: 123, perPage: 50, include: 'variants' })

getProduct(parameters)

Get a product.

Returns a Product object.

API reference.

Parameters
ParameterTypeDefaultNotes
id requirednumber
includestringComma-separated list of object names:
  • store
  • variants
Example
const products = await ls.getProduct({ id: 123 })

More methods to follow.

Keywords

FAQs

Package last updated on 21 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc