Registry / http-networking / lago-javascript-client

lago-javascript-client

JSON →
library1.45.0jsnpmunverified

The `lago-javascript-client` is an official JavaScript wrapper for interacting with the Lago API, providing a structured way to manage billing and invoicing operations. It is currently at version 1.45.0, with frequent minor releases indicated by the recent changelog, often involving version bumps. This client is notable for its broad compatibility, designed to function across various JavaScript runtimes including Node.js (specifically Node.js >= 18 for native support), Cloudflare Workers, and Deno. It is automatically generated from the Lago OpenAPI document, ensuring it stays synchronized with the API's latest specifications. A key architectural decision is its reliance on the Fetch API for HTTP requests, which means users on older Node.js environments (pre-18) must either enable `--experimental-fetch` or provide a custom Fetch implementation like `node-fetch`. The library also ships with TypeScript types, facilitating robust development and error handling using its `getLagoError` utility.

npm install lago-javascript-client
INSTALL
IMPORT
SIG · LAGO-JAVASCRIPT-CL
L
lago-javascript-client
http-networkingjavascriptv1.45.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Client
import { Client } from 'lago-javascript-client';
const { Client } = require('lago-javascript-client');
The library primarily uses ES Modules. While Node.js has some CJS-ESM interoperability, using `import` is the recommended and type-safe approach.
getLagoError
import { getLagoError } from 'lago-javascript-client';
const { getLagoError } = require('lago-javascript-client');
Used for robust error handling and type extraction from API responses. Follows the ESM import pattern.
Client
import { Client } from 'https://deno.land/x/lago/mod.ts';
For Deno environments, import directly from the Deno Land URL.

This quickstart demonstrates how to initialize the Lago client, configure it for Node.js compatibility (if needed), and perform an asynchronous API call to create a billable metric with proper error handling.

import { Client, getLagoError } from 'lago-javascript-client'; import fetch from 'node-fetch'; // Required for Node.js < 18 or without --experimental-fetch // Initialize the client with your API key. // For Node.js < 18, you might need to pass a custom fetch instance. const lagoClient = Client(process.env.LAGO_API_KEY ?? '', { customFetch: fetch }); async function createBillableMetric() { const billableMetric = { billableMetric: { name: 'api_calls', code: 'api_calls', aggregation_type: 'count', description: 'Number of API calls made.' } }; try { // Example: Creating a new billable metric const { data } = await lagoClient.billableMetrics.createBillableMetric(billableMetric); console.log('Successfully created billable metric:', data); } catch (error) { // Use getLagoError for structured error handling and type inference const lagoError = await getLagoError(error); console.error('Error creating billable metric:', lagoError.message, lagoError.response); } } createBillableMetric();
Debug
Known issues
breakingThe Lago JavaScript Client relies on the Fetch API. Node.js versions prior to 18 do not support Fetch natively. Attempting to use the client without a polyfill or the `--experimental-fetch` flag will result in runtime errors.
fix
For Node.js < 18, either start Node.js with `--experimental-fetch` or install and pass `node-fetch` as a custom fetch implementation: `import fetch from 'node-fetch'; const lagoClient = Client('key', { customFetch: fetch });`
affects: <1.0.0
gotchaThe package is built with `dnt` to support multiple runtimes (Node.js, Deno, Cloudflare Workers). This means its primary module format is ESM. While some interoperability exists, mixing `require()` with this library can lead to unexpected behavior or require additional configuration.
fix
Always use ES Module `import` syntax (`import { Client } from 'lago-javascript-client';`) for consistency and full TypeScript support.
affects: >=1.0.0
deprecatedThe previous `lago-nodejs-client` package is deprecated in favor of `lago-javascript-client` which offers TypeScript support and broader runtime compatibility. Users of the old package should migrate.
fix
Update your `package.json` to `lago-javascript-client` and refactor imports and usage according to the new client's API.
affects: <1.0.0 (lago-nodejs-client)
breakingThe underlying Lago API, which this client wraps, has undergone significant changes in how 'groups' are handled, replaced by 'filters', and has made `external_subscription_id` mandatory for events. Several legacy API fields have also been deprecated. These changes will impact how you define and send billing data.
fix
Refer to the official Lago API documentation (doc.getlago.com) for the specific changes and update your data models and API calls accordingly, especially regarding billable metrics, plans, fees, customer usage, and events. Users were advised to update before July 9, 2024.
affects: N/A (API level)
Errors
Common errors & fixes
ReferenceError: fetch is not defined
Node.js version is older than 18, or the `--experimental-fetch` flag is not used, and no polyfill for `fetch` is provided.
fix
Upgrade Node.js to version 18 or higher, or install `node-fetch` and pass it as a `customFetch` option to the `Client` constructor. Alternatively, run Node.js with `node --experimental-fetch your-script.js`.
TypeError: (0 , lago_javascript_client__WEBPACK_IMPORTED_MODULE_0__.Client) is not a function
This error often occurs in environments where CommonJS `require()` is implicitly or explicitly trying to load an ES Module library that primarily uses named exports, or when bundlers mishandle the module type.
fix
Ensure you are using ES Module `import { Client } from 'lago-javascript-client';` syntax throughout your project. Verify your `tsconfig.json` (if TypeScript) and bundler configuration (`module` and `moduleResolution`) are set for `ESNext` or `NodeNext` to properly handle ESM.
Upgrade
Version history
1.45.0latest on npm
Audit
Dependencies
node-fetchoptionalPolyfill for Fetch API on Node.js versions below 18 or without the `--experimental-fetch` flag enabled.
Agent activity
25 hits · last 30 days
node
22
OpenAI (training)
1
Resources