sunuid-sdk 1.0.32 → 1.0.34

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,11 +280,12 @@ 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
290
291
  onSuccess: null,
@@ -305,7 +306,10 @@ function _unsupportedIterableToArray(r, a) {
305
306
  }
306
307
  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
308
  }(),
308
- token: null
309
+ token: null,
310
+ // Configuration pour forcer l'utilisation du serveur distant
311
+ forceRemoteServer: true,
312
+ useLocalFallback: false
309
313
  };
310
314
 
311
315
  /**
@@ -356,31 +360,43 @@ function _unsupportedIterableToArray(r, a) {
356
360
  this.logSecurityEvent('SDK_INIT_START', {
357
361
  apiUrl: this.config.apiUrl,
358
362
  type: this.config.type,
359
- partnerName: this.config.partnerName,
360
363
  secureInit: this.config.secureInit
361
364
  });
362
365
 
366
+ // Récupérer les informations du partenaire depuis l'API
367
+ _context.n = 4;
368
+ return this.fetchPartnerInfo();
369
+ case 4:
363
370
  // Obscurcir les credentials dans les logs
364
371
  this.obfuscateCredentials();
365
372
  this.isInitialized = true;
366
373
  console.log('SunuID SDK initialisé avec succès');
374
+ console.log('📋 Configuration SDK:', {
375
+ apiUrl: this.config.apiUrl,
376
+ type: this.config.type,
377
+ partnerName: this.config.partnerName,
378
+ clientId: this.config.clientId ? '***' + this.config.clientId.slice(-4) : 'null',
379
+ secretId: this.config.secretId ? '***' + this.config.secretId.slice(-4) : 'null',
380
+ secureInit: this.config.secureInit,
381
+ theme: this.config.theme
382
+ });
367
383
  this.logSecurityEvent('SDK_INIT_SUCCESS');
368
384
 
369
385
  // Initialiser la connexion WebSocket
370
386
  this.initWebSocket();
371
- _context.n = 5;
387
+ _context.n = 6;
372
388
  break;
373
- case 4:
374
- _context.p = 4;
389
+ case 5:
390
+ _context.p = 5;
375
391
  _t = _context.v;
376
392
  this.logSecurityEvent('SDK_INIT_ERROR', {
377
393
  error: _t.message
378
394
  });
379
395
  throw _t;
380
- case 5:
396
+ case 6:
381
397
  return _context.a(2);
382
398
  }
383
- }, _callee, this, [[0, 4]]);
399
+ }, _callee, this, [[0, 5]]);
384
400
  }));
385
401
  function init() {
386
402
  return _init.apply(this, arguments);
@@ -427,6 +443,7 @@ function _unsupportedIterableToArray(r, a) {
427
443
  return response.json();
428
444
  case 3:
429
445
  result = _context2.v;
446
+ console.log('📋 Réponse initialisation sécurisée:', result);
430
447
  if (result.success) {
431
448
  _context2.n = 4;
432
449
  break;
@@ -534,25 +551,30 @@ function _unsupportedIterableToArray(r, a) {
534
551
 
535
552
  // Initialiser la connexion WebSocket si elle n'existe pas
536
553
  if (!this.socket) {
554
+ console.log('🌐 Initialisation Socket.IO...');
537
555
  this.socket = io('wss://samasocket.fayma.sn:9443', {
538
556
  query: {
539
557
  token: this.config.clientId,
540
558
  type: 'web',
541
559
  userId: this.config.clientId,
542
560
  username: ip
543
- }
561
+ },
562
+ transports: ['websocket', 'polling']
544
563
  });
545
564
 
546
565
  // Gestion des événements WebSocket
547
566
  this.socket.on('connect', function () {
548
567
  console.log('🌐 WebSocket connecté avec succès');
549
568
  console.log('📊 Socket ID:', _this.socket.id);
569
+ _this.socket.connected = true;
550
570
  });
551
571
  this.socket.on('disconnect', function (reason) {
552
572
  console.log('❌ WebSocket déconnecté:', reason);
573
+ _this.socket.connected = false;
553
574
  });
554
575
  this.socket.on('connect_error', function (error) {
555
576
  console.error('❌ Erreur connexion WebSocket:', error);
577
+ _this.socket.connected = false;
556
578
  });
557
579
 
558
580
  // Écouter les événements spécifiques
@@ -568,6 +590,8 @@ function _unsupportedIterableToArray(r, a) {
568
590
  console.log('⏰ QR expiré reçu:', data);
569
591
  _this.handleQRExpired(data);
570
592
  });
593
+ } else {
594
+ console.log('🌐 WebSocket déjà connecté');
571
595
  }
572
596
  } catch (error) {
573
597
  console.error('❌ Erreur initialisation WebSocket:', error);
@@ -755,8 +779,6 @@ function _unsupportedIterableToArray(r, a) {
755
779
  if (this.socket && this.socket.connected) {
756
780
  this.socket.emit(event, data);
757
781
  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
782
  } else {
761
783
  console.warn('⚠️ WebSocket non connecté, impossible d\'émettre l\'événement:', event);
762
784
  }
@@ -792,18 +814,23 @@ function _unsupportedIterableToArray(r, a) {
792
814
  }, {
793
815
  key: "generateQR",
794
816
  value: (function () {
795
- var _generateQR = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(containerId) {
796
- var _this2 = this;
797
- var options,
817
+ var _generateQR = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
818
+ var containerId,
819
+ options,
820
+ connectionStatus,
821
+ socketId,
822
+ qrContent,
823
+ partnerName,
798
824
  response,
799
- imageBaseUrl,
800
825
  qrImageUrl,
801
- _waitForSocketId,
826
+ isLocal,
802
827
  _args3 = arguments,
803
- _t3;
828
+ _t3,
829
+ _t4;
804
830
  return _regenerator().w(function (_context3) {
805
831
  while (1) switch (_context3.p = _context3.n) {
806
832
  case 0:
833
+ containerId = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : 'sunuid-qr-container';
807
834
  options = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : {};
808
835
  if (!this.initPromise) {
809
836
  _context3.n = 2;
@@ -820,68 +847,88 @@ function _unsupportedIterableToArray(r, a) {
820
847
  }
821
848
  throw new Error('SunuID: SDK non initialisé');
822
849
  case 3:
823
- _context3.p = 3;
824
- _context3.n = 4;
850
+ console.log('🎯 generateQR appelé avec containerId:', containerId);
851
+
852
+ // Attendre que les connexions soient prêtes
853
+ console.log('🔍 Attente connexions API et WebSocket...');
854
+ _context3.p = 4;
855
+ _context3.n = 5;
856
+ return this.waitForConnections(5000);
857
+ case 5:
858
+ connectionStatus = _context3.v;
859
+ // 5 secondes max
860
+ console.log('✅ Connexions prêtes:', connectionStatus);
861
+ _context3.n = 7;
862
+ break;
863
+ case 6:
864
+ _context3.p = 6;
865
+ _t3 = _context3.v;
866
+ console.error('❌ Erreur connexions:', _t3.message);
867
+ throw new Error('Connexions non disponibles - Impossible de générer le QR code');
868
+ case 7:
869
+ _context3.p = 7;
870
+ // Utiliser uniquement le socketID comme contenu du QR
871
+ socketId = this.socket ? this.socket.id : 'timeout-socket-id';
872
+ qrContent = socketId;
873
+ console.log('📄 Contenu QR préparé:', qrContent);
874
+ console.log('🔌 Socket ID:', socketId);
875
+
876
+ // Générer le QR avec le contenu complet
877
+ partnerName = this.config.partnerName || 'Partner_unknown';
878
+ _context3.n = 8;
825
879
  return this.makeRequest('/qr-generate', _objectSpread2({
826
- type: this.config.type
880
+ type: this.config.type,
881
+ content: qrContent,
882
+ // Contenu personnalisé pour le QR
883
+ label: "".concat(this.getTypeName(this.config.type), " ").concat(partnerName)
827
884
  }, options));
828
- case 4:
885
+ case 8:
829
886
  response = _context3.v;
830
887
  if (!response.success) {
831
- _context3.n = 5;
888
+ _context3.n = 9;
832
889
  break;
833
890
  }
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();
891
+ // Construire l'URL complète du QR code
892
+ qrImageUrl = response.data.qrCodeUrl; // Si l'URL est relative, la rendre absolue
893
+ if (qrImageUrl.startsWith('/')) {
894
+ qrImageUrl = "".concat(this.config.apiUrl).concat(qrImageUrl);
860
895
  }
896
+ this.currentQRUrl = qrImageUrl;
897
+ console.log('✅ QR code généré par API principale:', qrImageUrl);
898
+ console.log('📄 Contenu QR final:', qrContent);
899
+ console.log('🏷️ Label QR:', response.data.label);
900
+ console.log('🆔 Session ID:', response.data.sessionId);
901
+
902
+ // Afficher le QR code
903
+ this.displayQRCode(containerId, qrImageUrl, this.config.type, options);
861
904
  this.startAutoRefresh(containerId, this.config.type, options);
862
905
 
863
906
  // Émettre un événement WebSocket pour la génération du QR
864
907
  this.emitWebSocketEvent('qr_generated', {
865
- serviceId: response.data.service_id,
866
908
  type: this.config.type,
867
909
  qrCodeUrl: qrImageUrl,
868
- code: response.data.code,
910
+ socketId: socketId,
911
+ qrContent: qrContent,
912
+ label: response.data.label,
913
+ sessionId: response.data.sessionId,
869
914
  timestamp: Date.now()
870
915
  });
871
916
  return _context3.a(2, _objectSpread2(_objectSpread2({}, response.data), {}, {
872
917
  qrCodeUrl: qrImageUrl,
873
- sessionId: response.data.service_id
918
+ qrContent: qrContent,
919
+ label: response.data.label,
920
+ sessionId: response.data.sessionId
874
921
  }));
875
- case 5:
922
+ case 9:
876
923
  throw new Error(response.message || 'Erreur lors de la génération du QR code');
877
- case 6:
878
- _context3.n = 8;
924
+ case 10:
925
+ _context3.n = 12;
879
926
  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);
927
+ case 11:
928
+ _context3.p = 11;
929
+ _t4 = _context3.v;
930
+ console.error('Erreur API détectée:', _t4.message);
931
+ console.error('Stack trace complet:', _t4.stack);
885
932
  console.error('Configuration SDK:', {
886
933
  apiUrl: this.config.apiUrl,
887
934
  type: this.config.type,
@@ -889,15 +936,33 @@ function _unsupportedIterableToArray(r, a) {
889
936
  clientId: this.config.clientId ? '***' + this.config.clientId.slice(-4) : 'null',
890
937
  secretId: this.config.secretId ? '***' + this.config.secretId.slice(-4) : 'null'
891
938
  });
939
+
940
+ // Fallback vers le service local seulement si activé
941
+ if (this.config.useLocalFallback) {
942
+ console.log('🔍 Vérification fallback local...');
943
+ console.log('🔍 Hostname:', window.location.hostname);
944
+ console.log('🔍 Protocol:', window.location.protocol);
945
+ console.log('🔍 URL complète:', window.location.href);
946
+ isLocal = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1' || window.location.protocol === 'file:';
947
+ console.log('🔍 Est local:', isLocal);
948
+ if (isLocal) {
949
+ console.log('🔄 Tentative fallback vers service QR local...');
950
+ console.log('❌ Fallback local non implémenté - utilisation serveur distant uniquement');
951
+ } else {
952
+ console.log('❌ Pas en local, pas de fallback');
953
+ }
954
+ } else {
955
+ console.log('🔒 Fallback local désactivé, utilisation serveur distant uniquement');
956
+ }
892
957
  console.log('Affichage du message "Service non disponible" pour type ' + this.config.type);
893
958
  this.displayServiceUnavailable(containerId, this.config.type);
894
959
  throw new Error('Service non disponible');
895
- case 8:
960
+ case 12:
896
961
  return _context3.a(2);
897
962
  }
898
- }, _callee3, this, [[3, 7]]);
963
+ }, _callee3, this, [[7, 11], [4, 6]]);
899
964
  }));
900
- function generateQR(_x) {
965
+ function generateQR() {
901
966
  return _generateQR.apply(this, arguments);
902
967
  }
903
968
  return generateQR;
@@ -910,14 +975,12 @@ function _unsupportedIterableToArray(r, a) {
910
975
  key: "generateCustomQR",
911
976
  value: (function () {
912
977
  var _generateCustomQR = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(containerId, type) {
913
- var _this3 = this;
914
978
  var options,
915
- _response,
979
+ response,
916
980
  imageBaseUrl,
917
981
  qrImageUrl,
918
- _waitForSocketId2,
919
982
  _args4 = arguments,
920
- _t4;
983
+ _t5;
921
984
  return _regenerator().w(function (_context4) {
922
985
  while (1) switch (_context4.p = _context4.n) {
923
986
  case 0:
@@ -943,52 +1006,35 @@ function _unsupportedIterableToArray(r, a) {
943
1006
  type: type
944
1007
  }, options));
945
1008
  case 4:
946
- _response = _context4.v;
947
- if (!_response.success) {
1009
+ response = _context4.v;
1010
+ if (!response.success) {
948
1011
  _context4.n = 5;
949
1012
  break;
950
1013
  }
951
1014
  // Construire l'URL complète de l'image QR avec la base URL pour les images
952
1015
  imageBaseUrl = 'https://sunuid.fayma.sn';
953
- qrImageUrl = "".concat(imageBaseUrl).concat(_response.data.qrcode);
1016
+ qrImageUrl = "".concat(imageBaseUrl).concat(response.data.qrcode);
954
1017
  this.displayQRCode(containerId, qrImageUrl, type, options);
955
1018
 
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
- }
1019
+ // Le QR code est déjà généré par l'API principale
1020
+ console.log('✅ QR code personnalisé généré par API principale:', qrImageUrl);
1021
+ console.log('📄 Code de session:', response.data.code);
1022
+ console.log('🆔 Service ID:', response.data.service_id);
977
1023
  this.startAutoRefresh(containerId, type, options);
978
- return _context4.a(2, _objectSpread2(_objectSpread2({}, _response.data), {}, {
1024
+ return _context4.a(2, _objectSpread2(_objectSpread2({}, response.data), {}, {
979
1025
  qrCodeUrl: qrImageUrl,
980
- sessionId: _response.data.service_id
1026
+ sessionId: response.data.service_id
981
1027
  }));
982
1028
  case 5:
983
- throw new Error(_response.message || 'Erreur lors de la génération du QR code');
1029
+ throw new Error(response.message || 'Erreur lors de la génération du QR code');
984
1030
  case 6:
985
1031
  _context4.n = 8;
986
1032
  break;
987
1033
  case 7:
988
1034
  _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);
1035
+ _t5 = _context4.v;
1036
+ console.error('Erreur API détectée:', _t5.message);
1037
+ console.error('Stack trace complet:', _t5.stack);
992
1038
  console.error('Configuration SDK (Custom):', {
993
1039
  apiUrl: this.config.apiUrl,
994
1040
  type: type,
@@ -1004,7 +1050,7 @@ function _unsupportedIterableToArray(r, a) {
1004
1050
  }
1005
1051
  }, _callee4, this, [[3, 7]]);
1006
1052
  }));
1007
- function generateCustomQR(_x2, _x3) {
1053
+ function generateCustomQR(_x, _x2) {
1008
1054
  return _generateCustomQR.apply(this, arguments);
1009
1055
  }
1010
1056
  return generateCustomQR;
@@ -1024,7 +1070,7 @@ function _unsupportedIterableToArray(r, a) {
1024
1070
  }
1025
1071
  }, _callee5, this);
1026
1072
  }));
1027
- function generateAuthQR(_x4) {
1073
+ function generateAuthQR(_x3) {
1028
1074
  return _generateAuthQR.apply(this, arguments);
1029
1075
  }
1030
1076
  return generateAuthQR;
@@ -1058,7 +1104,7 @@ function _unsupportedIterableToArray(r, a) {
1058
1104
  }
1059
1105
  }, _callee6, this, [[1,, 3, 4]]);
1060
1106
  }));
1061
- function generateKYCQR(_x5) {
1107
+ function generateKYCQR(_x4) {
1062
1108
  return _generateKYCQR.apply(this, arguments);
1063
1109
  }
1064
1110
  return generateKYCQR;
@@ -1092,7 +1138,7 @@ function _unsupportedIterableToArray(r, a) {
1092
1138
  }
1093
1139
  }, _callee7, this, [[1,, 3, 4]]);
1094
1140
  }));
1095
- function generateSignatureQR(_x6) {
1141
+ function generateSignatureQR(_x5) {
1096
1142
  return _generateSignatureQR.apply(this, arguments);
1097
1143
  }
1098
1144
  return generateSignatureQR;
@@ -1104,7 +1150,7 @@ function _unsupportedIterableToArray(r, a) {
1104
1150
  key: "checkQRStatus",
1105
1151
  value: (function () {
1106
1152
  var _checkQRStatus = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(sessionId) {
1107
- var _response2, _t5;
1153
+ var response, _t6;
1108
1154
  return _regenerator().w(function (_context8) {
1109
1155
  while (1) switch (_context8.p = _context8.n) {
1110
1156
  case 0:
@@ -1120,36 +1166,225 @@ function _unsupportedIterableToArray(r, a) {
1120
1166
  serviceId: sessionId
1121
1167
  });
1122
1168
  case 2:
1123
- _response2 = _context8.v;
1124
- if (!_response2.success) {
1169
+ response = _context8.v;
1170
+ if (!response.success) {
1125
1171
  _context8.n = 3;
1126
1172
  break;
1127
1173
  }
1128
- return _context8.a(2, _response2.data);
1174
+ return _context8.a(2, response.data);
1129
1175
  case 3:
1130
- throw new Error(_response2.message || 'Erreur lors de la vérification du statut');
1176
+ throw new Error(response.message || 'Erreur lors de la vérification du statut');
1131
1177
  case 4:
1132
1178
  _context8.n = 6;
1133
1179
  break;
1134
1180
  case 5:
1135
1181
  _context8.p = 5;
1136
- _t5 = _context8.v;
1137
- this.handleError(_t5);
1138
- throw _t5;
1182
+ _t6 = _context8.v;
1183
+ this.handleError(_t6);
1184
+ throw _t6;
1139
1185
  case 6:
1140
1186
  return _context8.a(2);
1141
1187
  }
1142
1188
  }, _callee8, this, [[1, 5]]);
1143
1189
  }));
1144
- function checkQRStatus(_x7) {
1190
+ function checkQRStatus(_x6) {
1145
1191
  return _checkQRStatus.apply(this, arguments);
1146
1192
  }
1147
1193
  return checkQRStatus;
1148
1194
  }()
1149
1195
  /**
1150
- * Afficher un QR code dans un conteneur
1196
+ * Générer un QR code avec un contenu spécifique
1197
+ */
1198
+ )
1199
+ }, {
1200
+ key: "generateQRWithContent",
1201
+ value: (function () {
1202
+ var _generateQRWithContent = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(content, containerId, type) {
1203
+ var options,
1204
+ localQRUrl,
1205
+ _args9 = arguments,
1206
+ _t7;
1207
+ return _regenerator().w(function (_context9) {
1208
+ while (1) switch (_context9.p = _context9.n) {
1209
+ case 0:
1210
+ options = _args9.length > 3 && _args9[3] !== undefined ? _args9[3] : {};
1211
+ console.log('🎨 Génération QR avec contenu:', content);
1212
+ _context9.p = 1;
1213
+ if (!(window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1' || window.location.protocol === 'file:')) {
1214
+ _context9.n = 3;
1215
+ break;
1216
+ }
1217
+ console.log('🏠 Utilisation service QR local...');
1218
+ _context9.n = 2;
1219
+ return this.generateQRLocal(content, containerId, type, options);
1220
+ case 2:
1221
+ localQRUrl = _context9.v;
1222
+ if (!localQRUrl) {
1223
+ _context9.n = 3;
1224
+ break;
1225
+ }
1226
+ return _context9.a(2, localQRUrl);
1227
+ case 3:
1228
+ // Fallback vers le service QR distant
1229
+ console.log('🌐 Utilisation service QR distant...');
1230
+ _context9.n = 4;
1231
+ return this.generateQRRemote(content, containerId, type, options);
1232
+ case 4:
1233
+ return _context9.a(2, _context9.v);
1234
+ case 5:
1235
+ _context9.p = 5;
1236
+ _t7 = _context9.v;
1237
+ console.error('❌ Erreur génération QR:', _t7);
1238
+ // Fallback vers affichage simple du contenu
1239
+ this.displayQRContent(containerId, content, type, options);
1240
+ return _context9.a(2, null);
1241
+ }
1242
+ }, _callee9, this, [[1, 5]]);
1243
+ }));
1244
+ function generateQRWithContent(_x7, _x8, _x9) {
1245
+ return _generateQRWithContent.apply(this, arguments);
1246
+ }
1247
+ return generateQRWithContent;
1248
+ }()
1249
+ /**
1250
+ * Générer QR code avec service local
1151
1251
  */
1152
1252
  )
