sunuid-sdk 1.0.33 → 1.0.35

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.
@@ -280,13 +280,16 @@ function _unsupportedIterableToArray(r, a) {
280
280
  secretId: null,
281
281
  type: 2,
282
282
  // Type par défaut (2 = authentification)
283
- partnerName: 'SunuID',
284
- // Nom du partenaire par défaut
283
+ partnerName: null,
284
+ // Nom du partenaire récupéré depuis l'API
285
285
  theme: 'light',
286
286
  language: 'fr',
287
- autoRefresh: true,
287
+ autoRefresh: false,
288
+ // Désactivé par défaut pour éviter les appels répétitifs
288
289
  refreshInterval: 30000,
289
290
  // 30 secondes
291
+ autoInit: true,
292
+ // Initialisation automatique par défaut
290
293
  onSuccess: null,
291
294
  onError: null,
292
295
  onStatusUpdate: null,
@@ -305,7 +308,10 @@ function _unsupportedIterableToArray(r, a) {
305
308
  }
306
309
  return ((_window$SunuIDConfig3 = window.SunuIDConfig) === null || _window$SunuIDConfig3 === void 0 || (_window$SunuIDConfig3 = _window$SunuIDConfig3.apiUrl) === null || _window$SunuIDConfig3 === void 0 ? void 0 : _window$SunuIDConfig3.replace('/api', '')) + '/secure-init.php' || 'https://api.sunuid.fayma.sn/secure-init.php';
307
310
  }(),
308
- token: null
311
+ token: null,
312
+ // Configuration pour forcer l'utilisation du serveur distant
313
+ forceRemoteServer: true,
314
+ useLocalFallback: false
309
315
  };
310
316
 
