sunuid-sdk 1.0.42 → 1.0.44

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
 
@@ -843,9 +854,26 @@ function _unsupportedIterableToArray(r, a) {
843
854
  }, {
844
855
  key: "handleQRScanSuccess",
845
856
  value: function handleQRScanSuccess(data) {
846
- console.log('✅ QR Scan Success:', data);
847
- if (this.config.onSuccess) {
848
- this.config.onSuccess(data);
857
+ console.log('✅ QR Scan Success reçu:', data);
858
+ try {
859
+ // Traiter l'authentification comme un callback
860
+ this.processAuthentication(data);
861
+
862
+ // Afficher un message de succès
863
+ this.showSuccessMessage(data);
864
+
865
+ // Appeler le callback de succès (pour compatibilité)
866
+ if (this.config.onSuccess) {
867
+ this.config.onSuccess(data);
868
+ }
869
+ console.log('✅ Authentification WebSocket traitée avec succès');
870
+ } catch (error) {
871
+ console.error('❌ Erreur lors du traitement WebSocket:', error);
872
+
873
+ // Appeler le callback d'erreur
874
+ if (this.config.onAuthenticationError) {
875
+ this.config.onAuthenticationError(error, data);
876
+ }
849
877
  }
850
878
  }
851
879
 
@@ -1594,7 +1622,7 @@ function _unsupportedIterableToArray(r, a) {
1594
1622
  key: "generateQRClientSide",
1595
1623
  value: (function () {
1596
1624
  var _generateQRClientSide = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee12(content, label, qrContainer) {
1597
- var _this3 = this;
1625
+ var _this2 = this;
1598
1626
  var canvas, ctx;
1599
1627
  return _regenerator().w(function (_context12) {
1600
1628
  while (1) switch (_context12.n) {
@@ -1641,13 +1669,13 @@ function _unsupportedIterableToArray(r, a) {
1641
1669
  var dataUrl = canvas.toDataURL('image/png');
1642
1670
 
1643
1671
  // Stocker l'URL
1644
- _this3.currentQRUrl = dataUrl;
1672
+ _this2.currentQRUrl = dataUrl;
1645
1673
 
1646
1674
  // Afficher le QR code
1647
1675
  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
1676
 
1649
1677
  // Afficher les instructions
1650
- _this3.showQRInstructions(qrContainer);
1678
+ _this2.showQRInstructions(qrContainer);
1651
1679
  resolve();
1652
1680
  });
1653
1681
  }));
@@ -1957,7 +1985,7 @@ function _unsupportedIterableToArray(r, a) {
1957
1985
  }, {
1958
1986
  key: "startAutoRefresh",
1959
1987
  value: function startAutoRefresh(containerId, type, options) {
1960
- var _this4 = this;
1988
+ var _this3 = this;
1961
1989
  if (!this.config.autoRefresh) return;
1962
1990
 
1963
1991
  // Arrêter le timer existant s'il y en a un
@@ -1973,7 +2001,7 @@ function _unsupportedIterableToArray(r, a) {
1973
2001
  _context16.p = 0;
1974
2002
  console.log('🔄 Rafraîchissement automatique du QR code...');
1975
2003
  _context16.n = 1;
1976
- return _this4.refreshQR(containerId, type, options);
2004
+ return _this3.refreshQR(containerId, type, options);
1977
2005
  case 1:
1978
2006
  _context16.n = 3;
1979
2007
  break;
@@ -2002,7 +2030,7 @@ function _unsupportedIterableToArray(r, a) {
2002
2030
  var _makeRequest = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee17(endpoint, data) {
2003
2031
  var _window$SunuIDConfig4,
2004
2032
  _window$SunuIDConfig5,
2005
- _this5 = this;
2033
+ _this4 = this;
2006
2034
  var sanitizedData, endpointPath, url, retryCount, maxRetries, _loop, _ret;
2007
2035
  return _regenerator().w(function (_context18) {
2008
2036
  while (1) switch (_context18.n) {
@@ -2065,7 +2093,7 @@ function _unsupportedIterableToArray(r, a) {
2065
2093
  controller = new AbortController();
2066
2094
  timeoutId = setTimeout(function () {
2067
2095
  return controller.abort();
2068
- }, _this5.config.requestTimeout); // Headers minimaux (API SunuID n'accepte que les headers essentiels)
2096
+ }, _this4.config.requestTimeout); // Headers minimaux (API SunuID n'accepte que les headers essentiels)
2069
2097
  headers = {
2070
2098
  'Content-Type': 'application/json'
2071
2099
  }; // Note: En mode sécurisé, les credentials sont dans le body
@@ -2098,7 +2126,7 @@ function _unsupportedIterableToArray(r, a) {
2098
2126
  message: errorText
2099
2127
  };
2100
2128
  }
2101
- _this5.logSecurityEvent('API_REQUEST_ERROR', {
2129
+ _this4.logSecurityEvent('API_REQUEST_ERROR', {
2102
2130
  status: response.status,
2103
2131
  statusText: response.statusText,
2104
2132
  error: errorData.message
@@ -2109,7 +2137,7 @@ function _unsupportedIterableToArray(r, a) {
2109
2137
  return response.json();
2110
2138
  case 4:
2111
2139
  result = _context17.v;
2112
- _this5.logSecurityEvent('API_REQUEST_SUCCESS', {
2140
+ _this4.logSecurityEvent('API_REQUEST_SUCCESS', {
2113
2141
  endpoint: endpointPath,
2114
2142
  responseKeys: Object.keys(result)
2115
2143
  });
@@ -2124,7 +2152,7 @@ function _unsupportedIterableToArray(r, a) {
2124
2152
  _context17.n = 7;
2125
2153
  break;
2126
2154
  }
2127
- _this5.logSecurityEvent('API_REQUEST_TIMEOUT', {
2155
+ _this4.logSecurityEvent('API_REQUEST_TIMEOUT', {
2128
2156
  retryCount: retryCount
2129
2157
  });
2130
2158
  if (!(retryCount > maxRetries)) {
@@ -2139,7 +2167,7 @@ function _unsupportedIterableToArray(r, a) {
2139
2167
  _context17.n = 8;
2140
2168
  break;
2141
2169
  }
2142
- _this5.logSecurityEvent('API_REQUEST_MAX_RETRIES', {
2170
+ _this4.logSecurityEvent('API_REQUEST_MAX_RETRIES', {
2143
2171
  retryCount: retryCount,
2144
2172
  error: _t11.message
2145
2173
  });
@@ -2565,6 +2593,37 @@ function _unsupportedIterableToArray(r, a) {
2565
2593
  console.log('✅ Loader affiché avec succès');
2566
2594
  }
2567
2595
 
2596
+ /**
2597
+ * Afficher un message de succès après authentification
2598
+ */
2599
+ }, {
2600
+ key: "showSuccessMessage",
2601
+ value: function showSuccessMessage(data) {
2602
+ console.log('✅ Affichage du message de succès');
2603
+
2604
+ // Chercher le conteneur QR dans différents IDs possibles
2605
+ var containerIds = ['qr-area', 'qr-container', 'sunuid-qr-container'];
2606
+ var container = null;
2607
+ for (var _i3 = 0, _containerIds2 = containerIds; _i3 < _containerIds2.length; _i3++) {
2608
+ var id = _containerIds2[_i3];
2609
+ container = document.getElementById(id);
2610
+ if (container) break;
2611
+ }
2612
+ if (!container) {
2613
+ console.warn('⚠️ Conteneur QR non trouvé pour afficher le message de succès');
2614
+ return;
2615
+ }
2616
+
2617
+ // Extraire les informations utilisateur
2618
+ var userInfo = data.user_info || {};
2619
+ var userName = userInfo.name || userInfo.username || 'Utilisateur';
2620
+ var userEmail = userInfo.email || '';
2621
+
2622
+ // Remplacer le contenu par un message de succès
2623
+ container.innerHTML = "\n <div style=\"\n text-align: center;\n padding: 40px 20px;\n background: #d4edda;\n border: 2px solid #28a745;\n border-radius: 10px;\n color: #155724;\n font-family: Arial, sans-serif;\n \">\n <div style=\"\n width: 60px;\n height: 60px;\n background: #28a745;\n border-radius: 50%;\n display: flex;\n align-items: center;\n justify-content: center;\n margin: 0 auto 20px auto;\n font-size: 30px;\n color: white;\n \">\u2705</div>\n <h3 style=\"margin: 0 0 10px 0; color: #155724;\">\uD83C\uDF89 Authentification r\xE9ussie !</h3>\n <p style=\"margin: 0 0 15px 0; font-size: 16px; font-weight: bold;\">\n Bienvenue, ".concat(userName, " !\n </p>\n ").concat(userEmail ? "<p style=\"margin: 0 0 15px 0; font-size: 14px; color: #6c757d;\">".concat(userEmail, "</p>") : '', "\n <p style=\"margin: 0; font-size: 14px;\">\n Votre identit\xE9 a \xE9t\xE9 v\xE9rifi\xE9e avec succ\xE8s.\n </p>\n <div style=\"margin-top: 20px; font-size: 12px; color: #6c757d;\">\n \uD83D\uDD04 Redirection en cours...\n </div>\n </div>\n ");
2624
+ console.log('✅ Message de succès affiché');
2625
+ }
2626
+
2568
2627
  /**
2569
2628
  * Gérer le callback SunuID
2570
2629
  */