API Reference

Public API @corelicense/node v0.5.9.


CoreLicense

Constructor

new CoreLicense(options: CoreLicenseOptions)

Lifecycle

MethodReturnsDescription
boot()Promise<void>Initialize, sync server, fail-closed
refresh()Promise<LicenseStatus>Force refresh policy
startBackgroundCheck()voidEnable sync interval
stopBackgroundCheck()voidDisable interval

License gates

MethodDescription
requireActive()Throw if not active
requireFeature(feature)Throw + audit if feature is off
checkLimit(name, current)Throw if limit exceeded
consumeQuota(name, amount?)Consume local quota
getStatus()Current status
getPolicy()Verified policy (null if not yet available)
getRuntimeConfig()Config derived from policy

HTTP integrations

MethodDescription
express(options?)Express RequestHandler
fastifyPlugin(options?)Fastify plugin

Worker / CLI

MethodDescription
guardWorker(name)Guard worker process
guardCommand(name)Guard CLI/cron command

Deep integration

MethodDescription
bootstrap(options)Register modules + services
createLicensedRegistry()Dedicated LicensedModuleRegistry
createLicensedContainer()Dedicated LicensedServiceContainer

Events

license.on(event, handler)

Events: statusChanged | policyUpdated | licenseRevoked | licenseSuspended | offlineMode

CoreLicense only exposes on(). To unsubscribe, keep a reference to the handler and use the internal EventBus if custom wiring is needed.


LicensedModuleRegistry

MethodDescription
bootstrap(definitions, ctx)Bulk register
registerLicensed(def, ctx)Register a single module
has(name)Is module bound?
get<T>(name)Get module + re-check license
list()Names of registered modules

LicensedServiceContainer

MethodDescription
bootstrap(definitions, ctx)Bind services
resolve<T>(name)Resolve + re-check license
has(name)Is service bound?

Helpers

loadOptionsFromEnv(overrides?: Partial<CoreLicenseOptions>): CoreLicenseOptions
resolveApiUrl(options, cachedApiUrl?): string
parseEmbeddedApiUrl(licenseKey): string | null
registerLicensedRoutes(app, registry, routes): string[]
isLicenseError(error): boolean
formatLicenseError(error): string
isFeatureEnabled(policy, feature): boolean

Subpath exports

@corelicense/node/express

createExpressMiddleware(license, options?): RequestHandler

@corelicense/node/fastify

createFastifyPlugin(license, options?): FastifyPluginAsync
coreLicenseFastifyPlugin

@corelicense/node/nestjs

CoreLicenseModule.forRoot(options): DynamicModule
CoreLicenseGuard
CoreLicenseFeatureGuard
CoreLicenseExceptionFilter
RequireFeature(feature)  // decorator
REQUIRE_FEATURE_KEY

Types

CoreLicenseOptions

See installation.md.

ExpressGuardOptions / FastifyGuardOptions

{
  allowPaths?: string[];
  mode?: 'block' | 'limited';
}

BootstrapResult

{
  modules: LicensedModuleRegistry;
  services: LicensedServiceContainer;
  registeredModules: string[];
  registeredServices: string[];
  skipped: { name: string; feature: string; reason: 'feature_disabled' }[];
}

LicenseStatus

{
  status: 'active' | 'suspended' | 'revoked' | 'expired' | 'invalid' | 'blocked' | 'offline' | 'grace_expired' | 'limited';
  policyVersion?: string;
  expiresAt?: number;
  graceUntil?: number;
  offline?: boolean;
  // ...
}

Error codes

Every LicenseError has code, source, message, toClientPayload(), toJSON().

