@licensespring/node-sdk
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

LicenseSpring node.js SDK

This package is a node.js implementation of Licensespring SDK. For more information and tutorials, see: https://docs.licensespring.com/sdk

Install

To install the SDK in your nodejs or typescript project run:

npm i --save @licensespring/node-sdk

LicenseAPI

Provides a direct interface to the LicenseSpring API. The LicenseAPI class encapsulates API calls, input checks, authentication and signature verification. Typescript definitions are provided for the arguments and return types of the class methods.

To import the LicenseAPI class use:

const { LicenseAPI } = require('@licensespring/node-sdk');

Creating an instance

const licenseAPI = new LicenseAPI({
  apiKey: '12345678-4bfe-4e3a-8737-757004d6294c',
  sharedKey: 'eYuHrlajvIVTiSFIXpxpKhw78f4Ewy-00-12345678',
  appName: 'js-sdk-test-1',
  appVersion: '0.0.1',
  /** NOTE: the following properties are set to their default values by the SDK and can be overriden manually: */
  // apiPath: 'http://api.dev.licensespring.com/api/v4',
  // publicKey: '...',
});

The constructor takes the a single argument of the following type:

{
  /** your Licensespring API key - required if using API key-based authentication */
  apiKey: string,
  /** your Licensespring API Shared key - required if using API key-based authentication **/
  sharedKey: string,
  /** your OAuth client ID - required if using OAuth API authentication */
  clientID: string,
  /** your OAuth client secret - required if using OAuth API authentication */
  clientSecret: string,
  /** optional override for OAuth token url */
  tokenUrl?: string,
  /** custom name for your application */
  appName: string,
  /** custom version string for your application */
  appVersion: string,
  /** your Air Gap Activation key (optional) */
  airGapKey?: string,
  /** override for License API url (default is https://api.licensespring.com/api/v4/) **/
  apiPath?: string,
  /** override for License API public key (default is pub key for api.licensespring.com) **/
  publicKey?: string,
  /** override for License File filename (default is "License") */
  filename?: string,
  /** override for License File path (default is current directory) */
  filePath?: string,
  /** override for License File encryption key */
  fileKey?: string,
  /** override for license grace period duration in hours (default is 24) */
  gracePeriod?: number,
  /** override for License File guard file (default is false) */
  isGuardFileEnabled?: boolean,
  /** override for Hardware ID calculation method (default is 0, for more info see "Hardware ID" section) */
  hardwareIDMethod?: number,
}

API methods

For more information on API functionality, see our LicenseSpring API docs.

For type definitions see Types.

getHardwareID

Generates a Hardware ID. This value is required for various API method calls.

If the optional argument is not provided, it defaults to the value set in the configuration object provided when instantiating the LicensespringAPI object. If no value was provided in the config object, it defaults to 0 (the default Hardware ID method).

getHardwareID(algorithm?: HardwareIdAlgorithm): string

Check License

https://docs.licensespring.com/license-api/check

checkLicense(payload: LicenseIdentificator, includeExpiredFeatures: boolean = false): Promise<LicenseResponse>

Activate License Online

https://docs.licensespring.com/license-api/activation-deactivation/activation

activateLicense(payload: LicenseActivationIdentificatorWithVariables): Promise<LicenseResponse>

Deactivate License Online

https://docs.licensespring.com/license-api/activation-deactivation/deactivation

deactivateLicense(payload: LicenseIdentificator): Promise<boolean>

Activate License Offline

createOfflineActivationPayload(payload: CreateOfflineActivationRequestPayload): string

checkOfflineActivationResponse(payload: string): LicenseResponseOffline

First create an offline request payload, which can be stored in a file:

const offlineActivationPayload = licenseAPI.createOfflineActivationPayload({
  'license_key': 'AAAA-0000-1111-2222',
  'product': 'productcode',
  'hardware_id': 'a0b1c2d3',
});

nodeFs.writeFileSync('activate_offline.req', offlineActivationPayload);

This file is then uploaded to the Offline Portal. If the file is valid, the system will activate the license. This will also generate an ls_activation.lic file, which you can forward to your offline application and verify it locally.

