Shamela provides runtime configuration through the configure() function, allowing you to set API credentials, customize WASM file locations, override fetch implementations, and configure logging.
Clears runtime overrides and restores the default silent logger. Use this in tests or long-running processes when you need a clean configuration slate.
import { resetConfig } from 'shamela';// Reset to defaultsresetConfig();
type ShamelaConfig = { /** API key used to authenticate against Shamela services */ apiKey?: string; /** Endpoint used for book metadata */ booksEndpoint?: string; /** Endpoint used for master metadata */ masterPatchEndpoint?: string; /** Optional override for the sql.js wasm asset location */ sqlJsWasmUrl?: string; /** Optional custom fetch implementation for environments without a global fetch */ fetchImplementation?: typeof fetch;};
For environments without a global fetch function, you can provide a custom implementation:
import { configure } from 'shamela';import nodeFetch from 'node-fetch';configure({ fetchImplementation: nodeFetch as unknown as typeof fetch, apiKey: process.env.SHAMELA_API_KEY,});
// Check if API key is configuredconst apiKey = getConfigValue('apiKey');if (!apiKey) { throw new Error('SHAMELA_API_KEY environment variable not set');}
Required endpoints must be configured before making API calls:
import { configure } from 'shamela';// Configure only the endpoints you needconfigure({ apiKey: process.env.SHAMELA_API_KEY, booksEndpoint: process.env.SHAMELA_BOOKS_ENDPOINT, // Required for book APIs masterPatchEndpoint: process.env.SHAMELA_MASTER_ENDPOINT, // Required for master APIs});