CodeHTTP (middleware)
LICENSE_REVOKED403
LICENSE_SUSPENDED403
LICENSE_EXPIRED403
LICENSE_INVALID403
LICENSE_NOT_FOUND403
LICENSE_NOT_STARTED403
OFFLINE_GRACE_EXPIRED403
FEATURE_DISABLED403
MODULE_NOT_LICENSED403
QUOTA_EXCEEDED403
MAX_INSTANCES403
INSTANCE_BLOCKED403
CONFIG_MISSING_ENV— (boot fail)
PRODUCT_NOT_FOUND— (boot fail)
PUBLIC_KEYS_NOT_PUBLISHED— (boot fail)
PUBLIC_KEYS_FETCH_FAILED— (boot fail)
LICENSE_API_UNREACHABLE— (boot fail)
LICENSE_API_TIMEOUT— (boot fail)
POLICY_SIGNATURE_ERROR— (boot fail)
BOOT_NOT_CALLED
POLICY_NOT_AVAILABLE— (boot fail)
RUNTIME_CONFIG_UNAVAILABLE
POLICY_TOKEN_MISSING
POLICY_LOAD_FAILED
POLICY_PRODUCT_MISMATCH
POLICY_INSTANCE_MISMATCH
INSTANCE_ID_UNRESOLVED
PUBLIC_KEY_PINNED_MISMATCH
PUBLIC_KEYS_EMPTY
MODULE_NOT_REGISTERED403
SERVICE_NOT_BOUND403
RATE_LIMITED— (retryable)
WORKER_NOT_ALLOWED
COMMAND_NOT_ALLOWED

Full list in source: src/errors/codes.ts

formatLicenseError(error) also returns retryable and httpStatus (when available) for transport/API errors.

License Server response → SDK mapping

Client API (POST /v1/client/*) — HTTP 200, body ok: false:

Server codeSDK codeRetry?
LICENSE_REVOKEDLICENSE_REVOKEDNo
LICENSE_SUSPENDEDLICENSE_SUSPENDEDNo
LICENSE_EXPIREDLICENSE_EXPIREDNo
LICENSE_NOT_STARTEDLICENSE_NOT_STARTEDNo
INVALID_PRODUCTPRODUCT_NOT_FOUNDNo
PRODUCT_NOT_FOUNDPRODUCT_NOT_FOUNDNo
INVALID_LICENSELICENSE_INVALIDNo
LICENSE_NOT_FOUNDLICENSE_NOT_FOUNDNo
LICENSE_INVALIDLICENSE_INVALIDNo
INSTANCE_BLOCKEDINSTANCE_BLOCKEDNo
MAX_INSTANCESMAX_INSTANCESNo
POLICY_SIGN_FAILEDPOLICY_SIGNATURE_ERRORNo

Public keys (GET /v1/public/products/{id}/keys) — HTTP error, body { code, message }:

Server code / HTTPSDK codeRetry?
PRODUCT_NOT_FOUND / 404PRODUCT_NOT_FOUNDNo
PUBLIC_KEYS_NOT_PUBLISHED / 404PUBLIC_KEYS_NOT_PUBLISHEDNo
NOT_FOUND / 404 (legacy)PUBLIC_KEYS_NOT_PUBLISHEDNo
RATE_LIMITED / 429RATE_LIMITEDYes
5xx / 408PUBLIC_KEYS_FETCH_FAILEDYes
Other 4xxPUBLIC_KEYS_FETCH_FAILEDNo
Network / DNS / refusedLICENSE_API_UNREACHABLEYes
TimeoutLICENSE_API_TIMEOUTYes

License API HTTP errors (400, 502, …) — not an ok: false body:

CaseSDK codeRetry?
429RATE_LIMITEDYes
5xx / 408LICENSE_API_ERRORYes
Other 4xxLICENSE_API_ERRORNo
Network / DNS / refusedLICENSE_API_UNREACHABLEYes
TimeoutLICENSE_API_TIMEOUTYes

Client API (License Server)

The SDK calls these endpoints (not typically called directly from the app):

EndpointDescription
POST /v1/client/activateFirst activation
POST /v1/client/checkPeriodic check
POST /v1/client/refreshForce refresh
GET /v1/public/products/{id}/keysPublic keys

Details: Client API Reference