-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfigs_new.ts
100 lines (77 loc) · 2.19 KB
/
configs_new.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import fs from "fs";
import yaml from "yaml";
import path from "path";
import $RefParser from "@apidevtools/json-schema-ref-parser";
import axios from "axios";
import logger from "./src/utils/logger"
class ConfigLoader {
config:any
constructor() {
this.config = null;
}
async init() {
try {
if (process.env.localConfig === "true") {
const config = yaml.parse(
fs.readFileSync(path.join(__dirname, "./configs/igm/index.yaml"), "utf8")
);
const schema = await $RefParser.dereference(config);
this.config = schema;
return schema
}else{
const url = process.env.CONFIG_URL_MAPPER;
if (!url) {
throw new Error("Config url not found");
}
const response = await axios.get(url);
this.config = response.data;
return response.data;
}
} catch (e : any) {
throw new Error(e);
}
}
getConfig() {
return this.config;
}
getConfigBasedOnFlow(flowId : string) {
let filteredInput = null;
let filteredCalls = null;
let filteredDomain = null;
let filteredSessiondata = null;
let filteredAdditionalFlows = null;
let filteredsummary = "";
let filtered_config = null
this.config.flows.forEach((flow : any) => {
if (flow.id === flowId) {
const { input, calls, domain, sessionData, additioalFlows, summary, config_selector } =
flow;
filteredInput = input;
filteredCalls = calls;
filteredDomain = domain;
filteredSessiondata = sessionData;
filteredAdditionalFlows = additioalFlows || [];
filteredsummary = summary;
filtered_config = config_selector
}
});
return {
filteredCalls,
filteredInput,
filteredDomain,
filteredSessiondata,
filteredAdditionalFlows,
filteredsummary,
filtered_config
};
}
getListOfFlow() {
return this.config.flows
.map((flow : any) => {
if (flow.shouldDispaly) return { key: flow.summary, value: flow.id, version: flow.version };
})
.filter((flow : any) => flow);
}
}
const configLoader = new ConfigLoader();
export { configLoader };