@zerosls/clm-sdk 1.1.4 → 1.1.6

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/.gitlab-ci.yml CHANGED
@@ -20,4 +20,4 @@ publish:
20
20
  - echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc
21
21
  - npm publish --access public
22
22
  rules:
23
- - if: $CI_COMMIT_BRANCH == "main"
23
+ - if: $CI_COMMIT_BRANCH == "develop"
@@ -62,27 +62,32 @@ export class ApiClient {
62
62
  ...(options.headers || {}),
63
63
  });
64
64
  const headers = new Headers(base);
65
- const legacyPattern = /(^|\/)legacy(\/|$)/i;
66
- const isLegacyEndpoint = legacyPattern.test(endpoint);
67
- if (isLegacyEndpoint) {
68
- const legacyToken = window.__LEGACY_TOKEN__ ||
69
- sessionStorage.getItem("legacy_token") ||
70
- null;
71
- if (legacyToken) {
72
- headers.set("Authorization", `Bearer ${legacyToken}`);
73
- if (this.debug) {
74
- console.log("🔐 Using legacy token for:", endpoint);
75
- }
65
+ //const legacyPattern = /(^|\/)legacy(\/|$)/i;
66
+ //const isLegacyEndpoint = legacyPattern.test(endpoint);
67
+ //if (isLegacyEndpoint) {
68
+ const legacyToken = window.__LEGACY_TOKEN__ ||
69
+ sessionStorage.getItem("legacy_token") ||
70
+ null;
71
+ if (legacyToken) {
72
+ headers.set("Authorization", `Bearer ${legacyToken}`);
73
+ if (this.debug) {
74
+ console.log("🔐 Using legacy token for:", endpoint);
76
75
  }
77
- else {
78
- console.warn("⚠️ No legacy token available for legacy endpoint:", endpoint);
76
+ }
77
+ else if (this.token) {
78
+ // ✅ Si no hay legacy token, usar token v1
79
+ if (this.debug) {
80
+ console.log("🔐 Using v1 token for:", endpoint);
79
81
  }
80
82
  }
81
83
  else {
82
- if (!this.token) {
83
- headers.delete("Authorization");
84
- }
84
+ console.warn("⚠️ No token available for endpoint:", endpoint);
85
85
  }
86
+ //} else {
87
+ // if (!this.token) {
88
+ // headers.delete("Authorization");
89
+ // }
90
+ //}
86
91
  const useCache = this.cacheEnabled && options.useCache !== false;
87
92
  if (useCache && method === "GET") {
88
93
  const cacheKey = generateCacheKey(method, url, data);
@@ -0,0 +1,26 @@
1
+ export interface LegacyLoginRequest {
2
+ userName: string;
3
+ password: string;
4
+ }
5
+ export interface LegacyLoginResponse {
6
+ dataResult: {
7
+ token: string;
8
+ userType: string;
9
+ userId: string;
10
+ userName: string;
11
+ area: string;
12
+ id_Area: number;
13
+ id_Role: string;
14
+ };
15
+ statusResponse: {
16
+ code: number;
17
+ success: boolean;
18
+ message: string;
19
+ };
20
+ }
21
+ export declare class LegacyApiClient {
22
+ private baseUrl;
23
+ constructor(baseUrl: string);
24
+ login(userName: string, password: string): Promise<LegacyLoginResponse>;
25
+ logout(): void;
26
+ }
@@ -0,0 +1,35 @@
1
+ export class LegacyApiClient {
2
+ constructor(baseUrl) {
3
+ this.baseUrl = baseUrl;
4
+ }
5
+ async login(userName, password) {
6
+ var _a, _b;
7
+ const url = `${this.baseUrl}/auth/login`;
8
+ const response = await fetch(url, {
9
+ method: 'POST',
10
+ headers: { 'Content-Type': 'application/json' },
11
+ credentials: 'include',
12
+ body: JSON.stringify({ userName, password }),
13
+ });
14
+ if (!response.ok) {
15
+ const errorData = await response.json().catch(() => ({
16
+ statusResponse: {
17
+ code: response.status,
18
+ success: false,
19
+ message: response.statusText
20
+ }
21
+ }));
22
+ throw new Error(((_a = errorData.statusResponse) === null || _a === void 0 ? void 0 : _a.message) || 'Legacy login failed');
23
+ }
24
+ const data = await response.json();
25
+ if ((_b = data.dataResult) === null || _b === void 0 ? void 0 : _b.token) {
26
+ sessionStorage.setItem('legacy_token', data.dataResult.token);
27
+ window.__LEGACY_TOKEN__ = data.dataResult.token;
28
+ }
29
+ return data;
30
+ }
31
+ logout() {
32
+ sessionStorage.removeItem('legacy_token');
33
+ delete window.__LEGACY_TOKEN__;
34
+ }
35
+ }
package/dist/index.d.ts CHANGED
@@ -12,6 +12,7 @@ import { ClassificationTypesApi } from "./modules/legacy/classificationtypes/cla
12
12
  */
13
13
  export declare class ClmSdk {
14
14
  private apiClient;
15
+ private legacyClient;
15
16
  private eventEmitter;
16
17
  private cacheInstance;
17
18
  auth: AuthApi;
@@ -22,6 +23,8 @@ export declare class ClmSdk {
22
23
  areas: AreasApi;
23
24
  classificationTypes: ClassificationTypesApi;
24
25
  constructor(config: Partial<SdkConfig>);
26
+ legacyLogin(userName: string, password: string): Promise<import("./core/legacy-api-client").LegacyLoginResponse>;
27
+ legacyLogout(): void;
25
28
  /**
26
29
  * Access to events system
27
30
  */
@@ -40,5 +43,6 @@ export * from "./modules/v1/auth/types";
40
43
  export * from "./modules/v1/users/types";
41
44
  export * from "./modules/v1/notifications/types";
42
45
  export * from "./modules/v1/_logs/types";
46
+ export * from "./core/legacy-api-client";
43
47
  export * from "./modules/legacy/areas/types";
44
48
  export * from "./modules/legacy/classificationtypes/types";
package/dist/index.js CHANGED
@@ -11,6 +11,7 @@ import { LogsApi } from "./modules/v1/_logs/logs-api";
11
11
  // Legacy
12
12
  import { AreasApi } from "./modules/legacy/areas/areas-api";
13
13
  import { ClassificationTypesApi } from "./modules/legacy/classificationtypes/classificationtypes-api";
14
+ import { LegacyApiClient } from "./core/legacy-api-client";
14
15
  /**
15
16
  * Main SDK for consuming CLM API
16
17
  */
@@ -30,6 +31,7 @@ export class ClmSdk {
30
31
  // Initialize core utilities
31
32
  this.cacheInstance = new Cache((_a = fullConfig.cache) === null || _a === void 0 ? void 0 : _a.ttl);
32
33
  this.apiClient = new ApiClient(fullConfig, this.eventEmitter);
34
+ this.legacyClient = new LegacyApiClient("http://216.250.117.119/ZeroServicesQA/api/v1");
33
35
  // Initialize modules v1
34
36
  this.auth = new AuthApi(this.apiClient);
35
37
  this.users = new UsersApi(this.apiClient);
@@ -40,6 +42,12 @@ export class ClmSdk {
40
42
  this.areas = new AreasApi(this.apiClient);
41
43
  this.classificationTypes = new ClassificationTypesApi(this.apiClient);
42
44
  }
45
+ async legacyLogin(userName, password) {
46
+ return await this.legacyClient.login(userName, password);
47
+ }
48
+ legacyLogout() {
49
+ this.legacyClient.logout();
50
+ }
43
51
  /**
44
52
  * Access to events system
45
53
  */
@@ -55,5 +63,6 @@ export * from "./modules/v1/users/types";
55
63
  export * from "./modules/v1/notifications/types";
56
64
  export * from "./modules/v1/_logs/types";
57
65
  // Export legacy types
66
+ export * from "./core/legacy-api-client";
58
67
  export * from "./modules/legacy/areas/types";
59
68
  export * from "./modules/legacy/classificationtypes/types";
@@ -1,6 +1,6 @@
1
1
  export class ClassificationTypesApi {
2
2
  constructor(apiClient) {
3
- this.basePath = "/legacy/catalog/clasificationtype";
3
+ this.basePath = "/catalog/clasificationtype";
4
4
  this.apiClient = apiClient;
5
5
  }
6
6
  async getClassificationTypes(options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zerosls/clm-sdk",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "description": "SDK for ZeroCLM API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -138,33 +138,36 @@ export class ApiClient {
138
138
 
139
139
  const headers = new Headers(base);
140
140
 
141
- const legacyPattern = /(^|\/)legacy(\/|$)/i;
142
- const isLegacyEndpoint = legacyPattern.test(endpoint);
143
-
144
- if (isLegacyEndpoint) {
145
- const legacyToken =
146
- (window as any).__LEGACY_TOKEN__ ||
147
- sessionStorage.getItem("legacy_token") ||
148
- null;
149
-
150
- if (legacyToken) {
151
- headers.set("Authorization", `Bearer ${legacyToken}`);
141
+ //const legacyPattern = /(^|\/)legacy(\/|$)/i;
142
+ //const isLegacyEndpoint = legacyPattern.test(endpoint);
152
143
 
153
- if (this.debug) {
154
- console.log("🔐 Using legacy token for:", endpoint);
155
- }
156
- } else {
157
- console.warn(
158
- "⚠️ No legacy token available for legacy endpoint:",
159
- endpoint
160
- );
144
+ //if (isLegacyEndpoint) {
145
+ const legacyToken =
146
+ (window as any).__LEGACY_TOKEN__ ||
147
+ sessionStorage.getItem("legacy_token") ||
148
+ null;
149
+
150
+ if (legacyToken) {
151
+ headers.set("Authorization", `Bearer ${legacyToken}`);
152
+
153
+ if (this.debug) {
154
+ console.log("🔐 Using legacy token for:", endpoint);
161
155
  }
162
- } else {
163
- if (!this.token) {
164
- headers.delete("Authorization");
156
+ } else if (this.token) {
157
+ // ✅ Si no hay legacy token, usar token v1
158
+ if (this.debug) {
159
+ console.log("🔐 Using v1 token for:", endpoint);
165
160
  }
161
+ } else {
162
+ console.warn("⚠️ No token available for endpoint:", endpoint);
166
163
  }
167
164
 
165
+ //} else {
166
+ // if (!this.token) {
167
+ // headers.delete("Authorization");
168
+ // }
169
+ //}
170
+
168
171
  const useCache = this.cacheEnabled && options.useCache !== false;
169
172
  if (useCache && method === "GET") {
170
173
  const cacheKey = generateCacheKey(method, url, data);
@@ -0,0 +1,66 @@
1
+ export interface LegacyLoginRequest {
2
+ userName: string;
3
+ password: string;
4
+ }
5
+
6
+ export interface LegacyLoginResponse {
7
+ dataResult: {
8
+ token: string;
9
+ userType: string;
10
+ userId: string;
11
+ userName: string;
12
+ area: string;
13
+ id_Area: number;
14
+ id_Role: string;
15
+ };
16
+ statusResponse: {
17
+ code: number;
18
+ success: boolean;
19
+ message: string;
20
+ };
21
+ }
22
+
23
+ export class LegacyApiClient {
24
+ private baseUrl: string;
25
+
26
+ constructor(baseUrl: string) {
27
+ this.baseUrl = baseUrl;
28
+ }
29
+
30
+ async login(userName: string, password: string): Promise<LegacyLoginResponse> {
31
+ const url = `${this.baseUrl}/auth/login`;
32
+
33
+ const response = await fetch(url, {
34
+ method: 'POST',
35
+ headers: { 'Content-Type': 'application/json' },
36
+ credentials: 'include',
37
+ body: JSON.stringify({ userName, password }),
38
+ });
39
+
40
+ if (!response.ok) {
41
+ const errorData = await response.json().catch(() => ({
42
+ statusResponse: {
43
+ code: response.status,
44
+ success: false,
45
+ message: response.statusText
46
+ }
47
+ }));
48
+
49
+ throw new Error(errorData.statusResponse?.message || 'Legacy login failed');
50
+ }
51
+
52
+ const data: LegacyLoginResponse = await response.json();
53
+
54
+ if (data.dataResult?.token) {
55
+ sessionStorage.setItem('legacy_token', data.dataResult.token);
56
+ (window as any).__LEGACY_TOKEN__ = data.dataResult.token;
57
+ }
58
+
59
+ return data;
60
+ }
61
+
62
+ logout(): void {
63
+ sessionStorage.removeItem('legacy_token');
64
+ delete (window as any).__LEGACY_TOKEN__;
65
+ }
66
+ }
package/src/index.ts CHANGED
@@ -15,12 +15,14 @@ import { LogsApi } from "./modules/v1/_logs/logs-api";
15
15
  // Legacy
16
16
  import { AreasApi } from "./modules/legacy/areas/areas-api";
17
17
  import { ClassificationTypesApi } from "./modules/legacy/classificationtypes/classificationtypes-api";
18
+ import { LegacyApiClient } from "./core/legacy-api-client";
18
19
 
19
20
  /**
20
21
  * Main SDK for consuming CLM API
21
22
  */
22
23
  export class ClmSdk {
23
24
  private apiClient: ApiClient;
25
+ private legacyClient: LegacyApiClient;
24
26
  private eventEmitter: EventEmitter;
25
27
  private cacheInstance: Cache;
26
28
 
@@ -45,6 +47,10 @@ export class ClmSdk {
45
47
  this.cacheInstance = new Cache(fullConfig.cache?.ttl);
46
48
  this.apiClient = new ApiClient(fullConfig, this.eventEmitter);
47
49
 
50
+ this.legacyClient = new LegacyApiClient(
51
+ "http://216.250.117.119/ZeroServicesQA/api/v1"
52
+ );
53
+
48
54
  // Initialize modules v1
49
55
  this.auth = new AuthApi(this.apiClient);
50
56
  this.users = new UsersApi(this.apiClient);
@@ -57,6 +63,14 @@ export class ClmSdk {
57
63
  this.classificationTypes = new ClassificationTypesApi(this.apiClient);
58
64
  }
59
65
 
66
+ async legacyLogin(userName: string, password: string) {
67
+ return await this.legacyClient.login(userName, password);
68
+ }
69
+
70
+ legacyLogout(): void {
71
+ this.legacyClient.logout();
72
+ }
73
+
60
74
  /**
61
75
  * Access to events system
62
76
  */
@@ -75,7 +89,7 @@ export class ClmSdk {
75
89
  clearByPrefix: (prefix: string) => this.cacheInstance.clearByPrefix(prefix),
76
90
  };
77
91
  }
78
-
92
+
79
93
  export * from "./types/common";
80
94
  export * from "./types/sdk";
81
95
 
@@ -86,5 +100,6 @@ export * from "./modules/v1/notifications/types";
86
100
  export * from "./modules/v1/_logs/types";
87
101
 
88
102
  // Export legacy types
103
+ export * from "./core/legacy-api-client";
89
104
  export * from "./modules/legacy/areas/types";
90
105
  export * from "./modules/legacy/classificationtypes/types";
@@ -10,7 +10,7 @@ import {
10
10
 
11
11
  export class ClassificationTypesApi {
12
12
  private apiClient: ApiClient;
13
- private readonly basePath = "/legacy/catalog/clasificationtype";
13
+ private readonly basePath = "/catalog/clasificationtype";
14
14
 
15
15
  constructor(apiClient: ApiClient) {
16
16
  this.apiClient = apiClient;