@unilic/core
v0.2.0
Published
Core types and utilities for Universal License SDK
Maintainers
Readme
@unilic/core
Core types, utilities, and constants for Universal License SDK.
Installation
npm install @unilic/core
# or
pnpm add @unilic/core
# or
yarn add @unilic/coreUsage
Import Types
import type { License, ValidateLicenseRequest, SubscriptionPlan } from '@unilic/core';
const license: License = {
id: 1,
licenseKey: 'PROD-ORG-2025-XXXX-XXXX-XXXX',
// ...
};Use Utilities
import { DeviceFingerprint, isValidLicenseKey, daysUntilExpiry } from '@unilic/core';
// Generate device fingerprint
const deviceId = await DeviceFingerprint.generate();
// Validate license key format
if (isValidLicenseKey('PROD-ORG-2025-XXXX-XXXX-XXXX')) {
console.log('Valid license key format');
}
// Calculate days until license expires
const days = daysUntilExpiry('2025-12-31T23:59:59Z');
console.log(`License expires in ${days} days`);Use Constants
import { LICENSE_TIERS, LICENSE_STATUS, ERROR_CODES } from '@unilic/core';
// Check tier hierarchy
if (LICENSE_TIER_HIERARCHY[userTier] >= LICENSE_TIER_HIERARCHY['pro']) {
// User has pro or higher
}
// Use error codes
throw new Error(ERROR_CODES.LICENSE_EXPIRED);Included Utilities
Device Fingerprinting
DeviceFingerprint.generate()- Generate unique device IDDeviceFingerprint.isValidDeviceId()- Validate device ID format
Note: The SDK surfaces two shapes for license objects. The validation response
ValidateLicenseResponse.licenseuses camelCase (e.g.,expiresAt,licenseKey,maxUsers), while low-levelLicenseentities returned by admin APIs use snake_case (e.g.,expires_at,license_key). Be mindful when moving objects between layers; prefer SDK helpers where possible.
Validators
isValidEmail()- Email validationisValidLicenseKey()- License key formatisValidProductCode()- Product code formatisLicenseExpired()- Check if license is expireddaysUntilExpiry()- Calculate days until expiry- And 15+ more validators
Crypto
sha256()- Hash stringsgenerateUUID()- Generate UUIDsverifySignature()- Verify RSA signaturesbase64Encode/Decode()- Base64 operations
Type Exports
All types from:
common.types.ts- API responses, paginationlicense.types.ts- License entitiespurchase.types.ts- Purchase ordersproduct.types.ts- Products and plansvalidation.types.ts- Validation resultsrenewal.types.ts- Renewal operations
Constants
LICENSE_TIERS- Available license tiersLICENSE_STATUS- License statusesPAYMENT_STATUS- Payment statusesAPI_ENDPOINTS- API endpoint pathsERROR_CODES- Standard error codesVALIDATION_PATTERNS- Regex patterns- And more...
License
This project is licensed under the MIT License - see the LICENSE file for details.
