@gleif-it/vlei-verifier-workflows
Version:
Workflows for vLEI users and vLEI credentials for the vLEI-verifier service
42 lines (41 loc) • 2.05 kB
JavaScript
import { WorkflowState } from '../workflow-state.js';
import { IssueCredentialStepRunner, NotifyCredentialIssueeStepRunner, RevokeCredentialStepRunner, CredentialVerificationStepRunner, CreateClientStepRunner, CreateAidStepRunner, CreateRegistryStepRunner, AddRootOfTrustStepRunner, } from './workflow-step-runners.js';
export class WorkflowRunner {
stepRunners = new Map();
configJson;
workflow;
executedSteps = new Set();
constructor(workflow, configJson) {
this.configJson = configJson;
this.workflow = workflow;
WorkflowState.getInstance(this.configJson);
this.registerPredefinedRunners();
}
registerPredefinedRunners() {
this.registerRunner('create_client', new CreateClientStepRunner());
this.registerRunner('create_aid', new CreateAidStepRunner());
this.registerRunner('create_registry', new CreateRegistryStepRunner());
this.registerRunner('issue_credential', new IssueCredentialStepRunner());
this.registerRunner('revoke_credential', new RevokeCredentialStepRunner());
this.registerRunner('add_root_of_trust', new AddRootOfTrustStepRunner());
this.registerRunner('notify_credential_issuee', new NotifyCredentialIssueeStepRunner());
this.registerRunner('credential_verification', new CredentialVerificationStepRunner());
}
registerRunner(name, runner) {
this.stepRunners.set(name, runner);
}
async runWorkflow() {
for (const [stepName, step] of Object.entries(this.workflow.workflow.steps)) {
console.log(`Executing: ${step.description}`);
const runner = this.stepRunners.get(step.type);
if (!runner) {
console.log(`No step runner was registered for step '${step.type}'`);
return false;
}
await runner.run(stepName, step, this.configJson);
this.executedSteps.add(step.id);
}
console.log(`Workflow steps execution finished successfully`);
return true;
}
}