@fctc/interface-logic 5.1.0 → 5.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,131 @@
1
+ 'use strict';
2
+
3
+ var chunkQ5YXX4OR_js = require('./chunk-Q5YXX4OR.js');
4
+ var chunkJDXUTKMX_js = require('./chunk-JDXUTKMX.js');
5
+
6
+ // src/environment/EnvStore.ts
7
+ var EventEmitter = class {
8
+ listeners = {};
9
+ on(event, callback) {
10
+ if (!this.listeners[event]) {
11
+ this.listeners[event] = [];
12
+ }
13
+ this.listeners[event].push(callback);
14
+ }
15
+ emit(event, data) {
16
+ if (this.listeners[event]) {
17
+ this.listeners[event].forEach((callback) => callback(data));
18
+ }
19
+ }
20
+ };
21
+ var EnvStore = class {
22
+ state;
23
+ emitter;
24
+ localStorageUtil;
25
+ sessionStorageUtil;
26
+ constructor(localStorageUtil = chunkJDXUTKMX_js.localStorageUtils(), sessionStorageUtil = chunkJDXUTKMX_js.sessionStorageUtils) {
27
+ this.state = {
28
+ baseUrl: "",
29
+ requests: null,
30
+ companies: [],
31
+ user: {},
32
+ config: null,
33
+ envFile: null,
34
+ defaultCompany: {
35
+ id: null,
36
+ logo: "",
37
+ secondary_color: "",
38
+ primary_color: ""
39
+ },
40
+ context: {
41
+ uid: null,
42
+ allowed_company_ids: [],
43
+ lang: "vi_VN",
44
+ tz: "Asia/Saigon"
45
+ },
46
+ localStorageUtils: localStorageUtil,
47
+ sessionStorageUtils: sessionStorageUtil
48
+ };
49
+ this.emitter = new EventEmitter();
50
+ this.localStorageUtil = localStorageUtil;
51
+ this.sessionStorageUtil = sessionStorageUtil;
52
+ }
53
+ getEnv() {
54
+ return { ...this.state };
55
+ }
56
+ onUpdate(callback) {
57
+ this.emitter.on("update", callback);
58
+ }
59
+ setupEnv(envConfig) {
60
+ this.state = {
61
+ ...this.state,
62
+ ...envConfig,
63
+ localStorageUtils: this.localStorageUtil,
64
+ sessionStorageUtils: this.sessionStorageUtil
65
+ };
66
+ this.state.requests = chunkQ5YXX4OR_js.axiosClient.init(this.state);
67
+ this.emitter.emit("update", this.getEnv());
68
+ return this.getEnv();
69
+ }
70
+ setUid(uid) {
71
+ this.state = {
72
+ ...this.state,
73
+ context: { ...this.state.context, uid }
74
+ };
75
+ this.emitter.emit("update", this.getEnv());
76
+ }
77
+ setLang(lang) {
78
+ this.state = {
79
+ ...this.state,
80
+ context: { ...this.state.context, lang }
81
+ };
82
+ this.emitter.emit("update", this.getEnv());
83
+ }
84
+ setAllowCompanies(allowed_company_ids) {
85
+ this.state = {
86
+ ...this.state,
87
+ context: { ...this.state.context, allowed_company_ids }
88
+ };
89
+ this.emitter.emit("update", this.getEnv());
90
+ }
91
+ setCompanies(companies) {
92
+ this.state = { ...this.state, companies };
93
+ this.emitter.emit("update", this.getEnv());
94
+ }
95
+ setDefaultCompany(defaultCompany) {
96
+ this.state = { ...this.state, defaultCompany };
97
+ this.emitter.emit("update", this.getEnv());
98
+ }
99
+ setUserInfo(user) {
100
+ this.state = { ...this.state, user };
101
+ this.emitter.emit("update", this.getEnv());
102
+ }
103
+ setConfig(config) {
104
+ this.state = { ...this.state, config };
105
+ this.emitter.emit("update", this.getEnv());
106
+ }
107
+ setEnvFile(envFile) {
108
+ this.state = { ...this.state, envFile };
109
+ this.emitter.emit("update", this.getEnv());
110
+ }
111
+ };
112
+ var env = null;
113
+ function initEnv({
114
+ localStorageUtils: localStorageUtil = chunkJDXUTKMX_js.localStorageUtils(),
115
+ sessionStorageUtils: sessionStorageUtil = chunkJDXUTKMX_js.sessionStorageUtils
116
+ }) {
117
+ if (!env) {
118
+ env = new EnvStore(localStorageUtil, sessionStorageUtil);
119
+ }
120
+ return env;
121
+ }
122
+ function getEnv() {
123
+ if (!env) {
124
+ env = initEnv({});
125
+ }
126
+ return env?.getEnv();
127
+ }
128
+
129
+ exports.EnvStore = EnvStore;
130
+ exports.getEnv = getEnv;
131
+ exports.initEnv = initEnv;
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+