@supsis/supsis-js 1.1.0 → 1.1.2

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Supsis JS SDK v1.0.0
2
+ * Supsis JS SDK v1.1.1
3
3
  * Supsis API SDK - Browser ve Node.js için omnichannel messaging, chatbot, automation, task, ticket ve voice agent entegrasyonu
4
4
  *
5
5
  * @license MIT
@@ -94,11 +94,22 @@ class HttpClient {
94
94
  * @param {boolean} [config.verbose=false] - Debug logları göster
95
95
  */
96
96
  constructor(config) {
97
+ config = config || {};
97
98
  this.config = Object.assign({}, DEFAULT_CONFIG, config);
98
99
  this.baseUrl = this._resolveBaseUrl();
99
100
  this.token = null;
100
- this.siteId = config.siteId || null;
101
- this.verbose = config.verbose || false;
101
+ this.siteId = this.config.siteId || null;
102
+ this.verbose = this.config.verbose || false;
103
+
104
+ // Debug: config değerlerini logla
105
+ if (this.verbose) {
106
+ console.log('[SupsisJS] HttpClient config:', {
107
+ timeout: this.config.timeout,
108
+ retryCount: this.config.retryCount,
109
+ env: this.config.env,
110
+ baseUrl: this.baseUrl
111
+ });
112
+ }
102
113
  }
103
114
 
104
115
  /**
@@ -236,10 +247,13 @@ class HttpClient {
236
247
  */
237
248
  async _fetchWithTimeout(url, options) {
238
249
  var self = this;
250
+ var timeout = this.config.timeout || 30000;
239
251
  var controller = new AbortController();
240
252
  var timeoutId = setTimeout(function() {
241
253
  controller.abort();
242
- }, this.config.timeout);
254
+ }, timeout);
255
+
256
+ self._log('info', 'Fetch timeout set to:', timeout, 'ms');
243
257
 