The contents of this file are verified using checkOfflineActivationResponse, for example:

const activationResponse = nodeFs.readFileSync('ls_activation.lic');

try {
  return licenseAPI.checkOfflineActivationResponse(activationResponse);
} catch (error) {
  return false;
}

Deactivate License Offline

createOfflineDeactivationPayload(payload: CreateOfflineActivationRequestPayload): string

First create an offline request payload, which can be stored in a file:

const offlineDeactivationPayload = licenseAPI.createOfflineDeactivationPayload({
  'license_key': 'AAAA-0000-1111-2222',
  'product': 'productcode',
  'hardware_id': 'a0b1c2d3',
});

nodeFs.writeFileSync('deactivate_offline.req', offlineDeactivationPayload);

This file is then uploaded to the Offline Portal. If the file is valid, the system will deactivate the license.

Get Trial License Key

https://docs.licensespring.com/license-api/trial-key

getTrialKey(payload: TrialKeyPayload): Promise<LicenseTrialResponse>

List Licenses for a User

https://docs.licensespring.com/license-api/user-licenses

getUserLicenses(payload: GetUserLicensesPayload): Promise<LicenseResponse[]>

List License Users for a Customer

https://docs.licensespring.com/license-api/customer-license-users

getCustomerLicenseUsers(payload: GetCustomerLicensesPayload): Promise<CustomerLicenseUsersResponse>

Check License Feature

https://docs.licensespring.com/license-api/license-feature-check

checkLicenseFeature(payload: LicenseIdentificatorAndFeature): Promise<LicenseFeatureResponse>

Add License Consumption

https://docs.licensespring.com/license-api/consumption/add

addConsumption(payload: LicenseIdentificatorAddConsumptions): Promise<LicenseConsumptionsResponse>

Add License Feature Consumption

https://docs.licensespring.com/license-api/consumption/add-feature

addFeatureConsumption(payload: LicenseIdentificatorAddFeatureConsumptions): Promise<LicenseFeatureConsumptionResponse>

Product Details

https://docs.licensespring.com/license-api/product-details

getProductDetails(payload: ProductDetailsPayload): Promise<ProductDetailsResponse>

Get Device Variables

https://docs.licensespring.com/license-api/device-variables/get

getDeviceVariables(payload: LicenseIdentificator): Promise<DeviceVariable[]>

Track Device Variables

https://docs.licensespring.com/license-api/device-variables/track

trackDeviceVariables(payload: LicenseIdentificatorWithVariables): Promise<DeviceVariable[]>

Borrow Floating License

https://docs.licensespring.com/license-api/floating/license/borrow

floatingBorrow(payload: LicenseIdentificatorWithBorrowedUntil): Promise<LicenseBorrowResponse>

Release Floating License

https://docs.licensespring.com/license-api/floating/license/release

floatingRelease(payload: LicenseIdentificator): Promise<boolean>

Release Floating Feature

https://docs.licensespring.com/license-api/floating/feature/release

featureRelease(payload: LicenseIdentificatorAndFeature): Promise<boolean>

Change User Password

https://docs.licensespring.com/license-api/change-password

changePassword(payload: PasswordChangePayload): Promise<boolean>

List Product Versions for License

https://docs.licensespring.com/license-api/versions

getVersions(payload: LicenseIdentificator): Promise<VersionsResponse>

Product Installation File Info for License

https://docs.licensespring.com/license-api/installation-file

getInstallationFile(payload: LicenseIdentificatorWithInstallation): Promise<InstallationFileResponse>

Get Single Sign On URL

https://docs.licensespring.com/license-api/sso-url

getSSOUrl(payload: SSOURLParams): Promise<{ url: string }>

Get Air Gap Activation Code

https://docs.licensespring.com/license-entitlements/activation-types/air-gapped

getAirGapActivationCode(initializationCode: string, licenseKey: string): string

Verify Air-Gap Confirmation Code

verifyConfirmationCode(confirmationCode: string, licenseKey: string, policyId?: string): boolean

