npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@n8n_io/license-sdk

v2.11.0

Published

License SDK

Downloads

51,326

Readme

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'

// bring your own logger, e.g. Pino, Winston etc.
const myLogger = pino()

// ------ INITIALIZATION ------

const license = new LicenseManager({
  server: 'https://license.your-server.com',
  tenantId: 1, // referencing to resp. license-server entity
  productIdentifier: 'Demo Product v1.2.3', // must regex-match cert.productIdentifierPattern
  autoRenewEnabled: true,
  renewOnInit: false,
  autoRenewOffset: 60 * 60 * 48, // = 48 hours
  logger: myLogger,
  loadCertStr: async () => {
    // code that returns a stored cert string from DB
    return '...'
  },
  saveCertStr: async (cert: TLicenseBlock) => {
    // code that persists a cert string into the DB
    // ...
  },
  deviceFingerprint: () => 'a-unique-instance-id', //optional! If omitted, a machine-ID fingerprint will be generated
  onFeatureChange: () =>
    console.log('availability of some features has just changed'), //optional
})

// important! Attempts to load and initialize the cert:
await license.initialize()

// without a valid cert, no feature will be available:
if (license.hasFeatureEnabled('a-special-feature')) {
  // this code will never execute!
}

license.isValid() // -> false

license.getFeatureValue('another-feature') // -> undefined

license.getFeatures() // -> []

// ------ ACTIVATION ------

try {
  // download a license key by 'activating' a reservation.
  // Reservations are typically configured to be activatable only once.
  await license.activate('3fa85f64-5717-4562-b3fc-2c963f66afa6')

  license.isValid() // -> true

  license.getFeatureValue('foo') // -> 'bar'

  if (license.hasFeatureEnabled('a-feature-that-exists')) {
    //do stuff
  }

  const currentConsumption = getUsageFromSomewhere()

  if (license.hasQuotaLeft('quota:demoQuota', currentConsumption)) {
    //do stuff
  }

  // print a human-readable string representation.
  console.log(`${license}`)
} catch (e) {
  // handle error...
}

// ------ RENEWAL ------
// renewals happen automatically based on the config options `autoRenewEnabled` and `autoRenewOffset`
// but can also be enforced, as long as the current cert is not yet terminated:
await license.renew()