Installation
Setup and usage
Initialize the client
You can create a client by passing your API key directly, or by loading it from a config file.import { KeyPort } from 'keyport-node';
const client = new KeyPort('kp_live_xxx');
When using a config file, load the client with KeyPort.fromConfigFile:const client = await KeyPort.fromConfigFile('./keyport.json');
Validate a license key
Call client.validate with the license key you want to check:const result = await client.validate({ license_key: 'ABCD-EFGH-IJKL-MNOP' });
This sends a POST /api/v1/validate request and returns the validation result. Retrieve license details
Call client.getLicense with the license key to fetch full license details:const detail = await client.getLicense('ABCD-EFGH-IJKL-MNOP');
This sends a GET /api/v1/license/:key request and returns the license detail object.
Full examples
import { KeyPort } from 'keyport-node';
const client = new KeyPort('kp_live_xxx');
// Validate a license key
const result = await client.validate({ license_key: 'ABCD-EFGH-IJKL-MNOP' });
// Retrieve full license details
const detail = await client.getLicense('ABCD-EFGH-IJKL-MNOP');
Store your API key in an environment variable or a keyport.json config file rather than hard-coding it in your source code.