UNPKG

@progress/telerik-blazor-mcp

Version:

Model Context Protocol for Blazor

33 lines (32 loc) 1.23 kB
import { LICENSE_ENV_VARS, LICENSE_ENV_PATH_VAR } from './constants.js'; import { readFileSync } from 'node:fs'; import { log } from './logger.js'; const LICENSE_PATH = process.env[LICENSE_ENV_PATH_VAR]; const LICENSE_KEY = process.env[LICENSE_ENV_VARS[0]] || process.env[LICENSE_ENV_VARS[1]]; // create a custom LicenseError class export class LicenseError extends Error { constructor(message) { super(message); this.name = 'LicenseError'; } } export function readLicense() { if (!LICENSE_PATH && !LICENSE_KEY) { throw new LicenseError(`No license found. Please set one of the following environment variables: ${LICENSE_ENV_VARS.join(', ')} or ${LICENSE_ENV_PATH_VAR}`); } let licenseKey; if (LICENSE_PATH) { try { licenseKey = readFileSync(LICENSE_PATH, 'utf8'); log('License key read from file: ', LICENSE_PATH); } catch (error) { throw new LicenseError(`Error reading license file: ${LICENSE_PATH}. Please verify the file exists and is readable.`); } } if (LICENSE_KEY) { licenseKey = LICENSE_KEY; log('License key read from environment variable.'); } return licenseKey; }