/lemonsqueezy.js

Official JavaScript SDK for Lemon Squeezy.

Primary LanguageTypeScriptMIT LicenseMIT

The official Lemon Squeezy JavaScript SDK

NPM version Functions usage APIs Count Weekly downloads NPM Downloads FOSSA Status

Introduction

This is the official JavaScript SDK for Lemon Squeezy, making it easy to incorporate billing into your JavaScript application.

Features

Installation

Install the package

# bun
bun install @lemonsqueezy/lemonsqueezy.js
# pnpm
pnpm install @lemonsqueezy/lemonsqueezy.js
# npm
npm install @lemonsqueezy/lemonsqueezy.js

Create an API key

Create a new API key from Settings > API in your Lemon Squeezy dashboard.

Add this API key into your project, for example as LEMONSQUEEZY_API_KEY in your .env file.

Caution

Do not use this package directly in the browser, as this will expose your API key. This would give anyone full API access to your Lemon Squeezy account and store(s). For more information see here.

Using the API in test mode

You can build and test a full API integration with Lemon Squeezy using Test Mode.

Any API keys created in test mode will interact with your test mode store data.

When you are ready to go live with your integration, make sure to create an API key in live mode and use that in your production application.

Usage

import {
  getAuthenticatedUser,
  lemonSqueezySetup,
} from "@lemonsqueezy/lemonsqueezy.js";

const apiKey = import.meta.env.LEMON_SQUEEZY_API_KEY;

lemonSqueezySetup({
  apiKey,
  onError: (error) => console.error("Error!", error),
});

const { data, error } = await getAuthenticatedUser();

if (error) {
  console.log(error.message);
} else {
  console.log(data);
}

For more functions usage, see Wiki.

Bundle size

Click to view
Export min+brotli
createDiscount 991 B
createCheckout 895 B
updateSubscriptionItem 849 B
updateSubscription 841 B
listWebhooks 831 B
listDiscountRedemptions 821 B
listLicenseKeyInstances 820 B
listSubscriptionInvoices 818 B
listLicenseKeys 817 B
listOrderItems 817 B
listSubscriptionItems 817 B
listCheckouts 814 B
listDiscounts 814 B
listSubscriptions 814 B
listUsageRecords 814 B
listVariants 814 B
listCustomers 813 B
listFiles 813 B
listOrders 813 B
listPrices 813 B
listProducts 813 B
listStores 813 B
updateLicenseKey 813 B
createWebhook 808 B
updateWebhook 793 B
generateSubscriptionInvoice 789 B
generateOrderInvoice 783 B
activateLicense 770 B
validateLicense 770 B
deactivateLicense 764 B
createUsageRecord 724 B
getLicenseKeyInstance 714 B
getSubscriptionInvoice 702 B
getDiscountRedemption 700 B
getSubscriptionItem 700 B
getUsageRecord 700 B
getOrderItem 699 B
getLicenseKey 698 B
getOrder 697 B
getPrice 697 B
getStore 697 B
getCheckout 696 B
getCustomer 696 B
getFile 696 B
getProduct 694 B
getWebhook 694 B
getDiscount 693 B
getSubscription 693 B
getVariant 693 B
updateCustomer 684 B
archiveCustomer 683 B
createCustomer 678 B
cancelSubscription 660 B
deleteDiscount 658 B
deleteWebhook 653 B
getSubscriptionItemCurrentUsage 651 B
getAuthenticatedUser 598 B
lemonSqueezySetup 106 B

Contributing

See the Contributing Guide.

License

FOSSA Status