UNPKG

@lefe-dev/lefe-verify-license

Version:
155 lines (106 loc) 3.89 kB
# `@lefe-dev/lefe-verify-license` A library to verify license keys, display watermarks for trial versions, and manage license information for the Lefe platform. ## Installation Install via npm: ```bash npm install @lefe-dev/lefe-verify-license ``` ## Usage ### License Verification ```javascript import { LicenseVerifier } from "@lefe-dev/lefe-verify-license"; const licenseVerifier = new LicenseVerifier({ scopes: [{ name: "your-package-name" }], organization: "your-organization-name", }); const result = licenseVerifier.verifyLicense({ licenseKey: "customer-license-key", packageScope: "your-package-name", }); console.log(result.status); ``` ### Watermark Display ```javascript import { showWatermark } from "@lefe-dev/lefe-verify-license"; showWatermark(result.status, "block", { parent: document.body, width: 100, height: 100, }); ``` ### License Management ```javascript import { LicenseInfo } from "@lefe-dev/lefe-verify-license"; const licenseInfo = new LicenseInfo({ organization: "your-organization-name", }); licenseInfo.setLicenseKey("customer-license-key"); const key = licenseInfo.getLicenseKey(); ``` ## API ### `LicenseVerifier` - **constructor({ scopes, organization })** - **scopes**: `ScopesTree` - A tree structure defining the scopes of licenses. - **organization**: `Organization` - The name of the organization managing the license. **Example:** ```javascript const licenseVerifier = new LicenseVerifier({ scopes: [ { name: "pro", children: [{ name: "package-one" }] }, { name: "premium", children: [{ name: "package-two" }, { name: "package-three" }], }, ], organization: "your-org-name", }); ``` - **verifyLicense({ licenseKey, packageScope })** - **licenseKey**: `string` - The license key to be verified. - **packageScope**: `ScopeName` - The scope of the package being verified. **Returns**: `{ status: LicenseStatus; meta?: object }` - **status**: `LicenseStatus` - The result of the license verification `NotFound`, `Invalid`, `ExpiredSubscription`, `ExpiredSubscriptionGrace`, `Valid`, `OutOfScope` - **meta**: `object` (optional) - Additional metadata about the license verification result. **Example:** ```javascript licenseVerifier.verifyLicense({ licenseKey: "customer-license-key", packageScope: "pro", }); ``` ### `showWatermark` - **showWatermark(status, type, options)** - **status**: `LicenseStatus` - The license status to check. - **type**: `string` - Type of watermark. - Possible values: `'image'`, `'block'` - **options**: `WatermarkOptions | ImageWatermarkOptions` - Options for watermark customization. - **parent**: `HTMLElement` - The parent element to attach the watermark. - **width**: `number` - The width of the watermark. - **height**: `number` - The height of the watermark. - **backgroundRepeat**: `string` (optional) - Controls the repetition of the watermark background. - **rotate**: `number` (optional) - Rotation angle of the watermark. Check [watermark-js-plus](https://www.npmjs.com/package/watermark-js-plus) package for more info. ### `LicenseInfo` - **constructor({ organization })** - **organization**: `Organization` - The name of the organization for which the license is managed. **Example:** ```javascript const licenseInfo = new LicenseInfo({ organization: "your-organization-name", }); ``` - **getLicenseKey()** - **Returns**: `License["key"]` - The current license key. **Example:** ```javascript const key = licenseInfo.getLicenseKey(); console.log(key); // Outputs the current license key ``` - **setLicenseKey(key)** - **key**: `string` (optional) - The new license key to set. **Example:** ```javascript licenseInfo.setLicenseKey("new-license-key"); ``` ## License Licensed under MIT.