1253
+ }, {
1254
+ key: "generateQRLocal",
1255
+ value: (function () {
1256
+ var _generateQRLocal = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0(content, containerId, type) {
1257
+ var options,
1258
+ response,
1259
+ data,
1260
+ qrUrl,
1261
+ _args0 = arguments,
1262
+ _t8;
1263
+ return _regenerator().w(function (_context0) {
1264
+ while (1) switch (_context0.p = _context0.n) {
1265
+ case 0:
1266
+ options = _args0.length > 3 && _args0[3] !== undefined ? _args0[3] : {};
1267
+ _context0.p = 1;
1268
+ _context0.n = 2;
1269
+ return fetch('http://localhost:8000/api/generate/text', {
1270
+ method: 'POST',
1271
+ headers: {
1272
+ 'Content-Type': 'application/x-www-form-urlencoded'
1273
+ },
1274
+ body: "text=".concat(encodeURIComponent(content), "&size=300")
1275
+ });
1276
+ case 2:
1277
+ response = _context0.v;
1278
+ if (!response.ok) {
1279
+ _context0.n = 4;
1280
+ break;
1281
+ }
1282
+ _context0.n = 3;
1283
+ return response.json();
1284
+ case 3:
1285
+ data = _context0.v;
1286
+ qrUrl = "data:image/png;base64,".concat(data.qrcode);
1287
+ this.displayQRCode(containerId, qrUrl, type, options);
1288
+ return _context0.a(2, qrUrl);
1289
+ case 4:
1290
+ _context0.n = 6;
1291
+ break;
1292
+ case 5:
1293
+ _context0.p = 5;
1294
+ _t8 = _context0.v;
1295
+ console.log('❌ Service QR local non disponible:', _t8.message);
1296
+ case 6:
1297
+ return _context0.a(2, null);
1298
+ }
1299
+ }, _callee0, this, [[1, 5]]);
1300
+ }));
1301
+ function generateQRLocal(_x0, _x1, _x10) {
1302
+ return _generateQRLocal.apply(this, arguments);
1303
+ }
1304
+ return generateQRLocal;
1305
+ }()
1306
+ /**
1307
+ * Générer QR code avec service distant
1308
+ */
1309
+ )
1310
+ }, {
1311
+ key: "generateQRRemote",
1312
+ value: (function () {
1313
+ var _generateQRRemote = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(content, containerId, type) {
1314
+ var options,
1315
+ response,
1316
+ data,
1317
+ qrUrl,
1318
+ _args1 = arguments,
1319
+ _t9;
1320
+ return _regenerator().w(function (_context1) {
1321
+ while (1) switch (_context1.p = _context1.n) {
1322
+ case 0:
1323
+ options = _args1.length > 3 && _args1[3] !== undefined ? _args1[3] : {};
1324
+ _context1.p = 1;
1325
+ _context1.n = 2;
1326
+ return fetch('https://api.sunuid.fayma.sn/qr-generate', {
1327
+ method: 'POST',
1328
+ headers: {
1329
+ 'Content-Type': 'application/json'
1330
+ },
1331
+ body: JSON.stringify({
1332
+ text: content,
1333
+ size: 300,
1334
+ type: type
1335
+ })
1336
+ });
1337
+ case 2:
1338
+ response = _context1.v;
1339
+ if (!response.ok) {
1340
+ _context1.n = 4;
1341
+ break;
1342
+ }
1343
+ _context1.n = 3;
1344
+ return response.json();
1345
+ case 3:
1346
+ data = _context1.v;
1347
+ qrUrl = "data:image/png;base64,".concat(data.qrcode);
1348
+ this.displayQRCode(containerId, qrUrl, type, options);
1349
+ return _context1.a(2, qrUrl);
1350
+ case 4:
1351
+ _context1.n = 6;
1352
+ break;
1353
+ case 5:
1354
+ _context1.p = 5;
1355
+ _t9 = _context1.v;
1356
+ console.error('❌ Erreur service QR distant:', _t9);
1357
+ case 6:
1358
+ // Fallback vers affichage du contenu
1359
+ this.displayQRContent(containerId, content, type, options);
1360
+ return _context1.a(2, null);
1361
+ }
1362
+ }, _callee1, this, [[1, 5]]);
1363
+ }));
1364
+ function generateQRRemote(_x11, _x12, _x13) {
1365
+ return _generateQRRemote.apply(this, arguments);
1366
+ }
1367
+ return generateQRRemote;
1368
+ }()
1369
+ /**
1370
+ * Afficher le contenu QR en texte (fallback)
1371
+ */
1372
+ )
1373
+ }, {
1374
+ key: "displayQRContent",
1375
+ value: function displayQRContent(containerId, content, type) {
1376
+ var container = document.getElementById(containerId);
1377
+ if (!container) {
1378
+ throw new Error("Conteneur avec l'ID \"".concat(containerId, "\" non trouv\xE9"));
1379
+ }
1380
+ var typeName = this.getTypeName(type);
1381
+ 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 ");
1382
+ console.log('✅ Contenu QR affiché:', content);
1383
+ }
1384
+
1385
+ /**
1386
+ * Afficher un QR code dans un conteneur
1387
+ */
1153
1388
  }, {
1154
1389
  key: "displayQRCode",
1155
1390
  value: function displayQRCode(containerId, qrUrl, type) {
@@ -1166,20 +1401,14 @@ function _unsupportedIterableToArray(r, a) {
1166
1401
  var qrElement = document.createElement('div');
1167
1402
  qrElement.className = 'sunuid-qr-code';
1168
1403
 
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 ");
1404
+ // Afficher l'image QR avec les informations
1405
+ var typeName = this.getTypeName(type);
1406
+ 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
1407
  container.appendChild(qrElement);
1173
1408
 
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
1409
  // Appliquer le thème
1182
1410
  this.applyTheme(options.theme || this.config.theme);
1411
+ console.log('✅ QR code affiché:', qrUrl);
1183
1412
  }
1184
1413
 
1185
1414
  /**
@@ -1188,195 +1417,306 @@ function _unsupportedIterableToArray(r, a) {
1188
1417
  }, {
1189
1418
  key: "generateCustomQRCode",
1190
1419
  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) {
1420
+ var _generateCustomQRCode = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10(content, label) {
1421
+ var qrContainer,
1422
+ _t0;
1423
+ return _regenerator().w(function (_context10) {
1424
+ while (1) switch (_context10.p = _context10.n) {
1201
1425
  case 0:
1202
- _context9.p = 1;
1203
- console.log('🎨 Début génération QR personnalisé avec PHP...');
1426
+ console.log('🎨 Début génération QR personnalisé...');
1204
1427
  console.log('📄 Contenu:', content);
1205
1428
  console.log('🏷️ Label:', label);
1206
- _qrContainer = document.getElementById('sunuid-qr-container');
1207
- if (_qrContainer) {
1208
- _context9.n = 2;
1429
+
1430
+ // Chercher le conteneur QR
1431
+ qrContainer = document.getElementById('sunuid-qr-container');
1432
+ if (!qrContainer) {
1433
+ qrContainer = document.getElementById('qr-container');
1434
+ }
1435
+ if (qrContainer) {
1436
+ _context10.n = 1;
1209
1437
  break;
1210
1438
  }
1211
1439
  console.error('❌ QR container not found');
1212
- this.displayFallbackImage();
1213
- return _context9.a(2);
1214
- case 2:
1440
+ return _context10.a(2);
1441
+ case 1:
1215
1442
  console.log('✅ QR container trouvé');
1216
1443
 
1217
1444
  // Nettoyer le conteneur
1218
- _qrContainer.innerHTML = '<div style="text-align: center; padding: 20px;"><p>Génération QR code avec PHP...</p></div>';
1445
+ qrContainer.innerHTML = '<div style="text-align: center; padding: 20px;"><p>Génération QR code...</p></div>';
1446
+ _context10.p = 2;
1447
+ // Utiliser directement l'API principale (plus fiable)
1448
+ console.log('🎨 Tentative génération via API principale...');
1449
+ _context10.n = 3;
1450
+ return this.generateQRPHP(content, label, qrContainer);
1451
+ case 3:
1452
+ console.log('✅ QR code généré avec succès');
1453
+ _context10.n = 5;
1454
+ break;
1455
+ case 4:
1456
+ _context10.p = 4;
1457
+ _t0 = _context10.v;
1458
+ console.error('❌ Erreur génération API:', _t0);
1459
+
1460
+ // Fallback final : image par défaut
1461
+ console.log('⚠️ Affichage image par défaut');
1462
+ this.displayDefaultQR(qrContainer, content, label);
1463
+ case 5:
1464
+ return _context10.a(2);
1465
+ }
1466
+ }, _callee10, this, [[2, 4]]);
1467
+ }));
1468
+ function generateCustomQRCode(_x14, _x15) {
1469
+ return _generateCustomQRCode.apply(this, arguments);
1470
+ }
1471
+ return generateCustomQRCode;
1472
+ }()
1473
+ /**
1474
+ * Générer un QR code côté client (méthode principale)
1475
+ */
1476
+ )
1477
+ }, {
1478
+ key: "generateQRClientSide",
1479
+ value: (function () {
1480
+ var _generateQRClientSide = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee11(content, label, qrContainer) {
1481
+ var _this2 = this;
1482
+ var canvas, ctx;
1483
+ return _regenerator().w(function (_context11) {
1484
+ while (1) switch (_context11.n) {
1485
+ case 0:
1486
+ _context11.n = 1;
1487
+ return this.ensureQRCodeLibrary();
1488
+ case 1:
1489
+ if (!(typeof QRCode === 'undefined')) {
1490
+ _context11.n = 2;
1491
+ break;
1492
+ }
1493
+ throw new Error('QRCode library non disponible');
1494
+ case 2:
1495
+ // Créer un canvas
1496
+ canvas = document.createElement('canvas');
1497
+ canvas.width = 300;
1498
+ canvas.height = 320;
1499
+ ctx = canvas.getContext('2d'); // Fond blanc
1500
+ ctx.fillStyle = '#FFFFFF';
1501
+ ctx.fillRect(0, 0, 300, 320);
1502
+
1503
+ // Générer le QR code
1504
+ return _context11.a(2, new Promise(function (resolve, reject) {
1505
+ QRCode.toCanvas(canvas, content, {
1506
+ width: 280,
1507
+ margin: 10,
1508
+ color: {
1509
+ dark: '#000000',
1510
+ light: '#FFFFFF'
1511
+ }
1512
+ }, function (error) {
1513
+ if (error) {
1514
+ reject(error);
1515
+ return;
1516
+ }
1517
+
1518
+ // Ajouter le label
1519
+ ctx.fillStyle = '#333333';
1520
+ ctx.font = 'bold 14px Arial';
1521
+ ctx.textAlign = 'center';
1522
+ ctx.fillText(label, 150, 305);
1523
+
1524
+ // Convertir en data URL
1525
+ var dataUrl = canvas.toDataURL('image/png');
1526
+
1527
+ // Stocker l'URL
1528
+ _this2.currentQRUrl = dataUrl;
1219
1529
 
1220
- // Appeler l'endpoint PHP
1221
- console.log('🔄 Appel endpoint PHP...');
1222
- // Construire l'URL du QR generator de manière plus robuste
1530
+ // Afficher le QR code
1531
+ 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 ");
1223
1532
 
1224
- if (this.config.apiUrl.includes('api.sunuid.fayma.sn')) {
1225
- qrGeneratorUrl = 'https://api.sunuid.fayma.sn/qr-generator.php';
1533
+ // Afficher les instructions
1534
+ _this2.showQRInstructions(qrContainer);
1535
+ resolve();
1536
+ });
1537
+ }));
1538
+ }
1539
+ }, _callee11, this);
1540
+ }));
1541
+ function generateQRClientSide(_x16, _x17, _x18) {
1542
+ return _generateQRClientSide.apply(this, arguments);
1543
+ }
1544
+ return generateQRClientSide;
1545
+ }()
1546
+ /**
1547
+ * Générer un QR code via endpoint PHP (fallback)
1548
+ */
1549
+ )
1550
+ }, {
1551
+ key: "generateQRPHP",
1552
+ value: (function () {
1553
+ var _generateQRPHP = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee12(content, label, qrContainer) {
1554
+ var qrGeneratorUrl, requestBody, contentType, response, responseData, qrImageUrl, imageBaseUrl;
1555
+ return _regenerator().w(function (_context12) {
1556
+ while (1) switch (_context12.n) {
1557
+ case 0:
1558
+ // Construire l'URL - Utiliser l'API principale qui fonctionne
1559
+
1560
+ if (this.config.forceRemoteServer) {
1561
+ qrGeneratorUrl = 'https://api.sunuid.fayma.sn/qr-generate';
1562
+ } else if (this.config.apiUrl.includes('api.sunuid.fayma.sn')) {
1563
+ qrGeneratorUrl = 'https://api.sunuid.fayma.sn/qr-generate';
1564
+ } else if (this.config.apiUrl.includes('localhost') || this.config.apiUrl.includes('127.0.0.1')) {
1565
+ qrGeneratorUrl = 'http://localhost:8000/api/generate/text';
1226
1566
  } else {
1227
- qrGeneratorUrl = this.config.apiUrl.replace('/api', '') + '/qr-generator.php';
1567
+ qrGeneratorUrl = this.config.apiUrl + '/qr-generate';
1228
1568
  }
1229
1569
  console.log('🔗 URL QR Generator:', qrGeneratorUrl);
1230
- _context9.n = 3;
1570
+
1571
+ // Adapter le format selon l'URL
1572
+
1573
+ if (qrGeneratorUrl.includes('localhost:8000')) {
1574
+ // Service local - format form-data
1575
+ contentType = 'application/x-www-form-urlencoded';
1576
+ requestBody = new URLSearchParams({
1577
+ text: content,
1578
+ size: 300,
1579
+ margin: 10,
1580
+ foreground_color: '000000',
1581
+ background_color: 'FFFFFF'
1582
+ });
1583
+ } else {
1584
+ // Service distant - format JSON avec les paramètres de l'API principale
1585
+ contentType = 'application/json';
1586
+ requestBody = JSON.stringify({
1587
+ type: this.config.type,
1588
+ client_id: this.config.clientId,
1589
+ secret_id: this.config.secretId,
1590
+ content: content,
1591
+ label: label
1592
+ });
1593
+ }
1594
+ _context12.n = 1;
1231
1595
  return fetch(qrGeneratorUrl, {
1232
1596
  method: 'POST',
1233
1597
  headers: {
1234
- 'Content-Type': 'application/json',
1598
+ 'Content-Type': contentType,
1235
1599
  'Accept': 'application/json'
1236
1600
  },
1237
- body: JSON.stringify({
1238
- content: content,
1239
- label: label,
1240
- size: 300,
1241
- margin: 10
1242
- })
1601
+ body: requestBody
1243
1602
  });
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;
1603
+ case 1:
1604
+ response = _context12.v;
1605
+ if (response.ok) {
1606
+ _context12.n = 2;
1249
1607
  break;
1250
1608
  }
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;
1609
+ throw new Error("Erreur HTTP: ".concat(response.status));
1610
+ case 2:
1611
+ _context12.n = 3;
1612
+ return response.json();
1613
+ case 3:
1614
+ responseData = _context12.v;
1257
1615
  if (responseData.success) {
1258
- _context9.n = 6;
1616
+ _context12.n = 4;
1259
1617
  break;
1260
1618
  }
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 spécifiquement
1294
- if (_t6.message.includes('Failed to fetch') || _t6.message.includes('CORS')) {
1295
- console.warn('🚫 Erreur CORS détectée, tentative de génération QR côté client...');
1296
- this.generateQRCodeClientSide(content, label, qrContainer);
1619
+ throw new Error("Erreur QR: ".concat(responseData.error));
1620
+ case 4:
1621
+ if (qrGeneratorUrl.includes('localhost:8000')) {
1622
+ // Service local
1623
+ qrImageUrl = responseData.data_uri;
1297
1624
  } else {
1298
- this.displayFallbackImage();
1625
+ // Service distant - utiliser le format de l'API principale
1626
+ imageBaseUrl = 'https://sunuid.fayma.sn';
1627
+ qrImageUrl = "".concat(imageBaseUrl).concat(responseData.data.qrcode);
1299
1628
  }
1300
- case 8:
1301
- return _context9.a(2);
1629
+
1630
+ // Stocker l'URL
1631
+ this.currentQRUrl = qrImageUrl;
1632
+
1633
+ // Afficher le QR code
1634
+ 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 ");
1635
+
1636
+ // Afficher les instructions
1637
+ this.showQRInstructions(qrContainer);
1638
+ case 5:
1639
+ return _context12.a(2);
1302
1640
  }
1303
- }, _callee9, this, [[1, 7]]);
1641
+ }, _callee12, this);
1304
1642
  }));
