UNPKG

@material-ui/x-license

Version:
2 lines (1 loc) 2.77 kB
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 n}from"@material-ui/utils";import*as r from"react";n.__MUI_LICENSE_INFO__=n.__MUI_LICENSE_INFO__||{key:void 0,releaseInfo:void 0};class a{static getKey(){return n.__MUI_LICENSE_INFO__.key}static getReleaseInfo(){return n.__MUI_LICENSE_INFO__.releaseInfo}static setLicenseKey(e){n.__MUI_LICENSE_INFO__.key=e}static setReleaseInfo(e){n.__MUI_LICENSE_INFO__.releaseInfo=e}}function o(e){console.error(["************************************************************","*************************************************************","",...e,"","*************************************************************","*************************************************************"].join("\n"))}function s(){o(["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 l(){o(["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 c(){o(["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."])}var u;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"}(u||(u={}));const d=/^.*EXPIRY=([0-9]+),.*$/;function _(e,n){if(!e)throw new Error("Material-UI: The release information is missing. Not able to validate license.");if(!n)return u.NotFound;const r=n.substr(0,32),a=n.substr(32);if(r!==t(a))return u.Invalid;const o=i(a);let s=0;try{if(s=parseInt(o.match(d)[1],10),!s||Number.isNaN(s))return console.error("Error checking license. Expiry timestamp not found or invalid!"),u.Invalid}catch(e){return console.error("Error extracting license expiry timestamp.",e),u.Invalid}const l=parseInt(i(e),10);if(Number.isNaN(l))throw new Error("Material-UI: The release information is invalid. Not able to validate license.");return s<l?u.Expired:u.Valid}function f(){const[e,t]=r.useState(u.Invalid);return r.useEffect((()=>{const e=_(a.getReleaseInfo(),a.getKey());t(e),e===u.Invalid?s():e===u.NotFound?l():e===u.Expired&&c()}),[]),e}export{a as LicenseInfo,u as LicenseStatus,I as generateReleaseInfo,c as showExpiredLicenseError,s as showInvalidLicenseError,l as showNotFoundLicenseError,f as useLicenseVerifier,_ as verifyLicense};