@ghentcdh/tools-vue 0.4.0 → 0.5.1
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.
- package/api.d.ts +5 -0
- package/index.d.ts +2 -0
- package/index.mjs +48 -3
- package/package.json +1 -1
- package/runtime.config.d.ts +11 -0
package/api.d.ts
ADDED
package/index.d.ts
CHANGED
package/index.mjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import a from "axios";
|
|
2
|
+
class r {
|
|
2
3
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
3
4
|
constructor() {
|
|
4
5
|
this._verboseEnabled = !1, this._debugEnabled = !1;
|
|
5
6
|
}
|
|
6
7
|
static get instance() {
|
|
7
|
-
return
|
|
8
|
+
return r._instance || (r._instance = new r()), r._instance;
|
|
8
9
|
}
|
|
9
10
|
static get verboseEnabled() {
|
|
10
11
|
return this.instance._verboseEnabled;
|
|
@@ -28,6 +29,50 @@ class t {
|
|
|
28
29
|
console.error(e);
|
|
29
30
|
}
|
|
30
31
|
}
|
|
32
|
+
let t = null;
|
|
33
|
+
async function d(o = {}) {
|
|
34
|
+
if (t)
|
|
35
|
+
return t;
|
|
36
|
+
try {
|
|
37
|
+
const n = await fetch("/config.json");
|
|
38
|
+
if (!n.ok)
|
|
39
|
+
throw new Error(`Failed to load config: ${n.status}`);
|
|
40
|
+
return t = await n.json(), t.authToken = o.authToken || "GHENTCDH_DEFAULT_TOKEN", t;
|
|
41
|
+
} catch (e) {
|
|
42
|
+
throw console.error("Failed to load runtime config:", e), new Error(e);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function c() {
|
|
46
|
+
if (!t)
|
|
47
|
+
throw new Error(
|
|
48
|
+
"Runtime config not loaded. Call loadRuntimeConfig() first."
|
|
49
|
+
);
|
|
50
|
+
return t;
|
|
51
|
+
}
|
|
52
|
+
const l = () => {
|
|
53
|
+
const o = a.create({
|
|
54
|
+
baseURL: c().API_URL,
|
|
55
|
+
headers: {
|
|
56
|
+
"Content-Type": "application/json"
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
return o.interceptors.request.use((e) => {
|
|
60
|
+
const n = localStorage.getItem("token");
|
|
61
|
+
n && (e.headers.Authorization = `Bearer ${n}`);
|
|
62
|
+
const s = localStorage.getItem("active-invertor-id");
|
|
63
|
+
return s && (e.headers["X-Inverter-Id"] = s), e;
|
|
64
|
+
}), o.interceptors.response.use(
|
|
65
|
+
(e) => e,
|
|
66
|
+
(e) => (e.response?.status === 401 && (localStorage.removeItem("token"), window.location.href = "/login"), Promise.reject(e))
|
|
67
|
+
), o;
|
|
68
|
+
};
|
|
69
|
+
let i;
|
|
70
|
+
function f() {
|
|
71
|
+
return i || (i = l()), i;
|
|
72
|
+
}
|
|
31
73
|
export {
|
|
32
|
-
|
|
74
|
+
r as Debugger,
|
|
75
|
+
c as getRuntimeConfig,
|
|
76
|
+
d as loadRuntimeConfig,
|
|
77
|
+
f as useApi
|
|
33
78
|
};
|
package/package.json
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface RuntimeConfig {
|
|
2
|
+
APP_VERSION: string;
|
|
3
|
+
BUILD_SHA: string;
|
|
4
|
+
API_URL: string;
|
|
5
|
+
env: 'DEV' | 'TST' | 'QAS' | 'PRD';
|
|
6
|
+
authToken: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function loadRuntimeConfig<RUNTIME_CONFIG extends RuntimeConfig>(config?: {
|
|
9
|
+
authToken?: string;
|
|
10
|
+
}): Promise<RUNTIME_CONFIG>;
|
|
11
|
+
export declare function getRuntimeConfig<RUNTIME_CONFIG extends RuntimeConfig>(): RUNTIME_CONFIG;
|