@moonbase.sh/licensing
v1.0.17
Published
Package to add sotftware licensing using Moonbase.sh to your node.js apps
Readme
@moonbase.sh/licensing
Node.js licensing SDK for Moonbase products.
Use it to request activation, validate licenses locally and online, persist licenses, and revoke activations.
Learn more in our official documentation here: https://moonbase.sh/docs/licensing/sdks/node/
Install
pnpm add @moonbase.sh/licensingCreate a licensing client
import { FileLicenseStore, MoonbaseLicensing } from '@moonbase.sh/licensing'
const licensing = new MoonbaseLicensing({
endpoint: 'https://demo.moonbase.sh',
productId: 'demo-app',
publicKey: process.env.MOONBASE_PUBLIC_KEY!,
accountId: process.env.MOONBASE_ACCOUNT_ID,
// Optionally adjust the license store with path
// to where the license should be stored, or use
// alternate storage mechanisms to persist the token.
licenseStore: new FileLicenseStore(),
})publicKeyis the Moonbase public key used to verify signed license tokens.FileLicenseStorepersists the license locally (license.mbby default).
Activation flow
const request = await licensing.client.requestActivation()
console.log('Open this URL in a browser:', request.browser)
let license = null
while (!license) {
await new Promise(resolve => setTimeout(resolve, 1000))
license = await licensing.client.getRequestedActivation(request)
}
await licensing.store.storeLocalLicense(license)
console.log('License stored locally')Validate on startup
const localLicense = await licensing.store.loadLocalLicense()
if (localLicense) {
// Validate token signature + device binding locally
const locallyValidated = await licensing.validator.validateLicense(localLicense.token)
// Re-validate against Moonbase (recommended for online activations)
const refreshed = await licensing.client.validateLicense(locallyValidated)
await licensing.store.storeLocalLicense(refreshed)
}Revoke a license activation
const localLicense = await licensing.store.loadLocalLicense()
if (localLicense) {
await licensing.client.revokeLicense(localLicense)
await licensing.store.deleteLocalLicense()
}Offline helpers
Generate a device token to support offline activation workflows:
const deviceToken = await licensing.generateDeviceToken()Read and validate raw license bytes (for example from a file):
const license = await licensing.readRawLicense(rawLicenseBuffer)Custom stores and device resolvers
You can inject your own ILicenseStore and IDeviceIdResolver implementations.
Note: the current configuration property name for custom device resolver is deivceIdResolver.
