@lambda-kata/licensing 0.1.1 → 0.1.3
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/out/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var a=Object.defineProperty;var
|
|
1
|
+
"use strict";var a=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var c=(i,e)=>()=>(i&&(e=i(i=0)),e);var u=(i,e)=>{for(var t in e)a(i,t,{get:e[t],enumerable:!0})},h=(i,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of p(e))!g.call(i,s)&&s!==t&&a(i,s,{get:()=>e[s],enumerable:!(r=d(e,s))||r.enumerable});return i};var f=i=>h(a({},"__esModule",{value:!0}),i);function l(){let i=n.getInstance();i.optimizeMemoryUsage(),i.optimizeStartupTime();let e=i.getMetrics();console.log(`[PERF] Optimizations applied - Loading: ${e.loadingTime}ms, Memory: ${Math.round(e.memoryUsage/1024)}KB`)}var n,m=c(()=>{"use strict";n=class i{static instance=null;metrics;startupTime;memoryBaseline;constructor(){this.startupTime=Date.now(),this.memoryBaseline=process.memoryUsage().heapUsed,this.metrics={memoryUsage:0,loadingTime:0,activeRequests:0,cacheHitRate:0}}static getInstance(){return i.instance||(i.instance=new i),i.instance}optimizeMemoryUsage(){global.gc&&global.gc(),this.configureV8MemoryOptimizations(),this.initializeStringInterning(),this.setupMemoryMonitoring()}optimizeStartupTime(){let e=Date.now();this.precompileRegexPatterns(),this.initializeObjectPools(),this.initializeOptimizedCache(),this.warmupCodePaths();let t=Date.now();this.metrics.loadingTime=t-e,this.metrics.loadingTime>100&&console.warn(`[PERF] Startup time ${this.metrics.loadingTime}ms exceeds 100ms target`)}getMetrics(){let e=process.memoryUsage().heapUsed;return this.metrics.memoryUsage=e-this.memoryBaseline,{...this.metrics}}trackRequestStart(){this.metrics.activeRequests++}trackRequestEnd(e){this.metrics.activeRequests=Math.max(0,this.metrics.activeRequests-1);let t=.1;this.metrics.cacheHitRate=t*(e?1:0)+(1-t)*this.metrics.cacheHitRate}configureV8MemoryOptimizations(){process.env.NODE_ENV==="production"&&(process.env.NODE_OPTIONS=process.env.NODE_OPTIONS||"",["--optimize-for-size","--max-old-space-size=64","--gc-interval=100","--expose-gc"].forEach(t=>{process.env.NODE_OPTIONS.includes(t)||(process.env.NODE_OPTIONS+=` ${t}`)}))}initializeStringInterning(){let e=["Invalid account ID format","Native validator unavailable","System error","Network error","Security error","Memory allocation error"],t=new Map;e.forEach(r=>{t.set(r,r)})}setupMemoryMonitoring(){if(process.env.NODE_ENV==="test"||process.env.JEST_WORKER_ID)return;let e=setInterval(()=>{let r=process.memoryUsage().heapUsed-this.memoryBaseline;r>800*1024&&(console.warn(`[PERF] Memory usage ${Math.round(r/1024)}KB approaching 1MB limit`),global.gc&&global.gc()),this.metrics.memoryUsage=r},3e4);process.on("exit",()=>{clearInterval(e)})}precompileRegexPatterns(){let e=/^\d{12}$/;global.__VALIDATOR_REGEX_CACHE={accountId:e}}initializeObjectPools(){let e=[];for(let t=0;t<5;t++)e.push({entitled:!1,message:null,layerArn:null,expiresAt:null});global.__VALIDATOR_OBJECT_POOL={responses:e,nextIndex:0}}initializeOptimizedCache(){let e=[];for(let t=0;t<16;t++)e.push("");global.__VALIDATOR_CACHE_KEYS=e}warmupCodePaths(){(global.__VALIDATOR_REGEX_CACHE?.accountId||/^\d{12}$/).test("123456789012");let r=global.__VALIDATOR_OBJECT_POOL;if(r){let s=r.responses[0];s.entitled=!1}process.memoryUsage()}}});var E={};u(E,{NativeLicensingService:()=>o,createLicensingService:()=>y,default:()=>v});module.exports=f(E);function y(){return new o}var o,v,O=c(()=>{m();l();o=class{addon=null;addonLoadAttempted=!1;performanceOptimizer;constructor(){this.performanceOptimizer=n.getInstance()}async checkEntitlement(e){this.performanceOptimizer.trackRequestStart();try{if(!this.isValidAccountId(e))return this.logError("Invalid account ID format provided",{accountIdLength:typeof e=="string"?e.length:"not-string",accountIdType:typeof e}),this.performanceOptimizer.trackRequestEnd(!1),{entitled:!1,message:"Invalid account ID format"};if(this.addonLoadAttempted||this.loadAddon(),!this.addon)return this.logError("Native validator unavailable",{addonLoadAttempted:this.addonLoadAttempted}),this.performanceOptimizer.trackRequestEnd(!1),{entitled:!1,message:"Native validator unavailable"};let t=await this.addon.checkEntitlement(e);this.logInfo("Validation completed",{entitled:t.entitled,hasLayerArn:!!t.layerArn,hasMessage:!!t.message,hasExpiresAt:!!t.expiresAt});let s=this.performanceOptimizer.getMetrics().cacheHitRate>.3;return this.performanceOptimizer.trackRequestEnd(s),t}catch(t){return this.logError("Unexpected error during validation",{errorType:t instanceof Error?t.constructor.name:typeof t,errorMessage:this.sanitizeErrorMessage(t)}),this.performanceOptimizer.trackRequestEnd(!1),{entitled:!1,message:"System error"}}}checkEntitlementSync(e){this.performanceOptimizer.trackRequestStart();try{if(!this.isValidAccountId(e))return this.logError("Invalid account ID format provided (sync)",{accountIdLength:typeof e=="string"?e.length:"not-string",accountIdType:typeof e}),this.performanceOptimizer.trackRequestEnd(!1),{entitled:!1,message:"Invalid account ID format"};if(this.addonLoadAttempted||this.loadAddon(),!this.addon)return this.logError("Native validator unavailable (sync)",{addonLoadAttempted:this.addonLoadAttempted}),this.performanceOptimizer.trackRequestEnd(!1),{entitled:!1,message:"Native validator unavailable"};let t=this.addon.checkEntitlementSync(e);return this.logInfo("Sync validation completed",{entitled:t.entitled,hasLayerArn:!!t.layerArn,hasMessage:!!t.message,hasExpiresAt:!!t.expiresAt}),this.performanceOptimizer.trackRequestEnd(!0),t}catch(t){return this.logError("Unexpected error during sync validation",{errorType:t instanceof Error?t.constructor.name:typeof t,errorMessage:this.sanitizeErrorMessage(t)}),this.performanceOptimizer.trackRequestEnd(!1),{entitled:!1,message:"System error"}}}getPerformanceMetrics(){return this.performanceOptimizer.getMetrics()}isValidAccountId(e){return typeof e!="string"||e.length!==12?!1:/^\d{12}$/.test(e)}loadAddon(){this.addonLoadAttempted=!0;try{this.addon=require("../build/Release/lambda_kata_licensing.node"),this.logInfo("Native addon loaded successfully",{})}catch(e){this.logError("Failed to load native licensing validator",{errorType:e instanceof Error?e.constructor.name:typeof e,errorMessage:this.sanitizeErrorMessage(e)}),this.addon=null}}isProductionMode(){return process.env.NODE_ENV==="production"}sanitizeErrorMessage(e){return this.isProductionMode()?e instanceof Error?`${e.constructor.name} occurred`:"Unknown error occurred":e instanceof Error?e.message:typeof e=="string"?e:String(e)}logInfo(e,t){this.isProductionMode()?console.log(`[INFO] native-licensing-validator: ${e}`):console.log(`[INFO] native-licensing-validator: ${e}`,t)}logError(e,t){this.isProductionMode()?console.error("[ERROR] native-licensing-validator: System error occurred"):console.error(`[ERROR] native-licensing-validator: ${e}`,t)}},v=o});O();0&&(module.exports={NativeLicensingService,createLicensingService});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lambda-kata/licensing",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Tamper-resistant native licensing validator for Lambda Kata Integration",
|
|
5
5
|
"main": "out/dist/index.js",
|
|
6
6
|
"types": "out/tsc/index.d.ts",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"build:clean": "rm -rf out/ build/ prebuilt/",
|
|
35
35
|
"build:native": "node-gyp rebuild || echo 'Native build failed - addon will be unavailable'",
|
|
36
36
|
"build:native:docker": "./scripts/build-docker.sh",
|
|
37
|
-
"build:ts": "esbuild src/index.ts --bundle --platform=node --target=node18 --format=cjs --outfile=out/dist/index.js --tree-shaking=true --minify --
|
|
37
|
+
"build:ts": "esbuild src/index.ts --bundle --platform=node --target=node18 --format=cjs --outfile=out/dist/index.js --tree-shaking=true --minify --external:*.node",
|
|
38
38
|
"build:types": "tsc --emitDeclarationOnly --outDir out/tsc",
|
|
39
39
|
"build:all": "./scripts/build-all.sh",
|
|
40
40
|
"build:prebuilt": "./scripts/build-prebuilt.sh",
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"lint": "eslint src/ test/ --ext .ts",
|
|
49
49
|
"lint:fix": "eslint src/ test/ --ext .ts --fix",
|
|
50
50
|
"docs": "typedoc src/index.ts --out docs/",
|
|
51
|
-
"
|
|
52
|
-
"
|
|
51
|
+
"_install": "node scripts/install.js",
|
|
52
|
+
"_postinstall": "node scripts/postinstall.js || echo 'Postinstall script failed, using fallback mode'"
|
|
53
53
|
},
|
|
54
54
|
"files": [
|
|
55
55
|
"out/",
|
|
@@ -93,4 +93,4 @@
|
|
|
93
93
|
9
|
|
94
94
|
]
|
|
95
95
|
}
|
|
96
|
-
}
|
|
96
|
+
}
|
|
Binary file
|
|
Binary file
|