@invoiceleaf/typescript-sdk
v0.1.0
Published
Official TypeScript SDK for the InvoiceLeaf public API
Maintainers
Readme
InvoiceLeaf TypeScript SDK
Official TypeScript SDK for the InvoiceLeaf public REST API.
Features
- OpenAPI-aligned request/response models
- API key and bearer-token authentication support
- Typed service clients for all public InvoiceLeaf endpoint groups
- Browser and Node.js compatible API client
Installation
npm install @invoiceleaf/typescript-sdkIf you are testing directly from GitHub before npm availability:
npm install github:InvoiceLeaf/typescript-sdkQuick Start
import { InvoiceLeafClient } from '@invoiceleaf/typescript-sdk';
const client = new InvoiceLeafClient({
accessToken: process.env.INVOICELEAF_ACCESS_TOKEN,
baseUrl: 'https://api.invoiceleaf.com/v1/',
});
const me = await client.profiles.getCurrentUser();
const spaces = await client.spaces.list({ page: 1, limit: 20 });
console.log(me.email);
console.log(spaces.items?.length ?? 0);Authentication
import { InvoiceLeafClient } from '@invoiceleaf/typescript-sdk';
const apiKeyClient = new InvoiceLeafClient({
apiKey: process.env.INVOICELEAF_API_KEY,
});
const tokenClient = new InvoiceLeafClient({
accessToken: process.env.INVOICELEAF_ACCESS_TOKEN,
});Available Services
accountingbarcodescategoriescompaniesdocumentsexportsinvoiceSeriesorganizationspaymentMethodsprofilesremindersspacesspaceMembersstatisticstags
Error Handling
import { ApiError, InvoiceLeafClient } from '@invoiceleaf/typescript-sdk';
const client = new InvoiceLeafClient({ apiKey: process.env.INVOICELEAF_API_KEY });
try {
await client.spaces.list();
} catch (error) {
if (error instanceof ApiError) {
console.error(error.status, error.code, error.message);
}
}Development
npm install
npm run typecheck
npm run buildRegenerate OpenAPI types from the backend spec:
npm run generate:openapi