UNPKG

@lefe-dev/lefe-license-utils

Version:

Common scripts for license generator and license verifyer

1 lines 4.05 kB
!function(e,o){if("object"==typeof exports&&"object"==typeof module)module.exports=o();else if("function"==typeof define&&define.amd)define([],o);else{var n=o();for(var i in n)("object"==typeof exports?exports:e)[i]=n[i]}}(this,(()=>(()=>{"use strict";var e={d:(o,n)=>{for(var i in n)e.o(n,i)&&!e.o(o,i)&&Object.defineProperty(o,i,{enumerable:!0,get:n[i]})},o:(e,o)=>Object.prototype.hasOwnProperty.call(e,o),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},o={};e.r(o),e.d(o,{LICENSE_STATUS:()=>s,LICENSING_MODELS:()=>l,base64Decode:()=>i,base64Encode:()=>r,findScopeNode:()=>m,md5:()=>c,showExpiredSubscriptionGraceLicenseKeyError:()=>h,showExpiredSubscriptionLicenseKeyError:()=>y,showInvalidLicenseKeyError:()=>d,showLicenseKeyScopeError:()=>u,showMissingLicenseKeyError:()=>f});const n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",i=e=>{let o,i,r,t,a,c,s,l="",p=0;for(e=e.replace(/[^A-Za-z0-9+/=]/g,"");p<e.length;)t=n.indexOf(e.charAt(p++)),a=n.indexOf(e.charAt(p++)),c=n.indexOf(e.charAt(p++)),s=n.indexOf(e.charAt(p++)),o=t<<2|a>>4,i=(15&a)<<4|c>>2,r=(3&c)<<6|s,l+=String.fromCharCode(o),64!=c&&(l+=String.fromCharCode(i)),64!=s&&(l+=String.fromCharCode(r));return l},r=e=>{let o,i,r,t,a,c,s,l="",p=0;for(e=function(e){for(let o=0;o<e.length;o++)if(e.charCodeAt(o)>=128)throw new Error("ASCII only support");return e}(e);p<e.length;)o=e.charCodeAt(p++),i=e.charCodeAt(p++),r=e.charCodeAt(p++),t=o>>2,a=(3&o)<<4|i>>4,c=(15&i)<<2|r>>6,s=63&r,isNaN(i)?c=s=64:isNaN(r)&&(s=64),l=l+n.charAt(t)+n.charAt(a)+n.charAt(c)+n.charAt(s);return l},t=[];let a=0;for(;a<64;)t[a]=0|4294967296*Math.sin(++a%Math.PI);function c(e){const o=[];let n,i,r,c=unescape(encodeURI(e))+"€",s=c.length;const l=[n=1732584193,i=4023233417,~n,~i];for(e=--s/4+2|15,o[--e]=8*s;~s;)o[s>>2]|=c.charCodeAt(s)<<8*s--;for(a=c=0;a<e;a+=16){for(s=l;c<64;s=[r=s[3],n+((r=s[0]+[n&i|~n&r,r&n|~r&i,n^i^r,i^(n|~r)][s=c>>4]+t[c]+~~o[a|15&[c,5*c+1,3*c+5,7*c][s]])<<(s=[7,12,17,22,5,9,14,20,4,11,16,23,6,10,15,21][4*s+c++%4])|r>>>-s),n,i])n=0|s[1],i=s[2];for(c=4;c;)l[--c]+=s[c]}for(e="";c<32;)e+=(l[c>>3]>>4*(1^c++)&15).toString(16);return e}var s;!function(e){e.NotFound="NotFound",e.Invalid="Invalid",e.ExpiredSubscription="ExpiredSubscription",e.ExpiredSubscriptionGrace="ExpiredSubscriptionGrace",e.Valid="Valid",e.OutOfScope="OutOfScope",e.InvalidDomain="InvalidDomain"}(s||(s={}));const l=["perpetual","subscription"];function p(e){console.error(["*************************************************************","",...e,"","*************************************************************"].join("\n"))}function d({organization:e}){p([`${e}: Invalid license key.`,"","Your icense key isn't valid.","","To solve the issue, you need to double check that `setLicenseKey()` is called with the right argument"])}function u({organization:e,packageName:o}){p([`${e}: License key plan mismatch.`,"",`Your use of ${o} is not compatible with the plan of your license key. The feature you are trying to use is not included in the plan of your license key.`])}function f({packageName:e,organization:o,scope:n}){p([`${o}: Missing license key.`,"",`The license key is missing. You might not be allowed to use \`${e}\` which is part of ${n} plan.`,"",`You need to purchase a license https://lefe.dev/${o}/license.`])}function h({scope:e,packageName:o,organization:n,licenseKey:i,expiryTimestamp:r}){p([`${n}: Expired license key.`,"",`Your subscription license key to use ${o} ${e} has expired.`,"",`- License key expiry timestamp: ${new Date(r)}`,`- Installed license key: ${i}`,""])}function y({scope:e,packageName:o,organization:n,licenseKey:i,expiryTimestamp:r}){throw new Error([`${n}: Expired license key.`,"",`Your subscription license key to use ${o} ${e} has expired.`,"",`- License key expiry timestamp: ${new Date(r)}`,`- Installed license key: ${i}`,""].join("\n"))}function m(e,o){return o?.find((({name:o,children:n})=>o===e||m(e,n)))}return o})()));