@jadermme/orus-core
Version:
ORUS Core Framework - Universal framework for 6 Pillars assessment, domain-agnostic
208 lines • 5.59 kB
JavaScript
/**
* ORUS Core - Configuration System
*
* Centralized configuration for customizing ORUS Core behavior.
* Allows verticals and shells to override defaults without modifying the core.
*
* @remarks
* Configuration hierarchy:
* 1. ORUS Core defaults (universal, domain-agnostic)
* 2. Vertical configuration (e.g., Finance overrides)
* 3. Shell configuration (e.g., Convexa360 branding)
* 4. Runtime configuration (user preferences)
*/
import { ORUS_CORE_PILLAR_LABELS, DEFAULT_STATUS_THRESHOLDS, DEFAULT_PRIORITIZATION_WEIGHTS } from './defaults.js';
/**
* ORUS Core instance
*
* @remarks
* Encapsulates configuration and provides configured utility functions.
* Create one instance per app/vertical.
*/
export class OrusCoreInstance {
/**
* Creates a new ORUS Core instance
*
* @param userConfig - User configuration (optional)
*
* @remarks
* Merges user config with defaults.
* Validates configuration on creation.
*
* @example
* ```typescript
* const orus = new OrusCoreInstance({
* pillarLabels: myFinanceLabels,
* vertical: {
* name: "ORUS Finance",
* version: "1.0.0"
* }
* });
* ```
*/
constructor(userConfig = {}) {
// Merge with defaults
this.config = {
pillarLabels: userConfig.pillarLabels || ORUS_CORE_PILLAR_LABELS,
statusThresholds: userConfig.statusThresholds || DEFAULT_STATUS_THRESHOLDS,
prioritizationWeights: userConfig.prioritizationWeights || DEFAULT_PRIORITIZATION_WEIGHTS,
verticalSchema: userConfig.verticalSchema,
vertical: userConfig.vertical || {
name: 'ORUS Core (Generic)',
version: '1.0.0'
},
debug: userConfig.debug ?? false
};
// Validate configuration
this.validateConfig();
if (this.config.debug) {
this.log('ORUS Core initialized', this.config);
}
}
/**
* Validates the configuration
*
* @throws Error if configuration is invalid
*/
validateConfig() {
// Validate pillar labels
const expectedPillars = [
'PILLAR_1',
'PILLAR_2',
'PILLAR_3',
'PILLAR_4',
'PILLAR_5',
'PILLAR_6'
];
expectedPillars.forEach((pillarId) => {
if (!this.config.pillarLabels[pillarId]) {
throw new Error(`Missing label for ${pillarId}`);
}
});
// Validate prioritization weights sum to ~1.0
const weights = this.config.prioritizationWeights;
const sum = weights.status + weights.score + weights.trend + weights.confidence;
if (Math.abs(sum - 1.0) > 0.01) {
throw new Error(`Prioritization weights must sum to 1.0, got ${sum.toFixed(2)}`);
}
}
/**
* Gets label for a pillar
*
* @param pillarId - Pillar ID
* @returns Human-readable label
*
* @example
* ```typescript
* const label = orus.getPillarLabel(PillarId.PILLAR_1);
* // => "Organização & Fluxo" (in Finance vertical)
* ```
*/
getPillarLabel(pillarId) {
return this.config.pillarLabels[pillarId];
}
/**
* Gets all pillar labels
*
* @returns Record of all labels
*/
getAllPillarLabels() {
return { ...this.config.pillarLabels };
}
/**
* Gets status thresholds
*
* @returns Status thresholds
*/
getStatusThresholds() {
return { ...this.config.statusThresholds };
}
/**
* Gets prioritization weights
*
* @returns Prioritization weights
*/
getPrioritizationWeights() {
return { ...this.config.prioritizationWeights };
}
/**
* Gets vertical schema
*
* @returns Vertical schema (if configured)
*/
getVerticalSchema() {
return this.config.verticalSchema;
}
/**
* Gets vertical info
*
* @returns Vertical identification
*/
getVerticalInfo() {
return { ...this.config.vertical };
}
/**
* Checks if debug mode is enabled
*
* @returns Whether debug is enabled
*/
isDebugEnabled() {
return this.config.debug;
}
/**
* Logs debug message (if debug enabled)
*
* @param message - Message to log
* @param data - Optional data to log
*/
log(message, data) {
if (this.config.debug) {
console.log(`[ORUS Core] ${message}`, data || '');
}
}
/**
* Creates a new instance with updated config
*
* @param updates - Config updates
* @returns New instance
*
* @remarks
* Immutable update - original instance unchanged.
*
* @example
* ```typescript
* const orusWithDebug = orus.withConfig({ debug: true });
* ```
*/
withConfig(updates) {
return new OrusCoreInstance({
...this.config,
...updates
});
}
}
/**
* Creates a new ORUS Core instance
*
* @param config - Configuration
* @returns ORUS Core instance
*
* @remarks
* Convenience factory function.
*
* @example
* ```typescript
* const orus = createOrusCore({
* pillarLabels: financeLabels,
* vertical: {
* name: "ORUS Finance",
* version: "1.0.0",
* shell: "Convexa360"
* }
* });
* ```
*/
export function createOrusCore(config) {
return new OrusCoreInstance(config);
}
//# sourceMappingURL=core.js.map