1305
- function generateCustomQRCode(_x8, _x9) {
1306
- return _generateCustomQRCode.apply(this, arguments);
1643
+ function generateQRPHP(_x19, _x20, _x21) {
1644
+ return _generateQRPHP.apply(this, arguments);
1307
1645
  }
1308
- return generateCustomQRCode;
1646
+ return generateQRPHP;
1309
1647
  }()
1310
1648
  /**
1311
- * Générer un QR code côté client en cas d'erreur CORS
1649
+ * Afficher une image QR par défaut (fallback final)
1312
1650
  */
1313
1651
  )
1314
1652
  }, {
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 = 300;
1332
- var ctx = canvas.getContext('2d');
1333
-
1334
- // Générer le QR code avec QRCode library
1335
- QRCode.toCanvas(canvas, content, {
1336
- width: 280,
1337
- margin: 10,
1338
- color: {
1339
- dark: '#000000',
1340
- light: '#FFFFFF'
1341
- }
1342
- }, function (error) {
1343
- if (error) {
1344
- console.error('❌ Erreur génération QR côté client:', error);
1345
- _this4.displayFallbackImage();
1346
- return;
1347
- }
1348
-
1349
- // Ajouter le label en bas du QR code
1350
- ctx.fillStyle = '#333333';
1351
- ctx.font = '14px Arial';
1352
- ctx.textAlign = 'center';
1353
- ctx.fillText(label, 150, 295);
1354
-
1355
- // Convertir en data URL
1356
- var dataUrl = canvas.toDataURL('image/png');
1357
-
1358
- // Stocker l'URL du QR code pour getQRCode()
1359
- _this4.currentQRUrl = dataUrl;
1360
-
1361
- // Afficher le QR code
1362
- 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 <p style=\"margin-top: 10px; font-size: 12px; color: #666;\">G\xE9n\xE9r\xE9 c\xF4t\xE9 client (CORS)</p>\n </div>\n ");
1653
+ key: "displayDefaultQR",
1654
+ value: function displayDefaultQR(qrContainer, content, label) {
1655
+ 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 ");
1656
+ }
1363
1657
 
1364
- // Afficher les instructions et le statut
1365
- var instructionsElement = qrContainer.parentElement.querySelector('.sunuid-qr-instructions');
1366
- var statusElement = qrContainer.parentElement.querySelector('.sunuid-qr-status');
1367
- if (instructionsElement) {
1368
- instructionsElement.style.display = 'block';
1369
- instructionsElement.classList.add('sunuid-qr-ready');
1370
- }
1371
- if (statusElement) {
1372
- statusElement.style.display = 'block';
1373
- statusElement.classList.add('sunuid-qr-ready');
1658
+ /**
1659
+ * S'assurer que la bibliothèque QRCode est disponible
1660
+ */
1661
+ }, {
1662
+ key: "ensureQRCodeLibrary",
1663
+ value: (function () {
1664
+ var _ensureQRCodeLibrary = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee13() {
1665
+ return _regenerator().w(function (_context13) {
1666
+ while (1) switch (_context13.n) {
1667
+ case 0:
1668
+ if (!(typeof QRCode !== 'undefined')) {
1669
+ _context13.n = 1;
1670
+ break;
1671
+ }
1672
+ console.log('✅ QRCode library déjà disponible');
1673
+ return _context13.a(2, true);
1674
+ case 1:
1675
+ console.log('📦 Chargement QRCode library...');
1676
+ return _context13.a(2, new Promise(function (resolve, reject) {
1677
+ var script = document.createElement('script');
1678
+ script.src = 'https://cdn.jsdelivr.net/npm/qrcode@1.5.3/lib/browser.min.js';
1679
+ script.onload = function () {
1680
+ setTimeout(function () {
1681
+ if (typeof QRCode !== 'undefined') {
1682
+ console.log('✅ QRCode library chargée');
1683
+ resolve(true);
1684
+ } else {
1685
+ console.error('❌ QRCode non disponible après chargement');
1686
+ reject(new Error('QRCode library non disponible après chargement'));
1687
+ }
1688
+ }, 200);
1689
+ };
1690
+ script.onerror = function () {
1691
+ console.error('❌ Erreur chargement QRCode library');
1692
+ reject(new Error('Erreur chargement QRCode library'));
1693
+ };
1694
+ document.head.appendChild(script);
1695
+ }));
1374
1696
  }
1375
- console.log('✅ QR code côté client généré avec succès');
1376
- });
1377
- } catch (error) {
1378
- console.error('❌ Erreur génération QR côté client:', error);
1379
- this.displayFallbackImage();
1697
+ }, _callee13);
1698
+ }));
1699
+ function ensureQRCodeLibrary() {
1700
+ return _ensureQRCodeLibrary.apply(this, arguments);
1701
+ }
1702
+ return ensureQRCodeLibrary;
1703
+ }()
1704
+ /**
1705
+ * Afficher les instructions pour le QR code
1706
+ */
1707
+ )
1708
+ }, {
1709
+ key: "showQRInstructions",
1710
+ value: function showQRInstructions(qrContainer) {
1711
+ var instructionsElement = qrContainer.parentElement.querySelector('.sunuid-qr-instructions');
1712
+ var statusElement = qrContainer.parentElement.querySelector('.sunuid-qr-status');
1713
+ if (instructionsElement) {
1714
+ instructionsElement.style.display = 'block';
1715
+ instructionsElement.classList.add('sunuid-qr-ready');
1716
+ }
1717
+ if (statusElement) {
1718
+ statusElement.style.display = 'block';
1719
+ statusElement.classList.add('sunuid-qr-ready');
1380
1720
  }
1381
1721
  }
1382
1722
 
@@ -1417,8 +1757,6 @@ function _unsupportedIterableToArray(r, a) {
1417
1757
  var qrContainer = document.getElementById('sunuid-qr-container');
1418
1758
  if (qrContainer) {
1419
1759
  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 ");
1420
- } else {
1421
- console.error('❌ Container QR non trouvé pour fallback');
1422
1760
  }
1423
1761
  }
1424
1762
 
@@ -1443,33 +1781,55 @@ function _unsupportedIterableToArray(r, a) {
1443
1781
  }, {
1444
1782
  key: "refreshQR",
1445
1783
  value: (function () {
1446
- var _refreshQR = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0(containerId) {
1784
+ var _refreshQR = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee14(containerId) {
1447
1785
  var options,
1448
1786
  result,
1449
- _args0 = arguments,
1450
- _t7;
1451
- return _regenerator().w(function (_context0) {
1452
- while (1) switch (_context0.p = _context0.n) {
1787
+ _result,
1788
+ _args14 = arguments,
1789
+ _t1;
1790
+ return _regenerator().w(function (_context14) {
1791
+ while (1) switch (_context14.p = _context14.n) {
1453
1792
  case 0:
1454
- options = _args0.length > 1 && _args0[1] !== undefined ? _args0[1] : {};
1455
- _context0.p = 1;
1456
- _context0.n = 2;
1793
+ options = _args14.length > 1 && _args14[1] !== undefined ? _args14[1] : {};
1794
+ _context14.p = 1;
1795
+ if (!this.currentQRUrl) {
1796
+ _context14.n = 3;
1797
+ break;
1798
+ }
1799
+ console.log('🔄 Vérification du statut du QR code existant...');
1800
+
1801
+ // Option 1: Vérifier le statut du QR code via l'API
1802
+ // (à implémenter si l'API le supporte)
1803
+
1804
+ // Option 2: Régénérer le QR code seulement si nécessaire
1805
+ // Pour l'instant, on régénère pour s'assurer qu'il est à jour
1806
+ _context14.n = 2;
1457
1807
  return this.generateQR(containerId, options);
1458
1808
  case 2:
1459
- result = _context0.v;
1460
- return _context0.a(2, result);
1809
+ result = _context14.v;
1810
+ return _context14.a(2, result);
1461
1811
  case 3:
1462
- _context0.p = 3;
1463
- _t7 = _context0.v;
1464
- console.error('Erreur lors du rafraîchissement:', _t7.message);
1465
- this.displayServiceUnavailable(containerId, this.config.type);
1466
- throw _t7;
1812
+ console.log('🔄 Pas de QR code existant, génération d\'un nouveau...');
1813
+ _context14.n = 4;
1814
+ return this.generateQR(containerId, options);
1467
1815
  case 4:
1468
- return _context0.a(2);
1816
+ _result = _context14.v;
1817
+ return _context14.a(2, _result);
1818
+ case 5:
1819
+ _context14.n = 7;
1820
+ break;
1821
+ case 6:
1822
+ _context14.p = 6;
1823
+ _t1 = _context14.v;
1824
+ console.error('Erreur lors du rafraîchissement:', _t1.message);
1825
+ this.displayServiceUnavailable(containerId, this.config.type);
1826
+ throw _t1;
1827
+ case 7:
1828
+ return _context14.a(2);
1469
1829
  }
1470
- }, _callee0, this, [[1, 3]]);
1830
+ }, _callee14, this, [[1, 6]]);
1471
1831
  }));
1472
- function refreshQR(_x0) {
1832
+ function refreshQR(_x22) {
1473
1833
  return _refreshQR.apply(this, arguments);
1474
1834
  }
1475
1835
  return refreshQR;
@@ -1481,28 +1841,36 @@ function _unsupportedIterableToArray(r, a) {
1481
1841
  }, {
1482
1842
  key: "startAutoRefresh",
1483
1843
  value: function startAutoRefresh(containerId, type, options) {
1484
- var _this5 = this;
1844
+ var _this3 = this;
1485
1845
  if (!this.config.autoRefresh) return;
1486
- this.refreshTimer = setInterval(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1() {
1487
- var _t8;
1488
- return _regenerator().w(function (_context1) {
1489
- while (1) switch (_context1.p = _context1.n) {
1846
+
1847
+ // Arrêter le timer existant s'il y en a un
1848
+ if (this.refreshTimer) {
1849
+ clearInterval(this.refreshTimer);
1850
+ console.log('🔄 Timer de rafraîchissement précédent arrêté');
1851
+ }
1852
+ this.refreshTimer = setInterval(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee15() {
1853
+ var _t10;
1854
+ return _regenerator().w(function (_context15) {
1855
+ while (1) switch (_context15.p = _context15.n) {
1490
1856
  case 0:
1491
- _context1.p = 0;
1492
- _context1.n = 1;
1493
- return _this5.refreshQR(containerId, type, options);
1857
+ _context15.p = 0;
1858
+ console.log('🔄 Rafraîchissement automatique du QR code...');
1859
+ _context15.n = 1;
1860
+ return _this3.refreshQR(containerId, type, options);
1494
1861
  case 1:
1495
- _context1.n = 3;
1862
+ _context15.n = 3;
1496
1863
  break;
1497
1864
  case 2:
1498
- _context1.p = 2;
1499
- _t8 = _context1.v;
1500
- console.warn('Erreur lors du rafraîchissement automatique:', _t8);
1865
+ _context15.p = 2;
1866
+ _t10 = _context15.v;
1867
+ console.warn('Erreur lors du rafraîchissement automatique:', _t10);
1501
1868
  case 3:
1502
- return _context1.a(2);
1869
+ return _context15.a(2);
1503
1870
  }
1504
- }, _callee1, null, [[0, 2]]);
1871
+ }, _callee15, null, [[0, 2]]);
1505
1872
  })), this.config.refreshInterval);
1873
+ console.log("\uD83D\uDD04 Timer de rafra\xEEchissement d\xE9marr\xE9 (".concat(this.config.refreshInterval, "ms)"));
1506
1874
  }
1507
1875
 
1508
1876
  /**
@@ -1515,16 +1883,16 @@ function _unsupportedIterableToArray(r, a) {
1515
1883
  }, {
1516
1884
  key: "makeRequest",
1517
1885
  value: (function () {
1518
- var _makeRequest = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10(endpoint, data) {
1886
+ var _makeRequest = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee16(endpoint, data) {
1519
1887
  var _window$SunuIDConfig4,
1520
1888
  _window$SunuIDConfig5,
1521
- _this6 = this;
1889
+ _this4 = this;
1522
1890
  var sanitizedData, endpointPath, url, retryCount, maxRetries, _loop, _ret;
1523
- return _regenerator().w(function (_context11) {
1524
- while (1) switch (_context11.n) {
1891
+ return _regenerator().w(function (_context17) {
1892
+ while (1) switch (_context17.n) {
1525
1893
  case 0:
1526
1894
  if (this.isInitialized) {
1527
- _context11.n = 1;
1895
+ _context17.n = 1;
1528
1896
  break;
1529
1897
  }
1530
1898
  this.logSecurityEvent('REQUEST_BEFORE_INIT', {
@@ -1533,12 +1901,12 @@ function _unsupportedIterableToArray(r, a) {
1533
1901
  throw new Error('SDK non initialisé');
1534
1902
  case 1:
1535
1903
  if (!this.config.secureInit) {
1536
- _context11.n = 2;
1904
+ _context17.n = 2;
1537
1905
  break;
1538
1906
  }
1539
1907
  this.config.requestCount++;
1540
1908
  if (!(this.config.requestCount > this.config.maxRequests)) {
1541
- _context11.n = 2;
1909
+ _context17.n = 2;
1542
1910
  break;
1543
1911
  }
1544
1912
  this.logSecurityEvent('API_REQUEST_LIMIT_EXCEEDED', {
@@ -1573,15 +1941,15 @@ function _unsupportedIterableToArray(r, a) {
1573
1941
  retryCount = 0;
1574
1942
  maxRetries = this.config.maxRetries;
1575
1943
  _loop = /*#__PURE__*/_regenerator().m(function _loop() {
1576
- var controller, timeoutId, headers, _response4, errorText, errorData, result, _t9;
1577
- return _regenerator().w(function (_context10) {
1578
- while (1) switch (_context10.p = _context10.n) {
1944
+ var controller, timeoutId, headers, response, errorText, errorData, result, _t11;
1945
+ return _regenerator().w(function (_context16) {
1946
+ while (1) switch (_context16.p = _context16.n) {
1579
1947
  case 0:
1580
- _context10.p = 0;
1948
+ _context16.p = 0;
1581
1949
  controller = new AbortController();
1582
1950
  timeoutId = setTimeout(function () {
1583
1951
  return controller.abort();
1584
- }, _this6.config.requestTimeout); // Headers minimaux (API SunuID n'accepte que les headers essentiels)
1952
+ }, _this4.config.requestTimeout); // Headers minimaux (API SunuID n'accepte que les headers essentiels)
1585
1953
  headers = {
1586
1954
  'Content-Type': 'application/json'
1587
1955
  }; // Note: En mode sécurisé, les credentials sont dans le body
@@ -1589,7 +1957,7 @@ function _unsupportedIterableToArray(r, a) {
1589
1957
  // if (this.config.secureInit && this.config.token) {
1590
1958
  // headers['X-Secure-Token'] = this.config.token;
1591
1959
  // }
1592
- _context10.n = 1;
1960
+ _context16.n = 1;
1593
1961
  return fetch(url, {
1594
1962
  method: 'POST',
1595
1963
  headers: headers,
@@ -1597,16 +1965,16 @@ function _unsupportedIterableToArray(r, a) {
1597
1965
  signal: controller.signal
1598
1966
  });
1599
1967
  case 1:
1600
- _response4 = _context10.v;
1968
+ response = _context16.v;
1601
1969
  clearTimeout(timeoutId);
1602
- if (_response4.ok) {
1603
- _context10.n = 3;
1970
+ if (response.ok) {
1971
+ _context16.n = 3;
1604
1972
  break;
1605
1973
  }
1606
- _context10.n = 2;
1607
- return _response4.text();
1974
+ _context16.n = 2;
1975
+ return response.text();
1608
1976
  case 2:
1609
- errorText = _context10.v;
1977
+ errorText = _context16.v;
1610
1978
  try {
1611
1979
  errorData = JSON.parse(errorText);
1612
1980
  } catch (e) {
@@ -1614,90 +1982,90 @@ function _unsupportedIterableToArray(r, a) {
1614
1982
  message: errorText
1615
1983
  };
1616
1984
  }
1617
- _this6.logSecurityEvent('API_REQUEST_ERROR', {
1618
- status: _response4.status,
1619
- statusText: _response4.statusText,
1985
+ _this4.logSecurityEvent('API_REQUEST_ERROR', {
1986
+ status: response.status,
1987
+ statusText: response.statusText,
1620
1988
  error: errorData.message
1621
1989
  });
1622
- throw new Error(errorData.message || "Erreur HTTP: ".concat(_response4.status));
1990
+ throw new Error(errorData.message || "Erreur HTTP: ".concat(response.status));
1623
1991
  case 3:
1624
- _context10.n = 4;
1625
- return _response4.json();
1992
+ _context16.n = 4;
1993
+ return response.json();
1626
1994
  case 4:
1627
- result = _context10.v;
1628
- _this6.logSecurityEvent('API_REQUEST_SUCCESS', {
1995
+ result = _context16.v;
1996
+ _this4.logSecurityEvent('API_REQUEST_SUCCESS', {
1629
1997
  endpoint: endpointPath,
1630
1998
  responseKeys: Object.keys(result)
1631
1999
  });
1632
- return _context10.a(2, {
2000
+ return _context16.a(2, {
1633
2001
  v: result
1634
2002
  });
1635
2003
  case 5:
1636
- _context10.p = 5;
1637
- _t9 = _context10.v;
2004
+ _context16.p = 5;
2005
+ _t11 = _context16.v;
1638
2006
  retryCount++;
1639
- if (!(_t9.name === 'AbortError')) {
1640
- _context10.n = 7;
2007
+ if (!(_t11.name === 'AbortError')) {
2008
+ _context16.n = 7;
1641
2009
  break;
1642
2010
  }
1643
- _this6.logSecurityEvent('API_REQUEST_TIMEOUT', {
2011
+ _this4.logSecurityEvent('API_REQUEST_TIMEOUT', {
1644
2012
  retryCount: retryCount
1645
2013
  });
1646
2014
  if (!(retryCount > maxRetries)) {
1647
- _context10.n = 6;
2015
+ _context16.n = 6;
1648
2016
  break;
1649
2017
  }
1650
2018
  throw new Error('Timeout de la requête API');
1651
2019
  case 6:
1652
- return _context10.a(2, 0);
2020
+ return _context16.a(2, 0);
1653
2021
  case 7:
1654
2022
  if (!(retryCount > maxRetries)) {
1655
- _context10.n = 8;
2023
+ _context16.n = 8;
1656
2024
  break;
1657
2025
  }
1658
- _this6.logSecurityEvent('API_REQUEST_MAX_RETRIES', {
2026
+ _this4.logSecurityEvent('API_REQUEST_MAX_RETRIES', {
1659
2027
  retryCount: retryCount,
1660
- error: _t9.message
2028
+ error: _t11.message
1661
2029
  });
1662
- throw _t9;
2030
+ throw _t11;
1663
2031
  case 8:
1664
- _context10.n = 9;
2032
+ _context16.n = 9;
1665
2033
  return new Promise(function (resolve) {
1666
2034
  return setTimeout(resolve, 1000 * retryCount);
1667
2035
  });
1668
2036
  case 9:
1669
- return _context10.a(2);
2037
+ return _context16.a(2);
1670
2038
  }
1671
2039
  }, _loop, null, [[0, 5]]);
1672
2040
  });
1673
2041
  case 3:
1674
2042
  if (!(retryCount <= maxRetries)) {
1675
- _context11.n = 7;
2043
+ _context17.n = 7;
1676
2044
  break;
1677
2045
  }
1678
- return _context11.d(_regeneratorValues(_loop()), 4);
2046
+ return _context17.d(_regeneratorValues(_loop()), 4);
1679
2047
  case 4:
1680
- _ret = _context11.v;
2048
+ _ret = _context17.v;
1681
2049
  if (!(_ret === 0)) {
1682
- _context11.n = 5;
2050
+ _context17.n = 5;
1683
2051
  break;
1684
2052
  }
1685
- return _context11.a(3, 3);
2053
+ return _context17.a(3, 3);
1686
2054
  case 5:
1687
2055
  if (!_ret) {
1688
- _context11.n = 6;
2056
+ _context17.n = 6;
1689
2057
  break;
1690
2058
  }
1691
- return _context11.a(2, _ret.v);
2059
+ return _context17.a(2, _ret.v);
1692
2060
  case 6:
1693
- _context11.n = 3;
2061
+ _context17.n = 3;
1694
2062
  break;
1695
2063
  case 7:
1696
- return _context11.a(2);
2064
+ return _context17.a(2);
1697
2065
  }
1698
- }, _callee10, this);
2066
+ }, _callee16, this);
1699
2067
  }));
1700
- function makeRequest(_x1, _x10) {
2068
+ function makeRequest(_x23, _x24) {
1701
2069
  return _makeRequest.apply(this, arguments);
1702
2070
  }
1703
2071
  return makeRequest;
@@ -1753,9 +2121,88 @@ function _unsupportedIterableToArray(r, a) {
1753
2121
  return 'req_' + Date.now() + '_' + Math.random().toString(36).substr(2, 9);
1754
2122
  }
1755
2123
 
2124
+ /**
2125
+ * Générer un code de session unique
2126
+ */
2127
+ }, {
2128
+ key: "generateSessionCode",
2129
+ value: function generateSessionCode() {
2130
+ var timestamp = Date.now();
2131
+ var random = Math.random().toString(36).substr(2, 9);
2132
+ var code = "".concat(timestamp, "_").concat(random);
2133
+ return btoa(code); // Encoder en base64
2134
+ }
2135
+
2136
+ /**
2137
+ * Récupérer les informations du partenaire depuis l'API
2138
+ */
2139
+ }, {
2140
+ key: "fetchPartnerInfo",
2141
+ value: (function () {
2142
+ var _fetchPartnerInfo = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee17() {
2143
+ var response, authTest, _t12;
2144
+ return _regenerator().w(function (_context18) {
2145
+ while (1) switch (_context18.p = _context18.n) {
2146
+ case 0:
2147
+ _context18.p = 0;
2148
+ _context18.n = 1;
2149
+ return this.makeRequest('/debug', {
2150
+ type: this.config.type,
2151
+ client_id: this.config.clientId,
2152
+ secret_id: this.config.secretId
2153
+ });
2154
+ case 1:
2155
+ response = _context18.v;
2156
+ console.log('📋 Réponse debug API:', response);
2157
+ if (response.success && response.authentication && response.authentication.auth_test) {
2158
+ authTest = response.authentication.auth_test;
2159
+ this.config.partnerId = authTest.partner_id;
2160
+
2161
+ // Récupérer le service_id depuis la réponse
2162
+ if (response.service_id) {
2163
+ this.config.serviceId = response.service_id;
2164
+ } else {
2165
+ // Fallback: utiliser le partner_id comme service_id
2166
+ this.config.serviceId = authTest.partner_id;
2167
+ }
2168
+
2169
+ // Utiliser le partner_id pour déterminer le nom du partenaire
2170
+ // Pour l'instant, on utilise une logique simple basée sur l'ID
2171
+ if (authTest.partner_id === 21) {
2172
+ this.config.partnerName = 'Fayma';
2173
+ } else {
2174
+ this.config.partnerName = "Partner_".concat(authTest.partner_id);
2175
+ }
2176
+ console.log('✅ Informations partenaire récupérées:', {
2177
+ partnerName: this.config.partnerName,
2178
+ partnerId: this.config.partnerId,
2179
+ serviceId: this.config.serviceId
2180
+ });
2181
+ } else {
2182
+ console.warn('⚠️ Impossible de récupérer les informations du partenaire, utilisation du partner_id');
2183
+ this.config.partnerName = "Partner_".concat(this.config.partnerId || 'unknown');
2184
+ }
2185
+ _context18.n = 3;
2186
+ break;
2187
+ case 2:
2188
+ _context18.p = 2;
2189
+ _t12 = _context18.v;
2190
+ console.warn('⚠️ Erreur lors de la récupération des informations du partenaire:', _t12.message);
2191
+ this.config.partnerName = 'Partner_unknown';
2192
+ case 3:
2193
+ return _context18.a(2);
2194
+ }
2195
+ }, _callee17, this, [[0, 2]]);
2196
+ }));
2197
+ function fetchPartnerInfo() {
2198
+ return _fetchPartnerInfo.apply(this, arguments);
2199
+ }
2200
+ return fetchPartnerInfo;
2201
+ }()
1756
2202
  /**
1757
2203
  * Appliquer le thème
1758
2204
  */
2205
+ )
1759
2206
  }, {
1760
2207
  key: "applyTheme",
1761
2208
  value: function applyTheme(theme) {
@@ -1777,9 +2224,124 @@ function _unsupportedIterableToArray(r, a) {
1777
2224
  }
1778
2225
  }
1779
2226
 
2227
+ /**
2228
+ * Vérifier le statut des connexions
2229
+ */
2230
+ }, {
2231
+ key: "checkConnections",
2232
+ value: (function () {
2233
+ var _checkConnections = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee18() {
2234
+ var status, testResponse, debugData, _t13;
2235
+ return _regenerator().w(function (_context19) {
2236
+ while (1) switch (_context19.p = _context19.n) {
2237
+ case 0:
2238
+ status = {
2239
+ api: false,
2240
+ websocket: false,
2241
+ ready: false
2242
+ }; // Vérifier l'API en utilisant l'endpoint debug
2243
+ _context19.p = 1;
2244
+ _context19.n = 2;
2245
+ return fetch(this.config.apiUrl + '/debug', {
2246
+ method: 'GET',
2247
+ timeout: 3000
2248
+ });
2249
+ case 2:
2250
+ testResponse = _context19.v;
2251
+ if (!testResponse.ok) {
2252
+ _context19.n = 4;
2253
+ break;
2254
+ }
2255
+ _context19.n = 3;
2256
+ return testResponse.json();
2257
+ case 3:
2258
+ debugData = _context19.v;
2259
+ status.api = debugData.status === 'operational';
2260
+ console.log('🔍 API Status:', debugData.status);
2261
+ _context19.n = 5;
2262
+ break;
2263
+ case 4:
2264
+ status.api = false;
2265
+ case 5:
2266
+ _context19.n = 7;
2267
+ break;
2268
+ case 6:
2269
+ _context19.p = 6;
2270
+ _t13 = _context19.v;
2271
+ console.log('🔍 Test API échoué:', _t13.message);
2272
+ status.api = false;
2273
+ case 7:
2274
+ // Vérifier le WebSocket
2275
+ status.websocket = this.socket && this.socket.connected;
2276
+
2277
+ // Connexions prêtes si API est accessible
2278
+ status.ready = status.api;
2279
+ return _context19.a(2, status);
2280
+ }
2281
+ }, _callee18, this, [[1, 6]]);
2282
+ }));
2283
+ function checkConnections() {
2284
+ return _checkConnections.apply(this, arguments);
2285
+ }
2286
+ return checkConnections;
2287
+ }()
2288
+ /**
2289
+ * Attendre que les connexions soient prêtes
2290
+ */
2291
+ )
2292
+ }, {
2293
+ key: "waitForConnections",
2294
+ value: (function () {
2295
+ var _waitForConnections = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee19() {
2296
+ var timeout,
2297
+ startTime,
2298
+ status,
2299
+ _args20 = arguments;
2300
+ return _regenerator().w(function (_context20) {
2301
+ while (1) switch (_context20.n) {
2302
+ case 0:
2303
+ timeout = _args20.length > 0 && _args20[0] !== undefined ? _args20[0] : 5000;
2304
+ startTime = Date.now();
2305
+ case 1:
2306
+ if (!(Date.now() - startTime < timeout)) {
2307
+ _context20.n = 5;
2308
+ break;
2309
+ }
2310
+ _context20.n = 2;
2311
+ return this.checkConnections();
2312
+ case 2:
2313
+ status = _context20.v;
2314
+ if (!status.ready) {
2315
+ _context20.n = 3;
2316
+ break;
2317
+ }
2318
+ console.log('✅ Connexions prêtes');
2319
+ return _context20.a(2, status);
2320
+ case 3:
2321
+ console.log('⏳ Attente connexions...', status);
2322
+ _context20.n = 4;
2323
+ return new Promise(function (resolve) {
2324
+ return setTimeout(resolve, 1000);
2325
+ });
2326
+ case 4:
2327
+ _context20.n = 1;
2328
+ break;
2329
+ case 5:
2330
+ throw new Error('Timeout connexions - Impossible de générer le QR code');
2331
+ case 6:
2332
+ return _context20.a(2);
2333
+ }
2334
+ }, _callee19, this);
2335
+ }));
2336
+ function waitForConnections() {
2337
+ return _waitForConnections.apply(this, arguments);
2338
+ }
2339
+ return waitForConnections;
2340
+ }()
1780
2341
  /**
1781
2342
  * Obtenir l'URL du QR code généré
1782
2343
  */
2344
+ )
1783
2345
  }, {
1784
2346
  key: "getQRCode",
1785
2347
  value: function getQRCode() {
@@ -1798,9 +2360,7 @@ function _unsupportedIterableToArray(r, a) {
1798
2360
  }, {
1799
2361
  key: "destroy",
1800
2362
  value: function destroy() {
1801
- if (this.refreshTimer) {
1802
- clearInterval(this.refreshTimer);
1803
- }
2363
+ this.stopAutoRefresh();
1804
2364
 
1805
2365
  // Fermer la connexion WebSocket
1806
2366
  if (this.socket) {
@@ -1813,6 +2373,19 @@ function _unsupportedIterableToArray(r, a) {
1813
2373
  console.log('SunuID SDK détruit');
1814
2374
  }
1815
2375
 
2376
+ /**
2377
+ * Arrêter le rafraîchissement automatique
2378
+ */
2379
+ }, {
2380
+ key: "stopAutoRefresh",
2381
+ value: function stopAutoRefresh() {
2382
+ if (this.refreshTimer) {
2383
+ clearInterval(this.refreshTimer);
2384
+ this.refreshTimer = null;
2385
+ console.log('🔄 Timer de rafraîchissement arrêté');
2386
+ }
2387
+ }
2388
+
1816
2389
  /**
1817
2390
  * Obtenir les logs de sécurité
1818
2391
  */