311
317
  /**
@@ -321,8 +327,10 @@ function _unsupportedIterableToArray(r, a) {
321
327
  this.isInitialized = false;
322
328
  this.socket = null;
323
329
 
324
- // Initialisation asynchrone
325
- this.initPromise = this.init();
330
+ // Initialisation asynchrone seulement si autoInit est activé
331
+ if (this.config.autoInit !== false) {
332
+ this.initPromise = this.init();
333
+ }
326
334
  }
327
335
 
328
336
  /**
@@ -356,31 +364,43 @@ function _unsupportedIterableToArray(r, a) {
356
364
  this.logSecurityEvent('SDK_INIT_START', {
357
365
  apiUrl: this.config.apiUrl,
358
366
  type: this.config.type,
359
- partnerName: this.config.partnerName,
360
367
  secureInit: this.config.secureInit
361
368
  });
362
369
 
370
+ // Récupérer les informations du partenaire depuis l'API
371
+ _context.n = 4;
372
+ return this.fetchPartnerInfo();
373
+ case 4:
363
374
  // Obscurcir les credentials dans les logs
364
375
  this.obfuscateCredentials();
365
376
  this.isInitialized = true;
366
377
  console.log('SunuID SDK initialisé avec succès');
378
+ console.log('📋 Configuration SDK:', {
379
+ apiUrl: this.config.apiUrl,
380
+ type: this.config.type,
381
+ partnerName: this.config.partnerName,
382
+ clientId: this.config.clientId ? '***' + this.config.clientId.slice(-4) : 'null',
383
+ secretId: this.config.secretId ? '***' + this.config.secretId.slice(-4) : 'null',
384
+ secureInit: this.config.secureInit,
385
+ theme: this.config.theme
386
+ });
367
387
  this.logSecurityEvent('SDK_INIT_SUCCESS');
368
388
 
369
389
  // Initialiser la connexion WebSocket
370
390
  this.initWebSocket();
371
- _context.n = 5;
391
+ _context.n = 6;
372
392
  break;
373
- case 4:
374
- _context.p = 4;
393
+ case 5:
394
+ _context.p = 5;
375
395
  _t = _context.v;
376
396
  this.logSecurityEvent('SDK_INIT_ERROR', {
377
397
  error: _t.message
378
398
  });
379
399
  throw _t;
380
- case 5:
400
+ case 6:
381
401
  return _context.a(2);
382
402
  }
383
- }, _callee, this, [[0, 4]]);
403
+ }, _callee, this, [[0, 5]]);
384
404
  }));
385
405
  function init() {
386
406
  return _init.apply(this, arguments);
@@ -427,6 +447,7 @@ function _unsupportedIterableToArray(r, a) {
427
447
  return response.json();
428
448
  case 3:
429
449
  result = _context2.v;
450
+ console.log('📋 Réponse initialisation sécurisée:', result);
430
451
  if (result.success) {
431
452
  _context2.n = 4;
432
453
  break;
@@ -534,25 +555,30 @@ function _unsupportedIterableToArray(r, a) {
534
555
 
535
556
  // Initialiser la connexion WebSocket si elle n'existe pas
536
557
  if (!this.socket) {
558
+ console.log('🌐 Initialisation Socket.IO...');
537
559
  this.socket = io('wss://samasocket.fayma.sn:9443', {
538
560
  query: {
539
561
  token: this.config.clientId,
540
562
  type: 'web',
541
563
  userId: this.config.clientId,
542
564
  username: ip
543
- }
565
+ },
566
+ transports: ['websocket', 'polling']
544
567
  });
545
568
 
546
569
  // Gestion des événements WebSocket
547
570
  this.socket.on('connect', function () {
548
571
  console.log('🌐 WebSocket connecté avec succès');
549
572
  console.log('📊 Socket ID:', _this.socket.id);
573
+ _this.socket.connected = true;
550
574
  });
551
575
  this.socket.on('disconnect', function (reason) {
552
576
  console.log('❌ WebSocket déconnecté:', reason);
577
+ _this.socket.connected = false;
553
578
  });
554
579
  this.socket.on('connect_error', function (error) {
555
580
  console.error('❌ Erreur connexion WebSocket:', error);
581
+ _this.socket.connected = false;
556
582
  });
557
583
 
558
584
  // Écouter les événements spécifiques
@@ -568,6 +594,21 @@ function _unsupportedIterableToArray(r, a) {
568
594
  console.log('⏰ QR expiré reçu:', data);
569
595
  _this.handleQRExpired(data);
570
596
  });
597
+
598
+ // Écouter tous les événements socket pour les logger
599
+ this.socket.onAny(function (eventName) {
600
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
601
+ args[_key - 1] = arguments[_key];
602
+ }
603
+ console.log("\uD83C\uDF10 Socket Event [".concat(eventName, "]:"), args);
604
+
605
+ // Si c'est un événement qr_scan_initiated, afficher le loader
606
+ if (eventName === 'qr_scan_initiated') {
607
+ _this.showQRLoader();
608
+ }
609
+ });
610
+ } else {
611
+ console.log('🌐 WebSocket déjà connecté');
571
612
  }
572
613
  } catch (error) {
573
614
  console.error('❌ Erreur initialisation WebSocket:', error);
@@ -719,6 +760,7 @@ function _unsupportedIterableToArray(r, a) {
719
760
  }, {
720
761
  key: "handleQRStatusUpdate",
721
762
  value: function handleQRStatusUpdate(data) {
763
+ console.log('📱 QR Status Update:', data);
722
764
  if (this.config.onStatusUpdate) {
723
765
  this.config.onStatusUpdate(data);
724
766
  }
@@ -730,6 +772,7 @@ function _unsupportedIterableToArray(r, a) {
730
772
  }, {
731
773
  key: "handleQRScanSuccess",
732
774
  value: function handleQRScanSuccess(data) {
775
+ console.log('✅ QR Scan Success:', data);
733
776
  if (this.config.onSuccess) {
734
777
  this.config.onSuccess(data);
735
778
  }
@@ -741,6 +784,7 @@ function _unsupportedIterableToArray(r, a) {
741
784
  }, {
742
785
  key: "handleQRExpired",
743
786
  value: function handleQRExpired(data) {
787
+ console.log('⏰ QR Expired:', data);
744
788
  if (this.config.onExpired) {
745
789
  this.config.onExpired(data);
746
790
  }
@@ -755,8 +799,6 @@ function _unsupportedIterableToArray(r, a) {
755
799
  if (this.socket && this.socket.connected) {
756
800
  this.socket.emit(event, data);
757
801
  console.log("\uD83D\uDCE4 \xC9v\xE9nement WebSocket \xE9mis: ".concat(event), data);
758
- } else if (typeof io === 'undefined') {
759
- console.warn('⚠️ Socket.IO non disponible, impossible d\'émettre l\'événement:', event);
760
802
  } else {
761
803
  console.warn('⚠️ WebSocket non connecté, impossible d\'émettre l\'événement:', event);
762
804
  }
@@ -792,18 +834,23 @@ function _unsupportedIterableToArray(r, a) {
792
834
  }, {
793
835
  key: "generateQR",
794
836
  value: (function () {
795
- var _generateQR = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(containerId) {
796
- var _this2 = this;
797
- var options,
837
+ var _generateQR = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
838
+ var containerId,
839
+ options,
840
+ connectionStatus,
841
+ socketId,
842
+ qrContent,
843
+ partnerName,
798
844
  response,
799
- imageBaseUrl,
800
845
  qrImageUrl,
801
- _waitForSocketId,
846
+ isLocal,
802
847
  _args3 = arguments,
803
- _t3;
848
+ _t3,
849
+ _t4;
804
850
  return _regenerator().w(function (_context3) {
805
851
  while (1) switch (_context3.p = _context3.n) {
806
852
  case 0:
853
+ containerId = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : 'sunuid-qr-container';
807
854
  options = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : {};
808
855
  if (!this.initPromise) {
809
856
  _context3.n = 2;
@@ -820,68 +867,88 @@ function _unsupportedIterableToArray(r, a) {
820
867
  }
821
868
  throw new Error('SunuID: SDK non initialisé');
822
869
  case 3:
823
- _context3.p = 3;
824
- _context3.n = 4;
870
+ console.log('🎯 generateQR appelé avec containerId:', containerId);
871
+
872
+ // Attendre que les connexions soient prêtes
873
+ console.log('🔍 Attente connexions API et WebSocket...');
874
+ _context3.p = 4;
875
+ _context3.n = 5;
876
+ return this.waitForConnections(5000);
877
+ case 5:
878
+ connectionStatus = _context3.v;
879
+ // 5 secondes max
880
+ console.log('✅ Connexions prêtes:', connectionStatus);
881
+ _context3.n = 7;
882
+ break;
883
+ case 6:
884
+ _context3.p = 6;
885
+ _t3 = _context3.v;
886
+ console.error('❌ Erreur connexions:', _t3.message);
887
+ throw new Error('Connexions non disponibles - Impossible de générer le QR code');
888
+ case 7:
889
+ _context3.p = 7;
890
+ // Utiliser uniquement le socketID comme contenu du QR
891
+ socketId = this.socket ? this.socket.id : 'timeout-socket-id';
892
+ qrContent = socketId;
893
+ console.log('📄 Contenu QR préparé:', qrContent);
894
+ console.log('🔌 Socket ID:', socketId);
895
+
896
+ // Générer le QR avec le contenu complet
897
+ partnerName = this.config.partnerName || 'Partner_unknown';
898
+ _context3.n = 8;
825
899
  return this.makeRequest('/qr-generate', _objectSpread2({
826
- type: this.config.type
900
+ type: this.config.type,
901
+ content: qrContent,
902
+ // Contenu personnalisé pour le QR
903
+ label: "".concat(this.getTypeName(this.config.type), " ").concat(partnerName)
827
904
  }, options));
828
- case 4:
905
+ case 8:
829
906
  response = _context3.v;
830
907
  if (!response.success) {
831
- _context3.n = 5;
908
+ _context3.n = 9;
832
909
  break;
833
910
  }
834
- // Construire l'URL complète de l'image QR avec la base URL pour les images
835
- imageBaseUrl = 'https://sunuid.fayma.sn';
836
- qrImageUrl = "".concat(imageBaseUrl).concat(response.data.qrcode);
837
- this.currentQRUrl = qrImageUrl; // Stocker l'URL pour getQRCode()
838
- this.displayQRCode(containerId, qrImageUrl, this.config.type, options);
839
-
840
- // Générer le QR code personnalisé avec le type + code de l'API + socket ID
841
- if (this.pendingQRInfo && response.data.code) {
842
- // Attendre que le socket ID soit bien défini
843
- _waitForSocketId = function waitForSocketId() {
844
- if (_this2.socket && _this2.socket.id && _this2.socket.id !== 'unknown') {
845
- var socketId = _this2.socket.id;
846
- var qrContent = "".concat(_this2.config.type, "-").concat(response.data.code, "-").concat(socketId);
847
-
848
- // Utiliser le partnerName de la réponse API et le nom du type
849
- var partnerName = response.data.partnerName || _this2.config.partnerName || 'SunuID';
850
- var typeName = _this2.getTypeName(_this2.config.type);
851
- var qrLabel = "".concat(typeName, " - ").concat(partnerName);
852
- _this2.generateCustomQRCode(qrContent, qrLabel, _this2.pendingQRInfo.options);
853
- _this2.pendingQRInfo = null; // Nettoyer
854
- } else {
855
- // Réessayer après un délai si le socket ID n'est pas encore disponible
856
- setTimeout(_waitForSocketId, 100);
857
- }
858
- };
859
- _waitForSocketId();
911
+ // Construire l'URL complète du QR code
912
+ qrImageUrl = response.data.qrCodeUrl; // Si l'URL est relative, la rendre absolue
913
+ if (qrImageUrl.startsWith('/')) {
914
+ qrImageUrl = "".concat(this.config.apiUrl).concat(qrImageUrl);
860
915
  }
916
+ this.currentQRUrl = qrImageUrl;
917
+ console.log('✅ QR code généré par API principale:', qrImageUrl);
918
+ console.log('📄 Contenu QR final:', qrContent);
919
+ console.log('🏷️ Label QR:', response.data.label);
920
+ console.log('🆔 Session ID:', response.data.sessionId);
921
+
922
+ // Afficher le QR code
923
+ this.displayQRCode(containerId, qrImageUrl, this.config.type, options);
861
924
  this.startAutoRefresh(containerId, this.config.type, options);
862
925
 
863
926
  // Émettre un événement WebSocket pour la génération du QR
864
927
  this.emitWebSocketEvent('qr_generated', {
865
- serviceId: response.data.service_id,
866
928
  type: this.config.type,
867
929
  qrCodeUrl: qrImageUrl,
868
- code: response.data.code,
930
+ socketId: socketId,
931
+ qrContent: qrContent,
932
+ label: response.data.label,
933
+ sessionId: response.data.sessionId,
869
934
  timestamp: Date.now()
870
935
  });
871
936
  return _context3.a(2, _objectSpread2(_objectSpread2({}, response.data), {}, {
872
937
  qrCodeUrl: qrImageUrl,
873
- sessionId: response.data.service_id
938
+ qrContent: qrContent,
939
+ label: response.data.label,
940
+ sessionId: response.data.sessionId
874
941
  }));
875
- case 5:
942
+ case 9:
876
943
  throw new Error(response.message || 'Erreur lors de la génération du QR code');
877
- case 6:
878
- _context3.n = 8;
944
+ case 10:
945
+ _context3.n = 12;
879
946
  break;
880
- case 7:
881
- _context3.p = 7;
882
- _t3 = _context3.v;
883
- console.error('Erreur API détectée:', _t3.message);
884
- console.error('Stack trace complet:', _t3.stack);
947
+ case 11:
948
+ _context3.p = 11;
949
+ _t4 = _context3.v;
950
+ console.error('Erreur API détectée:', _t4.message);
951
+ console.error('Stack trace complet:', _t4.stack);
885
952
  console.error('Configuration SDK:', {
886
953
  apiUrl: this.config.apiUrl,
887
954
  type: this.config.type,
@@ -889,15 +956,33 @@ function _unsupportedIterableToArray(r, a) {
889
956
  clientId: this.config.clientId ? '***' + this.config.clientId.slice(-4) : 'null',
890
957
  secretId: this.config.secretId ? '***' + this.config.secretId.slice(-4) : 'null'
891
958
  });
959
+
960
+ // Fallback vers le service local seulement si activé
961
+ if (this.config.useLocalFallback) {
962
+ console.log('🔍 Vérification fallback local...');
963
+ console.log('🔍 Hostname:', window.location.hostname);
964
+ console.log('🔍 Protocol:', window.location.protocol);
965
+ console.log('🔍 URL complète:', window.location.href);
966
+ isLocal = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1' || window.location.protocol === 'file:';
967
+ console.log('🔍 Est local:', isLocal);
968
+ if (isLocal) {
969
+ console.log('🔄 Tentative fallback vers service QR local...');
970
+ console.log('❌ Fallback local non implémenté - utilisation serveur distant uniquement');
971
+ } else {
972
+ console.log('❌ Pas en local, pas de fallback');
973
+ }
974
+ } else {
975
+ console.log('🔒 Fallback local désactivé, utilisation serveur distant uniquement');
976
+ }
892
977
  console.log('Affichage du message "Service non disponible" pour type ' + this.config.type);
893
978
  this.displayServiceUnavailable(containerId, this.config.type);
894
979
  throw new Error('Service non disponible');
895
- case 8:
980
+ case 12:
896
981
  return _context3.a(2);
897
982
  }
898
- }, _callee3, this, [[3, 7]]);
983
+ }, _callee3, this, [[7, 11], [4, 6]]);
899
984
  }));
900
- function generateQR(_x) {
985
+ function generateQR() {
901
986
  return _generateQR.apply(this, arguments);
902
987
  }
903
988
  return generateQR;
@@ -910,14 +995,12 @@ function _unsupportedIterableToArray(r, a) {
910
995
  key: "generateCustomQR",
911
996
  value: (function () {
912
997
  var _generateCustomQR = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(containerId, type) {
913
- var _this3 = this;
914
998
  var options,
915
- _response,
999
+ response,
916
1000
  imageBaseUrl,
917
1001
  qrImageUrl,
918
- _waitForSocketId2,
919
1002
  _args4 = arguments,
920
- _t4;
1003
+ _t5;
921
1004
  return _regenerator().w(function (_context4) {
922
1005
  while (1) switch (_context4.p = _context4.n) {
923
1006
  case 0:
@@ -943,52 +1026,35 @@ function _unsupportedIterableToArray(r, a) {
943
1026
  type: type
944
1027
  }, options));
945
1028
  case 4:
946
- _response = _context4.v;
947
- if (!_response.success) {
1029
+ response = _context4.v;
1030
+ if (!response.success) {
948
1031
  _context4.n = 5;
949
1032
  break;
950
1033
  }
951
1034
  // Construire l'URL complète de l'image QR avec la base URL pour les images
952
1035
  imageBaseUrl = 'https://sunuid.fayma.sn';
953
- qrImageUrl = "".concat(imageBaseUrl).concat(_response.data.qrcode);
1036
+ qrImageUrl = "".concat(imageBaseUrl).concat(response.data.qrcode);
954
1037
  this.displayQRCode(containerId, qrImageUrl, type, options);
955
1038
 
956
- // Générer le QR code personnalisé avec le type + code de l'API + socket ID
957
- if (this.pendingQRInfo && _response.data.code) {
958
- // Attendre que le socket ID soit bien défini
959
- _waitForSocketId2 = function waitForSocketId() {
960
- if (_this3.socket && _this3.socket.id && _this3.socket.id !== 'unknown') {
961
- var socketId = _this3.socket.id;
962
- var qrContent = "".concat(type, "-").concat(_response.data.code, "-").concat(socketId);
963
-
964
- // Utiliser le partnerName de la réponse API et le nom du type
965
- var partnerName = _response.data.partnerName || _this3.config.partnerName || 'SunuID';
966
- var typeName = _this3.getTypeName(type);
967
- var qrLabel = "".concat(typeName, " - ").concat(partnerName);
968
- _this3.generateCustomQRCode(qrContent, qrLabel, _this3.pendingQRInfo.options);
969
- _this3.pendingQRInfo = null; // Nettoyer
970
- } else {
971
- // Réessayer après un délai si le socket ID n'est pas encore disponible
972
- setTimeout(_waitForSocketId2, 100);
973
- }
974
- };
975
- _waitForSocketId2();
976
- }
1039
+ // Le QR code est déjà généré par l'API principale
1040
+ console.log('✅ QR code personnalisé généré par API principale:', qrImageUrl);
1041
+ console.log('📄 Code de session:', response.data.code);
1042
+ console.log('🆔 Service ID:', response.data.service_id);
977
1043
  this.startAutoRefresh(containerId, type, options);
978
- return _context4.a(2, _objectSpread2(_objectSpread2({}, _response.data), {}, {
1044
+ return _context4.a(2, _objectSpread2(_objectSpread2({}, response.data), {}, {
979
1045
  qrCodeUrl: qrImageUrl,
980
- sessionId: _response.data.service_id
1046
+ sessionId: response.data.service_id
981
1047
  }));
982
1048
  case 5:
983
- throw new Error(_response.message || 'Erreur lors de la génération du QR code');
1049
+ throw new Error(response.message || 'Erreur lors de la génération du QR code');
984
1050
  case 6:
985
1051
  _context4.n = 8;
986
1052
  break;
987
1053
  case 7:
988
1054
  _context4.p = 7;
989
- _t4 = _context4.v;
990
- console.error('Erreur API détectée:', _t4.message);
991
- console.error('Stack trace complet:', _t4.stack);
1055
+ _t5 = _context4.v;
1056
+ console.error('Erreur API détectée:', _t5.message);
1057
+ console.error('Stack trace complet:', _t5.stack);
992
1058
  console.error('Configuration SDK (Custom):', {
993
1059
  apiUrl: this.config.apiUrl,
994
1060
  type: type,
@@ -1004,7 +1070,7 @@ function _unsupportedIterableToArray(r, a) {
1004
1070
  }
1005
1071
  }, _callee4, this, [[3, 7]]);
1006
1072
  }));
1007
- function generateCustomQR(_x2, _x3) {
1073
+ function generateCustomQR(_x, _x2) {
1008
1074
  return _generateCustomQR.apply(this, arguments);
1009
1075
  }
1010
1076
  return generateCustomQR;
@@ -1024,7 +1090,7 @@ function _unsupportedIterableToArray(r, a) {
1024
1090
  }
1025
1091
  }, _callee5, this);
1026
1092
  }));
1027
- function generateAuthQR(_x4) {
1093
+ function generateAuthQR(_x3) {
1028
1094
  return _generateAuthQR.apply(this, arguments);
1029
1095
  }
1030
1096
  return generateAuthQR;
@@ -1058,7 +1124,7 @@ function _unsupportedIterableToArray(r, a) {
1058
1124
  }
1059
1125
  }, _callee6, this, [[1,, 3, 4]]);
1060
1126
  }));
1061
- function generateKYCQR(_x5) {
1127
+ function generateKYCQR(_x4) {
1062
1128
  return _generateKYCQR.apply(this, arguments);
1063
1129
  }
1064
1130
  return generateKYCQR;
@@ -1092,7 +1158,7 @@ function _unsupportedIterableToArray(r, a) {
1092
1158
  }
1093
1159
  }, _callee7, this, [[1,, 3, 4]]);
1094
1160
  }));
1095
- function generateSignatureQR(_x6) {
1161
+ function generateSignatureQR(_x5) {
1096
1162
  return _generateSignatureQR.apply(this, arguments);
1097
1163
  }
1098
1164
  return generateSignatureQR;
@@ -1104,7 +1170,7 @@ function _unsupportedIterableToArray(r, a) {
1104
1170
  key: "checkQRStatus",
1105
1171
  value: (function () {
1106
1172
  var _checkQRStatus = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(sessionId) {
1107
- var _response2, _t5;
1173
+ var response, _t6;
1108
1174
  return _regenerator().w(function (_context8) {
1109
1175
  while (1) switch (_context8.p = _context8.n) {
1110
1176
  case 0:
@@ -1120,36 +1186,225 @@ function _unsupportedIterableToArray(r, a) {
1120
1186
  serviceId: sessionId
1121
1187
  });
1122
1188
  case 2:
1123
- _response2 = _context8.v;
1124
- if (!_response2.success) {
1189
+ response = _context8.v;
1190
+ if (!response.success) {
1125
1191
  _context8.n = 3;
1126
1192
  break;
1127
1193
  }
1128
- return _context8.a(2, _response2.data);
1194
+ return _context8.a(2, response.data);
1129
1195
  case 3:
1130
- throw new Error(_response2.message || 'Erreur lors de la vérification du statut');
1196
+ throw new Error(response.message || 'Erreur lors de la vérification du statut');
1131
1197
  case 4:
1132
1198
  _context8.n = 6;
1133
1199
  break;
1134
1200
  case 5:
1135
1201
  _context8.p = 5;
1136
- _t5 = _context8.v;
1137
- this.handleError(_t5);
1138
- throw _t5;
1202
+ _t6 = _context8.v;
1203
+ this.handleError(_t6);
1204
+ throw _t6;
1139
1205
  case 6:
1140
1206
  return _context8.a(2);
1141
1207
  }
1142
1208
  }, _callee8, this, [[1, 5]]);
1143
1209
  }));
1144
- function checkQRStatus(_x7) {
1210
+ function checkQRStatus(_x6) {
1145
1211
  return _checkQRStatus.apply(this, arguments);
1146
1212
  }
1147
1213
  return checkQRStatus;
1148
1214
  }()
1149
1215
  /**
1150
- * Afficher un QR code dans un conteneur
1216
+ * Générer un QR code avec un contenu spécifique
1217
+ */
1218
+ )
1219
+ }, {
1220
+ key: "generateQRWithContent",
1221
+ value: (function () {
1222
+ var _generateQRWithContent = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(content, containerId, type) {
1223
+ var options,
1224
+ localQRUrl,
1225
+ _args9 = arguments,
1226
+ _t7;
1227
+ return _regenerator().w(function (_context9) {
1228
+ while (1) switch (_context9.p = _context9.n) {
1229
+ case 0:
1230
+ options = _args9.length > 3 && _args9[3] !== undefined ? _args9[3] : {};
1231
+ console.log('🎨 Génération QR avec contenu:', content);
1232
+ _context9.p = 1;
1233
+ if (!(window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1' || window.location.protocol === 'file:')) {
1234
+ _context9.n = 3;
1235
+ break;
1236
+ }
1237
+ console.log('🏠 Utilisation service QR local...');
1238
+ _context9.n = 2;
1239
+ return this.generateQRLocal(content, containerId, type, options);
1240
+ case 2:
1241
+ localQRUrl = _context9.v;
1242
+ if (!localQRUrl) {
1243
+ _context9.n = 3;
1244
+ break;
1245
+ }
1246
+ return _context9.a(2, localQRUrl);
1247
+ case 3:
1248
+ // Fallback vers le service QR distant
1249
+ console.log('🌐 Utilisation service QR distant...');
1250
+ _context9.n = 4;
1251
+ return this.generateQRRemote(content, containerId, type, options);
1252
+ case 4:
1253
+ return _context9.a(2, _context9.v);
1254
+ case 5:
1255
+ _context9.p = 5;
1256
+ _t7 = _context9.v;
1257
+ console.error('❌ Erreur génération QR:', _t7);
1258
+ // Fallback vers affichage simple du contenu
1259
+ this.displayQRContent(containerId, content, type, options);
1260
+ return _context9.a(2, null);
1261
+ }
1262
+ }, _callee9, this, [[1, 5]]);
1263
+ }));
1264
+ function generateQRWithContent(_x7, _x8, _x9) {
1265
+ return _generateQRWithContent.apply(this, arguments);
1266
+ }
1267
+ return generateQRWithContent;
1268
+ }()
1269
+ /**
1270
+ * Générer QR code avec service local
1271
+ */
1272
+ )
1273
+ }, {
1274
+ key: "generateQRLocal",
1275
+ value: (function () {
1276
+ var _generateQRLocal = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0(content, containerId, type) {
1277
+ var options,
1278
+ response,
1279
+ data,
1280
+ qrUrl,
1281
+ _args0 = arguments,
1282
+ _t8;
1283
+ return _regenerator().w(function (_context0) {
1284
+ while (1) switch (_context0.p = _context0.n) {
1285
+ case 0:
1286
+ options = _args0.length > 3 && _args0[3] !== undefined ? _args0[3] : {};
1287
+ _context0.p = 1;
1288
+ _context0.n = 2;
1289
+ return fetch('http://localhost:8000/api/generate/text', {
1290
+ method: 'POST',
1291
+ headers: {
1292
+ 'Content-Type': 'application/x-www-form-urlencoded'
1293
+ },
1294
+ body: "text=".concat(encodeURIComponent(content), "&size=300")
1295
+ });
1296
+ case 2:
1297
+ response = _context0.v;
1298
+ if (!response.ok) {
1299
+ _context0.n = 4;
1300
+ break;
1301
+ }
1302
+ _context0.n = 3;
1303
+ return response.json();
1304
+ case 3:
1305
+ data = _context0.v;
1306
+ qrUrl = "data:image/png;base64,".concat(data.qrcode);
1307
+ this.displayQRCode(containerId, qrUrl, type, options);
1308
+ return _context0.a(2, qrUrl);
1309
+ case 4:
1310
+ _context0.n = 6;
1311
+ break;
1312
+ case 5:
1313
+ _context0.p = 5;
1314
+ _t8 = _context0.v;
1315
+ console.log('❌ Service QR local non disponible:', _t8.message);
1316
+ case 6:
1317
+ return _context0.a(2, null);
1318
+ }
1319
+ }, _callee0, this, [[1, 5]]);
1320
+ }));
1321
+ function generateQRLocal(_x0, _x1, _x10) {
1322
+ return _generateQRLocal.apply(this, arguments);
1323
+ }
1324
+ return generateQRLocal;
1325
+ }()
1326
+ /**
1327
+ * Générer QR code avec service distant
1328
+ */
1329
+ )
1330
+ }, {
1331
+ key: "generateQRRemote",
1332
+ value: (function () {
1333
+ var _generateQRRemote = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(content, containerId, type) {
1334
+ var options,
1335
+ response,
1336
+ data,
1337
+ qrUrl,
1338
+ _args1 = arguments,
1339
+ _t9;
1340
+ return _regenerator().w(function (_context1) {
1341
+ while (1) switch (_context1.p = _context1.n) {
1342
+ case 0:
1343
+ options = _args1.length > 3 && _args1[3] !== undefined ? _args1[3] : {};
1344
+ _context1.p = 1;
1345
+ _context1.n = 2;
1346
+ return fetch('https://api.sunuid.fayma.sn/qr-generate', {
1347
+ method: 'POST',
1348
+ headers: {
1349
+ 'Content-Type': 'application/json'
1350
+ },
1351
+ body: JSON.stringify({
1352
+ text: content,
1353
+ size: 300,
1354
+ type: type
1355
+ })
1356
+ });
1357
+ case 2:
1358
+ response = _context1.v;
1359
+ if (!response.ok) {
1360
+ _context1.n = 4;
1361
+ break;
1362
+ }
1363
+ _context1.n = 3;
1364
+ return response.json();
1365
+ case 3:
1366
+ data = _context1.v;
1367
+ qrUrl = "data:image/png;base64,".concat(data.qrcode);
1368
+ this.displayQRCode(containerId, qrUrl, type, options);
1369
+ return _context1.a(2, qrUrl);
1370
+ case 4:
1371
+ _context1.n = 6;
1372
+ break;
1373
+ case 5:
1374
+ _context1.p = 5;
1375
+ _t9 = _context1.v;
1376
+ console.error('❌ Erreur service QR distant:', _t9);
1377
+ case 6:
1378
+ // Fallback vers affichage du contenu
1379
+ this.displayQRContent(containerId, content, type, options);
1380
+ return _context1.a(2, null);
1381
+ }
1382
+ }, _callee1, this, [[1, 5]]);
1383
+ }));
1384
+ function generateQRRemote(_x11, _x12, _x13) {
1385
+ return _generateQRRemote.apply(this, arguments);
1386
+ }
1387
+ return generateQRRemote;
1388
+ }()
1389
+ /**
1390
+ * Afficher le contenu QR en texte (fallback)
1151
1391
  */
