Skip to content

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.

Terminal window
npm install @zumito-team/builtbybit-license

Add to your zumito.config.ts:

bundles: ['@zumito-team/builtbybit-license']
  1. On module initialization, a LicenseVerifier is created with your configuration.
  2. When the framework is ready (onAllReady), the verifier performs an HTTP request to the BuiltByBit API.
  3. If the license is valid:
    • onValid callback fires.
    • If checkInterval is set, periodic re-verification starts.
  4. If the license is invalid:
    • onInvalid callback fires.
    • If exitOnInvalid is true (default), the process exits with the configured exit code.
  5. If an error occurs:
    • The request is retried up to retryAttempts times with retryDelay ms between attempts.
    • If all retries fail, onError callback fires.
import { BuiltByBitLicenseModule } from '@zumito-team/builtbybit-license';
// In your zumito.config.ts or module setup:
new BuiltByBitLicenseModule(__dirname, {
licenseKey: 'your-license-key-here'
});
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);
}
});
OptionTypeDefaultDescription
licenseKeystringrequiredBuiltByBit license key.
apiUrlstringhttps://api.builtbybit.com/v1/licensesAPI endpoint.
productIdstringResource/product ID on BuiltByBit.
requestHeadersRecord<string,string>Custom HTTP headers.
retryAttemptsnumber0Retry count on failure.
retryDelaynumber5000Delay between retries (ms).
exitOnInvalidbooleantrueWhether to process.exit() on invalid license.
exitCodenumber1Exit code for process termination.
validateResponse(body, status) => boolean | Promise<boolean>built-inCustom 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.
checkIntervalnumberRe-verify periodically (ms). Set to 0 to disable.

By default, the validator checks the response in this order:

  1. HTTP status 200 → license is valid.
  2. body.valid === true → license is valid.
  3. body.success === true → license is valid.
  4. body.status === "active" → license is valid.

Override with validateResponse for custom logic.

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;
}

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}` })
});
}

Set checkInterval to a value greater than 0 to continuously enforce the license. The interval starts after the first successful verification.

  • zumito-framework

The module also accepts standard Zumito module options:

OptionTypeDescription
commandWhiteliststring[]Only allow these commands.
commandBlackliststring[]Block these commands.
commandRenamesRecord<string, string>Rename commands.