Activate Air-Gapped License

https://docs.licensespring.com/license-entitlements/activation-types/air-gapped

activateAirgappedLicense(activationPayload: OfflineActivation, licenseKey: string, policyId: string): LicenseResponse

LicenseManager

Provides a high-level interface for managing licenses, including local licenses. The LicenseManager is required to work with local license files. Typescript definitions are provided for the arguments and return types of the class methods.

To import the LicenseManager class use:

const { LicenseManager } = require('@licensespring/node-sdk');

To create an instance:

const licenseManager = new LicenseManager({
  apiKey: '12345678-4bfe-4e3a-8737-757004d6294c',
  sharedKey: 'eYuHrlajvIVTiSFIXpxpKhw78f4Ewy-00-12345678',
  appName: 'js-sdk-test-1',
  appVersion: '0.0.1',
  productCode: 'lkp',
  /** NOTE: the following properties are set to their default values by the SDK and can be overriden manually: */
  // apiPath: 'http://api.dev.licensespring.com/api/v4',
  // publicKey: '...',
});

The constructor takes the a single argument of the following type:

{
  /** your Licensespring API key */
  apiKey: string,
  /** your Licensespring API Shared key **/
  sharedKey: string,
  /** custom name for your application */
  appName: string,
  /** custom version string for your application */
  appVersion: string,
  /** your product short code */
  productCode: string,
  /** your Air Gap Activation key (optional) */
  airGapKey?: string,
  /** override for License API url (default is https://api.licensespring.com/api/v4/) **/
  apiPath?: string,
  /** override for License API public key (default is pub key for api.licensespring.com) **/
  publicKey?: string,
  /** override for License File filename (default is "License") */
  filename?: string,
  /** override for License File path (default is current directory) */
  filePath?: string,
  /** override for License File encryption key */
  fileKey?: string,
  /** override for license grace period duration in hours (default is 24) */
  gracePeriod?: number,
  /** override for License File guard file (default is false) */
  isGuardFileEnabled?: boolean,
  /** override for Hardware ID calculation method (default is 0, for more info see "Hardware ID" section) */
  hardwareIDMethod?: number,
}

Methods

Methods that take a Managed License identificator are the same as in License API, except that product and hardware_id do not have to be specified in the payload as they are provided by the License Manager object.

Check License

https://docs.licensespring.com/license-api/check

checkLicense(payload: Managed<LicenseIdentificator>): Promise<LicenseResponse>

Activate License Online

https://docs.licensespring.com/license-api/activation-deactivation/activation

activateLicense(payload: Managed<LicenseIdentificatorWithVariables>): Promise<LicenseResponse>

Deactivate License Online

https://docs.licensespring.com/license-api/activation-deactivation/deactivation

deactivateLicense(payload: Managed<LicenseIdentificator>): Promise<boolean>

Activate License Offline

createOfflineActivationPayload(payload: Managed<CreateOfflineActivationRequestPayload>): string

activateOffline(payload: string): LicenseResponseOffline

First create an offline request payload, which can be stored in a file:

const offlineActivationPayload = licenseManager.createOfflineActivationPayload({
  'license_key': 'AAAA-0000-1111-2222'
});

nodeFs.writeFileSync('activate_offline.req', offlineActivationPayload);

This file is then uploaded to the Offline Portal. If the file is valid, the system will activate the license. This will also generate an ls_activation.lic file, which you can forward to your offline application.

You can then pass the contents of this ls_activation.lic file to activateOffline which will verify the file response and (if valid) apply the activation locally. For example:

const activationResponse = nodeFs.readFileSync('ls_activation.lic');
activateOffline(activationResponse);

Deactivate License Offline

createOfflineDeactivationPayload(payload: Managed<CreateOfflineActivationRequestPayload>): string

deactivateOffline(): void

First create an offline request payload, which can be stored in a file:

const offlineDeactivationPayload = licenseManager.createOfflineDeactivationPayload({
  'license_key': 'AAAA-0000-1111-2222'
});

