@zerosls/clm-sdk 2.1.9 → 2.2.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/dist/config/config.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
function normalizeUrl(url) {
|
|
2
2
|
return url.trim().replace(/\/+$/, "");
|
|
3
3
|
}
|
|
4
|
-
//function resolveDefaultBaseUrl(){
|
|
5
|
-
// const fromWindow = (globalThis as any)?.SDK_CONFIG?.API_BASE_URL;
|
|
6
|
-
// if (fromWindow) return normalizeUrl(String(fromWindow));
|
|
7
|
-
//}
|
|
8
4
|
export const DEFAULT_CONFIG = {
|
|
9
|
-
baseUrl: "https://zero-api-production.up.railway.app/ZeroApiQA/api/v1",
|
|
10
|
-
organization: "
|
|
5
|
+
baseUrl: "https://zero-api-production.up.railway.app/ZeroApiQA/api/v1",
|
|
6
|
+
organization: "qa",
|
|
11
7
|
cache: { enabled: true, ttl: 60000 },
|
|
12
8
|
debug: true,
|
|
13
9
|
credentials: "include",
|
|
@@ -2,70 +2,6 @@ export class AuthApi {
|
|
|
2
2
|
constructor(apiClient) {
|
|
3
3
|
this.apiClient = apiClient;
|
|
4
4
|
}
|
|
5
|
-
/*async login(
|
|
6
|
-
credentials: LoginCredentials,
|
|
7
|
-
mode: LoginMode = "new"
|
|
8
|
-
): Promise<{ ok: boolean }> {
|
|
9
|
-
const path = mode === "legacy" ? "/legacy/login" : "/auth/login";
|
|
10
|
-
|
|
11
|
-
console.log(`🔐 Login attempt (${mode}):`, credentials.email);
|
|
12
|
-
|
|
13
|
-
const response = await fetch(`${this.apiClient["baseUrl"]}${path}`, {
|
|
14
|
-
method: "POST",
|
|
15
|
-
headers: {
|
|
16
|
-
"Content-Type": "application/json",
|
|
17
|
-
"X-Organization": this.apiClient["organization"] || "default-org",
|
|
18
|
-
},
|
|
19
|
-
credentials: "include",
|
|
20
|
-
body: JSON.stringify({
|
|
21
|
-
email: credentials.email,
|
|
22
|
-
password: credentials.password,
|
|
23
|
-
}),
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
if (!response.ok) {
|
|
27
|
-
if (response.status === 401) throw new Error("Invalid credentials");
|
|
28
|
-
throw new Error(`Login failed: ${response.status}`);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const data: any = await response.json().catch(() => null);
|
|
32
|
-
|
|
33
|
-
if (mode === "legacy") {
|
|
34
|
-
// ✅ Token LEGACY (del sistema viejo)
|
|
35
|
-
const legacyToken = data?.dataResult?.token || data?.token;
|
|
36
|
-
|
|
37
|
-
if (legacyToken) {
|
|
38
|
-
if (typeof sessionStorage !== "undefined") {
|
|
39
|
-
sessionStorage.setItem("legacy_token", legacyToken);
|
|
40
|
-
}
|
|
41
|
-
if (typeof window !== "undefined") {
|
|
42
|
-
(window as any).__LEGACY_TOKEN__ = legacyToken;
|
|
43
|
-
}
|
|
44
|
-
console.log("✅ Legacy token saved");
|
|
45
|
-
} else {
|
|
46
|
-
console.warn("⚠️ No legacy token received");
|
|
47
|
-
}
|
|
48
|
-
} else {
|
|
49
|
-
// ✅ Token NUEVO (del sistema moderno)
|
|
50
|
-
const newToken = data?.token;
|
|
51
|
-
|
|
52
|
-
if (newToken) {
|
|
53
|
-
if (typeof sessionStorage !== "undefined") {
|
|
54
|
-
sessionStorage.setItem("auth_token", newToken);
|
|
55
|
-
}
|
|
56
|
-
if (typeof window !== "undefined") {
|
|
57
|
-
(window as any).__AUTH_TOKEN__ = newToken;
|
|
58
|
-
}
|
|
59
|
-
console.log("✅ Auth token saved");
|
|
60
|
-
} else {
|
|
61
|
-
console.warn("⚠️ No auth token received");
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
this.apiClient.setToken(null);
|
|
66
|
-
|
|
67
|
-
return { ok: true };
|
|
68
|
-
}*/
|
|
69
5
|
async login(credentials, mode = "new") {
|
|
70
6
|
var _a;
|
|
71
7
|
const path = mode === "legacy" ? "/legacy/login" : "/auth/login";
|
|
@@ -74,7 +10,7 @@ export class AuthApi {
|
|
|
74
10
|
method: "POST",
|
|
75
11
|
headers: {
|
|
76
12
|
"Content-Type": "application/json",
|
|
77
|
-
"X-Organization": this.apiClient["organization"] || "
|
|
13
|
+
"X-Organization": this.apiClient["organization"] || "qa",
|
|
78
14
|
},
|
|
79
15
|
credentials: "include",
|
|
80
16
|
body: JSON.stringify({
|
|
@@ -88,11 +24,10 @@ export class AuthApi {
|
|
|
88
24
|
throw new Error("Invalid credentials");
|
|
89
25
|
throw new Error(`Login failed: ${response.status}`);
|
|
90
26
|
}
|
|
91
|
-
// ✅ Lee el JSON con manejo de errores
|
|
92
27
|
let data;
|
|
93
28
|
try {
|
|
94
29
|
data = await response.json();
|
|
95
|
-
console.log(`📦 Response data (${mode}):`, data);
|
|
30
|
+
console.log(`📦 Response data (${mode}):`, data);
|
|
96
31
|
}
|
|
97
32
|
catch (error) {
|
|
98
33
|
console.error("❌ Error parsing JSON:", error);
|
package/package.json
CHANGED
package/src/config/config.ts
CHANGED
|
@@ -4,14 +4,9 @@ function normalizeUrl(url: string) {
|
|
|
4
4
|
return url.trim().replace(/\/+$/, "");
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
//function resolveDefaultBaseUrl(){
|
|
8
|
-
// const fromWindow = (globalThis as any)?.SDK_CONFIG?.API_BASE_URL;
|
|
9
|
-
// if (fromWindow) return normalizeUrl(String(fromWindow));
|
|
10
|
-
//}
|
|
11
|
-
|
|
12
7
|
export const DEFAULT_CONFIG: Partial<SdkConfig> = {
|
|
13
|
-
baseUrl: "https://zero-api-production.up.railway.app/ZeroApiQA/api/v1",
|
|
14
|
-
organization: "
|
|
8
|
+
baseUrl: "https://zero-api-production.up.railway.app/ZeroApiQA/api/v1",
|
|
9
|
+
organization: "qa",
|
|
15
10
|
cache: { enabled: true, ttl: 60000 },
|
|
16
11
|
debug: true,
|
|
17
12
|
credentials: "include",
|
|
@@ -10,70 +10,6 @@ export class AuthApi {
|
|
|
10
10
|
this.apiClient = apiClient;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
/*async login(
|
|
14
|
-
credentials: LoginCredentials,
|
|
15
|
-
mode: LoginMode = "new"
|
|
16
|
-
): Promise<{ ok: boolean }> {
|
|
17
|
-
const path = mode === "legacy" ? "/legacy/login" : "/auth/login";
|
|
18
|
-
|
|
19
|
-
console.log(`🔐 Login attempt (${mode}):`, credentials.email);
|
|
20
|
-
|
|
21
|
-
const response = await fetch(`${this.apiClient["baseUrl"]}${path}`, {
|
|
22
|
-
method: "POST",
|
|
23
|
-
headers: {
|
|
24
|
-
"Content-Type": "application/json",
|
|
25
|
-
"X-Organization": this.apiClient["organization"] || "default-org",
|
|
26
|
-
},
|
|
27
|
-
credentials: "include",
|
|
28
|
-
body: JSON.stringify({
|
|
29
|
-
email: credentials.email,
|
|
30
|
-
password: credentials.password,
|
|
31
|
-
}),
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
if (!response.ok) {
|
|
35
|
-
if (response.status === 401) throw new Error("Invalid credentials");
|
|
36
|
-
throw new Error(`Login failed: ${response.status}`);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const data: any = await response.json().catch(() => null);
|
|
40
|
-
|
|
41
|
-
if (mode === "legacy") {
|
|
42
|
-
// ✅ Token LEGACY (del sistema viejo)
|
|
43
|
-
const legacyToken = data?.dataResult?.token || data?.token;
|
|
44
|
-
|
|
45
|
-
if (legacyToken) {
|
|
46
|
-
if (typeof sessionStorage !== "undefined") {
|
|
47
|
-
sessionStorage.setItem("legacy_token", legacyToken);
|
|
48
|
-
}
|
|
49
|
-
if (typeof window !== "undefined") {
|
|
50
|
-
(window as any).__LEGACY_TOKEN__ = legacyToken;
|
|
51
|
-
}
|
|
52
|
-
console.log("✅ Legacy token saved");
|
|
53
|
-
} else {
|
|
54
|
-
console.warn("⚠️ No legacy token received");
|
|
55
|
-
}
|
|
56
|
-
} else {
|
|
57
|
-
// ✅ Token NUEVO (del sistema moderno)
|
|
58
|
-
const newToken = data?.token;
|
|
59
|
-
|
|
60
|
-
if (newToken) {
|
|
61
|
-
if (typeof sessionStorage !== "undefined") {
|
|
62
|
-
sessionStorage.setItem("auth_token", newToken);
|
|
63
|
-
}
|
|
64
|
-
if (typeof window !== "undefined") {
|
|
65
|
-
(window as any).__AUTH_TOKEN__ = newToken;
|
|
66
|
-
}
|
|
67
|
-
console.log("✅ Auth token saved");
|
|
68
|
-
} else {
|
|
69
|
-
console.warn("⚠️ No auth token received");
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
this.apiClient.setToken(null);
|
|
74
|
-
|
|
75
|
-
return { ok: true };
|
|
76
|
-
}*/
|
|
77
13
|
async login(
|
|
78
14
|
credentials: LoginCredentials,
|
|
79
15
|
mode: LoginMode = "new"
|
|
@@ -86,7 +22,7 @@ export class AuthApi {
|
|
|
86
22
|
method: "POST",
|
|
87
23
|
headers: {
|
|
88
24
|
"Content-Type": "application/json",
|
|
89
|
-
"X-Organization": this.apiClient["organization"] || "
|
|
25
|
+
"X-Organization": this.apiClient["organization"] || "qa",
|
|
90
26
|
},
|
|
91
27
|
credentials: "include",
|
|
92
28
|
body: JSON.stringify({
|
|
@@ -101,11 +37,10 @@ export class AuthApi {
|
|
|
101
37
|
throw new Error(`Login failed: ${response.status}`);
|
|
102
38
|
}
|
|
103
39
|
|
|
104
|
-
// ✅ Lee el JSON con manejo de errores
|
|
105
40
|
let data: any;
|
|
106
41
|
try {
|
|
107
42
|
data = await response.json();
|
|
108
|
-
console.log(`📦 Response data (${mode}):`, data);
|
|
43
|
+
console.log(`📦 Response data (${mode}):`, data);
|
|
109
44
|
} catch (error) {
|
|
110
45
|
console.error("❌ Error parsing JSON:", error);
|
|
111
46
|
return { ok: false };
|