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.
Install
Section titled “Install”npm install @sidub-inc/licensing-clientConfigure and get an authorization
Section titled “Configure and get an authorization”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.
Identifying yourself
Section titled “Identifying yourself”You have two ways to give the client a credential, and you pick one:
encodedCredential, the portable string startingSIDUB_LIC_that carries everything in one value. This is the simpler option and the one above.- The four parts separately:
apiKey,licenseId,serviceKeyIdandserviceKeyPublicMember. Use this when your configuration already holds them individually.
Other settings
Section titled “Other settings”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.
In React
Section titled “In React”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.
Assertions
Section titled “Assertions”Rather than reading an authorization and writing your own conditionals, you can express the condition as an assertion. The package ships five:
ServiceAccessAssertionFeatureExistsAssertionRateLimitAssertionCompositeAssertion, which combines other assertionsNotAssertion, which negates one
RateLimitAssertion is the one to reach for when a feature is rate limited; see
Consumption and metering.
Getting the calls written for you
Section titled “Getting the calls written for you”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.
- Credentials and keys for minting and rotating
MONAIQ_CREDENTIAL. - Endpoints for the addresses used above.