@vertigis/licensing 5.1.3 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.min.js +1 -1
- package/lib/index.d.ts +8 -12
- package/lib/obfuscate.d.ts +1 -0
- package/lib/types.d.ts +30 -1
- package/package.json +1 -1
package/dist/main.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,
|
|
1
|
+
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(this,(()=>(()=>{"use strict";var e={71:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.licenseEndpoint=t.rootLicenses=t.publicKey=void 0,t.publicKey={kty:"RSA",alg:"RS256",e:"AQAB",n:"nlHt1VzvxiuksjLFPxA4609Dk5OxKsDoIq3dtXsyLvqhj5iWyCNUQR4bAW0SwPEeQVTlgX14gktc6PYlTpTwkqf__PBU32-suYxha_cZBQyG-KZJVPECzZzR21wrFYKkl7mVQBvPPS8XckDGL8EOW1XadTWYBebTpSk8HeaTZgRkJNi4X2a0i3ZrU39FT730BcZ4oWwpeYJYkE_jrb0KgUT0bAdQfoAgaiHDe8RopKNctOL2nfy6clVKDrMQnmVsUatc-Uc1vRIxD-vexp9waUxj_pFYkyH6zSLCcx54N2hWiY60H6H0mP7ym4Z6yaos4BYR_6U1AIVVxal6hfuOgQ"},t.rootLicenses=[{signerToken:"3q4GGyI1VbSeUUTBQS36XyZ2OAYwoGZTZ_fDAX6ivPY",validUntil:"2019-06-01T00:00:00Z"}],t.licenseEndpoint="https://licensing.geocortex.com/licenses"},208:(e,t)=>{var r;Object.defineProperty(t,"__esModule",{value:!0}),t.getExtendedLicenseInfo=t.LicenseState=void 0,function(e){e.NO_LICENSE="noLicense",e.VALID_TRIAL="validTrial",e.EXPIRED_TRIAL="expiredTrial",e.VALID_LICENSE="validLicense",e.VALID_LICENSE_WARN_LEVEL_1="validLicenseWarnLevel1",e.VALID_LICENSE_WARN_LEVEL_2="validLicenseWarnLevel2",e.INVALID_LICENSE_WARN_LEVEL_1="invalidLicenseWarnLevel1",e.INVALID_LICENSE_WARN_LEVEL_2="invalidLicenseWarnLevel2",e.INVALID_LICENSE_WARN_LEVEL_3="invalidLicenseWarnLevel3"}(r||(t.LicenseState=r={})),t.getExtendedLicenseInfo=function(e){let t=r.NO_LICENSE,n=Number(e.daysUntilExpiry);const i=Number(e.daysSinceExpiry);let s,o;return e.expires&&(e.isEval?n>0?(t=r.VALID_TRIAL,n>60&&(n=60)):t=r.EXPIRED_TRIAL:n>0?t=n>60?r.VALID_LICENSE:n>30?r.VALID_LICENSE_WARN_LEVEL_1:r.VALID_LICENSE_WARN_LEVEL_2:i>0&&(i>90?t=r.INVALID_LICENSE_WARN_LEVEL_3:i>60?(t=r.INVALID_LICENSE_WARN_LEVEL_2,o=91-i):(t=r.INVALID_LICENSE_WARN_LEVEL_1,o=91-i,s=61-i))),{isAccessRestricted:t===r.NO_LICENSE||t===r.INVALID_LICENSE_WARN_LEVEL_3||t===r.EXPIRED_TRIAL,state:t,daysUntilExpiry:n,daysUntilAccessBlocked:o,daysUntilUserNotification:s}}},211:(e,t)=>{function r(e,t,r){var n;if(void 0===r&&(r={}),!t.codes){t.codes={};for(var i=0;i<t.chars.length;++i)t.codes[t.chars[i]]=i}if(!r.loose&&e.length*t.bits&7)throw new SyntaxError("Invalid padding");for(var s=e.length;"="===e[s-1];)if(--s,!(r.loose||(e.length-s)*t.bits&7))throw new SyntaxError("Invalid padding");for(var o=new(null!=(n=r.out)?n:Uint8Array)(s*t.bits/8|0),a=0,c=0,l=0,u=0;u<s;++u){var d=t.codes[e[u]];if(void 0===d)throw new SyntaxError("Invalid character "+e[u]);c=c<<t.bits|d,(a+=t.bits)>=8&&(a-=8,o[l++]=255&c>>a)}if(a>=t.bits||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return o}function n(e,t,r){void 0===r&&(r={});for(var n=r.pad,i=void 0===n||n,s=(1<<t.bits)-1,o="",a=0,c=0,l=0;l<e.length;++l)for(c=c<<8|255&e[l],a+=8;a>t.bits;)a-=t.bits,o+=t.chars[s&c>>a];if(a&&(o+=t.chars[s&c<<t.bits-a]),i)for(;o.length*t.bits&7;)o+="=";return o}Object.defineProperty(t,"__esModule",{value:!0});var i={chars:"0123456789ABCDEF",bits:4},s={chars:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bits:5},o={chars:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bits:5},a={chars:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bits:6},c={chars:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bits:6},l={parse:function(e,t){return r(e.toUpperCase(),i,t)},stringify:function(e,t){return n(e,i,t)}},u={parse:function(e,t){return void 0===t&&(t={}),r(t.loose?e.toUpperCase().replace(/0/g,"O").replace(/1/g,"L").replace(/8/g,"B"):e,s,t)},stringify:function(e,t){return n(e,s,t)}},d={parse:function(e,t){return r(e,o,t)},stringify:function(e,t){return n(e,o,t)}},f={parse:function(e,t){return r(e,a,t)},stringify:function(e,t){return n(e,a,t)}},p={parse:function(e,t){return r(e,c,t)},stringify:function(e,t){return n(e,c,t)}},E={parse:r,stringify:n};t.base16=l,t.base32=u,t.base32hex=d,t.base64=f,t.base64url=p,t.codec=E},323:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.error=void 0,t.error=console.error},340:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0})},361:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.LicenseToken=void 0;const n=r(211),i=r(71);function s(e){return n.base64url.parse(e,{loose:!0})}t.LicenseToken=class{constructor(){this.licenses=[],this.accountId="",this.agolOrgs=[]}init(e){return new Promise(((t,r)=>{(function(e){if("undefined"!=typeof window&&!window.isSecureContext)return Promise.resolve(!0);const t=e.lastIndexOf("."),r=e.substr(t+1),n=e.substr(0,t),o=s(r),a=(new TextEncoder).encode(n);return window?.crypto?.subtle.importKey("jwk",i.publicKey,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]).then((e=>window?.crypto?.subtle.verify("RSASSA-PKCS1-v1_5",e,o,a)))})(e).then((n=>{n||r("JWT verification failed.");const i=function(e){const t=e.indexOf(".")+1,r=e.lastIndexOf(".")-t,n=(i=s(e.substr(t,r)),new TextDecoder("utf-8").decode(i));var i;return function(e,t){if(null==e)throw new Error(t);if("string"==typeof e&&e.length<1)throw new Error(t);if(!1===e)throw new Error(t);return e}(JSON.parse(n),"JWT payload is invalid.")}(e);this.licenses=i.licenses||[],this.accountId=i.accountId||"",this.agolOrgs=i.agolOrgs||[],t()}),(e=>r(e)))}))}isLicenseFor(e,t){return"string"!=typeof e.signerToken&&(void 0===e.sku||!t.sku||("string"==typeof t.sku?-1!==e.sku.indexOf(t.sku):t.sku instanceof RegExp&&t.sku.test(e.sku)))}findLicensesFor(e){const t=[];if("string"!=typeof e.sku&&!(e.sku instanceof RegExp))return t;if(!Array.isArray(e.roots))return t;for(const r of this.licenses)this.isLicenseFor(r,e)&&t.push(r);return t}}},509:function(e,t,r){var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var i=Object.getOwnPropertyDescriptor(t,r);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,i)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),i=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),t.getLicenseInfo=t.validateJwt=t.validate=t.clearCache=void 0;const s=r(323),o=r(71),a=r(361),c=r(667);let l;function u(e,t=/^((?!-EVAL).)+$/){return new Promise(((r,n)=>{if(!e)return r({error:{message:"Invalid license JWT"},isEval:!1,isValid:!1});(function(e,t){return new Promise((r=>{if("string"!=typeof e)return r(void 0);const n=o.rootLicenses,i={sku:t,roots:n},c=new a.LicenseToken;c.init(e).then((()=>r({licenses:c.findLicensesFor(i),accountId:c.accountId,agolOrgs:c.agolOrgs}))).catch((e=>((0,s.error)("Error while processing licenses",e),r(void 0))))}))})(e,t).then((e=>{if(!e)return r({error:{message:"Failed to retrieve licenses from JWT"},isEval:!1,isValid:!1});const t=d(e.licenses);t.accountId=e.accountId,t.agolOrgs=e.agolOrgs,r(t)})).catch((e=>n(e)))}))}function d(e){let t,r,n=!1,i=!1;if(!e||0===e.length)return{expires:t,isEval:n,isValid:i,sku:r};const s=new Date;let o,a;for(const c of e){const e=/-EVAL$/.test(c.sku),l=c.validFrom?new Date(c.validFrom):s,u=new Date(c.validUntil);isFinite(l.valueOf())&&l.valueOf()>s.valueOf()?(!o||o>l)&&(o=l,a=u):(u>s&&(i=!0),t?u>t&&(t=u,n=e,r=c.sku):(t=u,n=e,r=c.sku))}let c,l;if(o&&a&&t&&o.valueOf()-t.valueOf()<=1728e5&&(t=a),t){const e=t.valueOf()-s.valueOf();c=Math.ceil(e/864e5),e<0&&(l=Math.abs(c)+1,c=void 0)}return{expires:t,isEval:n,isValid:i,sku:r,daysUntilExpiry:c,daysSinceExpiry:l}}i(r(340),t),i(r(208),t),t.clearCache=function(){l={}},t.validate=async function({sku:e,orgId:t,isDesigner:r,portalUrl:n,userName:i,useCache:s=!0}){if(!t||!n)return{error:{message:"An orgId and a portalUrl must be provided to evaluate a license."},isEval:!1,isValid:!1};const a=new URL(`${o.licenseEndpoint}/${t}`),d=await(0,c.default)(n),f=await(0,c.default)(i);a.searchParams.append("sku",e??"ANY-VALID-NON-EVAL"),f&&a.searchParams.append("user",f),d&&a.searchParams.append("portal",d),r&&a.searchParams.append("designer","true");const p=await async function(e,t,r){return new Promise(((n,i)=>{if(r&&l&&t&&l[t])return n(l[t]());const s=new XMLHttpRequest;s.onload=()=>{if(200===s.status){let e;if(e=String(s.responseText),"{"===e[0])try{const i=JSON.parse(e);e=i.jwt,t&&r&&(l||(l={}),l[t]=function(){return e}),n(e)}catch(e){n(void 0)}else e=e.replace(/\s+/g,""),t&&r&&(l||(l={}),l[t]=function(){return e}),n(e)}else n(void 0)},s.onerror=e=>i("The request to fetch the license failed."),s.ontimeout=e=>i("The request to fetch the license timed out"),s.onabort=e=>i("The license request was aborted"),s.open("GET",e,!0),s.send()}))}(a.toString(),f??t,s);return p?u(p,e):{error:{message:"Failed to retrieve JWT"},isEval:!1,isValid:!1}},t.validateJwt=u,t.getLicenseInfo=d},667:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});t.default=async function(e){if(e)return function(e){const t=new Uint8Array(e),r=(e,r)=>[...t.slice(e,r)].map((e=>e.toString(16).padStart(2,"0"))).join("");let n=0;return[r(n,n+=4),r(n,n+=2),r(n,n+=2),r(n,n+=2),r(n,n+=6)].join("-")}(await async function(e){return window?.crypto?.subtle.digest("SHA-256",e)}(function(e){const t=(new TextEncoder).encode(e+" "),r=Array.from(t,(e=>String.fromCodePoint(e))).join(""),n=btoa(r);return Uint8Array.from(n,(e=>e.codePointAt(0)))}(e)))}}},t={};return function r(n){var i=t[n];if(void 0!==i)return i.exports;var s=t[n]={exports:{}};return e[n].call(s.exports,s,s.exports,r),s.exports}(509)})()));
|
package/lib/index.d.ts
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { License, LicenseInfo, ValidateLicenseArgs } from "./types";
|
|
2
2
|
export * from "./types";
|
|
3
3
|
export * from "./extended";
|
|
4
|
-
export declare function
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}): Promise<LicenseInfo>;
|
|
12
|
-
export declare function validateJwt(jwt: string, sku: string | RegExp, opts?: {
|
|
13
|
-
cryptoApi?: CryptoApi;
|
|
14
|
-
}): Promise<LicenseInfo>;
|
|
4
|
+
export declare function validate({ sku, orgId, isDesigner, portalUrl, userName, useCache, }: ValidateLicenseArgs): Promise<LicenseInfo>;
|
|
5
|
+
/**
|
|
6
|
+
* If no SKU is provided this will validate using any non-EVAL SKU. This is
|
|
7
|
+
* required for add-on products that aren't tied to any particular SKU but
|
|
8
|
+
* require a license, eg: Item Manager
|
|
9
|
+
*/
|
|
10
|
+
export declare function validateJwt(jwt: string, sku?: string | RegExp): Promise<LicenseInfo>;
|
|
15
11
|
/**
|
|
16
12
|
* Returns a LicenseInfo model from a collection of Licenses.
|
|
17
13
|
* @param licenses The licenses.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function obfuscate(input?: string): Promise<string | undefined>;
|
package/lib/types.d.ts
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
1
|
+
export interface ValidateLicenseArgs {
|
|
2
|
+
/**
|
|
3
|
+
* The SKU to evaluate. Leaving this undefined will evaluate any non EVAL
|
|
4
|
+
* SKU.
|
|
5
|
+
*/
|
|
6
|
+
sku: string | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* The org that is being evaluated.
|
|
9
|
+
*/
|
|
10
|
+
orgId: string;
|
|
11
|
+
/**
|
|
12
|
+
* Flag license requests coming from designer apps. For logging purposes
|
|
13
|
+
* only.
|
|
14
|
+
*/
|
|
15
|
+
isDesigner?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* The portal associated with this request. For logging purposes only.
|
|
18
|
+
*/
|
|
19
|
+
portalUrl: string;
|
|
20
|
+
/**
|
|
21
|
+
* The unique user associated with this request. The string provided will be
|
|
22
|
+
* obfuscated and logged.
|
|
23
|
+
*/
|
|
24
|
+
userName: string | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Prevent refetching the license if requested in the same session. The
|
|
27
|
+
* cache will be keyed by user if set, by org otherwise.
|
|
28
|
+
*/
|
|
29
|
+
useCache?: boolean;
|
|
30
|
+
}
|
|
1
31
|
export interface LicenseInfo {
|
|
2
32
|
/** Whether there were any errors trying to retrieve the license. */
|
|
3
33
|
error?: {
|
|
@@ -42,4 +72,3 @@ export interface LicenseError {
|
|
|
42
72
|
message: string;
|
|
43
73
|
exception: Error;
|
|
44
74
|
}
|
|
45
|
-
export type CryptoApi = Pick<SubtleCrypto, "importKey" | "verify">;
|