@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,127 @@
1
+ import { axiosClient } from './chunk-ACSPOGTI.mjs';
2
+ import { localStorageUtils, sessionStorageUtils } from './chunk-BPJZ3QRN.mjs';
3
+
4
+ // src/environment/EnvStore.ts
5
+ var EventEmitter = class {
6
+ listeners = {};
7
+ on(event, callback) {
8
+ if (!this.listeners[event]) {
9
+ this.listeners[event] = [];
10
+ }
11
+ this.listeners[event].push(callback);
12
+ }
13
+ emit(event, data) {
14
+ if (this.listeners[event]) {
15
+ this.listeners[event].forEach((callback) => callback(data));
16
+ }
17
+ }
18
+ };
19
+ var EnvStore = class {
20
+ state;
21
+ emitter;
22
+ localStorageUtil;
23
+ sessionStorageUtil;
24
+ constructor(localStorageUtil = localStorageUtils(), sessionStorageUtil = sessionStorageUtils) {
25
+ this.state = {
26
+ baseUrl: "",
27
+ requests: null,
28
+ companies: [],
29
+ user: {},
30
+ config: null,
31
+ envFile: null,
32
+ defaultCompany: {
33
+ id: null,
34
+ logo: "",
35
+ secondary_color: "",
36
+ primary_color: ""
37
+ },
38
+ context: {
39
+ uid: null,
40
+ allowed_company_ids: [],
41
+ lang: "vi_VN",
42
+ tz: "Asia/Saigon"
43
+ },
44
+ localStorageUtils: localStorageUtil,
45
+ sessionStorageUtils: sessionStorageUtil
46
+ };
47
+ this.emitter = new EventEmitter();
48
+ this.localStorageUtil = localStorageUtil;
49
+ this.sessionStorageUtil = sessionStorageUtil;
50
+ }
51
+ getEnv() {
52
+ return { ...this.state };
53
+ }
54
+ onUpdate(callback) {
55
+ this.emitter.on("update", callback);
56
+ }
57
+ setupEnv(envConfig) {
58
+ this.state = {
59
+ ...this.state,
60
+ ...envConfig,
61
+ localStorageUtils: this.localStorageUtil,
62
+ sessionStorageUtils: this.sessionStorageUtil
63
+ };
64
+ this.state.requests = axiosClient.init(this.state);
65
+ this.emitter.emit("update", this.getEnv());
66
+ return this.getEnv();
67
+ }
68
+ setUid(uid) {
69
+ this.state = {
70
+ ...this.state,
71
+ context: { ...this.state.context, uid }
72
+ };
73
+ this.emitter.emit("update", this.getEnv());
74
+ }
75
+ setLang(lang) {
76
+ this.state = {
77
+ ...this.state,
78
+ context: { ...this.state.context, lang }
79
+ };
80
+ this.emitter.emit("update", this.getEnv());
81
+ }
82
+ setAllowCompanies(allowed_company_ids) {
83
+ this.state = {
84
+ ...this.state,
85
+ context: { ...this.state.context, allowed_company_ids }
86
+ };
87
+ this.emitter.emit("update", this.getEnv());
88
+ }
89
+ setCompanies(companies) {
90
+ this.state = { ...this.state, companies };
91
+ this.emitter.emit("update", this.getEnv());
92
+ }
93
+ setDefaultCompany(defaultCompany) {
94
+ this.state = { ...this.state, defaultCompany };
95
+ this.emitter.emit("update", this.getEnv());
96
+ }
97
+ setUserInfo(user) {
98
+ this.state = { ...this.state, user };
99
+ this.emitter.emit("update", this.getEnv());
100
+ }
101
+ setConfig(config) {
102
+ this.state = { ...this.state, config };
103
+ this.emitter.emit("update", this.getEnv());
104
+ }
105
+ setEnvFile(envFile) {
106
+ this.state = { ...this.state, envFile };
107
+ this.emitter.emit("update", this.getEnv());
108
+ }
109
+ };
110
+ var env = null;
111
+ function initEnv({
112
+ localStorageUtils: localStorageUtil = localStorageUtils(),
113
+ sessionStorageUtils: sessionStorageUtil = sessionStorageUtils
114
+ }) {
115
+ if (!env) {
116
+ env = new EnvStore(localStorageUtil, sessionStorageUtil);
117
+ }
118
+ return env;
119
+ }
120
+ function getEnv() {
121
+ if (!env) {
122
+ env = initEnv({});
123
+ }
124
+ return env?.getEnv();
125
+ }
126
+
127
+ export { EnvStore, getEnv, initEnv };