UNPKG

oidc-client-rx

Version:

ReactiveX enhanced OIDC and OAuth2 protocol support for browser-based JavaScript applications

52 lines (51 loc) 2.75 kB
import { Injectable, inject } from "injection-js"; import { LoggerService } from "../../logging/logger.service.js"; import { allMultipleConfigRules, allRules } from "./rules/index.js"; function _ts_decorate(decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc); else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; } class ConfigValidationService { validateConfigs(passedConfigs) { return this.validateConfigsInternal(passedConfigs ?? [], allMultipleConfigRules); } validateConfig(passedConfig) { return this.validateConfigInternal(passedConfig, allRules); } validateConfigsInternal(passedConfigs, allRulesToUse) { if (0 === passedConfigs.length) return false; const allValidationResults = allRulesToUse.map((rule)=>rule(passedConfigs)); let overallErrorCount = 0; for (const passedConfig of passedConfigs){ const errorCount = this.processValidationResultsAndGetErrorCount(allValidationResults, passedConfig); overallErrorCount += errorCount; } return 0 === overallErrorCount; } validateConfigInternal(passedConfig, allRulesToUse) { const allValidationResults = allRulesToUse.map((rule)=>rule(passedConfig)); const errorCount = this.processValidationResultsAndGetErrorCount(allValidationResults, passedConfig); return 0 === errorCount; } processValidationResultsAndGetErrorCount(allValidationResults, config) { const allMessages = allValidationResults.filter((x)=>x.messages.length > 0); const allErrorMessages = this.getAllMessagesOfType("error", allMessages); const allWarnings = this.getAllMessagesOfType("warning", allMessages); for (const message of allErrorMessages)this.loggerService.logError(config, message); for (const message of allWarnings)this.loggerService.logWarning(config, message); return allErrorMessages.length; } getAllMessagesOfType(type, results) { const allMessages = results.filter((x)=>x.level === type).map((result)=>result.messages); return allMessages.reduce((acc, val)=>acc.concat(val), []); } constructor(){ this.loggerService = inject(LoggerService); } } ConfigValidationService = _ts_decorate([ Injectable() ], ConfigValidationService); export { ConfigValidationService };