nodeFs.writeFileSync('deactivate_offline.req', offlineDeactivationPayload);

This file is then uploaded to the Offline Portal. If the file is valid, the system will deactivate the license.

To apply the license deactivation locally, you can call licenseManager.deactivateOffline().

Get Trial License Key

https://docs.licensespring.com/license-api/trial-key

getTrialKey(payload: Managed<TrialKeyPayload>): Promise<LicenseTrialResponse>

List Licenses for a User

https://docs.licensespring.com/license-api/user-licenses

getUserLicenses(payload: Managed<GetUserLicensesPayload>): Promise<LicenseResponse[]>

List License Users for a Customer

https://docs.licensespring.com/license-api/customer-license-users

getCustomerLicenseUsers(payload: Managed<GetCustomerLicensesPayload>): Promise<CustomerLicenseUsersResponse>

Check License Feature

https://docs.licensespring.com/license-api/license-feature-check

checkLicenseFeature(payload: Managed<LicenseIdentificatorAndFeature>): Promise<LicenseFeatureResponse>

Add License Consumption

https://docs.licensespring.com/license-api/consumption/add

addConsumption(payload: Managed<LicenseIdentificatorAddConsumptions>): Promise<LicenseConsumptionsResponse>

Add License Feature Consumption

https://docs.licensespring.com/license-api/consumption/add-feature

addFeatureConsumption(payload: Managed<LicenseIdentificatorAddFeatureConsumptions>): Promise<LicenseFeatureConsumptionResponse>

Product Details

https://docs.licensespring.com/license-api/product-details

getProductDetails(payload: Managed<ProductDetailsPayload>): Promise<ProductDetailsResponse>

Get Device Variables

https://docs.licensespring.com/license-api/device-variables/get

getDeviceVariables(payload: Managed<LicenseIdentificator>): Promise<DeviceVariable[]>

Track Device Variables

https://docs.licensespring.com/license-api/device-variables/track

trackDeviceVariables(payload: Managed<LicenseIdentificatorWithVariables>): Promise<DeviceVariable[]>

Borrow Floating License

https://docs.licensespring.com/license-api/floating/license/borrow

floatingBorrow(payload: Managed<LicenseIdentificatorWithBorrowedUntil>): Promise<LicenseBorrowResponse>

Release Floating License

https://docs.licensespring.com/license-api/floating/license/release

floatingRelease(payload: Managed<LicenseIdentificator>): Promise<boolean>

Release Floating Feature

https://docs.licensespring.com/license-api/floating/feature/release

featureRelease(payload: Managed<LicenseIdentificatorAndFeature>): Promise<boolean>

Change User Password

https://docs.licensespring.com/license-api/change-password

changePassword(payload: PasswordChangePayload): Promise<boolean>

List Product Versions for License

https://docs.licensespring.com/license-api/versions

getVersions(payload: Managed<LicenseIdentificator>): Promise<VersionsResponse>

Product Installation File Info for License

https://docs.licensespring.com/license-api/installation-file

getInstallationFile(payload: Managed<LicenseIdentificatorWithInstallation>): Promise<InstallationFileResponse>

Get Single Sign On URL

https://docs.licensespring.com/license-api/sso-url

getSSOUrl(payload: SSOURLParams): Promise<{ url: string }>

Get Air Gap Activation Code

https://docs.licensespring.com/license-entitlements/activation-types/air-gapped

getAirGapActivationCode(initializationCode: string, licenseKey: string)

Activate Air-Gapped License

Performs verifyConfirmationCode and activates Air-Gapped License:

activateAirGapLicense(confirmationCode: string, licenseKey: string, policyFilePath: string, policyID: string)

Is License Valid

Checks if License is enabled, active and not expired:

isValid(license: LicenseResponse): boolean

Maintenance Days Remaining

Returns days remaining in maintenance period:

maintenanceDaysRemaining(license: LicenseResponse): number

Validity Days Remaining

Returns days remaining in license validity period:

daysRemaining(license: LicenseResponse): number

Load License File

See License File

loadLicense(): License

Check License File For Corruption

