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.
@@ -330,7 +330,6 @@
330
330
  */
331
331
  var SunuID = /*#__PURE__*/function () {
332
332
  function SunuID() {
333
- var _this = this;
334
333
  var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
335
334
  _classCallCheck(this, SunuID);
336
335
  this.config = _objectSpread2(_objectSpread2({}, DEFAULT_CONFIG), config);
@@ -340,13 +339,9 @@
340
339
  this.socket = null;
341
340
  this.initPromise = null;
342
341
 
343
- // Initialisation asynchrone seulement si autoInit est explicitement activé
344
- if (this.config.autoInit === true) {
345
- // Délai pour éviter les conflits avec d'autres scripts
346
- setTimeout(function () {
347
- _this.init();
348
- }, 100);
349
- }
342
+ // DÉSACTIVÉ : Initialisation automatique pour éviter les boucles
343
+ // L'utilisateur doit appeler init() manuellement
344
+ console.log('🔧 SDK SunuID créé - Appelez init() manuellement');
350
345
  }
351
346
 
352
347
  /**
@@ -357,7 +352,7 @@
357
352
  value: (function () {
358
353
  var _init = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
359
354
  return _regenerator().w(function (_context) {
360
- while (1) switch (_context.n) {
355
+ while (1) switch (_context.p = _context.n) {
361
356
  case 0:
362
357
  if (!this.isInitialized) {
363
358
  _context.n = 1;
@@ -373,10 +368,26 @@
373
368
  console.log('⚠️ Initialisation déjà en cours, attente...');
374
369
  return _context.a(2, this.initPromise);
375
370
  case 2:
371
+ if (!this._initInProgress) {
372
+ _context.n = 3;
373
+ break;
374
+ }
375
+ console.log('⚠️ Initialisation en cours, ignoré');
376
+ return _context.a(2);
377
+ case 3:
378
+ this._initInProgress = true;
376
379
  this.initPromise = this._doInit();
380
+ _context.p = 4;
381
+ _context.n = 5;
382
+ return this.initPromise;
383
+ case 5:
384
+ _context.p = 5;
385
+ this._initInProgress = false;
386
+ return _context.f(5);
387
+ case 6:
377
388
  return _context.a(2, this.initPromise);
378
389
  }
379
- }, _callee, this);
390
+ }, _callee, this, [[4,, 5, 6]]);
380
391
  }));
381
392
  function init() {
382
393
  return _init.apply(this, arguments);
@@ -596,14 +607,14 @@
596
607
  }, {
597
608
  key: "initWebSocket",
598
609
  value: function initWebSocket() {
599
- var _this2 = this;
610
+ var _this = this;
600
611
  try {
601
612
  // Vérifier si Socket.IO est disponible
602
613
  if (typeof io === 'undefined') {
603
614
  console.warn('⚠️ Socket.IO non disponible, WebSocket sera initialisé plus tard');
604
615
  // Réessayer après un délai
605
616
  setTimeout(function () {
606
- return _this2.initWebSocket();
617
+ return _this.initWebSocket();
607
618
  }, 1000);
608
619
  return;
609
620
  }
@@ -627,36 +638,36 @@
627
638
  // Gestion des événements WebSocket
628
639
  this.socket.on('connect', function () {
629
640
  console.log('🌐 WebSocket connecté avec succès');
630
- console.log('📊 Socket ID:', _this2.socket.id);
631
- _this2.socket.connected = true;
641
+ console.log('📊 Socket ID:', _this.socket.id);
642
+ _this.socket.connected = true;
632
643
  });
633
644
  this.socket.on('disconnect', function (reason) {
634
645
  console.log('❌ WebSocket déconnecté:', reason);
635
- _this2.socket.connected = false;
646
+ _this.socket.connected = false;
636
647
  });
637
648
  this.socket.on('connect_error', function (error) {
638
649
  console.error('❌ Erreur connexion WebSocket:', error);
639
- _this2.socket.connected = false;
650
+ _this.socket.connected = false;
640
651
  });
641
652
 
642
653
  // Écouter les événements spécifiques
643
654
  this.socket.on('qr_status_update', function (data) {
644
655
  console.log('📱 Mise à jour statut QR reçue:', data);
645
- _this2.handleQRStatusUpdate(data);
656
+ _this.handleQRStatusUpdate(data);
646
657
  });
647
658
  this.socket.on('qr_scan_success', function (data) {
648
659
  console.log('✅ Scan QR réussi reçu:', data);
649
- _this2.handleQRScanSuccess(data);
660
+ _this.handleQRScanSuccess(data);
650
661
  });
651
662
  this.socket.on('qr_expired', function (data) {
652
663
  console.log('⏰ QR expiré reçu:', data);
653
- _this2.handleQRExpired(data);
664
+ _this.handleQRExpired(data);
654
665
  });
655
666
 
656
667
  // Écouter l'événement qr_scan_initiated spécifiquement
657
668
  this.socket.on('qr_scan_initiated', function (data) {
658
669
  console.log('🔍 QR Scan Initiated reçu:', data);
659
- _this2.showQRLoader();
670
+ _this.showQRLoader();
660
671
  });
661
672
 
662
673
  // Écouter l'événement message générique (fallback)
@@ -664,7 +675,7 @@
664
675
  console.log('📨 Message socket reçu:', data);
665
676
  if (data && data.type === 'qr_scan_initiated') {
666
677
  console.log('🔍 QR Scan Initiated détecté dans message:', data);
667
- _this2.showQRLoader();
678
+ _this.showQRLoader();
668
679
  }
669
680
  });
670
681
 
@@ -846,9 +857,26 @@
846
857
  }, {
847
858
  key: "handleQRScanSuccess",
848
859
  value: function handleQRScanSuccess(data) {
849
- console.log('✅ QR Scan Success:', data);
850
- if (this.config.onSuccess) {
851
- this.config.onSuccess(data);
860
+ console.log('✅ QR Scan Success reçu:', data);
861
+ try {
862
+ // Traiter l'authentification comme un callback
863
+ this.processAuthentication(data);
864
+
865
+ // Afficher un message de succès
866
+ this.showSuccessMessage(data);
867
+
868
+ // Appeler le callback de succès (pour compatibilité)
869
+ if (this.config.onSuccess) {
870
+ this.config.onSuccess(data);
871
+ }
872
+ console.log('✅ Authentification WebSocket traitée avec succès');
873
+ } catch (error) {
874
+ console.error('❌ Erreur lors du traitement WebSocket:', error);
875
+
876
+ // Appeler le callback d'erreur
877
+ if (this.config.onAuthenticationError) {
878
+ this.config.onAuthenticationError(error, data);
879
+ }
852
880
  }
853
881
  }
854
882
 
@@ -1597,7 +1625,7 @@
1597
1625
  key: "generateQRClientSide",
1598
1626
  value: (function () {
1599
1627
  var _generateQRClientSide = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee12(content, label, qrContainer) {
1600
- var _this3 = this;
1628
+ var _this2 = this;
1601
1629
  var canvas, ctx;
1602
1630
  return _regenerator().w(function (_context12) {
1603
1631
  while (1) switch (_context12.n) {
@@ -1644,13 +1672,13 @@
1644
1672
  var dataUrl = canvas.toDataURL('image/png');
1645
1673
 
1646
1674
  // Stocker l'URL
1647
- _this3.currentQRUrl = dataUrl;
1675
+ _this2.currentQRUrl = dataUrl;
1648
1676
 
1649
1677
  // Afficher le QR code
1650
1678
  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 ");
1651
1679
 
1652
1680
  // Afficher les instructions
1653
- _this3.showQRInstructions(qrContainer);
1681
+ _this2.showQRInstructions(qrContainer);
1654
1682
  resolve();
1655
1683
  });
1656
1684
  }));
@@ -1960,7 +1988,7 @@
1960
1988
  }, {
1961
1989
  key: "startAutoRefresh",
1962
1990
  value: function startAutoRefresh(containerId, type, options) {
1963
- var _this4 = this;
1991
+ var _this3 = this;
1964
1992
  if (!this.config.autoRefresh) return;
1965
1993
 
1966
1994
  // Arrêter le timer existant s'il y en a un
@@ -1976,7 +2004,7 @@
1976
2004
  _context16.p = 0;
1977
2005
  console.log('🔄 Rafraîchissement automatique du QR code...');
1978
2006
  _context16.n = 1;
1979
- return _this4.refreshQR(containerId, type, options);
2007
+ return _this3.refreshQR(containerId, type, options);
1980
2008
  case 1:
1981
2009
  _context16.n = 3;
1982
2010
  break;
@@ -2005,7 +2033,7 @@
2005
2033
  var _makeRequest = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee17(endpoint, data) {
2006
2034
  var _window$SunuIDConfig4,
2007
2035
  _window$SunuIDConfig5,
2008
- _this5 = this;
2036
+ _this4 = this;
2009
2037
  var sanitizedData, endpointPath, url, retryCount, maxRetries, _loop, _ret;
2010
2038
  return _regenerator().w(function (_context18) {
2011
2039
  while (1) switch (_context18.n) {
@@ -2068,7 +2096,7 @@
2068
2096
  controller = new AbortController();
2069
2097
  timeoutId = setTimeout(function () {
2070
2098
  return controller.abort();
2071
- }, _this5.config.requestTimeout); // Headers minimaux (API SunuID n'accepte que les headers essentiels)
2099
+ }, _this4.config.requestTimeout); // Headers minimaux (API SunuID n'accepte que les headers essentiels)
2072
2100
  headers = {
2073
2101
  'Content-Type': 'application/json'
2074
2102
  }; // Note: En mode sécurisé, les credentials sont dans le body
@@ -2101,7 +2129,7 @@
2101
2129
  message: errorText
2102
2130
  };
2103
2131
  }
2104
- _this5.logSecurityEvent('API_REQUEST_ERROR', {
2132
+ _this4.logSecurityEvent('API_REQUEST_ERROR', {
2105
2133
  status: response.status,
2106
2134
  statusText: response.statusText,
2107
2135
  error: errorData.message
@@ -2112,7 +2140,7 @@
2112
2140
  return response.json();
2113
2141
  case 4:
2114
2142
  result = _context17.v;
2115
- _this5.logSecurityEvent('API_REQUEST_SUCCESS', {
2143
+ _this4.logSecurityEvent('API_REQUEST_SUCCESS', {
2116
2144
  endpoint: endpointPath,
2117
2145
  responseKeys: Object.keys(result)
2118
2146
  });
@@ -2127,7 +2155,7 @@
2127
2155
  _context17.n = 7;
2128
2156
  break;
2129
2157
  }
2130
- _this5.logSecurityEvent('API_REQUEST_TIMEOUT', {
2158
+ _this4.logSecurityEvent('API_REQUEST_TIMEOUT', {
2131
2159
  retryCount: retryCount
2132
2160
  });
2133
2161
  if (!(retryCount > maxRetries)) {
@@ -2142,7 +2170,7 @@
2142
2170
  _context17.n = 8;
2143
2171
  break;
2144
2172
  }
2145
- _this5.logSecurityEvent('API_REQUEST_MAX_RETRIES', {
2173
+ _this4.logSecurityEvent('API_REQUEST_MAX_RETRIES', {
2146
2174
  retryCount: retryCount,
2147
2175
  error: _t11.message
2148
2176
  });
@@ -2568,6 +2596,37 @@
2568
2596
  console.log('✅ Loader affiché avec succès');
2569
2597
  }
2570
2598
 
2599
+ /**
2600
+ * Afficher un message de succès après authentification
2601
+ */
2602
+ }, {
2603
+ key: "showSuccessMessage",
2604
+ value: function showSuccessMessage(data) {
2605
+ console.log('✅ Affichage du message de succès');
2606
+
2607
+ // Chercher le conteneur QR dans différents IDs possibles
2608
+ var containerIds = ['qr-area', 'qr-container', 'sunuid-qr-container'];
2609
+ var container = null;
2610
+ for (var _i3 = 0, _containerIds2 = containerIds; _i3 < _containerIds2.length; _i3++) {
2611
+ var id = _containerIds2[_i3];
2612
+ container = document.getElementById(id);
2613
+ if (container) break;
2614
+ }
2615
+ if (!container) {
2616
+ console.warn('⚠️ Conteneur QR non trouvé pour afficher le message de succès');
2617
+ return;
2618
+ }
2619
+
2620
+ // Extraire les informations utilisateur
2621
+ var userInfo = data.user_info || {};
2622
+ var userName = userInfo.name || userInfo.username || 'Utilisateur';
2623
+ var userEmail = userInfo.email || '';
2624
+
2625
+ // Remplacer le contenu par un message de succès
2626
+ 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 ");
2627
+ console.log('✅ Message de succès affiché');
2628
+ }
2629
+
2571
2630
  /**
2572
2631
  * Gérer le callback SunuID
2573
2632
  */