Lago JavaScript Client
This is a JavaScript wrapper for Lago API. Works in Cloudflare Workers, Deno, and Node.js. Generated from the Lago Swagger document.
Installation
Install the lago-javascript-client
via npm:
npm install lago-javascript-client
import { Client, getLagoError } from 'lago-javascript-client';
const lagoClient = Client('__YOUR_API_KEY__');
try {
const { data } = await lagoClient.billableMetrics.createBillableMetric(billableMetric);
} catch (error) {
const lagoError = await getLagoError<typeof lagoClient.billableMetrics.createBillableMetric>(error);
}
Compatibility
This SDK uses the Fetch API and natively supported Node.js version >= 18. For other Node versions:
Ideally, run Node with the
--experimental-fetch
flagOtherwise, polyfill the Fetch API by doing both:
Pass a Fetch instance to the Lago client
import { Client } from 'lago-javascript-client'; import fetch from 'node-fetch'; const lagoClient = Client("api_key", { customFetch: fetch });
Usage
Check the Lago API reference
Error Handling
Use the get getLagoError<>()
utility function to extract the error object and TypeScript type:
try {
const { data } = await lagoClient.billableMetrics.createBillableMetric(billableMetric);
} catch (error) {
const lagoError = await getLagoError<typeof lagoClient.billableMetrics.createBillableMetric>(error);
}
Development
Uses dnt to build and test for Deno and Node.
Dependencies
Requires Deno and Node.js >= 18
Run tests
deno task test
Build
deno task build
Publish to NPM
deno task build
cd npm
npm publish
Documentation
The Lago documentation is available at doc.getlago.com.
Contributing
The contribution documentation is available here
License
Lago Node.js client is distributed under AGPL-3.0.