Skip to content

Node and React quickstart

This page gets the Monaiq client installed and authorized in a Node application, and points at the React and assertion pieces that build on it.

The package is @sidub-inc/licensing-client. It is written in TypeScript and works in plain Node and in React.

Terminal window
npm install @sidub-inc/licensing-client
import { LicensingClient } from '@sidub-inc/licensing-client';
const client = new LicensingClient({
licenseServiceUri: 'https://api.monaiq.com/licensing',
encodedCredential: process.env.MONAIQ_CREDENTIAL // SIDUB_LIC_...
});
const authorization = await client.getAuthorization();

licenseServiceUri is the licensing API and is required. getAuthorization() returns the authorization for the credential you configured, which is what tells you what this customer is licensed for.

You have two ways to give the client a credential, and you pick one:

  • encodedCredential, the portable string starting SIDUB_LIC_ that carries everything in one value. This is the simpler option and the one above.
  • The four parts separately: apiKey, licenseId, serviceKeyId and serviceKeyPublicMember. Use this when your configuration already holds them individually.

The constructor also accepts consumptionServiceUri, billableResourceId and billablePlanId for metered features, covered in Consumption and metering, plus timeout, validateSignatures, cacheEnabled and cacheMaxSize. The Node client reference lists them with what each one does.

The package ships React bindings on top of the same client: LicensingProvider puts a licensing context into your component tree, and useLicensingContext reads it from a component. It is the same client underneath, so nothing you learn here is wasted when you move from a script to a component tree. See Node client reference.

Rather than reading an authorization and writing your own conditionals, you can express the condition as an assertion. The package ships five:

  • ServiceAccessAssertion
  • FeatureExistsAssertion
  • RateLimitAssertion
  • CompositeAssertion, which combines other assertions
  • NotAssertion, which negates one

RateLimitAssertion is the one to reach for when a feature is rate limited; see Consumption and metering.

If you would rather not wire the call sites by hand, the AI-assisted path returns the base wiring and a feature check for your own project, and can plumb the credential in for you. See AI-assisted setup.