SDK
The SDK provides a convenient way to work with license keys issued by the n8n license-server.
Usage
import {
LicenseManager,
TLicenseBlock,
} from '@n8n_io/license-sdk/src/LicenseManager'
import pino from 'pino'
const myLogger = pino()
const license = new LicenseManager({
server: 'https://license.your-server.com',
tenantId: 1,
productIdentifier: 'Demo Product v1.2.3',
autoRenewEnabled: true,
renewOnInit: false,
autoRenewOffset: 60 * 60 * 48,
logger: myLogger,
loadCertStr: async () => {
return '...'
},
saveCertStr: async (cert: TLicenseBlock) => {
},
deviceFingerprint: () => 'a-unique-instance-id',
onFeatureChange: () =>
console.log('availability of some features has just changed'),
})
await license.initialize()
if (license.hasFeatureEnabled('a-special-feature')) {
}
license.isValid()
license.getFeatureValue('another-feature')
license.getFeatures()
try {
await license.activate('3fa85f64-5717-4562-b3fc-2c963f66afa6')
license.isValid()
license.getFeatureValue('foo')
if (license.hasFeatureEnabled('a-feature-that-exists')) {
}
const currentConsumption = getUsageFromSomewhere()
if (license.hasQuotaLeft('quota:demoQuota', currentConsumption)) {
}
console.log(`${license}`)
} catch (e) {
}
await license.renew()