Skip to main content

Function Signature

configure(config: ConfigureOptions): void
Updates the runtime configuration for the library. This function merges the provided options with existing overrides and optionally configures a custom logger implementation.

Parameters

config
ConfigureOptions
required
Runtime configuration overrides and optional logger instance

Return Value

This function does not return a value. Configuration is stored internally and accessed by other library functions.

Examples

Standard Node.js

import { configure } from 'shamela';

configure({
  apiKey: process.env.SHAMELA_API_KEY!,
  booksEndpoint: process.env.SHAMELA_BOOKS_ENDPOINT!,
  masterPatchEndpoint: process.env.SHAMELA_MASTER_ENDPOINT!,
  // sqlJsWasmUrl is auto-detected in standard Node.js
});

Next.js / Bundled Environments

import { configure } from 'shamela';
import { join } from 'node:path';

configure({
  sqlJsWasmUrl: join(process.cwd(), 'node_modules', 'sql.js', 'dist', 'sql-wasm.wasm'),
  apiKey: process.env.SHAMELA_API_KEY!,
  booksEndpoint: process.env.SHAMELA_BOOKS_ENDPOINT!,
  masterPatchEndpoint: process.env.SHAMELA_MASTER_ENDPOINT!,
});

Browser Environment

import { configure } from 'shamela';

configure({
  apiKey: 'your-api-key',
  booksEndpoint: 'https://shamela.ws/api/books',
  masterPatchEndpoint: 'https://shamela.ws/api/master_patch',
  // Automatically uses CDN: https://cdn.jsdelivr.net/npm/sql.js@1.13.0/dist/sql-wasm.wasm
});

Custom Fetch Implementation

import { configure } from 'shamela';
import nodeFetch from 'node-fetch';

configure({
  apiKey: process.env.SHAMELA_API_KEY!,
  booksEndpoint: process.env.SHAMELA_BOOKS_ENDPOINT!,
  masterPatchEndpoint: process.env.SHAMELA_MASTER_ENDPOINT!,
  fetchImplementation: nodeFetch as unknown as typeof fetch,
});

Custom Logger

import { configure } from 'shamela';

const customLogger = {
  info: (msg: string) => console.log(`[INFO] ${msg}`),
  warn: (msg: string) => console.warn(`[WARN] ${msg}`),
  error: (msg: string) => console.error(`[ERROR] ${msg}`),
};

configure({
  apiKey: process.env.SHAMELA_API_KEY!,
  booksEndpoint: process.env.SHAMELA_BOOKS_ENDPOINT!,
  masterPatchEndpoint: process.env.SHAMELA_MASTER_ENDPOINT!,
  logger: customLogger,
});

Configuration Priority

Configuration values are resolved in the following order (highest to lowest priority):
  1. Values passed to configure() (runtime overrides)
  2. Environment variables (e.g., SHAMELA_API_KEY)
  3. undefined (not set)
The fetchImplementation option cannot be set via environment variables and must be provided directly to configure().

Environment Variables

Configuration KeyEnvironment Variable
apiKeySHAMELA_API_KEY
booksEndpointSHAMELA_API_BOOKS_ENDPOINT
masterPatchEndpointSHAMELA_API_MASTER_PATCH_ENDPOINT
sqlJsWasmUrlSHAMELA_SQLJS_WASM_URL
fetchImplementationNot available

See Also