theorim-sdk
v2.1.0
Published
Theorim client SDK for browser and Node.js
Readme
theorim-sdk
Client SDK for the Theorim API. Works in browsers (classic <script> tag) and in Node.js / bundler environments via require or import.
Browser (classic script)
<script src="/js/theorim-sdk/theorim.js"></script>
<script>
// Auto-instantiated as window.Theorim, with a same-origin baseUrl
Theorim.api({ command: 'user_get_def', method: 'GET' });
</script>When loaded in a browser, the SDK exposes:
TheorimClient— the classwindow.Theorim— a default instance pointed at the same origin
Node.js / bundlers
CommonJS:
const TheorimClient = require('theorim-sdk');
const client = new TheorimClient('https://api.example.com');
await client.api({ command: 'user_get_def', method: 'GET' });ESM:
import TheorimClient from 'theorim-sdk';
const client = new TheorimClient('https://api.example.com');Node 18+ provides global fetch. The web-worker / WebSocket features
(get_def, get_table, mcp) are browser-only and will not initialize when
window is undefined.
CLI
Installing the package globally (or via npx) registers a theorim command:
theorim add-profile https://example.com theorim_mykey_abc123
theorim list-profiles
theorim switch-profile https://example.com
theorim list-routes
theorim some_command --foo bar --count 3- Profiles are stored at
~/.theorim/profiles.json(file mode0600). - The first profile registered becomes the active profile automatically.
- Any command that isn't built in is forwarded to the active profile as
GET /api/<command>with--key valueflags becoming the query payload. - The
x-api-keyheader is set from the active profile's API key.
Run theorim with no arguments to see the list of built-in commands.
Files
theorim.js— main entry, definesTheorimClientcli.js— Node CLI entry point (theorimbin)Worker.js— browser-only web worker for streaming dataset reads