244
258
  try {
245
259
  var response = await fetch(url, Object.assign({}, options, {
@@ -250,19 +264,44 @@ class HttpClient {
250
264
  } catch (error) {
251
265
  clearTimeout(timeoutId);
252
266
 
253
- self._log('error', 'Fetch error:', error.name, error.message);
267
+ // Detaylı hata bilgisi
268
+ self._log('error', 'Fetch error details:', {
269
+ name: error.name,
270
+ message: error.message,
271
+ code: error.code,
272
+ cause: error.cause ? String(error.cause) : undefined
273
+ });
254
274
 
275
+ // AbortError - gerçek timeout mu yoksa başka bir sebep mi?
255
276
  if (error.name === 'AbortError') {
256
- throw new SupsisAPIError('Request timeout after ' + self.config.timeout + 'ms', 408, { originalError: error.message });
277
+ // error.cause varsa gerçek sebebi göster
278
+ var realCause = error.cause ? String(error.cause) : error.message;
279
+ throw new SupsisAPIError('Request aborted: ' + realCause, 408, {
280
+ originalError: error.message,
281
+ cause: realCause,
282
+ timeout: timeout
283
+ });
257
284
  }
258
285
 
259
286
  // Network hataları için daha açıklayıcı hata mesajı
260
- if (error.code === 'ECONNREFUSED' || error.code === 'ENOTFOUND' || error.message.indexOf('fetch') !== -1) {
261
- throw new SupsisAPIError('Network error: ' + error.message, 0, { originalError: error.message, code: error.code });
287
+ if (error.code === 'ECONNREFUSED') {
288
+ throw new SupsisAPIError('Connection refused: ' + url, 0, { originalError: error.message, code: error.code });
289
+ }
290
+
291
+ if (error.code === 'ENOTFOUND') {
292
+ throw new SupsisAPIError('Host not found: ' + url, 0, { originalError: error.message, code: error.code });
293
+ }
294
+
295
+ if (error.code === 'UNABLE_TO_VERIFY_LEAF_SIGNATURE' || error.code === 'CERT_HAS_EXPIRED' || error.code === 'DEPTH_ZERO_SELF_SIGNED_CERT') {
296
+ throw new SupsisAPIError('SSL/TLS certificate error: ' + error.message, 0, { originalError: error.message, code: error.code });
262
297
  }
263
298
 
264
299
  // Diğer hatalar için SupsisAPIError'a çevir
265
- throw new SupsisAPIError(error.message || 'Unknown fetch error', 0, { originalError: error.message });
300
+ throw new SupsisAPIError(error.message || 'Unknown fetch error', 0, {
301
+ originalError: error.message,
302
+ code: error.code,
303
+ cause: error.cause ? String(error.cause) : undefined
304
+ });
266
305
  }
267
306
  }
268
307
 
@@ -3733,15 +3772,19 @@ class SupsisJS {
3733
3772
  /** @private */
3734
3773
  this._verbose = config.verbose || false;
3735
3774
 
3736
- /** @private */
3737
- this._http = new HttpClient({
3775
+ // HttpClient config - undefined değerleri filtrele (DEFAULT_CONFIG'in override edilmemesi için)
3776
+ var httpConfig = {
3738
3777
  env: config.env || 'production',
3739
- baseApiAddress: config.baseApiAddress,
3740
3778
  siteId: config.siteId,
3741
- timeout: config.timeout,
3742
- retryCount: config.retryCount,
3743
3779
  verbose: config.verbose
3744
- });
3780
+ };
3781
+ if (config.baseApiAddress) httpConfig.baseApiAddress = config.baseApiAddress;
3782
+ if (config.timeout !== undefined) httpConfig.timeout = config.timeout;
3783
+ if (config.retryCount !== undefined) httpConfig.retryCount = config.retryCount;
3784
+ if (config.retryDelay !== undefined) httpConfig.retryDelay = config.retryDelay;
3785
+
3786
+ /** @private */
3787
+ this._http = new HttpClient(httpConfig);
3745
3788
 
3746
3789
  /** @private */
3747
3790
  this._connected = false;
@@ -3922,11 +3965,21 @@ class SupsisJS {
3922
3965
  }
3923
3966
 
3924
3967
  this._token = response.token;
3925
- this._user = response.user || response;
3968
+
3969
+ // API yanıtı: { user: { isSuccess: true, user: {...} }, token: "..." }
3970
+ // Gerçek user verisi response.user.user içinde
3971
+ if (response.user && response.user.user) {
3972
+ this._user = response.user.user;
3973
+ } else if (response.user) {
3974
+ this._user = response.user;
3975
+ } else {
3976
+ this._user = response;
3977
+ }
3978
+
3926
3979
  this._http.setToken(this._token);
3927
3980
  this._connected = true;
3928
3981
 
3929
- this._log('info', 'Connected successfully as:', this._user.fullname || this._user.email);
3982
+ this._log('info', 'Connected successfully as:', this._user.fullname || this._user.email || this._user._id);
3930
3983
 
3931
3984
  return this._user;
3932
3985
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Supsis JS SDK v1.0.0
2
+ * Supsis JS SDK v1.1.1
3
3
  * Supsis API SDK - Browser ve Node.js için omnichannel messaging, chatbot, automation, task, ticket ve voice agent entegrasyonu
4
4
  *
5
5
  * @license MIT
@@ -90,11 +90,22 @@ class HttpClient {
90
90
  * @param {boolean} [config.verbose=false] - Debug logları göster
91
91
  */
92
92
  constructor(config) {
93
+ config = config || {};
93
94
  this.config = Object.assign({}, DEFAULT_CONFIG, config);
94
95
  this.baseUrl = this._resolveBaseUrl();
95
96
  this.token = null;
96
- this.siteId = config.siteId || null;
97
- this.verbose = config.verbose || false;
97
+ this.siteId = this.config.siteId || null;
98
+ this.verbose = this.config.verbose || false;
99
+
100
+ // Debug: config değerlerini logla
101
+ if (this.verbose) {
102
+ console.log('[SupsisJS] HttpClient config:', {
103
+ timeout: this.config.timeout,
104
+ retryCount: this.config.retryCount,
105
+ env: this.config.env,
106
+ baseUrl: this.baseUrl
107
+ });
108
+ }
98
109
  }
99
110
 
100
111
  /**
@@ -232,10 +243,13 @@ class HttpClient {
232
243
  */
233
244
  async _fetchWithTimeout(url, options) {
234
245
  var self = this;
246
+ var timeout = this.config.timeout || 30000;
235
247
  var controller = new AbortController();
236
248
  var timeoutId = setTimeout(function() {
237
249
  controller.abort();
238
- }, this.config.timeout);
250
+ }, timeout);
251
+
252
+ self._log('info', 'Fetch timeout set to:', timeout, 'ms');
239
253
 
240
254
  try {
241
255
  var response = await fetch(url, Object.assign({}, options, {
@@ -246,19 +260,44 @@ class HttpClient {
246
260
  } catch (error) {
247
261
  clearTimeout(timeoutId);
248
262
 
249
- self._log('error', 'Fetch error:', error.name, error.message);
263
+ // Detaylı hata bilgisi
264
+ self._log('error', 'Fetch error details:', {
265
+ name: error.name,
266
+ message: error.message,
267
+ code: error.code,
268
+ cause: error.cause ? String(error.cause) : undefined
269
+ });
250
270
 
271
+ // AbortError - gerçek timeout mu yoksa başka bir sebep mi?
251
272
  if (error.name === 'AbortError') {
252
- throw new SupsisAPIError('Request timeout after ' + self.config.timeout + 'ms', 408, { originalError: error.message });
273
+ // error.cause varsa gerçek sebebi göster
274
+ var realCause = error.cause ? String(error.cause) : error.message;
275
+ throw new SupsisAPIError('Request aborted: ' + realCause, 408, {
276
+ originalError: error.message,
277
+ cause: realCause,
278
+ timeout: timeout
279
+ });
253
280
  }
254
281
 
255
282
  // Network hataları için daha açıklayıcı hata mesajı
256
- if (error.code === 'ECONNREFUSED' || error.code === 'ENOTFOUND' || error.message.indexOf('fetch') !== -1) {
257
- throw new SupsisAPIError('Network error: ' + error.message, 0, { originalError: error.message, code: error.code });
283
+ if (error.code === 'ECONNREFUSED') {
284
+ throw new SupsisAPIError('Connection refused: ' + url, 0, { originalError: error.message, code: error.code });
285
+ }
286
+
287
+ if (error.code === 'ENOTFOUND') {
288
+ throw new SupsisAPIError('Host not found: ' + url, 0, { originalError: error.message, code: error.code });
289
+ }
290
+
291
+ if (error.code === 'UNABLE_TO_VERIFY_LEAF_SIGNATURE' || error.code === 'CERT_HAS_EXPIRED' || error.code === 'DEPTH_ZERO_SELF_SIGNED_CERT') {
292
+ throw new SupsisAPIError('SSL/TLS certificate error: ' + error.message, 0, { originalError: error.message, code: error.code });
258
293
  }
259
294
 
260
295
  // Diğer hatalar için SupsisAPIError'a çevir
261
- throw new SupsisAPIError(error.message || 'Unknown fetch error', 0, { originalError: error.message });
296
+ throw new SupsisAPIError(error.message || 'Unknown fetch error', 0, {
297
+ originalError: error.message,
298
+ code: error.code,
299
+ cause: error.cause ? String(error.cause) : undefined
300
+ });
262
301
  }
263
302
  }
264
303
 
@@ -3729,15 +3768,19 @@ class SupsisJS {
3729
3768
  /** @private */
3730
3769
  this._verbose = config.verbose || false;
3731
3770
 
3732
- /** @private */
3733
- this._http = new HttpClient({
3771
+ // HttpClient config - undefined değerleri filtrele (DEFAULT_CONFIG'in override edilmemesi için)
3772
+ var httpConfig = {
3734
3773
  env: config.env || 'production',
3735
- baseApiAddress: config.baseApiAddress,
3736
3774
  siteId: config.siteId,
3737
- timeout: config.timeout,
3738
- retryCount: config.retryCount,
3739
3775
  verbose: config.verbose
3740
- });
3776
+ };
3777
+ if (config.baseApiAddress) httpConfig.baseApiAddress = config.baseApiAddress;
3778
+ if (config.timeout !== undefined) httpConfig.timeout = config.timeout;
3779
+ if (config.retryCount !== undefined) httpConfig.retryCount = config.retryCount;
3780
+ if (config.retryDelay !== undefined) httpConfig.retryDelay = config.retryDelay;
3781
+
3782
+ /** @private */
3783
+ this._http = new HttpClient(httpConfig);
3741
3784
 
3742
3785
  /** @private */
3743
3786
  this._connected = false;
@@ -3918,11 +3961,21 @@ class SupsisJS {
3918
3961
  }
3919
3962
 
3920
3963
  this._token = response.token;
3921
- this._user = response.user || response;
3964
+
3965
+ // API yanıtı: { user: { isSuccess: true, user: {...} }, token: "..." }
3966
+ // Gerçek user verisi response.user.user içinde
3967
+ if (response.user && response.user.user) {
3968
+ this._user = response.user.user;
3969
+ } else if (response.user) {
3970
+ this._user = response.user;
3971
+ } else {
3972
+ this._user = response;
3973
+ }
3974
+
3922
3975
  this._http.setToken(this._token);
3923
3976
  this._connected = true;
3924
3977
 
3925
- this._log('info', 'Connected successfully as:', this._user.fullname || this._user.email);
3978
+ this._log('info', 'Connected successfully as:', this._user.fullname || this._user.email || this._user._id);
3926
3979
 
3927
3980
  return this._user;
3928
3981
  }
package/dist/supsis.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Supsis JS SDK v1.0.0
2
+ * Supsis JS SDK v1.1.1
3
3
  * Supsis API SDK - Browser ve Node.js için omnichannel messaging, chatbot, automation, task, ticket ve voice agent entegrasyonu
4
4
  *
5
5
  * @license MIT
@@ -96,11 +96,22 @@
96
96
  * @param {boolean} [config.verbose=false] - Debug logları göster
97
97
  */
98
98
  constructor(config) {
99
+ config = config || {};
99
100
  this.config = Object.assign({}, DEFAULT_CONFIG, config);
100
101
  this.baseUrl = this._resolveBaseUrl();
101
102
  this.token = null;
102
- this.siteId = config.siteId || null;
103
- this.verbose = config.verbose || false;
103
+ this.siteId = this.config.siteId || null;
104
+ this.verbose = this.config.verbose || false;
105
+
106
+ // Debug: config değerlerini logla
107
+ if (this.verbose) {
108
+ console.log('[SupsisJS] HttpClient config:', {
109
+ timeout: this.config.timeout,
110
+ retryCount: this.config.retryCount,
111
+ env: this.config.env,
112
+ baseUrl: this.baseUrl
113
+ });
114
+ }
104
115
  }
105
116
 
106
117
  /**
@@ -238,10 +249,13 @@
238
249
  */
239
250
  async _fetchWithTimeout(url, options) {
240
251
  var self = this;
252
+ var timeout = this.config.timeout || 30000;
241
253
  var controller = new AbortController();
242
254
  var timeoutId = setTimeout(function() {
243
255
  controller.abort();
244
- }, this.config.timeout);
256
+ }, timeout);
257
+
258
+ self._log('info', 'Fetch timeout set to:', timeout, 'ms');
245
259
 
246
260
  try {
247
261
  var response = await fetch(url, Object.assign({}, options, {
@@ -252,19 +266,44 @@
252
266
  } catch (error) {
253
267
  clearTimeout(timeoutId);
254
268
 
255
- self._log('error', 'Fetch error:', error.name, error.message);
269
+ // Detaylı hata bilgisi
270
+ self._log('error', 'Fetch error details:', {
271
+ name: error.name,
272
+ message: error.message,
273
+ code: error.code,
274
+ cause: error.cause ? String(error.cause) : undefined
275
+ });
256
276
 
277
+ // AbortError - gerçek timeout mu yoksa başka bir sebep mi?
257
278
  if (error.name === 'AbortError') {
258
- throw new SupsisAPIError('Request timeout after ' + self.config.timeout + 'ms', 408, { originalError: error.message });
279
+ // error.cause varsa gerçek sebebi göster
280
+ var realCause = error.cause ? String(error.cause) : error.message;
281
+ throw new SupsisAPIError('Request aborted: ' + realCause, 408, {
282
+ originalError: error.message,
283
+ cause: realCause,
284
+ timeout: timeout
285
+ });
259
286
  }
260
287
 
261
288
  // Network hataları için daha açıklayıcı hata mesajı
262
- if (error.code === 'ECONNREFUSED' || error.code === 'ENOTFOUND' || error.message.indexOf('fetch') !== -1) {
263
- throw new SupsisAPIError('Network error: ' + error.message, 0, { originalError: error.message, code: error.code });
289
+ if (error.code === 'ECONNREFUSED') {
290
+ throw new SupsisAPIError('Connection refused: ' + url, 0, { originalError: error.message, code: error.code });
291
+ }
292
+
293
+ if (error.code === 'ENOTFOUND') {
294
+ throw new SupsisAPIError('Host not found: ' + url, 0, { originalError: error.message, code: error.code });
295
+ }
296
+
297
+ if (error.code === 'UNABLE_TO_VERIFY_LEAF_SIGNATURE' || error.code === 'CERT_HAS_EXPIRED' || error.code === 'DEPTH_ZERO_SELF_SIGNED_CERT') {
298
+ throw new SupsisAPIError('SSL/TLS certificate error: ' + error.message, 0, { originalError: error.message, code: error.code });
264
299
  }
265
300
 
266
301
  // Diğer hatalar için SupsisAPIError'a çevir
267
- throw new SupsisAPIError(error.message || 'Unknown fetch error', 0, { originalError: error.message });
302
+ throw new SupsisAPIError(error.message || 'Unknown fetch error', 0, {
303
+ originalError: error.message,
304
+ code: error.code,
305
+ cause: error.cause ? String(error.cause) : undefined
306
+ });
268
307
  }
269
308
  }
270
309
 
@@ -3735,15 +3774,19 @@
3735
3774
  /** @private */
3736
3775
  this._verbose = config.verbose || false;
3737
3776
 
3738
- /** @private */
3739
- this._http = new HttpClient({
3777
+ // HttpClient config - undefined değerleri filtrele (DEFAULT_CONFIG'in override edilmemesi için)
3778
+ var httpConfig = {
3740
3779
  env: config.env || 'production',
3741
- baseApiAddress: config.baseApiAddress,
3742
3780
  siteId: config.siteId,
3743
- timeout: config.timeout,
3744
- retryCount: config.retryCount,
3745
3781
  verbose: config.verbose
3746
- });
3782
+ };
3783
+ if (config.baseApiAddress) httpConfig.baseApiAddress = config.baseApiAddress;
3784
+ if (config.timeout !== undefined) httpConfig.timeout = config.timeout;
3785
+ if (config.retryCount !== undefined) httpConfig.retryCount = config.retryCount;
3786
+ if (config.retryDelay !== undefined) httpConfig.retryDelay = config.retryDelay;
3787
+
3788
+ /** @private */
3789
+ this._http = new HttpClient(httpConfig);
3747
3790
 
3748
3791
  /** @private */
3749
3792
  this._connected = false;
@@ -3924,11 +3967,21 @@
3924
3967
  }
3925
3968
 
3926
3969
  this._token = response.token;
3927
- this._user = response.user || response;
3970
+
3971
+ // API yanıtı: { user: { isSuccess: true, user: {...} }, token: "..." }
3972
+ // Gerçek user verisi response.user.user içinde
3973
+ if (response.user && response.user.user) {
3974
+ this._user = response.user.user;
3975
+ } else if (response.user) {
3976
+ this._user = response.user;
3977
+ } else {
3978
+ this._user = response;
3979
+ }
3980
+
3928
3981
  this._http.setToken(this._token);
3929
3982
  this._connected = true;
3930
3983
 
3931
- this._log('info', 'Connected successfully as:', this._user.fullname || this._user.email);
3984
+ this._log('info', 'Connected successfully as:', this._user.fullname || this._user.email || this._user._id);
3932
3985
 
3933
3986
  return this._user;
3934
3987
  }