bkper-js
bkper-js library is a simple and secure way to access the Bkper REST API on Node.js and modern browsers.
It provides a set of classes and functions to interact with the Bkper API, including authentication, authorization, and data manipulation.
Installation
Add the package:
bun add bkper-jsnpm i -S bkper-jspnpm add bkper-jsyarn add bkper-jsUsage
Node.js / CLI Scripts
For local scripts and CLI tools, use the bkper CLI package for authentication:
import { Bkper } from 'bkper-js';import { getOAuthToken } from 'bkper';
// Configure with CLI authenticationBkper.setConfig({ oauthTokenProvider: async () => getOAuthToken(),});
// Create Bkper instanceconst bkper = new Bkper();
// Get a book and work with itconst book = await bkper.getBook('your-book-id');console.log(`Book: ${book.getName()}`);
// List all booksconst books = await bkper.getBooks();console.log(`You have ${books.length} books`);First, login via CLI: bkper auth login
Web Applications
For browser-based apps, use the @bkper/web-auth SDK:
import { Bkper } from 'bkper-js';import { BkperAuth } from '@bkper/web-auth';
// Initialize authenticationconst auth = new BkperAuth({ onLoginSuccess: () => initializeApp(), onLoginRequired: () => showLoginButton(),});
// Restore session on app loadawait auth.init();
// Configure Bkper with web authBkper.setConfig({ oauthTokenProvider: async () => auth.getAccessToken(),});
// Create Bkper instance and use itconst bkper = new Bkper();const books = await bkper.getBooks();See the @bkper/web-auth documentation for more details.
API Key (Optional)
API keys are optional and only needed for dedicated quota limits. If not provided, requests use a shared managed quota via the Bkper API proxy.
Bkper.setConfig({ oauthTokenProvider: async () => getOAuthToken(), apiKeyProvider: async () => process.env.BKPER_API_KEY, // Optional - for dedicated quota});