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
Runtime configuration overrides and optional logger instance Show ConfigureOptions properties
API key used to authenticate against Shamela services. Can also be set via SHAMELA_API_KEY environment variable.
Endpoint used for book metadata. Can also be set via SHAMELA_API_BOOKS_ENDPOINT environment variable. Example: https://shamela.ws/api/books
Endpoint used for master metadata. Can also be set via SHAMELA_API_MASTER_PATCH_ENDPOINT environment variable. Example: https://shamela.ws/api/master_patch
Optional override for the sql.js WASM asset location. Can also be set via SHAMELA_SQLJS_WASM_URL environment variable.
Standard Node.js : Auto-detected, no configuration needed
Bundled environments (Next.js, webpack): Must be explicitly configured
Browsers : Defaults to CDN-hosted WASM file
Optional custom fetch implementation for environments without a global fetch. This option cannot be set via environment variables - it must be provided directly to configure().
Optional custom logger implementation. Must implement the Logger interface with info(), warn(), and error() methods.
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):
Values passed to configure() (runtime overrides)
Environment variables (e.g., SHAMELA_API_KEY)
undefined (not set)
The fetchImplementation option cannot be set via environment variables and must be provided directly to configure().
Environment Variables
Configuration Key Environment Variable apiKeySHAMELA_API_KEYbooksEndpointSHAMELA_API_BOOKS_ENDPOINTmasterPatchEndpointSHAMELA_API_MASTER_PATCH_ENDPOINTsqlJsWasmUrlSHAMELA_SQLJS_WASM_URLfetchImplementationNot available
See Also