1152
1392
  )
1393
+ }, {
1394
+ key: "displayQRContent",
1395
+ value: function displayQRContent(containerId, content, type) {
1396
+ var container = document.getElementById(containerId);
1397
+ if (!container) {
1398
+ throw new Error("Conteneur avec l'ID \"".concat(containerId, "\" non trouv\xE9"));
1399
+ }
1400
+ var typeName = this.getTypeName(type);
1401
+ container.innerHTML = "\n <div class=\"sunuid-qr-code\">\n <div class=\"sunuid-qr-header\">\n <h3>".concat(typeName, "</h3>\n </div>\n <div class=\"sunuid-qr-content\" style=\"text-align: center; padding: 20px; background: #f8f9fa; border: 1px solid #dee2e6; border-radius: 5px; margin: 10px 0;\">\n <p><strong>Contenu QR Code:</strong></p>\n <p style=\"font-family: monospace; font-size: 14px; word-break: break-all;\">").concat(content, "</p>\n </div>\n <div class=\"sunuid-qr-instructions\">\n <p>Contenu QR g\xE9n\xE9r\xE9 avec le format: {type}-{code}-{socketid}</p>\n </div>\n </div>\n ");
1402
+ console.log('✅ Contenu QR affiché:', content);
1403
+ }
1404
+
1405
+ /**
1406
+ * Afficher un QR code dans un conteneur
1407
+ */
1153
1408
  }, {
1154
1409
  key: "displayQRCode",
1155
1410
  value: function displayQRCode(containerId, qrUrl, type) {
@@ -1166,20 +1421,14 @@ function _unsupportedIterableToArray(r, a) {
1166
1421
  var qrElement = document.createElement('div');
1167
1422
  qrElement.className = 'sunuid-qr-code';
1168
1423
 
1169
- // Afficher un loader en attendant la réponse API et la connexion socket
1170
- this.getTypeName(type);
1171
- qrElement.innerHTML = "\n <div class=\"sunuid-qr-header\">\n <h3>".concat(type === 1 ? 'Vérification KYC' : type === 2 ? 'Authentification' : type === 3 ? 'Signature' : 'Service Type ' + type, "</h3>\n </div>\n <div class=\"sunuid-qr-image\" id=\"sunuid-qr-container\">\n <div style=\"text-align: center; padding: 40px;\">\n <div class=\"sunuid-loader\">\n <div class=\"sunuid-spinner\"></div>\n <p style=\"margin-top: 20px; color: #666;\">Initialisation en cours...</p>\n <p style=\"font-size: 12px; color: #999; margin-top: 10px;\">Connexion API et WebSocket</p>\n <p style=\"font-size: 11px; color: #ccc; margin-top: 5px;\">Attente du Socket ID...</p>\n </div>\n </div>\n </div>\n <div class=\"sunuid-qr-instructions\" style=\"display: none;\">\n <p>Scannez ce QR code avec l'application ").concat(this.config.partnerName, " pour vous connecter</p>\n </div>\n <div class=\"sunuid-qr-status\" id=\"sunuid-status\" style=\"display: none;\">\n <p>En attente de scan...</p>\n </div>\n ");
1424
+ // Afficher l'image QR avec les informations
1425
+ var typeName = this.getTypeName(type);
1426
+ qrElement.innerHTML = "\n <div class=\"sunuid-qr-header\">\n <h3>".concat(type === 1 ? 'Vérification KYC' : type === 2 ? 'Authentification' : type === 3 ? 'Signature' : 'Service Type ' + type, "</h3>\n </div>\n <div class=\"sunuid-qr-image\">\n <img src=\"").concat(qrUrl, "\" alt=\"QR Code ").concat(typeName, "\" style=\"max-width: 300px; border: 1px solid #ddd; border-radius: 5px;\" />\n </div>\n \n ");
1172
1427
  container.appendChild(qrElement);
1173
1428
 
1174
- // Stocker les informations pour la génération ultérieure
1175
- this.pendingQRInfo = {
1176
- containerId: containerId,
1177
- type: type,
1178
- options: options
1179
- };
1180
-
1181
1429
  // Appliquer le thème
1182
1430
  this.applyTheme(options.theme || this.config.theme);
1431
+ console.log('✅ QR code affiché:', qrUrl);
1183
1432
  }
1184
1433
 
1185
1434
  /**
@@ -1188,199 +1437,306 @@ function _unsupportedIterableToArray(r, a) {
1188
1437
  }, {
1189
1438
  key: "generateCustomQRCode",
1190
1439
  value: (function () {
1191
- var _generateCustomQRCode = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(content, label) {
1192
- var _qrContainer,
1193
- qrGeneratorUrl,
1194
- _response3,
1195
- responseData,
1196
- instructionsElement,
1197
- statusElement,
1198
- _t6;
1199
- return _regenerator().w(function (_context9) {
1200
- while (1) switch (_context9.p = _context9.n) {
1440
+ var _generateCustomQRCode = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10(content, label) {
1441
+ var qrContainer,
1442
+ _t0;
1443
+ return _regenerator().w(function (_context10) {
1444
+ while (1) switch (_context10.p = _context10.n) {
1201
1445
  case 0:
1202
- _context9.p = 1;
1203
- console.log('🎨 Début génération QR personnalisé avec PHP...');
1446
+ console.log('🎨 Début génération QR personnalisé...');
1204
1447
  console.log('📄 Contenu:', content);
1205
1448
  console.log('🏷️ Label:', label);
1206
- _qrContainer = document.getElementById('sunuid-qr-container');
1207
- if (_qrContainer) {
1208
- _context9.n = 2;
1449
+
1450
+ // Chercher le conteneur QR
1451
+ qrContainer = document.getElementById('sunuid-qr-container');
1452
+ if (!qrContainer) {
1453
+ qrContainer = document.getElementById('qr-container');
1454
+ }
1455
+ if (qrContainer) {
1456
+ _context10.n = 1;
1209
1457
  break;
1210
1458
  }
1211
1459
  console.error('❌ QR container not found');
1212
- this.displayFallbackImage();
1213
- return _context9.a(2);
1214
- case 2:
1460
+ return _context10.a(2);
1461
+ case 1:
1215
1462
  console.log('✅ QR container trouvé');
1216
1463
 
1217
1464
  // Nettoyer le conteneur
1218
- _qrContainer.innerHTML = '<div style="text-align: center; padding: 20px;"><p>Génération QR code avec PHP...</p></div>';
1465
+ qrContainer.innerHTML = '<div style="text-align: center; padding: 20px;"><p>Génération QR code...</p></div>';
1466
+ _context10.p = 2;
1467
+ // Utiliser directement l'API principale (plus fiable)
1468
+ console.log('🎨 Tentative génération via API principale...');
1469
+ _context10.n = 3;
1470
+ return this.generateQRPHP(content, label, qrContainer);
1471
+ case 3:
1472
+ console.log('✅ QR code généré avec succès');
1473
+ _context10.n = 5;
1474
+ break;
1475
+ case 4:
1476
+ _context10.p = 4;
1477
+ _t0 = _context10.v;
1478
+ console.error('❌ Erreur génération API:', _t0);
1219
1479
 
1220
- // Appeler l'endpoint PHP
1221
- console.log('🔄 Appel endpoint PHP...');
1222
- // Construire l'URL du QR generator de manière plus robuste
1480
+ // Fallback final : image par défaut
1481
+ console.log('⚠️ Affichage image par défaut');
1482
+ this.displayDefaultQR(qrContainer, content, label);
1483
+ case 5:
1484
+ return _context10.a(2);
1485
+ }
1486
+ }, _callee10, this, [[2, 4]]);
1487
+ }));
1488
+ function generateCustomQRCode(_x14, _x15) {
1489
+ return _generateCustomQRCode.apply(this, arguments);
1490
+ }
1491
+ return generateCustomQRCode;
1492
+ }()
1493
+ /**
1494
+ * Générer un QR code côté client (méthode principale)
1495
+ */
1496
+ )
1497
+ }, {
1498
+ key: "generateQRClientSide",
1499
+ value: (function () {
1500
+ var _generateQRClientSide = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee11(content, label, qrContainer) {
1501
+ var _this2 = this;
1502
+ var canvas, ctx;
1503
+ return _regenerator().w(function (_context11) {
1504
+ while (1) switch (_context11.n) {
1505
+ case 0:
1506
+ _context11.n = 1;
1507
+ return this.ensureQRCodeLibrary();
1508
+ case 1:
1509
+ if (!(typeof QRCode === 'undefined')) {
1510
+ _context11.n = 2;
1511
+ break;
1512
+ }
1513
+ throw new Error('QRCode library non disponible');
1514
+ case 2:
1515
+ // Créer un canvas
1516
+ canvas = document.createElement('canvas');
1517
+ canvas.width = 300;
1518
+ canvas.height = 320;
1519
+ ctx = canvas.getContext('2d'); // Fond blanc
1520
+ ctx.fillStyle = '#FFFFFF';
1521
+ ctx.fillRect(0, 0, 300, 320);
1522
+
1523
+ // Générer le QR code
1524
+ return _context11.a(2, new Promise(function (resolve, reject) {
1525
+ QRCode.toCanvas(canvas, content, {
1526
+ width: 280,
1527
+ margin: 10,
1528
+ color: {
1529
+ dark: '#000000',
1530
+ light: '#FFFFFF'
1531
+ }
1532
+ }, function (error) {
1533
+ if (error) {
1534
+ reject(error);
1535
+ return;
1536
+ }
1223
1537
 
1224
- if (this.config.apiUrl.includes('api.sunuid.fayma.sn')) {
1225
- qrGeneratorUrl = 'https://api.sunuid.fayma.sn/qr-generator.php';
1538
+ // Ajouter le label
1539
+ ctx.fillStyle = '#333333';
1540
+ ctx.font = 'bold 14px Arial';
1541
+ ctx.textAlign = 'center';
1542
+ ctx.fillText(label, 150, 305);
1543
+
1544
+ // Convertir en data URL
1545
+ var dataUrl = canvas.toDataURL('image/png');
1546
+
1547
+ // Stocker l'URL
1548
+ _this2.currentQRUrl = dataUrl;
1549
+
1550
+ // Afficher le QR code
1551
+ 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 ");
1552
+
1553
+ // Afficher les instructions
1554
+ _this2.showQRInstructions(qrContainer);
1555
+ resolve();
1556
+ });
1557
+ }));
1558
+ }
1559
+ }, _callee11, this);
1560
+ }));
1561
+ function generateQRClientSide(_x16, _x17, _x18) {
1562
+ return _generateQRClientSide.apply(this, arguments);
1563
+ }
1564
+ return generateQRClientSide;
1565
+ }()
1566
+ /**
1567
+ * Générer un QR code via endpoint PHP (fallback)
1568
+ */
1569
+ )
1570
+ }, {
1571
+ key: "generateQRPHP",
1572
+ value: (function () {
1573
+ var _generateQRPHP = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee12(content, label, qrContainer) {
1574
+ var qrGeneratorUrl, requestBody, contentType, response, responseData, qrImageUrl, imageBaseUrl;
1575
+ return _regenerator().w(function (_context12) {
1576
+ while (1) switch (_context12.n) {
1577
+ case 0:
1578
+ // Construire l'URL - Utiliser l'API principale qui fonctionne
1579
+
1580
+ if (this.config.forceRemoteServer) {
1581
+ qrGeneratorUrl = 'https://api.sunuid.fayma.sn/qr-generate';
1582
+ } else if (this.config.apiUrl.includes('api.sunuid.fayma.sn')) {
1583
+ qrGeneratorUrl = 'https://api.sunuid.fayma.sn/qr-generate';
1584
+ } else if (this.config.apiUrl.includes('localhost') || this.config.apiUrl.includes('127.0.0.1')) {
1585
+ qrGeneratorUrl = 'http://localhost:8000/api/generate/text';
1226
1586
  } else {
1227
- qrGeneratorUrl = this.config.apiUrl.replace('/api', '') + '/qr-generator.php';
1587
+ qrGeneratorUrl = this.config.apiUrl + '/qr-generate';
1228
1588
  }
1229
1589
  console.log('🔗 URL QR Generator:', qrGeneratorUrl);
1230
- _context9.n = 3;
1590
+
1591
+ // Adapter le format selon l'URL
1592
+
1593
+ if (qrGeneratorUrl.includes('localhost:8000')) {
1594
+ // Service local - format form-data
1595
+ contentType = 'application/x-www-form-urlencoded';
1596
+ requestBody = new URLSearchParams({
1597
+ text: content,
1598
+ size: 300,
1599
+ margin: 10,
1600
+ foreground_color: '000000',
1601
+ background_color: 'FFFFFF'
1602
+ });
1603
+ } else {
1604
+ // Service distant - format JSON avec les paramètres de l'API principale
1605
+ contentType = 'application/json';
1606
+ requestBody = JSON.stringify({
1607
+ type: this.config.type,
1608
+ client_id: this.config.clientId,
1609
+ secret_id: this.config.secretId,
1610
+ content: content,
1611
+ label: label
1612
+ });
1613
+ }
1614
+ _context12.n = 1;
1231
1615
  return fetch(qrGeneratorUrl, {
1232
1616
  method: 'POST',
1233
1617
  headers: {
1234
- 'Content-Type': 'application/json',
1618
+ 'Content-Type': contentType,
1235
1619
  'Accept': 'application/json'
1236
1620
  },
1237
- body: JSON.stringify({
1238
- content: content,
1239
- label: label,
1240
- size: 300,
1241
- margin: 10
1242
- })
1621
+ body: requestBody
1243
1622
  });
1244
- case 3:
1245
- _response3 = _context9.v;
1246
- console.log('📥 Réponse PHP reçue - Status:', _response3.status);
1247
- if (_response3.ok) {
1248
- _context9.n = 4;
1623
+ case 1:
1624
+ response = _context12.v;
1625
+ if (response.ok) {
1626
+ _context12.n = 2;
1249
1627
  break;
1250
1628
  }
1251
- throw new Error("Erreur HTTP: ".concat(_response3.status));
1252
- case 4:
1253
- _context9.n = 5;
1254
- return _response3.json();
1255
- case 5:
1256
- responseData = _context9.v;
1629
+ throw new Error("Erreur HTTP: ".concat(response.status));
1630
+ case 2:
1631
+ _context12.n = 3;
1632
+ return response.json();
1633
+ case 3:
1634
+ responseData = _context12.v;
1257
1635
  if (responseData.success) {
1258
- _context9.n = 6;
1636
+ _context12.n = 4;
1259
1637
  break;
1260
1638
  }
1261
- throw new Error("Erreur PHP: ".concat(responseData.error));
1262
- case 6:
1263
- console.log('✅ QR code généré par PHP avec succès');
1264
- console.log('📊 Taille:', responseData.data.size + 'px');
1265
- console.log('📊 Longueur base64:', responseData.data.length + ' caractères');
1266
-
1267
- // Stocker l'URL du QR code pour getQRCode()
1268
- this.currentQRUrl = responseData.data.dataUrl;
1269
-
1270
- // Créer le conteneur avec le QR code PHP
1271
- _qrContainer.innerHTML = "\n <div class=\"sunuid-qr-ready\" style=\"text-align: center; padding: 20px;\">\n <img src=\"".concat(responseData.data.dataUrl, "\" alt=\"QR Code ").concat(this.config.partnerName, "\" style=\"max-width: 300px; border: 2px solid #ddd; border-radius: 10px;\">\n </div>\n ");
1272
-
1273
- // Afficher les instructions et le statut maintenant que le QR est prêt
1274
- instructionsElement = _qrContainer.parentElement.querySelector('.sunuid-qr-instructions');
1275
- statusElement = _qrContainer.parentElement.querySelector('.sunuid-qr-status');
1276
- if (instructionsElement) {
1277
- instructionsElement.style.display = 'block';
1278
- instructionsElement.classList.add('sunuid-qr-ready');
1279
- }
1280
- if (statusElement) {
1281
- statusElement.style.display = 'block';
1282
- statusElement.classList.add('sunuid-qr-ready');
1283
- }
1284
- console.log('✅ QR code PHP affiché dans le conteneur');
1285
- _context9.n = 8;
1286
- break;
1287
- case 7:
1288
- _context9.p = 7;
1289
- _t6 = _context9.v;
1290
- console.error('❌ Erreur génération QR PHP:', _t6);
1291
- console.error('Stack trace:', _t6.stack);
1292
-
1293
- // Détecter les erreurs CORS ou 404 pour activer le fallback côté client
1294
- if (_t6.message.includes('Failed to fetch') || _t6.message.includes('CORS') || _t6.message.includes('404') || _t6.message.includes('Not Found')) {
1295
- console.warn('🚫 Erreur PHP détectée (CORS/404), tentative de génération QR côté client...');
1296
- this.generateQRCodeClientSide(content, label, qrContainer);
1639
+ throw new Error("Erreur QR: ".concat(responseData.error));
1640
+ case 4:
1641
+ if (qrGeneratorUrl.includes('localhost:8000')) {
1642
+ // Service local
1643
+ qrImageUrl = responseData.data_uri;
1297
1644
  } else {
1298
- this.displayFallbackImage();
1645
+ // Service distant - utiliser le format de l'API principale
1646
+ imageBaseUrl = 'https://sunuid.fayma.sn';
1647
+ qrImageUrl = "".concat(imageBaseUrl).concat(responseData.data.qrcode);
1299
1648
  }
1300
- case 8:
1301
- return _context9.a(2);
1649
+
1650
+ // Stocker l'URL
1651
+ this.currentQRUrl = qrImageUrl;
1652
+
1653
+ // Afficher le QR code
1654
+ qrContainer.innerHTML = "\n <div style=\"text-align: center; padding: 20px;\">\n <img src=\"".concat(qrImageUrl, "\" alt=\"QR Code\" style=\"max-width: 300px; border: 2px solid #ddd; border-radius: 10px;\">\n </div>\n ");
1655
+
1656
+ // Afficher les instructions
1657
+ this.showQRInstructions(qrContainer);
1658
+ case 5:
1659
+ return _context12.a(2);
1302
1660
  }
1303
- }, _callee9, this, [[1, 7]]);
1661
+ }, _callee12, this);
1304
1662
  }));
1305
- function generateCustomQRCode(_x8, _x9) {
1306
- return _generateCustomQRCode.apply(this, arguments);
1663
+ function generateQRPHP(_x19, _x20, _x21) {
1664
+ return _generateQRPHP.apply(this, arguments);
1307
1665
  }
1308
- return generateCustomQRCode;
1666
+ return generateQRPHP;
1309
1667
  }()
1310
1668
  /**
1311
- * Générer un QR code côté client en cas d'erreur CORS
1669
+ * Afficher une image QR par défaut (fallback final)
1312
1670
  */
1313
1671
  )