isLicenseFileCorrupted(): boolean

Clear Local Storage

clearLocalStorage(): void

License File

For more info see our docs: https://docs.licensespring.com/sdks/tutorials/best-practices/local-license-file and https://docs.licensespring.com/sdks/python/licensefile

To load a local license file, create an instance of LicenseManager and call the method loadLicense:

const licenseFile = licenseManager.loadLicense();

The License class provides an interface for working with the License File.

Methods

Get Feature Data

public featureData(featureCode: string): ProductFeature

Check License Status

Throws an exception if the license is disabled, inactive or expired

checkLicenseStatus(): void

Perform Full License Check

Checks License status and saves to local license file

check(includeExpiredFeatures: boolean = false): Promise<LicenseResponse>

Get Air-Gap License Deactivation Code

getDeactivationCode(initializationCode: string): string

Deactivate Air-Gap License

deactivateAirGap(confirmationCode: string): void

Deactivate License

Deactivates a License, updates local license file. Optionally deletes license file

deactivate(deleteLicense: boolean = false): Promise<boolean>

Local License Check

Performs a local check using the local license file. Throws an exception if license is not valid

localCheck(): Promise<true>

Change Password

Performs password change for user associated to License

changePassword(oldPassword: string, newPassword: string): Promise<boolean>

Add Local Consumption

Adds a License consumption to the local license data

addLocalConsumption(consumptions: number = 1)

Add Local Feature Consumption

Adds a License feature consumption to the local license data

addLocalFeatureConsumption(featureCode: string, consumptions: number = 1)

Sync License Feature Consumption

Sends a feature consumption request to the server and updates local data

syncFeatureConsumption(feature: { code: string, local_consumption: number }): Promise<boolean>

Sync License Consumption

Syncs local consumptions to server

syncConsumption(overages: number = -1): Promise<boolean>

Borrow Floating License

floatingBorrow(borrowUntil: string, password?: string): Promise<boolean>

Release Floating License

floatingRelease(): Promise<boolean>

Check Feature Status

Checks License Feature status, throws exception if not active

checkFeature(featureCode: string): Promise<void>

Release Borrowed Feature

releaseFeature(featureCode: string): Promise<void>

Update Offline

Update local cache from Offline License File (at given `path`). Optionally reset local consumption value.
public updateOffline(path: string, resetConsumption: boolean): boolean

Deactivate Offline License

deactivateOffline(offlinePath: string): Promise<void>

Get Product Details

Retrieves Product Details from server

productDetails(includeLatestVersion: boolean = false, includeCustomFields: boolean = false, includeExpiredFeatures: boolean = false): Promise<ProductDetailsResponse>

Get Product Details Local

Retrieves Product Details from local data

get productDetailsLocal()

Set Device Variables Local

Set custom variables to local data

setDeviceVariablesLocal(variables: { [key: string]: string|number }, save: boolean = true): void

Set Device Variables

Send locally stored variables to server. Optionally save to license file

setDeviceVariables(save: boolean = false): Promise<void>

Get Device Variable Local

Get the value of a variable from local data

getDeviceVariableLocal(variable: string)

Get Device Variables Local

Get all variables from local data

getDeviceVariablesLocal()

Get Device Variables

getDeviceVariables(): Promise<DeviceVariable[]>

Getters

get allowGraceSubscriptionPeriod()
get allowOverages()
get allowUnlimitedActivations()
get allowUnlimitedConsumptions()
get borrowUntil()
get consumptionPeriod()
get consumptionReset()
get customerInformation()
get customFields()
get daysRemaining()
get daysSinceLastCheck()
get expiryDate()
get features()
get floatingClientId()
get floatingEndDate()
get floatingInUseDevices()
get floatingTimeout()
get gracePeriod()
get gracePeriodHoursRemaining()
get id()
get isAirGapped()
get isBorrowed()
get isControlledByFloatingServer()
get isDeviceTransferAllowed()
get isDeviceTransferLimited()
get isExpired()
get isFloating()
get isFloatingExpired()
get isGracePeriod()
get isGracePeriodStarted()
get isMaintenancePeriodExpired()
get isSubcriptionGracePeriodStarted()
get isTrial()
get isValid()
get isValidityPeriodExpired()
get lastCheck()
get lastUsage()
get licenseActive()
get licenseEnabled()
get licenseKey()
get licenseType()
get licenseUser()
get localConsumptions()
get maintenanceDaysRemaining()
get maintenancePeriod()
get maxActivations()
get maxConsumptions()
get maxFloatingUsers()
get maxOverages()
get maxTransfers()
get metadata()
get policyID()
get preventVm()
get startDate()
get subscriptionGracePeriod()
get totalConsumptions()
get transferCount()
get validityPeriod()
get validityWithGracePeriod()

