Package Exports
- autumn-js
- autumn-js/express
- autumn-js/fastify
- autumn-js/hono
- autumn-js/next
- autumn-js/react
- autumn-js/remix
- autumn-js/tanstack
Readme
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-jsConfiguration
Add your Autumn secret key to your environment variables:
AUTUMN_SECRET_KEY=your_secret_key_hereUsage
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 customercheck({ featureId }): Checks if the customer is entitled to use a specific featuretrack({ featureId, value }): Send usage for a particular featureopenBillingPortal(): 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