@revmax/agent-sdk
Version:
Official Node.js SDK for RevMax - billing, customer management, and usage tracking
96 lines (80 loc) • 2.86 kB
JavaScript
/**
* RevMax SDK - Customer Management
*
* Create, list, get, and update customers via the SDK.
*
* Usage:
* REVMAX_API_KEY=revx_pk_xxx node 05-customer-management.js
*/
const { RevMaxClient } = require('../dist');
// Configuration
const API_KEY = process.env.REVMAX_API_KEY || 'revx_pk_your_api_key_here';
const BASE_URL = process.env.REVMAX_API_URL || 'http://localhost:3005/v1/sdk';
async function main() {
console.log('🚀 RevMax SDK - Customer Management\n');
// Create and connect client
const client = new RevMaxClient(API_KEY, {
baseURL: BASE_URL,
logging: { enabled: false },
});
await client.connect();
console.log(`✅ Connected to: ${client.getOrganization().name}\n`);
// 1. Create a new customer
console.log('1️⃣ Creating a new customer...');
const uniqueId = `demo-${Date.now()}`;
const newCustomer = await client.customers.create({
name: 'Acme Corporation',
externalId: uniqueId, // Your internal customer ID
email: 'billing@acme.com',
phone: '+1-555-0123',
addressLine1: '123 Main Street',
city: 'San Francisco',
state: 'CA',
zipCode: '94105',
country: 'USA',
status: 'active',
metadata: {
plan: 'enterprise',
salesRep: 'Jane Doe',
},
});
console.log(` ✅ Created: ${newCustomer.name}`);
console.log(` ID: ${newCustomer.id}`);
console.log(` External ID: ${newCustomer.externalId}\n`);
// 2. List all customers
console.log('2️⃣ Listing customers...');
const customerList = await client.customers.list({
page: 1,
limit: 5,
});
console.log(` Found ${customerList.totalResults} total customers`);
console.log(` Showing page ${customerList.page} of ${customerList.totalPages}:`);
customerList.results.forEach((c, i) => {
console.log(` ${i + 1}. ${c.name} (${c.externalId || 'no external ID'})`);
});
console.log('');
// 3. Get a specific customer
console.log('3️⃣ Getting customer details...');
const customer = await client.customers.get(newCustomer.id);
console.log(` Name: ${customer.name}`);
console.log(` Email: ${customer.email}`);
console.log(` Status: ${customer.status}`);
console.log(` Created: ${new Date(customer.createdAt).toLocaleDateString()}\n`);
// 4. Update the customer
console.log('4️⃣ Updating customer...');
const updatedCustomer = await client.customers.update(newCustomer.id, {
name: 'Acme Corporation (Updated)',
metadata: {
...customer.metadata,
lastUpdated: new Date().toISOString(),
updatedVia: 'SDK example',
},
});
console.log(` ✅ Updated name: ${updatedCustomer.name}`);
console.log(` ✅ Metadata updated\n`);
console.log('✅ Customer management examples complete!');
}
main().catch((err) => {
console.error('❌ Error:', err.message);
process.exit(1);
});