1314
1672
  }, {
1315
- key: "generateQRCodeClientSide",
1316
- value: function generateQRCodeClientSide(content, label, qrContainer) {
1317
- var _this4 = this;
1318
- try {
1319
- console.log('🎨 Génération QR côté client...');
1320
-
1321
- // Vérifier si QRCode est disponible
1322
- if (typeof QRCode === 'undefined') {
1323
- console.error('❌ QRCode library non disponible');
1324
- this.displayFallbackImage();
1325
- return;
1326
- }
1327
-
1328
- // Créer un canvas pour le QR code
1329
- var canvas = document.createElement('canvas');
1330
- canvas.width = 300;
1331
- canvas.height = 320; // Plus d'espace pour le label
1332
- var ctx = canvas.getContext('2d');
1333
-
1334
- // Remplir le fond en blanc
1335
- ctx.fillStyle = '#FFFFFF';
1336
- ctx.fillRect(0, 0, 300, 320);
1337
-
1338
- // Générer le QR code avec QRCode library
1339
- QRCode.toCanvas(canvas, content, {
1340
- width: 280,
1341
- margin: 10,
1342
- color: {
1343
- dark: '#000000',
1344
- light: '#FFFFFF'
1345
- }
1346
- }, function (error) {
1347
- if (error) {
1348
- console.error('❌ Erreur génération QR côté client:', error);
1349
- _this4.displayFallbackImage();
1350
- return;
1351
- }
1352
-
1353
- // Ajouter le label en bas du QR code (sans afficher le contenu)
1354
- ctx.fillStyle = '#333333';
1355
- ctx.font = 'bold 14px Arial';
1356
- ctx.textAlign = 'center';
1357
- ctx.fillText(label, 150, 305);
1358
-
1359
- // Convertir en data URL
1360
- var dataUrl = canvas.toDataURL('image/png');
1361
-
1362
- // Stocker l'URL du QR code pour getQRCode()
1363
- _this4.currentQRUrl = dataUrl;
1364
-
1365
- // Afficher le QR code (sans le contenu)
1366
- qrContainer.innerHTML = "\n <div class=\"sunuid-qr-ready\" style=\"text-align: center; padding: 20px;\">\n <img src=\"".concat(dataUrl, "\" alt=\"QR Code ").concat(_this4.config.partnerName, "\" style=\"max-width: 300px; border: 2px solid #ddd; border-radius: 10px;\">\n </div>\n ");
1673
+ key: "displayDefaultQR",
1674
+ value: function displayDefaultQR(qrContainer, content, label) {
1675
+ qrContainer.innerHTML = "\n <div style=\"text-align: center; padding: 20px; color: #666;\">\n <div style=\"width: 300px; height: 300px; background: #f0f0f0; border: 2px solid #ddd; border-radius: 10px; display: flex; align-items: center; justify-content: center; margin: 0 auto;\">\n <div>\n <p style=\"font-size: 24px; margin: 0;\">\uD83D\uDCF1</p>\n <p style=\"font-size: 14px; margin: 10px 0 0 0;\">QR Code</p>\n </div>\n </div>\n <p style=\"margin-top: 10px; font-size: 12px;\">".concat(label, "</p>\n <p style=\"font-size: 10px; color: #999; margin-top: 5px;\">Contenu: ").concat(content, "</p>\n </div>\n ");
1676
+ }
1367
1677
 
1368
- // Afficher les instructions et le statut
1369
- var instructionsElement = qrContainer.parentElement.querySelector('.sunuid-qr-instructions');
1370
- var statusElement = qrContainer.parentElement.querySelector('.sunuid-qr-status');
1371
- if (instructionsElement) {
1372
- instructionsElement.style.display = 'block';
1373
- instructionsElement.classList.add('sunuid-qr-ready');
1374
- }
1375
- if (statusElement) {
1376
- statusElement.style.display = 'block';
1377
- statusElement.classList.add('sunuid-qr-ready');
1678
+ /**
1679
+ * S'assurer que la bibliothèque QRCode est disponible
1680
+ */
1681
+ }, {
1682
+ key: "ensureQRCodeLibrary",
1683
+ value: (function () {
1684
+ var _ensureQRCodeLibrary = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee13() {
1685
+ return _regenerator().w(function (_context13) {
1686
+ while (1) switch (_context13.n) {
1687
+ case 0:
1688
+ if (!(typeof QRCode !== 'undefined')) {
1689
+ _context13.n = 1;
1690
+ break;
1691
+ }
1692
+ console.log('✅ QRCode library déjà disponible');
1693
+ return _context13.a(2, true);
1694
+ case 1:
1695
+ console.log('📦 Chargement QRCode library...');
1696
+ return _context13.a(2, new Promise(function (resolve, reject) {
1697
+ var script = document.createElement('script');
1698
+ script.src = 'https://cdn.jsdelivr.net/npm/qrcode@1.5.3/lib/browser.min.js';
1699
+ script.onload = function () {
1700
+ setTimeout(function () {
1701
+ if (typeof QRCode !== 'undefined') {
1702
+ console.log('✅ QRCode library chargée');
1703
+ resolve(true);
1704
+ } else {
1705
+ console.error('❌ QRCode non disponible après chargement');
1706
+ reject(new Error('QRCode library non disponible après chargement'));
1707
+ }
1708
+ }, 200);
1709
+ };
1710
+ script.onerror = function () {
1711
+ console.error('❌ Erreur chargement QRCode library');
1712
+ reject(new Error('Erreur chargement QRCode library'));
1713
+ };
1714
+ document.head.appendChild(script);
1715
+ }));
1378
1716
  }
1379
- console.log('✅ QR code côté client généré avec succès');
1380
- });
1381
- } catch (error) {
1382
- console.error('❌ Erreur génération QR côté client:', error);
1383
- this.displayFallbackImage();
1717
+ }, _callee13);
1718
+ }));
1719
+ function ensureQRCodeLibrary() {
1720
+ return _ensureQRCodeLibrary.apply(this, arguments);
1721
+ }
1722
+ return ensureQRCodeLibrary;
1723
+ }()
1724
+ /**
1725
+ * Afficher les instructions pour le QR code
1726
+ */
1727
+ )
1728
+ }, {
1729
+ key: "showQRInstructions",
1730
+ value: function showQRInstructions(qrContainer) {
1731
+ var instructionsElement = qrContainer.parentElement.querySelector('.sunuid-qr-instructions');
1732
+ var statusElement = qrContainer.parentElement.querySelector('.sunuid-qr-status');
1733
+ if (instructionsElement) {
1734
+ instructionsElement.style.display = 'block';
1735
+ instructionsElement.classList.add('sunuid-qr-ready');
1736
+ }
1737
+ if (statusElement) {
1738
+ statusElement.style.display = 'block';
1739
+ statusElement.classList.add('sunuid-qr-ready');
1384
1740
  }
1385
1741
  }
1386
1742
 
@@ -1421,8 +1777,6 @@ function _unsupportedIterableToArray(r, a) {
1421
1777
  var qrContainer = document.getElementById('sunuid-qr-container');
1422
1778
  if (qrContainer) {
1423
1779
  qrContainer.innerHTML = "\n <div style=\"text-align: center; padding: 20px; color: #666;\">\n <p>\u26A0\uFE0F G\xE9n\xE9ration QR personnalis\xE9 non disponible</p>\n <p>Utilisation de l'image par d\xE9faut</p>\n <p><strong>Debug:</strong> QRCode disponible: ".concat(typeof QRCode !== 'undefined', "</p>\n <p><strong>Debug:</strong> Container trouv\xE9: ").concat(qrContainer !== null, "</p>\n </div>\n ");
1424
- } else {
1425
- console.error('❌ Container QR non trouvé pour fallback');
1426
1780
  }
1427
1781
  }
1428
1782
 
@@ -1447,33 +1801,55 @@ function _unsupportedIterableToArray(r, a) {
1447
1801
  }, {
1448
1802
  key: "refreshQR",
1449
1803
  value: (function () {
1450
- var _refreshQR = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0(containerId) {
1804
+ var _refreshQR = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee14(containerId) {
1451
1805
  var options,
1452
1806
  result,
1453
- _args0 = arguments,
1454
- _t7;
1455
- return _regenerator().w(function (_context0) {
1456
- while (1) switch (_context0.p = _context0.n) {
1807
+ _result,
1808
+ _args14 = arguments,
1809
+ _t1;
1810
+ return _regenerator().w(function (_context14) {
1811
+ while (1) switch (_context14.p = _context14.n) {
1457
1812
  case 0:
1458
- options = _args0.length > 1 && _args0[1] !== undefined ? _args0[1] : {};
1459
- _context0.p = 1;
1460
- _context0.n = 2;
1813
+ options = _args14.length > 1 && _args14[1] !== undefined ? _args14[1] : {};
1814
+ _context14.p = 1;
1815
+ if (!this.currentQRUrl) {
1816
+ _context14.n = 3;
1817
+ break;
1818
+ }
1819
+ console.log('🔄 Vérification du statut du QR code existant...');
1820
+
1821
+ // Option 1: Vérifier le statut du QR code via l'API
1822
+ // (à implémenter si l'API le supporte)
1823
+
1824
+ // Option 2: Régénérer le QR code seulement si nécessaire
1825
+ // Pour l'instant, on régénère pour s'assurer qu'il est à jour
1826
+ _context14.n = 2;
1461
1827
  return this.generateQR(containerId, options);
1462
1828
  case 2:
1463
- result = _context0.v;
1464
- return _context0.a(2, result);
1829
+ result = _context14.v;
1830
+ return _context14.a(2, result);
1465
1831
  case 3:
1466
- _context0.p = 3;
1467
- _t7 = _context0.v;
1468
- console.error('Erreur lors du rafraîchissement:', _t7.message);
1469
- this.displayServiceUnavailable(containerId, this.config.type);
1470
- throw _t7;
1832
+ console.log('🔄 Pas de QR code existant, génération d\'un nouveau...');
1833
+ _context14.n = 4;
1834
+ return this.generateQR(containerId, options);
1471
1835
  case 4:
1472
- return _context0.a(2);
1836
+ _result = _context14.v;
1837
+ return _context14.a(2, _result);
1838
+ case 5:
1839
+ _context14.n = 7;
1840
+ break;
1841
+ case 6:
1842
+ _context14.p = 6;
1843
+ _t1 = _context14.v;
1844
+ console.error('Erreur lors du rafraîchissement:', _t1.message);
1845
+ this.displayServiceUnavailable(containerId, this.config.type);
1846
+ throw _t1;
1847
+ case 7:
1848
+ return _context14.a(2);
1473
1849
  }
1474
- }, _callee0, this, [[1, 3]]);
1850
+ }, _callee14, this, [[1, 6]]);
1475
1851
  }));
1476
- function refreshQR(_x0) {
1852
+ function refreshQR(_x22) {
1477
1853
  return _refreshQR.apply(this, arguments);
1478
1854
  }
1479
1855
  return refreshQR;
@@ -1485,28 +1861,36 @@ function _unsupportedIterableToArray(r, a) {
1485
1861
  }, {
1486
1862
  key: "startAutoRefresh",
1487
1863
  value: function startAutoRefresh(containerId, type, options) {
1488
- var _this5 = this;
1864
+ var _this3 = this;
1489
1865
  if (!this.config.autoRefresh) return;
1490
- this.refreshTimer = setInterval(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1() {
1491
- var _t8;
1492
- return _regenerator().w(function (_context1) {
1493
- while (1) switch (_context1.p = _context1.n) {
1866
+
1867
+ // Arrêter le timer existant s'il y en a un
1868
+ if (this.refreshTimer) {
1869
+ clearInterval(this.refreshTimer);
1870
+ console.log('🔄 Timer de rafraîchissement précédent arrêté');
1871
+ }
1872
+ this.refreshTimer = setInterval(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee15() {
1873
+ var _t10;
1874
+ return _regenerator().w(function (_context15) {
1875
+ while (1) switch (_context15.p = _context15.n) {
1494
1876
  case 0:
1495
- _context1.p = 0;
1496
- _context1.n = 1;
1497
- return _this5.refreshQR(containerId, type, options);
1877
+ _context15.p = 0;
1878
+ console.log('🔄 Rafraîchissement automatique du QR code...');
1879
+ _context15.n = 1;
1880
+ return _this3.refreshQR(containerId, type, options);
1498
1881
  case 1:
1499
- _context1.n = 3;
1882
+ _context15.n = 3;
1500
1883
  break;
1501
1884
  case 2:
1502
- _context1.p = 2;
1503
- _t8 = _context1.v;
1504
- console.warn('Erreur lors du rafraîchissement automatique:', _t8);
1885
+ _context15.p = 2;
1886
+ _t10 = _context15.v;
1887
+ console.warn('Erreur lors du rafraîchissement automatique:', _t10);
1505
1888
  case 3:
1506
- return _context1.a(2);
1889
+ return _context15.a(2);
1507
1890
  }
1508
- }, _callee1, null, [[0, 2]]);
1891
+ }, _callee15, null, [[0, 2]]);
1509
1892
  })), this.config.refreshInterval);
1893
+ console.log("\uD83D\uDD04 Timer de rafra\xEEchissement d\xE9marr\xE9 (".concat(this.config.refreshInterval, "ms)"));
1510
1894
  }
1511
1895
 
1512
1896
  /**
@@ -1519,16 +1903,16 @@ function _unsupportedIterableToArray(r, a) {
1519
1903
  }, {
1520
1904
  key: "makeRequest",
1521
1905
  value: (function () {
1522
- var _makeRequest = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10(endpoint, data) {
1906
+ var _makeRequest = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee16(endpoint, data) {
1523
1907
  var _window$SunuIDConfig4,
1524
1908
  _window$SunuIDConfig5,
1525
- _this6 = this;
1909
+ _this4 = this;
1526
1910
  var sanitizedData, endpointPath, url, retryCount, maxRetries, _loop, _ret;
1527
- return _regenerator().w(function (_context11) {
1528
- while (1) switch (_context11.n) {
1911
+ return _regenerator().w(function (_context17) {
1912
+ while (1) switch (_context17.n) {
1529
1913
  case 0:
1530
1914
  if (this.isInitialized) {
1531
- _context11.n = 1;
1915
+ _context17.n = 1;
1532
1916
  break;
1533
1917
  }
1534
1918
  this.logSecurityEvent('REQUEST_BEFORE_INIT', {
@@ -1537,12 +1921,12 @@ function _unsupportedIterableToArray(r, a) {
1537
1921
  throw new Error('SDK non initialisé');
1538
1922
  case 1:
1539
1923
  if (!this.config.secureInit) {
1540
- _context11.n = 2;
1924
+ _context17.n = 2;
1541
1925
  break;
1542
1926
  }
1543
1927
  this.config.requestCount++;
1544
1928
  if (!(this.config.requestCount > this.config.maxRequests)) {
1545
- _context11.n = 2;
1929
+ _context17.n = 2;
1546
1930
  break;
1547
1931
  }
1548
1932
  this.logSecurityEvent('API_REQUEST_LIMIT_EXCEEDED', {
@@ -1577,15 +1961,15 @@ function _unsupportedIterableToArray(r, a) {
1577
1961
  retryCount = 0;
1578
1962
  maxRetries = this.config.maxRetries;
1579
1963
  _loop = /*#__PURE__*/_regenerator().m(function _loop() {
1580
- var controller, timeoutId, headers, _response4, errorText, errorData, result, _t9;
1581
- return _regenerator().w(function (_context10) {
1582
- while (1) switch (_context10.p = _context10.n) {
1964
+ var controller, timeoutId, headers, response, errorText, errorData, result, _t11;
1965
+ return _regenerator().w(function (_context16) {
1966
+ while (1) switch (_context16.p = _context16.n) {
1583
1967
  case 0:
1584
- _context10.p = 0;
1968
+ _context16.p = 0;
1585
1969
  controller = new AbortController();
1586
1970
  timeoutId = setTimeout(function () {
1587
1971
  return controller.abort();
1588
- }, _this6.config.requestTimeout); // Headers minimaux (API SunuID n'accepte que les headers essentiels)
1972
+ }, _this4.config.requestTimeout); // Headers minimaux (API SunuID n'accepte que les headers essentiels)
1589
1973
  headers = {
1590
1974
  'Content-Type': 'application/json'
1591
1975
  }; // Note: En mode sécurisé, les credentials sont dans le body
@@ -1593,7 +1977,7 @@ function _unsupportedIterableToArray(r, a) {
1593
1977
  // if (this.config.secureInit && this.config.token) {
1594
1978
  // headers['X-Secure-Token'] = this.config.token;
1595
1979
  // }
1596
- _context10.n = 1;
1980
+ _context16.n = 1;
1597
1981
  return fetch(url, {
1598
1982
  method: 'POST',
1599
1983
  headers: headers,
@@ -1601,16 +1985,16 @@ function _unsupportedIterableToArray(r, a) {
1601
1985
  signal: controller.signal
1602
1986
  });
1603
1987
  case 1:
1604
- _response4 = _context10.v;
1988
+ response = _context16.v;
1605
1989
  clearTimeout(timeoutId);
1606
- if (_response4.ok) {
1607
- _context10.n = 3;
1990
+ if (response.ok) {
1991
+ _context16.n = 3;
1608
1992
  break;
1609
1993
  }
1610
- _context10.n = 2;
1611
- return _response4.text();
1994
+ _context16.n = 2;
1995
+ return response.text();
1612
1996
  case 2:
1613
- errorText = _context10.v;
1997
+ errorText = _context16.v;
1614
1998
  try {
1615
1999
  errorData = JSON.parse(errorText);
1616
2000
  } catch (e) {
@@ -1618,90 +2002,90 @@ function _unsupportedIterableToArray(r, a) {
1618
2002
  message: errorText
1619
2003
  };
1620
2004
  }
1621
- _this6.logSecurityEvent('API_REQUEST_ERROR', {
1622
- status: _response4.status,
1623
- statusText: _response4.statusText,
2005
+ _this4.logSecurityEvent('API_REQUEST_ERROR', {
2006
+ status: response.status,
2007
+ statusText: response.statusText,
1624
2008
  error: errorData.message
1625
2009
  });
1626
- throw new Error(errorData.message || "Erreur HTTP: ".concat(_response4.status));
2010
+ throw new Error(errorData.message || "Erreur HTTP: ".concat(response.status));
1627
2011
  case 3:
1628
- _context10.n = 4;
1629
- return _response4.json();
2012
+ _context16.n = 4;
2013
+ return response.json();
1630
2014
  case 4:
1631
- result = _context10.v;
1632
- _this6.logSecurityEvent('API_REQUEST_SUCCESS', {
2015
+ result = _context16.v;
2016
+ _this4.logSecurityEvent('API_REQUEST_SUCCESS', {
1633
2017
  endpoint: endpointPath,
1634
2018
  responseKeys: Object.keys(result)
1635
2019
  });
1636
- return _context10.a(2, {
2020
+ return _context16.a(2, {
1637
2021
  v: result
1638
2022
  });
1639
2023
  case 5:
1640
- _context10.p = 5;
1641
- _t9 = _context10.v;
2024
+ _context16.p = 5;
2025
+ _t11 = _context16.v;
1642
2026
  retryCount++;
1643
- if (!(_t9.name === 'AbortError')) {
1644
- _context10.n = 7;
2027
+ if (!(_t11.name === 'AbortError')) {
2028
+ _context16.n = 7;
1645
2029
  break;
1646
2030
  }
1647
- _this6.logSecurityEvent('API_REQUEST_TIMEOUT', {
2031
+ _this4.logSecurityEvent('API_REQUEST_TIMEOUT', {
1648
2032
  retryCount: retryCount
1649
2033
  });
1650
2034
  if (!(retryCount > maxRetries)) {
1651
- _context10.n = 6;
2035
+ _context16.n = 6;
1652
2036
  break;
1653
2037
  }
1654
2038
  throw new Error('Timeout de la requête API');
1655
2039
  case 6:
1656
- return _context10.a(2, 0);
2040
+ return _context16.a(2, 0);
1657
2041
  case 7:
1658
2042
  if (!(retryCount > maxRetries)) {
1659
- _context10.n = 8;
2043
+ _context16.n = 8;
1660
2044
  break;
1661
2045
  }
1662
- _this6.logSecurityEvent('API_REQUEST_MAX_RETRIES', {
2046
+ _this4.logSecurityEvent('API_REQUEST_MAX_RETRIES', {
1663
2047
  retryCount: retryCount,
1664
- error: _t9.message
2048
+ error: _t11.message
1665
2049
  });
1666
- throw _t9;
2050
+ throw _t11;
1667
2051
  case 8:
1668
- _context10.n = 9;
2052
+ _context16.n = 9;
1669
2053
  return new Promise(function (resolve) {
1670
2054
  return setTimeout(resolve, 1000 * retryCount);
1671
2055
  });
1672
2056
  case 9:
1673
- return _context10.a(2);
2057
+ return _context16.a(2);
1674
2058
  }
1675
2059
  }, _loop, null, [[0, 5]]);
1676
2060
  });
1677
2061
  case 3:
1678
2062
  if (!(retryCount <= maxRetries)) {
1679
- _context11.n = 7;
2063
+ _context17.n = 7;
1680
2064
  break;
1681
2065
  }
1682
- return _context11.d(_regeneratorValues(_loop()), 4);
2066
+ return _context17.d(_regeneratorValues(_loop()), 4);
1683
2067
  case 4:
1684
- _ret = _context11.v;
2068
+ _ret = _context17.v;
1685
2069
  if (!(_ret === 0)) {
1686
- _context11.n = 5;
2070
+ _context17.n = 5;
1687
2071
  break;
1688
2072
  }
1689
- return _context11.a(3, 3);
2073
+ return _context17.a(3, 3);
1690
2074
  case 5:
1691
2075
  if (!_ret) {
1692
- _context11.n = 6;
2076
+ _context17.n = 6;
1693
2077
  break;
1694
2078
  }
1695
- return _context11.a(2, _ret.v);
2079
+ return _context17.a(2, _ret.v);
1696
2080
  case 6:
1697
- _context11.n = 3;
2081
+ _context17.n = 3;
1698
2082
  break;
1699
2083
  case 7:
1700
- return _context11.a(2);
2084
+ return _context17.a(2);
1701
2085
  }
1702
- }, _callee10, this);
2086
+ }, _callee16, this);
1703
2087
  }));
1704
- function makeRequest(_x1, _x10) {
2088
+ function makeRequest(_x23, _x24) {
1705
2089
  return _makeRequest.apply(this, arguments);
1706
2090
  }
1707
2091
  return makeRequest;
@@ -1757,9 +2141,88 @@ function _unsupportedIterableToArray(r, a) {
1757
2141
  return 'req_' + Date.now() + '_' + Math.random().toString(36).substr(2, 9);
1758
2142
  }
1759
2143
 
2144
+ /**
2145
+ * Générer un code de session unique
2146
+ */
2147
+ }, {
2148
+ key: "generateSessionCode",
2149
+ value: function generateSessionCode() {
2150
+ var timestamp = Date.now();
2151
+ var random = Math.random().toString(36).substr(2, 9);
2152
+ var code = "".concat(timestamp, "_").concat(random);
2153
+ return btoa(code); // Encoder en base64
2154
+ }
2155
+
2156
+ /**
2157
+ * Récupérer les informations du partenaire depuis l'API
2158
+ */
2159
+ }, {
2160
+ key: "fetchPartnerInfo",
2161
+ value: (function () {
2162
+ var _fetchPartnerInfo = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee17() {
2163
+ var response, authTest, _t12;
2164
+ return _regenerator().w(function (_context18) {
2165
+ while (1) switch (_context18.p = _context18.n) {
2166
+ case 0:
2167
+ _context18.p = 0;
2168
+ _context18.n = 1;
2169
+ return this.makeRequest('/debug', {
2170
+ type: this.config.type,
2171
+ client_id: this.config.clientId,
2172
+ secret_id: this.config.secretId
2173
+ });
2174
+ case 1:
2175
+ response = _context18.v;
2176
+ console.log('📋 Réponse debug API:', response);
2177
+ if (response.success && response.authentication && response.authentication.auth_test) {
2178
+ authTest = response.authentication.auth_test;
2179
+ this.config.partnerId = authTest.partner_id;
2180
+
2181
+ // Récupérer le service_id depuis la réponse
2182
+ if (response.service_id) {
2183
+ this.config.serviceId = response.service_id;
2184
+ } else {
2185
+ // Fallback: utiliser le partner_id comme service_id
2186
+ this.config.serviceId = authTest.partner_id;
2187
+ }
2188
+
2189
+ // Utiliser le partner_id pour déterminer le nom du partenaire
2190
+ // Pour l'instant, on utilise une logique simple basée sur l'ID
2191
+ if (authTest.partner_id === 21) {
2192
+ this.config.partnerName = 'Fayma';
2193
+ } else {
2194
+ this.config.partnerName = "Partner_".concat(authTest.partner_id);
2195
+ }
2196
+ console.log('✅ Informations partenaire récupérées:', {
2197
+ partnerName: this.config.partnerName,
2198
+ partnerId: this.config.partnerId,
2199
+ serviceId: this.config.serviceId
2200
+ });
2201
+ } else {
2202
+ console.warn('⚠️ Impossible de récupérer les informations du partenaire, utilisation du partner_id');
2203
+ this.config.partnerName = "Partner_".concat(this.config.partnerId || 'unknown');
2204
+ }
2205
+ _context18.n = 3;
2206
+ break;
2207
+ case 2:
2208
+ _context18.p = 2;
2209
+ _t12 = _context18.v;
2210
+ console.warn('⚠️ Erreur lors de la récupération des informations du partenaire:', _t12.message);
2211
+ this.config.partnerName = 'Partner_unknown';
2212
+ case 3:
2213
+ return _context18.a(2);
2214
+ }
2215
+ }, _callee17, this, [[0, 2]]);
2216
+ }));
2217
+ function fetchPartnerInfo() {
2218
+ return _fetchPartnerInfo.apply(this, arguments);
2219
+ }
2220
+ return fetchPartnerInfo;
2221
+ }()
1760
2222
  /**
1761
2223
  * Appliquer le thème
1762
2224
  */
2225
+ )
1763
2226
  }, {
1764
2227
  key: "applyTheme",
1765
2228
  value: function applyTheme(theme) {
@@ -1781,9 +2244,124 @@ function _unsupportedIterableToArray(r, a) {
1781
2244
  }
1782
2245
  }
1783
2246
 
2247
+ /**
2248
+ * Vérifier le statut des connexions
2249
+ */
2250
+ }, {
2251
+ key: "checkConnections",
2252
+ value: (function () {
2253
+ var _checkConnections = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee18() {
2254
+ var status, testResponse, debugData, _t13;
2255
+ return _regenerator().w(function (_context19) {
2256
+ while (1) switch (_context19.p = _context19.n) {
2257
+ case 0:
2258
+ status = {
2259
+ api: false,
2260
+ websocket: false,
2261
+ ready: false
2262
+ }; // Vérifier l'API en utilisant l'endpoint debug
2263
+ _context19.p = 1;
2264
+ _context19.n = 2;
2265
+ return fetch(this.config.apiUrl + '/debug', {
2266
+ method: 'GET',
2267
+ timeout: 3000
2268
+ });
2269
+ case 2:
2270
+ testResponse = _context19.v;
2271
+ if (!testResponse.ok) {
2272
+ _context19.n = 4;
2273
+ break;
2274
+ }
2275
+ _context19.n = 3;
2276
+ return testResponse.json();
2277
+ case 3:
2278
+ debugData = _context19.v;
2279
+ status.api = debugData.status === 'operational';
2280
+ console.log('🔍 API Status:', debugData.status);
2281
+ _context19.n = 5;
2282
+ break;
2283
+ case 4:
2284
+ status.api = false;
2285
+ case 5:
2286
+ _context19.n = 7;
2287
+ break;
2288
+ case 6:
2289
+ _context19.p = 6;
2290
+ _t13 = _context19.v;
2291
+ console.log('🔍 Test API échoué:', _t13.message);
2292
+ status.api = false;
2293
+ case 7:
2294
+ // Vérifier le WebSocket
2295
+ status.websocket = this.socket && this.socket.connected;
2296
+
2297
+ // Connexions prêtes si API est accessible
2298
+ status.ready = status.api;
2299
+ return _context19.a(2, status);
2300
+ }
2301
+ }, _callee18, this, [[1, 6]]);
2302
+ }));
2303
+ function checkConnections() {
2304
+ return _checkConnections.apply(this, arguments);
2305
+ }
2306
+ return checkConnections;
2307
+ }()
2308
+ /**
2309
+ * Attendre que les connexions soient prêtes
2310
+ */
2311
+ )
2312
+ }, {
2313
+ key: "waitForConnections",
2314
+ value: (function () {
2315
+ var _waitForConnections = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee19() {
2316
+ var timeout,
2317
+ startTime,
2318
+ status,
2319
+ _args20 = arguments;
2320
+ return _regenerator().w(function (_context20) {
2321
+ while (1) switch (_context20.n) {
2322
+ case 0:
2323
+ timeout = _args20.length > 0 && _args20[0] !== undefined ? _args20[0] : 5000;
2324
+ startTime = Date.now();
2325
+ case 1:
2326
+ if (!(Date.now() - startTime < timeout)) {
2327
+ _context20.n = 5;
2328
+ break;
2329
+ }
2330
+ _context20.n = 2;
2331
+ return this.checkConnections();
2332
+ case 2:
2333
+ status = _context20.v;
2334
+ if (!status.ready) {
2335
+ _context20.n = 3;
2336
+ break;
2337
+ }
2338
+ console.log('✅ Connexions prêtes');
2339
+ return _context20.a(2, status);
2340
+ case 3:
2341
+ console.log('⏳ Attente connexions...', status);
2342
+ _context20.n = 4;
2343
+ return new Promise(function (resolve) {
2344
+ return setTimeout(resolve, 1000);
2345
+ });
2346
+ case 4:
2347
+ _context20.n = 1;
2348
+ break;
2349
+ case 5:
2350
+ throw new Error('Timeout connexions - Impossible de générer le QR code');
2351
+ case 6:
2352
+ return _context20.a(2);
2353
+ }
2354
+ }, _callee19, this);
2355
+ }));
2356
+ function waitForConnections() {
2357
+ return _waitForConnections.apply(this, arguments);
2358
+ }
2359
+ return waitForConnections;
2360
+ }()
1784
2361
  /**
1785
2362
  * Obtenir l'URL du QR code généré
1786
2363
  */
2364
+ )
1787
2365
  }, {
1788
2366
  key: "getQRCode",
1789
2367
  value: function getQRCode() {
@@ -1802,9 +2380,7 @@ function _unsupportedIterableToArray(r, a) {
1802
2380
  }, {
1803
2381
  key: "destroy",
1804
2382
  value: function destroy() {
1805
- if (this.refreshTimer) {
1806
- clearInterval(this.refreshTimer);
1807
- }
2383
+ this.stopAutoRefresh();
1808
2384
 
1809
2385
  // Fermer la connexion WebSocket
1810
2386
  if (this.socket) {
@@ -1817,6 +2393,19 @@ function _unsupportedIterableToArray(r, a) {
1817
2393
  console.log('SunuID SDK détruit');
1818
2394
  }
1819
2395
 
2396
+ /**
2397
+ * Arrêter le rafraîchissement automatique
2398
+ */
2399
+ }, {
2400
+ key: "stopAutoRefresh",
2401
+ value: function stopAutoRefresh() {
2402
+ if (this.refreshTimer) {
2403
+ clearInterval(this.refreshTimer);
2404
+ this.refreshTimer = null;
2405
+ console.log('🔄 Timer de rafraîchissement arrêté');
2406
+ }
2407
+ }
2408
+
1820
2409
  /**
1821
2410
  * Obtenir les logs de sécurité
1822
2411
  */
@@ -1835,6 +2424,32 @@ function _unsupportedIterableToArray(r, a) {
1835
2424
  window.SunuIDSecurityLogs = [];
1836
2425
  this.logSecurityEvent('SECURITY_LOGS_CLEARED');
1837
2426
  }
2427
+
2428
+ /**
2429
+ * Afficher un loader pendant le scan du QR code
2430
+ */
2431
+ }, {
2432
+ key: "showQRLoader",
2433
+ value: function showQRLoader() {
2434
+ console.log('🔄 Affichage du loader - Scan QR initié');
2435
+
2436
+ // Chercher le conteneur QR dans différents IDs possibles
2437
+ var containerIds = ['qr-area', 'qr-container', 'sunuid-qr-container'];
2438
+ var container = null;
2439
+ for (var _i2 = 0, _containerIds = containerIds; _i2 < _containerIds.length; _i2++) {
2440
+ var id = _containerIds[_i2];
2441
+ container = document.getElementById(id);
2442
+ if (container) break;
2443
+ }
2444
+ if (!container) {
2445
+ console.warn('⚠️ Conteneur QR non trouvé pour afficher le loader');
2446
+ return;
2447
+ }
2448
+
2449
+ // Remplacer le contenu par un loader animé
2450
+ container.innerHTML = "\n <div style=\"\n text-align: center;\n padding: 40px 20px;\n background: #f8f9fa;\n border: 2px solid #007bff;\n border-radius: 10px;\n color: #007bff;\n font-family: Arial, sans-serif;\n \">\n <div style=\"\n width: 60px;\n height: 60px;\n border: 4px solid #e3f2fd;\n border-top: 4px solid #007bff;\n border-radius: 50%;\n animation: spin 1s linear infinite;\n margin: 0 auto 20px auto;\n \"></div>\n <h3 style=\"margin: 0 0 10px 0; color: #007bff;\">\uD83D\uDD0D Scan en cours...</h3>\n <p style=\"margin: 0; font-size: 14px;\">\n Veuillez patienter pendant la v\xE9rification de votre identit\xE9.\n </p>\n <div style=\"margin-top: 15px; font-size: 12px; color: #6c757d;\">\n \u23F1\uFE0F Traitement en cours...\n </div>\n </div>\n <style>\n @keyframes spin {\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n }\n </style>\n ";
2451
+ console.log('✅ Loader affiché avec succès');
2452
+ }
1838
2453
  }]);
1839
2454
  }(); // Exposer la classe globalement
1840
2455
  window.SunuID = SunuID;