devextreme
Version:
JavaScript/TypeScript Component Suite for Responsive Web Development
184 lines (179 loc) • 5.22 kB
JavaScript
/**
* DevExtreme (esm/__internal/core/license/license_validation.js)
* Version: 26.1.3
* Build date: Wed Jun 10 2026
*
* Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED
* Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
*/
import config from "../../../core/config";
import errors from "../../../core/errors";
import {
fullVersion
} from "../../../core/version";
import {
assertedVersionsCompatible,
parseVersion
} from "../../utils/version";
import {
BUY_NOW_LINK,
LICENSE_KEY_PLACEHOLDER,
LICENSING_DOC_LINK,
RTM_MIN_PATCH_VERSION,
SUBSCRIPTION_NAMES
} from "./const";
import {
isProductOnlyLicense,
parseDevExpressProductKey
} from "./lcp_key_validation/lcp_key_validator";
import {
logLicenseWarning
} from "./license_warnings";
import {
showTrialPanel
} from "./trial_panel";
import {
GENERAL_ERROR,
TokenKind
} from "./types";
let validationPerformed = false;
export function parseLicenseKey(encodedKey) {
if (void 0 === encodedKey) {
return GENERAL_ERROR
}
if (isProductOnlyLicense(encodedKey)) {
return parseDevExpressProductKey(encodedKey)
}
return GENERAL_ERROR
}
function isPreview(patch) {
return isNaN(patch) || patch < RTM_MIN_PATCH_VERSION
}
function hasLicensePrefix(licenseKey, prefix) {
return licenseKey.trim().startsWith(prefix)
}
function displayTrialPanel() {
const buyNowLink = config().buyNowLink ?? BUY_NOW_LINK;
const licensingDocLink = config().licensingDocLink ?? LICENSING_DOC_LINK;
showTrialPanel(buyNowLink, licensingDocLink, fullVersion, SUBSCRIPTION_NAMES)
}
function getLicenseCheckParams(_ref) {
let {
licenseKey: licenseKey,
version: version
} = _ref;
let preview = false;
try {
preview = isPreview(version.patch);
const {
major: major,
minor: minor
} = version;
if (!licenseKey || licenseKey === LICENSE_KEY_PLACEHOLDER) {
return {
preview: preview,
error: "W0019",
warningType: "no-key"
}
}
if (hasLicensePrefix(licenseKey, "LCX")) {
return {
preview: preview,
error: "W0021",
warningType: "lcx-used"
}
}
if (hasLicensePrefix(licenseKey, "ewog")) {
return {
preview: preview,
error: "W0021",
warningType: "old-devextreme-key"
}
}
const license = parseLicenseKey(licenseKey);
if (license.kind === TokenKind.corrupted) {
if ("product-kind" === license.error) {
return {
preview: preview,
error: "W0021",
warningType: "no-devextreme-license"
}
}
return {
preview: preview,
error: "W0021",
warningType: "invalid-key"
}
}
if (license.kind !== TokenKind.verified) {
return {
preview: preview,
error: "W0021",
warningType: "invalid-key"
}
}
if (!(major && minor)) {
return {
preview: preview,
error: "W0021",
warningType: "invalid-key"
}
}
if (10 * major + minor > license.payload.maxVersionAllowed) {
return {
preview: preview,
error: "W0020",
warningType: "version-mismatch",
maxVersionAllowed: license.payload.maxVersionAllowed
}
}
return {
preview: preview,
error: void 0
}
} catch {
return {
preview: preview,
error: "W0021",
warningType: "invalid-key"
}
}
}
export function validateLicense(licenseKey) {
let versionStr = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : fullVersion;
if (validationPerformed) {
return
}
validationPerformed = true;
const version = parseVersion(versionStr);
assertedVersionsCompatible(version);
const {
error: error,
warningType: warningType,
maxVersionAllowed: maxVersionAllowed
} = getLicenseCheckParams({
licenseKey: licenseKey,
version: version
});
if (error) {
displayTrialPanel()
}
if (error) {
if (warningType) {
const versionInfo = "version-mismatch" === warningType && void 0 !== maxVersionAllowed ? {
keyVersion: `${Math.floor(maxVersionAllowed/10)}.${maxVersionAllowed%10}`,
requiredVersion: `${version.major}.${version.minor}`
} : void 0;
logLicenseWarning(warningType, versionStr, versionInfo)
} else {
errors.log(error)
}
}
}
export function peekValidationPerformed() {
return validationPerformed
}
export function setLicenseCheckSkipCondition() {}
export default {
validateLicense: validateLicense
};