catalyst-core 0.0.1-beta.15 → 0.0.1-beta.17

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/changelog.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.0.1-beta.16] - 28-08-2025
4
+
5
+ - Adds SDK for Open Telemetry
6
+
7
+ ## [0.0.1-beta.15] - 1-07-2025
8
+
9
+ - Adds SDK for Sentry
10
+
3
11
  ## [0.0.1-beta.14] - 19-05-2025
4
12
 
5
13
  - Fixes header sent bug
package/dist/otel.js ADDED
@@ -0,0 +1,4 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _api=require("@opentelemetry/api");var _sdkNode=require("@opentelemetry/sdk-node");var _resources=require("@opentelemetry/resources");var _sdkTraceNode=require("@opentelemetry/sdk-trace-node");var _sdkMetrics=require("@opentelemetry/sdk-metrics");var _exporterTraceOtlpHttp=require("@opentelemetry/exporter-trace-otlp-http");var _exporterMetricsOtlpHttp=require("@opentelemetry/exporter-metrics-otlp-http");var _autoInstrumentationsNode=require("@opentelemetry/auto-instrumentations-node");var _semanticConventions=require("@opentelemetry/semantic-conventions");function init(config={}){const{serviceName="catalyst-server",serviceVersion="1.0.0",environment="development",traceUrl="http://localhost:4318/v1/traces",metricUrl="http://localhost:4318/v1/metrics",traceHeaders={},metricHeaders={},exportIntervalMillis=10000,exportTimeoutMillis=10000}=config;try{const otlpTraceExporter=new _exporterTraceOtlpHttp.OTLPTraceExporter({url:traceUrl,headers:traceHeaders});const otlpMetricExporter=new _exporterMetricsOtlpHttp.OTLPMetricExporter({url:metricUrl,headers:metricHeaders});const sdk=new _sdkNode.NodeSDK({resource:(0,_resources.resourceFromAttributes)({[_semanticConventions.ATTR_SERVICE_NAME]:serviceName,[_semanticConventions.ATTR_SERVICE_VERSION]:serviceVersion,[_semanticConventions.ATTR_DEPLOYMENT_ENVIRONMENT]:environment}),spanProcessor:new _sdkTraceNode.BatchSpanProcessor(otlpTraceExporter,{exportTimeoutMillis,scheduledDelayMillis:exportIntervalMillis,maxQueueSize:100,maxExportBatchSize:10}),metricReader:new _sdkMetrics.PeriodicExportingMetricReader({exporter:otlpMetricExporter,exportIntervalMillis}),instrumentations:[(0,_autoInstrumentationsNode.getNodeAutoInstrumentations)()]});sdk.start();logger.info("✅ OpenTelemetry started successfully");const meter=initializeCustomMetrics(serviceName,serviceVersion);const gracefulShutdown=signal=>{logger.info(`📡 Received ${signal}, shutting down OpenTelemetry gracefully...`);sdk.shutdown().then(()=>logger.info("✅ OpenTelemetry shutdown completed")).catch(error=>{logger.error("❌ Error terminating OpenTelemetry:",error);}).finally(()=>process.exit());};process.on("SIGTERM",()=>gracefulShutdown("SIGTERM"));process.on("SIGINT",()=>gracefulShutdown("SIGINT"));return{sdk,meter};}catch(error){logger.error("❌ Failed to initialize OpenTelemetry:",error);throw error;}}function initializeCustomMetrics(serviceName,serviceVersion){let customMetrics={};const meter=_api.metrics.getMeter(serviceName,serviceVersion);// CPU usage gauge
2
+ customMetrics.cpuUsage=meter.createObservableGauge("process_cpu_usage_percent",{description:"Current CPU usage percentage"});// Memory usage gauges
3
+ customMetrics.memoryUsage=meter.createObservableGauge("process_memory_usage_bytes",{description:"Current memory usage in bytes",unit:"bytes"});customMetrics.memoryHeapUsed=meter.createObservableGauge("process_memory_heap_used_bytes",{description:"Current heap memory used in bytes",unit:"bytes"});customMetrics.memoryHeapTotal=meter.createObservableGauge("process_memory_heap_total_bytes",{description:"Current heap memory total in bytes",unit:"bytes"});let lastCpuUsage=process.cpuUsage();let lastMeasureTime=process.hrtime.bigint();customMetrics.cpuUsage.addCallback(result=>{const currentCpuUsage=process.cpuUsage(lastCpuUsage);const currentTime=process.hrtime.bigint();const timeDiff=Number(currentTime-lastMeasureTime)/1000000;// Convert to milliseconds
4
+ const cpuPercent=(currentCpuUsage.user+currentCpuUsage.system)/1000/timeDiff*100;result.observe(cpuPercent);lastCpuUsage=process.cpuUsage();lastMeasureTime=currentTime;});customMetrics.memoryUsage.addCallback(result=>{const memUsage=process.memoryUsage();result.observe(memUsage.rss,{type:"rss"});result.observe(memUsage.external,{type:"external"});result.observe(memUsage.arrayBuffers,{type:"arrayBuffers"});});customMetrics.memoryHeapUsed.addCallback(result=>{const memUsage=process.memoryUsage();result.observe(memUsage.heapUsed);});customMetrics.memoryHeapTotal.addCallback(result=>{const memUsage=process.memoryUsage();result.observe(memUsage.heapTotal);});return meter;}var _default=exports.default={init};
@@ -1,3 +1,3 @@
1
- "use strict";const path=require("path");const{spawnSync}=require("child_process");const{green,cyan,yellow}=require("picocolors");const{name}=require(`${process.cwd()}/package.json`);const{BUILD_OUTPUT_PATH}=require(`${process.cwd()}/config/config.json`);const{arrayToObject,printBundleInformation}=require("./scriptUtils.js");/**
1
+ "use strict";const path=require("path");const{green,cyan,yellow}=require("picocolors");const{name}=require(`${process.cwd()}/package.json`);const{BUILD_OUTPUT_PATH}=require(`${process.cwd()}/config/config.json`);const{arrayToObject,printBundleInformation,runBuildCommands}=require("./scriptUtils.js");/**
2
2
  * @description - creates a production build of the application.
3
- */function build(){const isWindows=process.platform==="win32";const commandLineArguments=process.argv.slice(2);const argumentsObject=arrayToObject(commandLineArguments);const dirname=path.resolve(__dirname,"../../");const commands=["node ./dist/scripts/checkVersion",`${isWindows?"rd -r -fo":"rm -rf"} ${process.cwd()}/${BUILD_OUTPUT_PATH} & node ./dist/scripts/loadScriptsBeforeServerStarts.js`,`cross-env APPLICATION=${name||"catalyst_app"} webpack --config ./dist/webpack/production.client.babel.js --progress`,`cross-env APPLICATION=${name||"catalyst_app"} SSR=true webpack --config ./dist/webpack/production.ssr.babel.js`,`cross-env APPLICATION=${name||"catalyst_app"} npx babel ./dist/server --out-dir ${process.cwd()}/${BUILD_OUTPUT_PATH} --ignore '**/*.test.js,./dist/server/renderer/handler.js' --quiet`,`cross-env APPLICATION=${name||"catalyst_app"} npx babel ${process.cwd()}/server --out-dir ${process.cwd()}/${BUILD_OUTPUT_PATH} --quiet`];const command=commands.join(isWindows?" && ":" ; ");console.log("Creating an optimized production build...");const result=spawnSync(command,[],{cwd:dirname,stdio:"inherit",shell:true,env:{...process.env,src_path:process.cwd(),BUILD_OUTPUT_PATH:BUILD_OUTPUT_PATH,NODE_ENV:"production",IS_DEV_COMMAND:false,...argumentsObject}});if(result.error){console.error("Error occurred:",result.error);}else{console.log(green("Compiled successfully."));console.log("\nFile sizes after gzip:\n");printBundleInformation();console.log(`\nThe ${cyan(BUILD_OUTPUT_PATH)} folder is ready to be deployed.`);console.log("You may serve it with a serve command:");console.log(cyan("\n npm run serve"));console.log("\nFind out more about deployment here:");console.log(yellow("\n https://catalyst.1mg.com/public_docs/content/Deployment%20and%20Production/deployment\n"));}}build();
3
+ */function build(){const isWindows=process.platform==="win32";const commandLineArguments=process.argv.slice(2);const argumentsObject=arrayToObject(commandLineArguments);const dirname=path.resolve(__dirname,"../../");const commands=["node ./dist/scripts/checkVersion",`${isWindows?"rd -r -fo":"rm -rf"} ${process.cwd()}/${BUILD_OUTPUT_PATH} & node ./dist/scripts/loadScriptsBeforeServerStarts.js`,`cross-env APPLICATION=${name||"catalyst_app"} webpack --config ./dist/webpack/production.client.babel.js --progress`,`cross-env APPLICATION=${name||"catalyst_app"} SSR=true webpack --config ./dist/webpack/production.ssr.babel.js`,`cross-env APPLICATION=${name||"catalyst_app"} npx babel ./dist/server --out-dir ${process.cwd()}/${BUILD_OUTPUT_PATH} --ignore '**/*.test.js,./dist/server/renderer/handler.js' --quiet`,`cross-env APPLICATION=${name||"catalyst_app"} npx babel ${process.cwd()}/server --out-dir ${process.cwd()}/${BUILD_OUTPUT_PATH} --quiet`];console.log("Creating an optimized production build...");runBuildCommands({commands,cwd:dirname,env:{...process.env,src_path:process.cwd(),BUILD_OUTPUT_PATH:BUILD_OUTPUT_PATH,NODE_ENV:"production",IS_DEV_COMMAND:false,...argumentsObject}});console.log(green("Compiled successfully."));console.log("\nFile sizes after gzip:\n");printBundleInformation();console.log(`\nThe ${cyan(BUILD_OUTPUT_PATH)} folder is ready to be deployed.`);console.log("You may serve it with a serve command:");console.log(cyan("\n npm run serve"));console.log("\nFind out more about deployment here:");console.log(yellow("\n https://catalyst.1mg.com/public_docs/content/Deployment%20and%20Production/deployment\n"));}build();
@@ -1,3 +1,3 @@
1
- "use strict";const path=require("path");const{spawnSync}=require("child_process");const{green,cyan,yellow}=require("picocolors");const{name}=require(`${process.cwd()}/package.json`);const{BUILD_OUTPUT_PATH}=require(`${process.cwd()}/config/config.json`);const{arrayToObject,printBundleInformation}=require("./scriptUtils.js");/**
1
+ "use strict";const path=require("path");const{green,cyan,yellow}=require("picocolors");const{name}=require(`${process.cwd()}/package.json`);const{BUILD_OUTPUT_PATH}=require(`${process.cwd()}/config/config.json`);const{arrayToObject,printBundleInformation,runBuildCommands}=require("./scriptUtils.js");/**
2
2
  * @description - creates a production build of the application.
3
- */function devBuild(){const isWindows=process.platform==="win32";const commandLineArguments=process.argv.slice(2);const argumentsObject=arrayToObject(commandLineArguments);const dirname=path.resolve(__dirname,"../../");const commands=["node ./dist/scripts/checkVersion",`${isWindows?"rd -r -fo":"rm -rf"} ${process.cwd()}/${BUILD_OUTPUT_PATH} & node ./dist/scripts/loadScriptsBeforeServerStarts.js`,`cross-env APPLICATION=${name||"catalyst_app"} webpack --config ./dist/webpack/production.client.babel.js --progress`,` cross-env APPLICATION=${name||"catalyst_app"} SSR=true webpack --config ./dist/webpack/production.ssr.babel.js`,`cross-env APPLICATION=${name||"catalyst_app"} npx babel ./dist/server --out-dir ${process.cwd()}/${BUILD_OUTPUT_PATH} --ignore '**/*.test.js,./dist/server/renderer/handler.js' --quiet`,`cross-env APPLICATION=${name||"catalyst_app"} npx babel ${process.cwd()}/server --out-dir ${process.cwd()}/${BUILD_OUTPUT_PATH} --quiet`];const command=commands.join(isWindows?" && ":" ; ");console.log("Creating an optimized local build...");const result=spawnSync(command,[],{cwd:dirname,stdio:"inherit",shell:true,env:{...process.env,src_path:process.cwd(),BUILD_OUTPUT_PATH:BUILD_OUTPUT_PATH,NODE_ENV:"production",IS_DEV_COMMAND:true,...argumentsObject}});if(result.error){console.error("Error occurred:",result.error);}else{console.log(green("Compiled successfully."));console.log("\nFile sizes after gzip:\n");printBundleInformation();console.log(`\nThe ${cyan(BUILD_OUTPUT_PATH)} folder is ready to be deployed.`);console.log("You may serve it with a serve command:");console.log(cyan("\n npm run devServe"));console.log("\nFind out more about deployment here:");console.log(yellow("\n https://catalyst.1mg.com/public_docs/content/Deployment%20and%20Production/deployment\n"));}}devBuild();
3
+ */function devBuild(){const isWindows=process.platform==="win32";const commandLineArguments=process.argv.slice(2);const argumentsObject=arrayToObject(commandLineArguments);const dirname=path.resolve(__dirname,"../../");const commands=["node ./dist/scripts/checkVersion",`${isWindows?"rd -r -fo":"rm -rf"} ${process.cwd()}/${BUILD_OUTPUT_PATH} & node ./dist/scripts/loadScriptsBeforeServerStarts.js`,`cross-env APPLICATION=${name||"catalyst_app"} webpack --config ./dist/webpack/production.client.babel.js --progress`,`cross-env APPLICATION=${name||"catalyst_app"} SSR=true webpack --config ./dist/webpack/production.ssr.babel.js`,`cross-env APPLICATION=${name||"catalyst_app"} npx babel ./dist/server --out-dir ${process.cwd()}/${BUILD_OUTPUT_PATH} --ignore '**/*.test.js,./dist/server/renderer/handler.js' --quiet`,`cross-env APPLICATION=${name||"catalyst_app"} npx babel ${process.cwd()}/server --out-dir ${process.cwd()}/${BUILD_OUTPUT_PATH} --quiet`];console.log("Creating an optimized local build...");runBuildCommands({commands,cwd:dirname,env:{...process.env,src_path:process.cwd(),BUILD_OUTPUT_PATH:BUILD_OUTPUT_PATH,NODE_ENV:"production",IS_DEV_COMMAND:true,...argumentsObject}});console.log(green("Compiled successfully."));console.log("\nFile sizes after gzip:\n");printBundleInformation();console.log(`\nThe ${cyan(BUILD_OUTPUT_PATH)} folder is ready to be deployed.`);console.log("You may serve it with a serve command:");console.log(cyan("\n npm run devServe"));console.log("\nFind out more about deployment here:");console.log(yellow("\n https://catalyst.1mg.com/public_docs/content/Deployment%20and%20Production/deployment\n"));}devBuild();
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.arrayToObject=arrayToObject;exports.printBundleInformation=void 0;const fs=require("fs");const path=require("path");const util=require("node:util");const{gray,cyan}=require("picocolors");const{BUILD_OUTPUT_PATH}=require(`${process.cwd()}/config/config.json`);// Function to get file size synchronously
2
- function getFileSizeSync(filePath){try{const stats=fs.statSync(filePath);return stats.size;}catch(err){console.error(`Error getting bundle information for file ${filePath}: ${err}`);return null;}}const printBundleInformation=()=>{let bundleList=[];const directoryPath=path.join(process.cwd(),`${BUILD_OUTPUT_PATH}/public`);try{const files=fs.readdirSync(directoryPath);files.forEach(file=>{if(!file.includes("txt")&&!file.includes("json")){const filePath=path.join(directoryPath,file);const fileSize=getFileSizeSync(filePath);if(fileSize!==null){bundleList.push({file,fileSize});}}});}catch(err){console.error("Unable to scan build folder: "+err);}bundleList.sort((a,b)=>b.fileSize-a.fileSize);bundleList.forEach(({file,fileSize})=>{const fileName=`${gray(`${BUILD_OUTPUT_PATH}/public/`)}${cyan(file)}`;const fileSizeInKb=(fileSize/1024).toFixed(2);const size=`\t${fileSizeInKb} kB`.padEnd(16);console.log(util.format(size,fileName));});};exports.printBundleInformation=printBundleInformation;function arrayToObject(array){const obj={};array.forEach(item=>{const[key,value]=item.split("=");if(value)obj[key]=value;});return obj;}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.arrayToObject=arrayToObject;exports.runBuildCommands=exports.printBundleInformation=void 0;const fs=require("fs");const path=require("path");const util=require("node:util");const{spawnSync}=require("child_process");const{gray,cyan}=require("picocolors");const{BUILD_OUTPUT_PATH}=require(`${process.cwd()}/config/config.json`);// Function to get file size synchronously
2
+ function getFileSizeSync(filePath){try{const stats=fs.statSync(filePath);return stats.size;}catch(err){console.error(`Error getting bundle information for file ${filePath}: ${err}`);return null;}}const printBundleInformation=()=>{let bundleList=[];const directoryPath=path.join(process.cwd(),`${BUILD_OUTPUT_PATH}/public`);try{const files=fs.readdirSync(directoryPath);files.forEach(file=>{if(!file.includes("txt")&&!file.includes("json")){const filePath=path.join(directoryPath,file);const fileSize=getFileSizeSync(filePath);if(fileSize!==null){bundleList.push({file,fileSize});}}});}catch(err){console.error("Unable to scan build folder: "+err);}bundleList.sort((a,b)=>b.fileSize-a.fileSize);bundleList.forEach(({file,fileSize})=>{const fileName=`${gray(`${BUILD_OUTPUT_PATH}/public/`)}${cyan(file)}`;const fileSizeInKb=(fileSize/1024).toFixed(2);const size=`\t${fileSizeInKb} kB`.padEnd(16);console.log(util.format(size,fileName));});};exports.printBundleInformation=printBundleInformation;function arrayToObject(array){const obj={};array.forEach(item=>{const[key,value]=item.split("=");if(value)obj[key]=value;});return obj;}const BUILD_FAILURE_MESSAGE="\nBuild Failed!";function shouldFailBuild(result){return result.error||result.signal||result.status!==null&&result.status!==0;}function logBuildFailure(result,failureMessage=BUILD_FAILURE_MESSAGE){console.error(failureMessage);if(result.error){console.error(`Error: ${result.error?.message||result.error}\n`);}if(result.signal){console.error(`Signal: ${result.signal}\n`);}if(result.status!==null){console.error(`Exit code: ${result.status}\n`);}}const runBuildCommands=({commands,cwd,env,failureMessage=BUILD_FAILURE_MESSAGE})=>{const command=commands.join(" && ");const result=spawnSync(command,[],{cwd,stdio:"inherit",shell:true,env});if(shouldFailBuild(result)){logBuildFailure(result,failureMessage);process.exit(result.status||1);}return result;};exports.runBuildCommands=runBuildCommands;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "catalyst-core",
3
- "version": "0.0.1-beta.15",
3
+ "version": "0.0.1-beta.17",
4
4
  "main": "index.js",
5
5
  "description": "Web framework that provides great performance out of the box",
6
6
  "bin": {
@@ -29,7 +29,8 @@
29
29
  "./logger": "./dist/logger.js",
30
30
  "./caching": "./dist/caching.js",
31
31
  "./router/ClientRouter": "./dist/router/ClientRouter.js",
32
- "./sentry": "./dist/sentry.js"
32
+ "./sentry": "./dist/sentry.js",
33
+ "./otel": "./dist/otel.js"
33
34
  },
34
35
  "scripts": {
35
36
  "lint": "eslint .",