@material-ui/x-license
Version:
Material-UI X License verification
2 lines (1 loc) • 2.74 kB
JavaScript
import{b as e,m as t,a as i}from"./generateLicense-4c697767.js";export{g as generateLicence}from"./generateLicense-4c697767.js";import{ponyfillGlobal as r}from"@material-ui/utils";import*as n from"react";r.__MUI_LICENSE_INFO__=r.__MUI_LICENSE_INFO__||{key:void 0,releaseInfo:void 0};class o{static getKey(){return r.__MUI_LICENSE_INFO__.key}static getReleaseInfo(){return r.__MUI_LICENSE_INFO__.releaseInfo}static setLicenseKey(e){r.__MUI_LICENSE_INFO__.key=e}static setReleaseInfo(e){r.__MUI_LICENSE_INFO__.releaseInfo=e}}var a;function s(e){console.error(["************************************************************","*************************************************************","",...e,"","*************************************************************","*************************************************************"].join("\n"))}function l(){s(["Material-UI X: Invalid license.","","Your license for Material-UI X is not valid, please visit","https://material-ui.com/r/x-license to get a valid license."])}function c(){s(["Material-UI X: License key not found.","","This is a trial-only version of Material-UI X.","While all the features are unlocked, it is not licensed for","development use on projects intended for production.","","To purchase a license, please visit","https://material-ui.com/r/x-license to get a valid license."])}function u(){s(["Material-UI X: License key expired.","","Please visit https://material-ui.com/r/x-license to renew","your subscription and get the latest version of Material-UI X."])}function I(){const t=new Date;return t.setHours(0,0,0,0),e(t.getTime().toString())}!function(e){e.NotFound="NotFound",e.Invalid="Invalid",e.Expired="Expired",e.Valid="Valid"}(a||(a={}));const d=/^.*EXPIRY=([0-9]+),.*$/;function _(e,r){if(!e)throw new Error("Material-UI: The release information is missing. Not able to validate license.");if(!r)return a.NotFound;const n=r.substr(0,32),o=r.substr(32);if(n!==t(o))return a.Invalid;const s=i(o);let l=0;try{if(l=parseInt(s.match(d)[1],10),!l||Number.isNaN(l))return console.error("Error checking license. Expiry timestamp not found or invalid!"),a.Invalid}catch(e){return console.error("Error extracting license expiry timestamp.",e),a.Invalid}const c=parseInt(i(e),10);if(Number.isNaN(c))throw new Error("Material-UI: The release information is invalid. Not able to validate license.");return l<c?a.Expired:a.Valid}function f(){return n.useMemo((()=>{const e=_(o.getReleaseInfo(),o.getKey());return e===a.Invalid?l():e===a.NotFound?c():e===a.Expired&&u(),e}),[])}export{o as LicenseInfo,a as LicenseStatus,I as generateReleaseInfo,u as showExpiredLicenseError,l as showInvalidLicenseError,c as showNotFoundLicenseError,f as useLicenseVerifier,_ as verifyLicense};