Hardware ID

Both LicenseAPI and LicenseManager use the Hardware ID module to calculate a unique fingerprint for the local machine. The module provides multiple methods of determining the ID:

export enum HardwareIdAlgorithm {
  Default = 0,
  WindowsHardwareFingerprintId = 1,
  WindowsComputerSystemProductId = 2,
  WindowsCryptographyId = 3,
  LinuxMachineId = 4,
  CloudPlatformsId = 5,
};

The default method (0) covers all cases and fallbacks. If you override the default method, the method used should be consistent accross your project. For both LicenseAPI and LicenseManager, this can be overriden globally by setting the required value in the config object when initializing the LicenseAPI/LicenseManager, e.g.:

const licenseAPI = new LicenseAPI({
  apiKey: '12345678-4bfe-4e3a-8737-757004d6294c',
  sharedKey: 'eYuHrlajvIVTiSFIXpxpKhw78f4Ewy-00-12345678',
  appName: 'js-sdk-test-1',
  appVersion: '0.0.1',
  hardwareIDMethod: 5,
});

Proxy

All calls to the server can be proxied by providing a proxy definition in either of the following two ways:

A. By providing a proxy definition in the initialization config argument for LicenseAPI, LicenseManager and FloatingAPI, e.g.:

const licenseAPI = new LicenseAPI({
  apiKey: '12345678-4bfe-4e3a-8737-757004d6294c',
  sharedKey: 'eYuHrlajvIVTiSFIXpxpKhw78f4Ewy-00-12345678',
  appName: 'js-sdk-test-1',
  appVersion: '0.0.1',
  proxy: {
    host: '127.0.0.1',
    port: 9000,
  },
});

B. or by calling the setProxy method on an initialized LicenseAPI, LicenseManager or FloatingAPI object, e.g.:

licenseAPI.setProxy({
  host: '127.0.0.1',
  port: 9000,
});

For the type declaration of the proxy definition object, see AxiosProxyConfig in the following Types section.

Types

The following are typescript definitions for all the types used in the SDK:

/** Date string in ISO 8601 format (always in UTC timezone) with optional separators and optional time component, e.g.:
 *
 * "2024-09-27T23:30:48.016Z"
 *
 * "2024-09-27 23:30:48.016"
 *
 * "2024-09-27 23:30:48"
 *
 * "2024-09-27 23:30"
 *
 * "2024-09-27"
 *
 */
export type DateInputString = string;

/** Date string in full ISO 8601 format, e.g. "2024-09-27T23:30:48.016Z". Note: this is always in UTC timezone */
export type DateISO8601UTC = string;

/** Date string in RFC 7231 format, e.g. "Fri, 27 Sep 2024 23:30:48 GMT". Note: this is always in GMT timezone */
export type DateRFC7231 = string;

/** Length of time expressed in days, months or years, e.g. 5d, 2m, 3y */
export type TimeLength = string;

export type LicensespringConfig = {
  apiKey: string,
  sharedKey: string,
  apiPath: string,
  publicKey: string,
  productCode: string,
  appName: string,
  appVersion: string,
  filePath: string,
  filename: string,
  gracePeriod: number,
  fileKey: string,
  airGapKey?: string,
  isGuardFileEnabled: boolean,
  hardwareIDMethod: number,
  sdkVersion: string,
  proxy?: AxiosProxyConfig,
};

