Node.js — Getting Started
@ledewire/node provides the full LedeWire API surface
— merchant authentication, content management, sales reporting, buyer flows, wallet, and
purchases — in a single typed npm package.
Who this is for: Developers building merchant stores, admin tools, or
server-side integrations with the LedeWire API.
Installation
npm install @ledewire/node
# or
pnpm add @ledewire/node
Authentication modes
createClient() supports two authentication strategies that can be combined or
used independently:
| Mode | Use case | Config |
|---|---|---|
| API key + secret | Seller operations: automated content publishing, sales dashboards | apiKey + apiSecret |
| Email / password | Merchant operations: user management, store config, content moderation | Call client.merchant.auth.loginWithEmail() |
| Buyer session | Server-side buyer flows on behalf of a logged-in end user | Call client.auth.loginWithEmail() |
Quick start — seller (API key)
import { createClient } from '@ledewire/node'
const client = createClient({
apiKey: process.env.LEDEWIRE_API_KEY,
apiSecret: process.env.LEDEWIRE_API_SECRET,
onAuthExpired: () => { throw new Error('Session expired') },
})
// List your content
const items = await client.seller.content.list()
console.log(items)
Quick start — merchant (email login)
import { createClient } from '@ledewire/node'
const client = createClient()
// Authenticate and list stores in one call
const { stores } = await client.merchant.auth.loginWithEmailAndListStores({
email: process.env.LEDEWIRE_EMAIL,
password: process.env.LEDEWIRE_PASSWORD,
})
const storeId = stores[0].id
// Sales summary
const summary = await client.merchant.sales.summary(storeId)
console.log(`Revenue: ${summary.total_revenue_cents / 100} USD`)
Error handling
All SDK errors extend LedewireError and carry a statusCode and
structured code / message
from the API. Import specific error classes to handle individual cases:
import { createClient, LedewireError, NotFoundError, AuthError } from '@ledewire/node'
try {
const content = await client.seller.content.get('some-id')
} catch (err) {
if (err instanceof NotFoundError) {
console.log('Content not found')
} else if (err instanceof AuthError) {
console.log('Not authenticated — call loginWithEmail first')
} else if (err instanceof LedewireError) {
console.error(`API error ${err.statusCode}: ${err.message}`)
} else {
throw err // unexpected — rethrow
}
}
Full namespace reference
| Namespace | Methods |
|---|---|
client.auth.* |
signup, loginWithEmail, loginWithGoogle, logout, requestPasswordReset, resetPassword |
client.merchant.auth.* |
loginWithEmail, loginWithGoogle, listStores, loginWithEmailAndListStores, loginWithGoogleAndListStores, requestPasswordReset, resetPassword |
client.merchant.users.* |
list, invite, remove, update |
client.merchant.sales.* |
summary, list, get, statistics |
client.merchant.config.* |
get |
client.seller.content.* |
create, list, get, update, delete, search |
client.wallet.* |
balance, transactions, createPaymentSession, getPaymentStatus |
client.purchases.* |
create, list, get |
client.content.* |
getWithAccess |
client.checkout.* |
state |
For full parameter and return type documentation, see the API Reference. For a complete runnable example, see examples/node-merchant/ .