sunuid-sdk 1.0.42 → 1.0.43

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.
@@ -327,7 +327,6 @@ function _unsupportedIterableToArray(r, a) {
327
327
  */
328
328
  var SunuID = /*#__PURE__*/function () {
329
329
  function SunuID() {
330
- var _this = this;
331
330
  var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
332
331
  _classCallCheck(this, SunuID);
333
332
  this.config = _objectSpread2(_objectSpread2({}, DEFAULT_CONFIG), config);
@@ -337,13 +336,9 @@ function _unsupportedIterableToArray(r, a) {
337
336
  this.socket = null;
338
337
  this.initPromise = null;
339
338
 
340
- // Initialisation asynchrone seulement si autoInit est explicitement activé
341
- if (this.config.autoInit === true) {
342
- // Délai pour éviter les conflits avec d'autres scripts
343
- setTimeout(function () {
344
- _this.init();
345
- }, 100);
346
- }
339
+ // DÉSACTIVÉ : Initialisation automatique pour éviter les boucles
340
+ // L'utilisateur doit appeler init() manuellement
341
+ console.log('🔧 SDK SunuID créé - Appelez init() manuellement');
347
342
  }
348
343
 
349
344
  /**
@@ -354,7 +349,7 @@ function _unsupportedIterableToArray(r, a) {
354
349
  value: (function () {
355
350
  var _init = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
356
351
  return _regenerator().w(function (_context) {
357
- while (1) switch (_context.n) {
352
+ while (1) switch (_context.p = _context.n) {
358
353
  case 0:
359
354
  if (!this.isInitialized) {
360
355
  _context.n = 1;
@@ -370,10 +365,26 @@ function _unsupportedIterableToArray(r, a) {
370
365
  console.log('⚠️ Initialisation déjà en cours, attente...');
371
366
  return _context.a(2, this.initPromise);
372
367
  case 2:
368
+ if (!this._initInProgress) {
369
+ _context.n = 3;
370
+ break;
371
+ }
372
+ console.log('⚠️ Initialisation en cours, ignoré');
373
+ return _context.a(2);
374
+ case 3:
375
+ this._initInProgress = true;
373
376
  this.initPromise = this._doInit();
377
+ _context.p = 4;
378
+ _context.n = 5;
379
+ return this.initPromise;
380
+ case 5:
381
+ _context.p = 5;
382
+ this._initInProgress = false;
383
+ return _context.f(5);
384
+ case 6:
374
385
  return _context.a(2, this.initPromise);
375
386
  }
376
- }, _callee, this);
387
+ }, _callee, this, [[4,, 5, 6]]);
377
388
  }));
378
389
  function init() {
379
390
  return _init.apply(this, arguments);
@@ -593,14 +604,14 @@ function _unsupportedIterableToArray(r, a) {
593
604
  }, {
594
605
  key: "initWebSocket",
595
606
  value: function initWebSocket() {
596
- var _this2 = this;
607
+ var _this = this;
597
608
  try {
598
609
  // Vérifier si Socket.IO est disponible
599
610
  if (typeof io === 'undefined') {
600
611
  console.warn('⚠️ Socket.IO non disponible, WebSocket sera initialisé plus tard');
601
612
  // Réessayer après un délai
602
613
  setTimeout(function () {
603
- return _this2.initWebSocket();
614
+ return _this.initWebSocket();
604
615
  }, 1000);
605
616
  return;
606
617
  }
@@ -624,36 +635,36 @@ function _unsupportedIterableToArray(r, a) {
624
635
  // Gestion des événements WebSocket
625
636
  this.socket.on('connect', function () {
626
637
  console.log('🌐 WebSocket connecté avec succès');
627
- console.log('📊 Socket ID:', _this2.socket.id);
628
- _this2.socket.connected = true;
638
+ console.log('📊 Socket ID:', _this.socket.id);
639
+ _this.socket.connected = true;
629
640
  });
630
641
  this.socket.on('disconnect', function (reason) {
631
642
  console.log('❌ WebSocket déconnecté:', reason);
632
- _this2.socket.connected = false;
643
+ _this.socket.connected = false;
633
644
  });
634
645
  this.socket.on('connect_error', function (error) {
635
646
  console.error('❌ Erreur connexion WebSocket:', error);
636
- _this2.socket.connected = false;
647
+ _this.socket.connected = false;
637
648
  });
638
649
 
639
650
  // Écouter les événements spécifiques
640
651
  this.socket.on('qr_status_update', function (data) {
641
652
  console.log('📱 Mise à jour statut QR reçue:', data);
642
- _this2.handleQRStatusUpdate(data);
653
+ _this.handleQRStatusUpdate(data);
643
654
  });
644
655
  this.socket.on('qr_scan_success', function (data) {
645
656
  console.log('✅ Scan QR réussi reçu:', data);
646
- _this2.handleQRScanSuccess(data);
657
+ _this.handleQRScanSuccess(data);
647
658
  });
648
659
  this.socket.on('qr_expired', function (data) {
649
660
  console.log('⏰ QR expiré reçu:', data);
650
- _this2.handleQRExpired(data);
661
+ _this.handleQRExpired(data);
651
662
  });
652
663
 
653
664
  // Écouter l'événement qr_scan_initiated spécifiquement
654
665
  this.socket.on('qr_scan_initiated', function (data) {
655
666
  console.log('🔍 QR Scan Initiated reçu:', data);
656
- _this2.showQRLoader();
667
+ _this.showQRLoader();
657
668
  });
658
669
 
659
670
  // Écouter l'événement message générique (fallback)
@@ -661,7 +672,7 @@ function _unsupportedIterableToArray(r, a) {
661
672
  console.log('📨 Message socket reçu:', data);
662
673
  if (data && data.type === 'qr_scan_initiated') {
663
674
  console.log('🔍 QR Scan Initiated détecté dans message:', data);
664
- _this2.showQRLoader();
675
+ _this.showQRLoader();
665
676
  }
666
677
  });
667
678
 
@@ -1594,7 +1605,7 @@ function _unsupportedIterableToArray(r, a) {
1594
1605
  key: "generateQRClientSide",
1595
1606
  value: (function () {
1596
1607
  var _generateQRClientSide = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee12(content, label, qrContainer) {
1597
- var _this3 = this;
1608
+ var _this2 = this;
1598
1609
  var canvas, ctx;
1599
1610
  return _regenerator().w(function (_context12) {
1600
1611
  while (1) switch (_context12.n) {
@@ -1641,13 +1652,13 @@ function _unsupportedIterableToArray(r, a) {
1641
1652
  var dataUrl = canvas.toDataURL('image/png');
1642
1653
 
1643
1654
  // Stocker l'URL
1644
- _this3.currentQRUrl = dataUrl;
1655
+ _this2.currentQRUrl = dataUrl;
1645
1656
 
1646
1657
  // Afficher le QR code
1647
1658
  qrContainer.innerHTML = "\n <div style=\"text-align: center; padding: 20px;\">\n <img src=\"".concat(dataUrl, "\" alt=\"QR Code\" style=\"max-width: 300px; border: 2px solid #ddd; border-radius: 10px;\">\n </div>\n ");
1648
1659
 
1649
1660
  // Afficher les instructions
1650
- _this3.showQRInstructions(qrContainer);
1661
+ _this2.showQRInstructions(qrContainer);
1651
1662
  resolve();
1652
1663
  });
1653
1664
  }));
@@ -1957,7 +1968,7 @@ function _unsupportedIterableToArray(r, a) {
1957
1968
  }, {
1958
1969
  key: "startAutoRefresh",
1959
1970
  value: function startAutoRefresh(containerId, type, options) {
1960
- var _this4 = this;
1971
+ var _this3 = this;
1961
1972
  if (!this.config.autoRefresh) return;
1962
1973
 
1963
1974
  // Arrêter le timer existant s'il y en a un
@@ -1973,7 +1984,7 @@ function _unsupportedIterableToArray(r, a) {
1973
1984
  _context16.p = 0;
1974
1985
  console.log('🔄 Rafraîchissement automatique du QR code...');
1975
1986
  _context16.n = 1;
1976
- return _this4.refreshQR(containerId, type, options);
1987
+ return _this3.refreshQR(containerId, type, options);
1977
1988
  case 1:
1978
1989
  _context16.n = 3;
1979
1990
  break;
@@ -2002,7 +2013,7 @@ function _unsupportedIterableToArray(r, a) {
2002
2013
  var _makeRequest = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee17(endpoint, data) {
2003
2014
  var _window$SunuIDConfig4,
2004
2015
  _window$SunuIDConfig5,
2005
- _this5 = this;
2016
+ _this4 = this;
2006
2017
  var sanitizedData, endpointPath, url, retryCount, maxRetries, _loop, _ret;
2007
2018
  return _regenerator().w(function (_context18) {
2008
2019
  while (1) switch (_context18.n) {
@@ -2065,7 +2076,7 @@ function _unsupportedIterableToArray(r, a) {
2065
2076
  controller = new AbortController();
2066
2077
  timeoutId = setTimeout(function () {
2067
2078
  return controller.abort();
2068
- }, _this5.config.requestTimeout); // Headers minimaux (API SunuID n'accepte que les headers essentiels)
2079
+ }, _this4.config.requestTimeout); // Headers minimaux (API SunuID n'accepte que les headers essentiels)
2069
2080
  headers = {
2070
2081
  'Content-Type': 'application/json'
2071
2082
  }; // Note: En mode sécurisé, les credentials sont dans le body
@@ -2098,7 +2109,7 @@ function _unsupportedIterableToArray(r, a) {
2098
2109
  message: errorText
2099
2110
  };
2100
2111
  }
2101
- _this5.logSecurityEvent('API_REQUEST_ERROR', {
2112
+ _this4.logSecurityEvent('API_REQUEST_ERROR', {
2102
2113
  status: response.status,
2103
2114
  statusText: response.statusText,
2104
2115
  error: errorData.message
@@ -2109,7 +2120,7 @@ function _unsupportedIterableToArray(r, a) {
2109
2120
  return response.json();
2110
2121
  case 4:
2111
2122
  result = _context17.v;
2112
- _this5.logSecurityEvent('API_REQUEST_SUCCESS', {
2123
+ _this4.logSecurityEvent('API_REQUEST_SUCCESS', {
2113
2124
  endpoint: endpointPath,
2114
2125
  responseKeys: Object.keys(result)
2115
2126
  });
@@ -2124,7 +2135,7 @@ function _unsupportedIterableToArray(r, a) {
2124
2135
  _context17.n = 7;
2125
2136
  break;
2126
2137
  }
2127
- _this5.logSecurityEvent('API_REQUEST_TIMEOUT', {
2138
+ _this4.logSecurityEvent('API_REQUEST_TIMEOUT', {
2128
2139
  retryCount: retryCount
2129
2140
  });
2130
2141
  if (!(retryCount > maxRetries)) {
@@ -2139,7 +2150,7 @@ function _unsupportedIterableToArray(r, a) {
2139
2150
  _context17.n = 8;
2140
2151
  break;
2141
2152
  }
2142
- _this5.logSecurityEvent('API_REQUEST_MAX_RETRIES', {
2153
+ _this4.logSecurityEvent('API_REQUEST_MAX_RETRIES', {
2143
2154
  retryCount: retryCount,
2144
2155
  error: _t11.message
2145
2156
  });