10000 GitHub - useautumn/autumn-js: Javascript SDK for Autumn
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

useautumn/autumn-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Autumn JS Library

autumn-js is a comprehensive JavaScript/TypeScript library for interacting with the Autumn pricing platform. This package provides both a server-side SDK for the Autumn API and a Next.js integration package for seamless client-side implementation.

Features

  • 🚀 Complete Autumn API SDK
  • ⚡ Next.js Integration
  • 🔒 Type-safe API interactions
  • 🛠️ Easy-to-use hooks and components

Installation

npm install autumn-js

Configuration

Add your Autumn secret key to your environment variables:

AUTUMN_SECRET_KEY=your_secret_key_here

Usage

Server-Side SDK

For server-side applications (Node.js, Express, etc.), use the SDK like this:

import { Autumn } from 'autumn-js'

// Initialize Autumn
const autumn = new Autumn()

// Create a customer
await autumn.customers.create({
  id: "customer_123",
  name: "John Doe"
})

Next.js Integration

For Next.js applications, Autumn.js provides a dedicated integration with helpful hooks and components.

1. First, wrap your application with the AutumnProvider in your root layout.tsx (this must be a Server Component):

// app/layout.tsx

import { AutumnProvider } from 'autumn-js/next'

export default function RootLayout({
  children,
}: {
  children: React.ReactNode
}) {
  return (
    <html>
      <body>
        <AutumnProvider customerId="YOUR_CUSTOMER_ID">
          {children}
        </AutumnProvider>
      </body>
    </html>
  )
}

2. Then use the useAutumn hook in your components:

import { useAutumn } from 'autumn-js/next'

export default function BillingPage() {
  const { attach, openBillingPortal } = useAutumn()

  return (
    <div>
      <button onClick={() => openBillingPortal()}>
        Manage Billing
      </button>
      <button onClick={() => attach()}>
        Upgrade to Pro
      </button>
    </div>
  )
}

The useAutumn hook exports several useful functions:

  • attach({ productId }): Opens a checkout URL automatically when called to attach a product to the customer
  • check({ featureId }): Checks if the customer is entitled to use a specific feature
  • track({ featureId, value }): Send usage for a particular feature
  • openBillingPortal(): Opens Stripe's billing portal for the current customer to manage their subscription and billing settings

3. For authentication, you can either pass a customer ID directly or use our auth plugin (which allows you to easily integrate with popular providers like Better Auth):

Better Auth Example:

<AutumnProvider
  authPlugin={{
    provider: "better-auth", 
    instance: auth, // Your server-side better-auth instance
    useOrg: true, // Set to true if organizations are your customers
  }}
>
  {children}
</AutumnProvider>

Supabase Example:

<AutumnProvider
  authPlugin={{
    provider: "supabase",
  }}
>
  {children}
</AutumnProvider>

Clerk Example:

<AutumnProvider
  authPlugin={{
    provider: "clerk",
    useOrg: true,
  }}
>
  {children}
</AutumnProvider>

API Reference

For detailed API documentation, visit docs.useautumn.com

Support

For support, email hey@useautumn.com!

License

MIT

About

Javascript SDK for Autumn

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  
0