BuiltByBit License Module
The BuiltByBit License Module (@zumito-team/builtbybit-license) validates license keys against the BuiltByBit API. It can periodically re-verify the license and optionally terminate the bot process if the license becomes invalid.
Installation
Section titled “Installation”npm install @zumito-team/builtbybit-licenseAdd to your zumito.config.ts:
bundles: ['@zumito-team/builtbybit-license']How it works
Section titled “How it works”- On module initialization, a
LicenseVerifieris created with your configuration. - When the framework is ready (
onAllReady), the verifier performs an HTTP request to the BuiltByBit API. - If the license is valid:
onValidcallback fires.- If
checkIntervalis set, periodic re-verification starts.
- If the license is invalid:
onInvalidcallback fires.- If
exitOnInvalidistrue(default), the process exits with the configured exit code.
- If an error occurs:
- The request is retried up to
retryAttemptstimes withretryDelayms between attempts. - If all retries fail,
onErrorcallback fires.
- The request is retried up to
Basic (license key only)
Section titled “Basic (license key only)”import { BuiltByBitLicenseModule } from '@zumito-team/builtbybit-license';
// In your zumito.config.ts or module setup:new BuiltByBitLicenseModule(__dirname, { licenseKey: 'your-license-key-here'});Full configuration
Section titled “Full configuration”new BuiltByBitLicenseModule(__dirname, { licenseKey: 'xxxx-xxxx-xxxx', apiUrl: 'https://api.builtbybit.com/v1/licenses', productId: '12345', requestHeaders: { 'X-Custom-Header': 'value' }, retryAttempts: 3, retryDelay: 5000, exitOnInvalid: true, exitCode: 1, checkInterval: 3600000, // Re-verify every hour validateResponse: async (body, status) => { // Custom validation logic return body.status === 'active' && body.product_id === '12345'; }, onValid: async () => { console.log('License valid! Bot starting...'); }, onInvalid: async (reason) => { console.error(`Invalid license: ${reason}`); }, onError: async (error) => { console.error('License check failed:', error.message); }});Configuration reference
Section titled “Configuration reference”| Option | Type | Default | Description |
|---|---|---|---|
licenseKey | string | required | BuiltByBit license key. |
apiUrl | string | https://api.builtbybit.com/v1/licenses | API endpoint. |
productId | string | — | Resource/product ID on BuiltByBit. |
requestHeaders | Record<string,string> | — | Custom HTTP headers. |
retryAttempts | number | 0 | Retry count on failure. |
retryDelay | number | 5000 | Delay between retries (ms). |
exitOnInvalid | boolean | true | Whether to process.exit() on invalid license. |
exitCode | number | 1 | Exit code for process termination. |
validateResponse | (body, status) => boolean | Promise<boolean> | built-in | Custom response validator. |
onValid | () => void | Promise<void> | — | Callback on successful verification. |
onInvalid | (reason?) => void | Promise<void> | — | Callback on invalid license. |
onError | (error: Error) => void | Promise<void> | — | Callback on network/request error. |
checkInterval | number | — | Re-verify periodically (ms). Set to 0 to disable. |
Default validation
Section titled “Default validation”By default, the validator checks the response in this order:
- HTTP status
200→ license is valid. body.valid === true→ license is valid.body.success === true→ license is valid.body.status === "active"→ license is valid.
Override with validateResponse for custom logic.
Extending
Section titled “Extending”Custom validation
Section titled “Custom validation”Provide your own validateResponse function to check additional fields, validate against a different API, or implement caching:
validateResponse: async (body, status) => { if (status !== 200) return false; // Check custom fields return body.data?.license?.active === true && body.data?.license?.product_id === myProductId;}Custom callbacks
Section titled “Custom callbacks”Use onValid, onInvalid, and onError to integrate with your own logging, notifications, or analytics:
onInvalid: async (reason) => { // Send a Discord webhook notification await fetch(webhookUrl, { method: 'POST', body: JSON.stringify({ content: `License invalid: ${reason}` }) });}Periodic checking
Section titled “Periodic checking”Set checkInterval to a value greater than 0 to continuously enforce the license. The interval starts after the first successful verification.
Dependencies
Section titled “Dependencies”zumito-framework
Additional options
Section titled “Additional options”The module also accepts standard Zumito module options:
| Option | Type | Description |
|---|---|---|
commandWhitelist | string[] | Only allow these commands. |
commandBlacklist | string[] | Block these commands. |
commandRenames | Record<string, string> | Rename commands. |