1- import { config as loadDotenv } from 'dotenv' ;
2- import { AppConfigSchema , type AppConfig , type WhitelistConfig , type StreamingConfig } from './schema' ;
3- import { z } from 'zod' ;
1+ import { config as loadDotenv } from "dotenv" ;
2+ import {
3+ AppConfigSchema ,
4+ type AppConfig ,
5+ type WhitelistConfig ,
6+ } from "./schema" ;
7+ import { z } from "zod" ;
48
59/**
610 * Configuration service to load and validate application settings
@@ -25,19 +29,26 @@ export class ConfigService {
2529 // Parse command whitelist from JSON string
2630 let commandWhitelist : WhitelistConfig ;
2731 try {
28- const whitelistJson = process . env . COMMAND_WHITELIST ?? '[]' ;
32+ const whitelistJson = process . env . COMMAND_WHITELIST ?? "[]" ;
2933 const parsedWhitelist : unknown = JSON . parse ( whitelistJson ) ;
3034 const whitelistArray : string [ ] = Array . isArray ( parsedWhitelist )
31- ? parsedWhitelist . filter ( ( item ) : item is string => typeof item === 'string' )
35+ ? parsedWhitelist . filter (
36+ ( item ) : item is string => typeof item === "string" ,
37+ )
3238 : [ ] ;
3339 const matchMode = process . env . COMMAND_WHITELIST_MATCH_MODE ;
3440 commandWhitelist = {
35- allowAll : process . env . COMMAND_WHITELIST_ALLOW_ALL === ' true' ,
41+ allowAll : process . env . COMMAND_WHITELIST_ALLOW_ALL === " true" ,
3642 whitelist : whitelistArray ,
37- matchMode : ( matchMode === 'exact' || matchMode === 'prefix' ) ? matchMode : 'exact' ,
43+ matchMode :
44+ matchMode === "exact" || matchMode === "prefix"
45+ ? matchMode
46+ : "exact" ,
3847 } ;
3948 } catch ( error ) {
40- throw new Error ( `Failed to parse COMMAND_WHITELIST: ${ error instanceof Error ? error . message : 'Unknown error' } ` ) ;
49+ throw new Error (
50+ `Failed to parse COMMAND_WHITELIST: ${ error instanceof Error ? error . message : "Unknown error" } ` ,
51+ ) ;
4152 }
4253
4354 // Parse package tasks from JSON string if provided
@@ -46,27 +57,43 @@ export class ConfigService {
4657 try {
4758 packageTasks = JSON . parse ( process . env . PACKAGE_TASKS ) ;
4859 } catch ( error ) {
49- throw new Error ( `Failed to parse PACKAGE_TASKS: ${ error instanceof Error ? error . message : 'Unknown error' } ` ) ;
60+ throw new Error (
61+ `Failed to parse PACKAGE_TASKS: ${ error instanceof Error ? error . message : "Unknown error" } ` ,
62+ ) ;
5063 }
5164 }
5265
5366 // Parse streaming configuration
5467 const streaming = {
55- bufferMs : process . env . STREAMING_BUFFER_MS ? parseInt ( process . env . STREAMING_BUFFER_MS , 10 ) : undefined ,
56- maxOutputSize : process . env . STREAMING_MAX_OUTPUT_SIZE ? parseInt ( process . env . STREAMING_MAX_OUTPUT_SIZE , 10 ) : undefined ,
57- maxLineLength : process . env . STREAMING_MAX_LINE_LENGTH ? parseInt ( process . env . STREAMING_MAX_LINE_LENGTH , 10 ) : undefined ,
68+ bufferMs : process . env . STREAMING_BUFFER_MS
69+ ? parseInt ( process . env . STREAMING_BUFFER_MS , 10 )
70+ : undefined ,
71+ maxOutputSize : process . env . STREAMING_MAX_OUTPUT_SIZE
72+ ? parseInt ( process . env . STREAMING_MAX_OUTPUT_SIZE , 10 )
73+ : undefined ,
74+ maxLineLength : process . env . STREAMING_MAX_LINE_LENGTH
75+ ? parseInt ( process . env . STREAMING_MAX_LINE_LENGTH , 10 )
76+ : undefined ,
5877 } ;
5978
6079 // Parse cache configuration
6180 const cache = {
62- inventoryTtl : process . env . CACHE_INVENTORY_TTL ? parseInt ( process . env . CACHE_INVENTORY_TTL , 10 ) : undefined ,
63- factsTtl : process . env . CACHE_FACTS_TTL ? parseInt ( process . env . CACHE_FACTS_TTL , 10 ) : undefined ,
81+ inventoryTtl : process . env . CACHE_INVENTORY_TTL
82+ ? parseInt ( process . env . CACHE_INVENTORY_TTL , 10 )
83+ : undefined ,
84+ factsTtl : process . env . CACHE_FACTS_TTL
85+ ? parseInt ( process . env . CACHE_FACTS_TTL , 10 )
86+ : undefined ,
6487 } ;
6588
6689 // Parse execution queue configuration
6790 const executionQueue = {
68- concurrentLimit : process . env . CONCURRENT_EXECUTION_LIMIT ? parseInt ( process . env . CONCURRENT_EXECUTION_LIMIT , 10 ) : undefined ,
69- maxQueueSize : process . env . MAX_QUEUE_SIZE ? parseInt ( process . env . MAX_QUEUE_SIZE , 10 ) : undefined ,
91+ concurrentLimit : process . env . CONCURRENT_EXECUTION_LIMIT
92+ ? parseInt ( process . env . CONCURRENT_EXECUTION_LIMIT , 10 )
93+ : undefined ,
94+ maxQueueSize : process . env . MAX_QUEUE_SIZE
95+ ? parseInt ( process . env . MAX_QUEUE_SIZE , 10 )
96+ : undefined ,
7097 } ;
7198
7299 // Build configuration object
@@ -75,7 +102,9 @@ export class ConfigService {
75102 host : process . env . HOST ,
76103 boltProjectPath : process . env . BOLT_PROJECT_PATH ,
77104 commandWhitelist,
78- executionTimeout : process . env . EXECUTION_TIMEOUT ? parseInt ( process . env . EXECUTION_TIMEOUT , 10 ) : undefined ,
105+ executionTimeout : process . env . EXECUTION_TIMEOUT
106+ ? parseInt ( process . env . EXECUTION_TIMEOUT , 10 )
107+ : undefined ,
79108 logLevel : process . env . LOG_LEVEL ,
80109 databasePath : process . env . DATABASE_PATH ,
81110 packageTasks,
@@ -88,7 +117,9 @@ export class ConfigService {
88117 return AppConfigSchema . parse ( rawConfig ) ;
89118 } catch ( error ) {
90119 if ( error instanceof z . ZodError ) {
91- const issues = error . issues . map ( issue => `${ issue . path . join ( '.' ) } : ${ issue . message } ` ) . join ( ', ' ) ;
120+ const issues = error . issues
121+ . map ( ( issue ) => `${ issue . path . join ( "." ) } : ${ issue . message } ` )
122+ . join ( ", " ) ;
92123 throw new Error ( `Configuration validation failed: ${ issues } ` ) ;
93124 }
94125 throw error ;
0 commit comments