interface AxiosProxyConfig {
  host: string,
  port: number,
  protocol?: string,
  auth?: {
    username: string,
    password: string,
  }
}

export type LicensespringAPIConfig = Omit<LicensespringConfig, 'productCode'>;

export type LicensespringConfigDef = Omit<LicensespringConfig, 'apiPath'|'publicKey'|'filename'|'filePath'|'gracePeriod'|'fileKey'|'isGuardFileEnabled'|'hardwareIDMethod'|'sdkVersion'> & {
  apiPath?: string,
  publicKey?: string,
  filename?: string,
  filePath?: string,
  gracePeriod?: number,
  fileKey?: string,
  isGuardFileEnabled?: boolean,
  hardwareIDMethod?: number,
  proxy?: AxiosProxyConfig,
};

export type LicensespringAPIConfigDef = Omit<LicensespringAPIConfig, 'apiPath'|'publicKey'|'filename'|'filePath'|'gracePeriod'|'fileKey'|'isGuardFileEnabled'|'hardwareIDMethod'|'sdkVersion'> & {
  apiPath?: string,
  publicKey?: string,
  filename?: string,
  filePath?: string,
  gracePeriod?: number,
  fileKey?: string,
  isGuardFileEnabled?: boolean,
  hardwareIDMethod?: number,
  proxy?: AxiosProxyConfig,
};

export type LicensespringFloatingConfig = {
  apiPath: string,
  appVersion: string,
  hardwareIDMethod: number,
  sdkVersion: string,
  proxy?: AxiosProxyConfig,
};

export type LicensespringFloatingConfigDef = Omit<LicensespringFloatingConfig, 'hardwareIDMethod'|'sdkVersion'> & {
  hardwareIDMethod?: number,
};

export enum HardwareIdAlgorithm {
  Default = 0,
  WindowsHardwareFingerprintId = 1,
  WindowsComputerSystemProductId = 2,
  WindowsCryptographyId = 3,
  LinuxMachineId = 4,
  CloudPlatformsId = 5,
};

Logging

The Logger class provides static properties which can be set to log events in the SDK. On the lowest level (debug), all function calls, function returns and exceptions are logged. You can also invoke logging functions manually. By default, all values are logged to both the js console and the log file. The log file is rotated after 5MB, with the last 5 files kept on disk. These values can be overriden by setting static properties on the Logger class.

The following is a list of the exposed static properties of the Logger, with their default values:

  /**
   * Sets the minimum logged level. Valid values are: 'off', 'debug', 'info', 'warn', 'error'
   */
  static level: LogLevel = 'off';
  /**
   * Determines whether logged events are written to console
   */
  static consoleLog: boolean = true;
  /**
   * Determines whether logged events are written to the log file
   */
  static fileLog: boolean = true;
  /**
   * Path to the log file
   */
  static logPath: string = resolve(process.cwd(), 'node_sdk.log');
  /**
   * Log file maximum size, for rotation purposes. When rotated, older log filenames will be appended with a sequential number, e.g. node_sdk.1.log
   */
  static maxLogSize: number = 5 * 1024 * 1024;
  /**
   * Maximum number of old log files to keep
   */
  static maxLogFiles: number = 5;

The Logger provides the following static functions for manual logging:

static debug(...args: any[]): void;
static info(...args: any[]): void;
static warn(...args: any[]): void;
static error(...args: any[]): void;

Example usage:

const { Logger } = require('@licensespring/node-sdk');

Logger.level = 'error';
Logger.consoleLog = false;
Logger.logPath = resolve(process.cwd(), 'my_log_file.log');

Logger.info('my custom logged value', { some_data: 123 });
Logger.warn('my custom warning', 456);

License

Readme

Keywords

none

Package Sidebar

Install

npm i @licensespring/node-sdk

Weekly Downloads

67

Version

1.2.0

License

ISC

Unpacked Size

251 MB

Total Files

243

Last publish

Collaborators

  • kresimir.ivkovic
  • karlokoloda
  • massimo.schianchi