soyba-lib 1.0.5 → 1.0.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/package.json +1 -1
- package/src/index.js +17 -4
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import { parseStringPromise } from 'xml2js';
|
|
|
5
5
|
class YBAClient {
|
|
6
6
|
constructor(options = {}) {
|
|
7
7
|
this.baseUrl = options.baseUrl || process.env.API_SOYBA;
|
|
8
|
+
this.baseUrlKq = options.baseUrlKq || process.env.API_SOYBA_KQ;
|
|
8
9
|
this.apiKey = options.apiKey || process.env.API_KEY;
|
|
9
10
|
this.timeout = options.timeout || 30000;
|
|
10
11
|
this.logger = options.logger || console;
|
|
@@ -12,6 +13,14 @@ class YBAClient {
|
|
|
12
13
|
if (!this.baseUrl) {
|
|
13
14
|
throw new Error('YBA baseUrl is required');
|
|
14
15
|
}
|
|
16
|
+
|
|
17
|
+
// Log configuration for debugging
|
|
18
|
+
this.logger.debug('YBAClient initialized', {
|
|
19
|
+
baseUrl: this.baseUrl,
|
|
20
|
+
baseUrlKq: this.baseUrlKq,
|
|
21
|
+
hasApiKey: !!this.apiKey,
|
|
22
|
+
timeout: this.timeout
|
|
23
|
+
});
|
|
15
24
|
}
|
|
16
25
|
|
|
17
26
|
_buildAuthorizationHeader(token) {
|
|
@@ -155,12 +164,16 @@ class YBAClient {
|
|
|
155
164
|
async getChiTietLichSu(cccd, ma_lk, token) {
|
|
156
165
|
const correlationId = `soyba_detail_${Date.now()}_${Math.random().toString(36).slice(2,9)}`;
|
|
157
166
|
|
|
158
|
-
if
|
|
159
|
-
|
|
160
|
-
|
|
167
|
+
// Use baseUrlKq for detail requests if different from baseUrl
|
|
168
|
+
const baseUrlToUse = this.baseUrlKq;
|
|
169
|
+
|
|
170
|
+
if (!baseUrlToUse) {
|
|
171
|
+
this.logger.error('SOYBAKQ base url not configured', { correlationId });
|
|
172
|
+
throw new Error('Missing API_SOYBA_KQ in environment');
|
|
161
173
|
}
|
|
162
174
|
|
|
163
|
-
|
|
175
|
+
// If baseUrlKq is different, use it directly, otherwise append path
|
|
176
|
+
const url = baseUrlToUse
|
|
164
177
|
const headers = { 'Content-Type': 'application/json' };
|
|
165
178
|
const auth = this._buildAuthorizationHeader(token);
|
|
166
179
|
if (auth) headers.Authorization = auth;
|