@vertigis/licensing 5.1.1
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 -0
- package/lib/LicenseToken.d.ts +1 -0
- package/lib/extended.d.ts +43 -0
- package/lib/index.d.ts +19 -0
- package/lib/log.d.ts +4 -0
- package/lib/stock.d.ts +2 -0
- package/lib/types.d.ts +45 -0
- package/package.json +40 -0
package/dist/main.min.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e,r){if("object"==typeof exports&&"object"==typeof module)module.exports=r();else if("function"==typeof define&&define.amd)define([],r);else{var t=r();for(var n in t)("object"==typeof exports?exports:e)[n]=t[n]}}(self,(()=>(()=>{"use strict";var e={802:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.LicenseToken=void 0;const n=t(352),i=t(119);function s(e){return n.base64url.parse(e,{loose:!0})}r.LicenseToken=class{constructor(){this.licenses=[],this.accountId="",this.agolOrgs=[]}init(e,r){return new Promise(((t,n)=>{(function(e,r){if(!r)return Promise.resolve(!0);if("undefined"!=typeof window&&!window.isSecureContext)return Promise.resolve(!0);const t=e.lastIndexOf("."),n=e.substr(t+1),o=e.substr(0,t),a=s(n),c=(new TextEncoder).encode(o);return r.importKey("jwk",i.publicKey,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]).then((e=>r.verify("RSASSA-PKCS1-v1_5",e,a,c)))})(e,r).then((r=>{r||n("JWT verification failed.");const i=function(e){const r=e.indexOf(".")+1,t=e.lastIndexOf(".")-r,n=(i=s(e.substr(r,t)),new TextDecoder("utf-8").decode(i));var i;return function(e,r){if(null==e)throw new Error(r);if("string"==typeof e&&e.length<1)throw new Error(r);if(!1===e)throw new Error(r);return e}(JSON.parse(n),"JWT payload is invalid.")}(e);this.licenses=i.licenses||[],this.accountId=i.accountId||"",this.agolOrgs=i.agolOrgs||[],t()}),(e=>n(e)))}))}isLicenseFor(e,r){return"string"!=typeof e.signerToken&&(void 0===e.sku||!r.sku||("string"==typeof r.sku?-1!==e.sku.indexOf(r.sku):r.sku instanceof RegExp&&r.sku.test(e.sku)))}findLicensesFor(e){const r=[];if("string"!=typeof e.sku&&!(e.sku instanceof RegExp))return r;if(!Array.isArray(e.roots))return r;for(const t of this.licenses)this.isLicenseFor(t,e)&&r.push(t);return r}}},276:(e,r)=>{var t;Object.defineProperty(r,"__esModule",{value:!0}),r.getExtendedLicenseInfo=r.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"}(t||(r.LicenseState=t={})),r.getExtendedLicenseInfo=function(e){let r=t.NO_LICENSE,n=Number(e.daysUntilExpiry);const i=Number(e.daysSinceExpiry);let s,o;return e.expires&&(e.isEval?n>0?(r=t.VALID_TRIAL,n>60&&(n=60)):r=t.EXPIRED_TRIAL:n>0?r=n>60?t.VALID_LICENSE:n>30?t.VALID_LICENSE_WARN_LEVEL_1:t.VALID_LICENSE_WARN_LEVEL_2:i>0&&(i>90?r=t.INVALID_LICENSE_WARN_LEVEL_3:i>60?(r=t.INVALID_LICENSE_WARN_LEVEL_2,o=91-i):(r=t.INVALID_LICENSE_WARN_LEVEL_1,o=91-i,s=61-i))),{isAccessRestricted:r===t.NO_LICENSE||r===t.INVALID_LICENSE_WARN_LEVEL_3||r===t.EXPIRED_TRIAL,state:r,daysUntilExpiry:n,daysUntilAccessBlocked:o,daysUntilUserNotification:s}}},568:function(e,r,t){var n=this&&this.__createBinding||(Object.create?function(e,r,t,n){void 0===n&&(n=t);var i=Object.getOwnPropertyDescriptor(r,t);i&&!("get"in i?!r.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,n,i)}:function(e,r,t,n){void 0===n&&(n=t),e[n]=r[t]}),i=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(r,t)||n(r,e,t)};Object.defineProperty(r,"__esModule",{value:!0}),r.getLicenseInfo=r.validateJwt=r.validate=r.clearCache=void 0;const s=t(853),o=t(119),a=t(802);let c;function l(e,r,t={}){return new Promise(((n,i)=>{if(!e)return n({error:{message:"Invalid license JWT"},isEval:!1,isValid:!1});const c=t.cryptoApi||window?.crypto?.subtle;(function(e,r,t){return new Promise((n=>{if("string"!=typeof e)return n(void 0);const i=o.rootLicenses,c={sku:r,roots:i},l=new a.LicenseToken;l.init(e,t).then((()=>n({licenses:l.findLicensesFor(c),accountId:l.accountId,agolOrgs:l.agolOrgs}))).catch((e=>((0,s.error)("Error while processing licenses",e),n(void 0))))}))})(e,r,c).then((e=>{if(!e)return n({error:{message:"Failed to retrieve licenses from JWT"},isEval:!1,isValid:!1});const r=u(e.licenses);r.accountId=e.accountId,r.agolOrgs=e.agolOrgs,n(r)})).catch((e=>i(e)))}))}function u(e){let r,t,n=!1,i=!1;if(!e||0===e.length)return{expires:r,isEval:n,isValid:i,sku:t};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),r?u>r&&(r=u,n=e,t=c.sku):(r=u,n=e,t=c.sku))}let c,l;if(o&&a&&r&&o.valueOf()-r.valueOf()<=1728e5&&(r=a),r){const e=r.valueOf()-s.valueOf();c=Math.ceil(e/864e5),e<0&&(l=Math.abs(c)+1,c=void 0)}return{expires:r,isEval:n,isValid:i,sku:t,daysUntilExpiry:c,daysSinceExpiry:l}}i(t(230),r),i(t(276),r),r.clearCache=function(){c={}},r.validate=function(e){return new Promise(((r,t)=>{if(void 0===e.useCache&&(e.useCache=!0),!e.url&&!e.orgId)return r({error:{message:"Either an orgId, or url need to be provided"},isEval:!1,isValid:!1});var n,i;e.url||(e.url=`${o.licenseEndpoint}/${e.orgId}`),(n=e.url,i=e.useCache,new Promise(((e,r)=>{const t=n.match(/licenses\/?(.*)/i);if(i&&c&&t&&c[t[1]])return e(c[t[1]]());const s=new XMLHttpRequest;s.onload=()=>{if(200===s.status){let r;if(r=String(s.responseText),"{"===r[0])try{const n=JSON.parse(r);r=n.jwt,t&&i&&(c||(c={}),c[t[1]]=function(){return r}),e(r)}catch(r){e(void 0)}else r=r.replace(/\s+/g,""),t&&i&&(c||(c={}),c[t[1]]=function(){return r}),e(r)}else e(void 0)},s.onerror=e=>r("The request to fetch the license failed."),s.ontimeout=e=>r("The request to fetch the license timed out"),s.onabort=e=>r("The license request was aborted"),s.open("GET",n,!0),s.send()}))).then((r=>r?l(r,e.sku,{cryptoApi:e.cryptoApi}):{error:{message:"Failed to retrieve JWT"},isEval:!1,isValid:!1})).then((e=>r(e))).catch((e=>t(e)))}))},r.validateJwt=l,r.getLicenseInfo=u},853:(e,r)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.error=void 0,r.error=console.error},119:(e,r)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.licenseEndpoint=r.rootLicenses=r.publicKey=void 0,r.publicKey={kty:"RSA",alg:"RS256",e:"AQAB",n:"nlHt1VzvxiuksjLFPxA4609Dk5OxKsDoIq3dtXsyLvqhj5iWyCNUQR4bAW0SwPEeQVTlgX14gktc6PYlTpTwkqf__PBU32-suYxha_cZBQyG-KZJVPECzZzR21wrFYKkl7mVQBvPPS8XckDGL8EOW1XadTWYBebTpSk8HeaTZgRkJNi4X2a0i3ZrU39FT730BcZ4oWwpeYJYkE_jrb0KgUT0bAdQfoAgaiHDe8RopKNctOL2nfy6clVKDrMQnmVsUatc-Uc1vRIxD-vexp9waUxj_pFYkyH6zSLCcx54N2hWiY60H6H0mP7ym4Z6yaos4BYR_6U1AIVVxal6hfuOgQ"},r.rootLicenses=[{signerToken:"3q4GGyI1VbSeUUTBQS36XyZ2OAYwoGZTZ_fDAX6ivPY",validUntil:"2019-06-01T00:00:00Z"}],r.licenseEndpoint="https://licensing.geocortex.com/licenses"},230:(e,r)=>{Object.defineProperty(r,"__esModule",{value:!0})},352:(e,r)=>{function t(e,r,t){var n;if(void 0===t&&(t={}),!r.codes){r.codes={};for(var i=0;i<r.chars.length;++i)r.codes[r.chars[i]]=i}if(!t.loose&&e.length*r.bits&7)throw new SyntaxError("Invalid padding");for(var s=e.length;"="===e[s-1];)if(--s,!(t.loose||(e.length-s)*r.bits&7))throw new SyntaxError("Invalid padding");for(var o=new(null!=(n=t.out)?n:Uint8Array)(s*r.bits/8|0),a=0,c=0,l=0,u=0;u<s;++u){var d=r.codes[e[u]];if(void 0===d)throw new SyntaxError("Invalid character "+e[u]);c=c<<r.bits|d,(a+=r.bits)>=8&&(a-=8,o[l++]=255&c>>a)}if(a>=r.bits||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return o}function n(e,r,t){void 0===t&&(t={});for(var n=t.pad,i=void 0===n||n,s=(1<<r.bits)-1,o="",a=0,c=0,l=0;l<e.length;++l)for(c=c<<8|255&e[l],a+=8;a>r.bits;)a-=r.bits,o+=r.chars[s&c>>a];if(a&&(o+=r.chars[s&c<<r.bits-a]),i)for(;o.length*r.bits&7;)o+="=";return o}Object.defineProperty(r,"__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,r){return t(e.toUpperCase(),i,r)},stringify:function(e,r){return n(e,i,r)}},u={parse:function(e,r){return void 0===r&&(r={}),t(r.loose?e.toUpperCase().replace(/0/g,"O").replace(/1/g,"L").replace(/8/g,"B"):e,s,r)},stringify:function(e,r){return n(e,s,r)}},d={parse:function(e,r){return t(e,o,r)},stringify:function(e,r){return n(e,o,r)}},f={parse:function(e,r){return t(e,a,r)},stringify:function(e,r){return n(e,a,r)}},v={parse:function(e,r){return t(e,c,r)},stringify:function(e,r){return n(e,c,r)}},E={parse:t,stringify:n};r.base16=l,r.base32=u,r.base32hex=d,r.base64=f,r.base64url=v,r.codec=E}},r={};return function t(n){var i=r[n];if(void 0!==i)return i.exports;var s=r[n]={exports:{}};return e[n].call(s.exports,s,s.exports,t),s.exports}(568)})()));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { LicenseInfo } from "./index";
|
|
2
|
+
export declare enum LicenseState {
|
|
3
|
+
NO_LICENSE = "noLicense",
|
|
4
|
+
VALID_TRIAL = "validTrial",
|
|
5
|
+
EXPIRED_TRIAL = "expiredTrial",
|
|
6
|
+
VALID_LICENSE = "validLicense",
|
|
7
|
+
VALID_LICENSE_WARN_LEVEL_1 = "validLicenseWarnLevel1",
|
|
8
|
+
VALID_LICENSE_WARN_LEVEL_2 = "validLicenseWarnLevel2",
|
|
9
|
+
INVALID_LICENSE_WARN_LEVEL_1 = "invalidLicenseWarnLevel1",
|
|
10
|
+
INVALID_LICENSE_WARN_LEVEL_2 = "invalidLicenseWarnLevel2",
|
|
11
|
+
INVALID_LICENSE_WARN_LEVEL_3 = "invalidLicenseWarnLevel3"
|
|
12
|
+
}
|
|
13
|
+
export interface ExtendedLicenseInfo {
|
|
14
|
+
/**
|
|
15
|
+
* The state of the license
|
|
16
|
+
*/
|
|
17
|
+
state: LicenseState;
|
|
18
|
+
/**
|
|
19
|
+
* The number of days until expiry. Only to be used for display purposes.
|
|
20
|
+
*/
|
|
21
|
+
daysUntilExpiry?: number;
|
|
22
|
+
/**
|
|
23
|
+
* The number of days until end users are notified of an expired license.
|
|
24
|
+
* Only to be used for display purposes.
|
|
25
|
+
*/
|
|
26
|
+
daysUntilUserNotification?: number;
|
|
27
|
+
/**
|
|
28
|
+
* The number of days until access blocked. Only to be used for display
|
|
29
|
+
* purposes.
|
|
30
|
+
*/
|
|
31
|
+
daysUntilAccessBlocked?: number;
|
|
32
|
+
/**
|
|
33
|
+
* Whether the license should be restricted access to the consuming
|
|
34
|
+
* application.
|
|
35
|
+
*/
|
|
36
|
+
isAccessRestricted: boolean;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Gets extended license information from a license.
|
|
40
|
+
* @param licenseInfo
|
|
41
|
+
* @returns the extended license information.
|
|
42
|
+
*/
|
|
43
|
+
export declare function getExtendedLicenseInfo(licenseInfo: LicenseInfo): ExtendedLicenseInfo;
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { CryptoApi, License, LicenseInfo } from "./types";
|
|
2
|
+
export * from "./types";
|
|
3
|
+
export * from "./extended";
|
|
4
|
+
export declare function clearCache(): void;
|
|
5
|
+
export declare function validate(args: {
|
|
6
|
+
sku: string | RegExp;
|
|
7
|
+
cryptoApi?: CryptoApi;
|
|
8
|
+
orgId?: string;
|
|
9
|
+
url?: string;
|
|
10
|
+
useCache?: boolean;
|
|
11
|
+
}): Promise<LicenseInfo>;
|
|
12
|
+
export declare function validateJwt(jwt: string, sku: string | RegExp, opts?: {
|
|
13
|
+
cryptoApi?: CryptoApi;
|
|
14
|
+
}): Promise<LicenseInfo>;
|
|
15
|
+
/**
|
|
16
|
+
* Returns a LicenseInfo model from a collection of Licenses.
|
|
17
|
+
* @param licenses The licenses.
|
|
18
|
+
*/
|
|
19
|
+
export declare function getLicenseInfo(licenses: License[]): LicenseInfo;
|
package/lib/log.d.ts
ADDED
package/lib/stock.d.ts
ADDED
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export interface LicenseInfo {
|
|
2
|
+
/** Whether there were any errors trying to retrieve the license. */
|
|
3
|
+
error?: {
|
|
4
|
+
message: string;
|
|
5
|
+
};
|
|
6
|
+
/** Whether the license is valid. */
|
|
7
|
+
isValid: boolean;
|
|
8
|
+
/** Whether the license is an evaluation. */
|
|
9
|
+
isEval: boolean;
|
|
10
|
+
/** When the license expires. */
|
|
11
|
+
expires?: Date;
|
|
12
|
+
/** The Stock keeping unit of the license. E.g "SN-GCXREP-STD-SAAS-EVAL" */
|
|
13
|
+
sku?: string;
|
|
14
|
+
/** The Licensee ID / Account ID */
|
|
15
|
+
accountId?: string;
|
|
16
|
+
/** The ArcGIS Online Organizations (by Id) associated with the Licensee */
|
|
17
|
+
agolOrgs?: string[];
|
|
18
|
+
/** The number of days until expiry; partial days are rounded up. Only to be used for display purposes. */
|
|
19
|
+
daysUntilExpiry?: number;
|
|
20
|
+
/** The number of days since expiry; partial days are rounded up. Only to be used for display purposes. */
|
|
21
|
+
daysSinceExpiry?: number;
|
|
22
|
+
}
|
|
23
|
+
export interface Factors {
|
|
24
|
+
roots?: License[];
|
|
25
|
+
/** The Stock keeping unit of the license. E.g "SN-GCXREP-STD-SAAS-EVAL" */
|
|
26
|
+
sku?: string | RegExp;
|
|
27
|
+
}
|
|
28
|
+
export interface License {
|
|
29
|
+
host?: string;
|
|
30
|
+
/** The Stock keeping unit of the license. E.g "SN-GCXREP-STD-SAAS-EVAL" */
|
|
31
|
+
sku?: string;
|
|
32
|
+
signerRole?: string;
|
|
33
|
+
signerToken?: string;
|
|
34
|
+
/** When the license begins */
|
|
35
|
+
validFrom?: string;
|
|
36
|
+
/** When the license ends */
|
|
37
|
+
validUntil?: string;
|
|
38
|
+
error?: LicenseError;
|
|
39
|
+
refreshUrl?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface LicenseError {
|
|
42
|
+
message: string;
|
|
43
|
+
exception: Error;
|
|
44
|
+
}
|
|
45
|
+
export type CryptoApi = Pick<SubtleCrypto, "importKey" | "verify">;
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vertigis/licensing",
|
|
3
|
+
"version": "5.1.1",
|
|
4
|
+
"main": "./dist/main.min.js",
|
|
5
|
+
"types": "./lib/index.d.ts",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist",
|
|
8
|
+
"lib"
|
|
9
|
+
],
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"rfc4648": "^1.5.3"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@babel/core": "^7.23.6",
|
|
15
|
+
"@babel/preset-env": "^7.23.6",
|
|
16
|
+
"@babel/preset-typescript": "^7.23.3",
|
|
17
|
+
"@types/jest": "^29.5.11",
|
|
18
|
+
"@types/node": "^20.10.4",
|
|
19
|
+
"husky": "^8.0.0",
|
|
20
|
+
"jest": "^29.7.0",
|
|
21
|
+
"lint-staged": "^15.2.0",
|
|
22
|
+
"prettier": "^3.1.1",
|
|
23
|
+
"shx": "^0.3.4",
|
|
24
|
+
"typescript": "~5.3.3",
|
|
25
|
+
"webpack": "^5.89.0",
|
|
26
|
+
"webpack-cli": "^5.1.4"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "npm run tsc && webpack",
|
|
30
|
+
"prepack": "shx find ./lib | grep \"\\.js$\" | xargs rm",
|
|
31
|
+
"prepare": "cd .. && husky install",
|
|
32
|
+
"prettier": "prettier --write",
|
|
33
|
+
"test": "jest",
|
|
34
|
+
"test:watch": "npm run test -- --watch",
|
|
35
|
+
"tsc": "tsc --project tsconfig.build.json"
|
|
36
|
+
},
|
|
37
|
+
"lint-staged": {
|
|
38
|
+
"*.{js,json,ts,tsx,md,xml}": "prettier --write"
|
|
39
|
+
}
|
|
40
|
+
}
|