sunuid-sdk 1.0.33 → 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.
- package/README.md +171 -499
- package/dist/sunuid-sdk.esm.js +936 -367
- package/dist/sunuid-sdk.esm.js.map +1 -1
- package/dist/sunuid-sdk.js +936 -367
- package/dist/sunuid-sdk.js.map +1 -1
- package/dist/sunuid-sdk.min.js +3 -3
- package/dist/sunuid-sdk.min.js.map +1 -1
- package/package.json +2 -2
package/dist/sunuid-sdk.min.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
!function(){"use strict";function e(e,
|
|
1
|
+
!function(){"use strict";function e(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=Array(n);t<n;t++)r[t]=e[t];return r}function n(e,n,t,r,i,o,s){try{var a=e[o](s),c=a.value}catch(e){return void t(e)}a.done?n(c):Promise.resolve(c).then(r,i)}function t(e){return function(){var t=this,r=arguments;return new Promise(function(i,o){var s=e.apply(t,r);function a(e){n(s,i,o,a,c,"next",e)}function c(e){n(s,i,o,a,c,"throw",e)}a(void 0)})}}function r(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,d(r.key),r)}}function i(e,n,t){return(n=d(n))in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function o(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter(function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable})),t.push.apply(t,r)}return t}function s(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?o(Object(t),!0).forEach(function(n){i(e,n,t[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):o(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))})}return e}function a(){
|
|
2
2
|
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
|
|
3
|
-
var e,t
|
|
3
|
+
var e,n,t="function"==typeof Symbol?Symbol:{},r=t.iterator||"@@iterator",i=t.toStringTag||"@@toStringTag";function o(t,r,i,o){var a=r&&r.prototype instanceof l?r:l,u=Object.create(a.prototype);return c(u,"_invoke",function(t,r,i){var o,a,c,l=0,u=i||[],d=!1,f={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(n,t){return o=n,a=0,c=e,f.n=t,s}};function p(t,r){for(a=t,c=r,n=0;!d&&l&&!i&&n<u.length;n++){var i,o=u[n],p=f.p,h=o[2];t>3?(i=h===r)&&(c=o[(a=o[4])?5:(a=3,3)],o[4]=o[5]=e):o[0]<=p&&((i=t<2&&p<o[1])?(a=0,f.v=r,f.n=o[1]):p<h&&(i=t<3||o[0]>r||r>h)&&(o[4]=t,o[5]=r,f.n=h,a=0))}if(i||t>1)return s;throw d=!0,r}return function(i,u,h){if(l>1)throw TypeError("Generator is already running");for(d&&1===u&&p(u,h),a=u,c=h;(n=a<2?e:c)||!d;){o||(a?a<3?(a>1&&(f.n=-1),p(a,c)):f.n=c:f.v=c);try{if(l=2,o){if(a||(i="next"),n=o[i]){if(!(n=n.call(o,c)))throw TypeError("iterator result is not an object");if(!n.done)return n;c=n.value,a<2&&(a=0)}else 1===a&&(n=o.return)&&n.call(o),a<2&&(c=TypeError("The iterator does not provide a '"+i+"' method"),a=1);o=e}else if((n=(d=f.n<0)?c:t.call(r,f))!==s)break}catch(n){o=e,a=1,c=n}finally{l=1}}return{value:n,done:d}}}(t,i,o),!0),u}var s={};function l(){}function u(){}function d(){}n=Object.getPrototypeOf;var f=[][r]?n(n([][r]())):(c(n={},r,function(){return this}),n),p=d.prototype=l.prototype=Object.create(f);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,d):(e.__proto__=d,c(e,i,"GeneratorFunction")),e.prototype=Object.create(p),e}return u.prototype=d,c(p,"constructor",d),c(d,"constructor",u),u.displayName="GeneratorFunction",c(d,i,"GeneratorFunction"),c(p),c(p,i,"Generator"),c(p,r,function(){return this}),c(p,"toString",function(){return"[object Generator]"}),(a=function(){return{w:o,m:h}})()}function c(e,n,t,r){var i=Object.defineProperty;try{i({},"",{})}catch(e){i=0}c=function(e,n,t,r){function o(n,t){c(e,n,function(e){return this._invoke(n,t,e)})}n?i?i(e,n,{value:t,enumerable:!r,configurable:!r,writable:!r}):e[n]=t:(o("next",0),o("throw",1),o("return",2))},c(e,n,t,r)}function l(e){if(null!=e){var n=e["function"==typeof Symbol&&Symbol.iterator||"@@iterator"],t=0;if(n)return n.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length))return{next:function(){return e&&t>=e.length&&(e=void 0),{value:e&&e[t++],done:!e}}}}throw new TypeError(typeof e+" is not iterable")}function u(n,t){return function(e){if(Array.isArray(e))return e}(n)||function(e,n){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var r,i,o,s,a=[],c=!0,l=!1;try{if(o=(t=t.call(e)).next,0===n){if(Object(t)!==t)return;c=!1}else for(;!(c=(r=o.call(t)).done)&&(a.push(r.value),a.length!==n);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&null!=t.return&&(s=t.return(),Object(s)!==s))return}finally{if(l)throw i}}return a}}(n,t)||function(n,t){if(n){if("string"==typeof n)return e(n,t);var r={}.toString.call(n).slice(8,-1);return"Object"===r&&n.constructor&&(r=n.constructor.name),"Map"===r||"Set"===r?Array.from(n):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?e(n,t):void 0}}
|
|
4
4
|
/**
|
|
5
5
|
* SunuID SDK - Package d'intégration pour partenaires
|
|
6
6
|
*
|
|
7
7
|
* @version 1.0.0
|
|
8
8
|
* @author SunuID Team
|
|
9
9
|
* @license MIT
|
|
10
|
-
*/(t,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function d(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var i=n.call(e,t||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}function f(e){return f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},f(e)}!function(e,t){var r,o,c={apiUrl:(null===(t=e.SunuIDConfig)||void 0===t?void 0:t.apiUrl)||"https://api.sunuid.fayma.sn",clientId:null,secretId:null,type:2,partnerName:"SunuID",theme:"light",language:"fr",autoRefresh:!0,refreshInterval:3e4,onSuccess:null,onError:null,onStatusUpdate:null,onExpired:null,enableSecurityLogs:!0,validateInputs:!0,maxRetries:3,requestTimeout:1e4,secureInit:!1,secureInitUrl:null!==(r=e.SunuIDConfig)&&void 0!==r&&null!==(r=r.apiUrl)&&void 0!==r&&r.includes("api.sunuid.fayma.sn")?"https://api.sunuid.fayma.sn/secure-init.php":(null===(o=e.SunuIDConfig)||void 0===o||null===(o=o.apiUrl)||void 0===o?void 0:o.replace("/api",""))+"/secure-init.php"||"https://api.sunuid.fayma.sn/secure-init.php",token:null},d=function(){return t=function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.config=s(s({},c),t),this.qrCode=null,this.refreshTimer=null,this.isInitialized=!1,this.socket=null,this.initPromise=this.init()},r=[{key:"init",value:(k=n(a().m(function e(){var t;return a().w(function(e){for(;;)switch(e.p=e.n){case 0:if(e.p=0,!this.config.secureInit){e.n=2;break}return e.n=1,this.secureInit();case 1:e.n=3;break;case 2:this.config.validateInputs&&this.validateSecurityParams();case 3:this.logSecurityEvent("SDK_INIT_START",{apiUrl:this.config.apiUrl,type:this.config.type,partnerName:this.config.partnerName,secureInit:this.config.secureInit}),this.obfuscateCredentials(),this.isInitialized=!0,console.log("SunuID SDK initialisé avec succès"),this.logSecurityEvent("SDK_INIT_SUCCESS"),this.initWebSocket(),e.n=5;break;case 4:throw e.p=4,t=e.v,this.logSecurityEvent("SDK_INIT_ERROR",{error:t.message}),t;case 5:return e.a(2)}},e,this,[[0,4]])})),function(){return k.apply(this,arguments)})},{key:"secureInit",value:(I=n(a().m(function e(){var t,n,i,r,o;return a().w(function(e){for(;;)switch(e.p=e.n){case 0:return e.p=0,this.logSecurityEvent("SECURE_INIT_START"),t={type:this.config.type,partnerName:this.config.partnerName,theme:this.config.theme},e.n=1,fetch(this.config.secureInitUrl,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(t)});case 1:if((n=e.v).ok){e.n=2;break}throw new Error("Erreur HTTP: ".concat(n.status));case 2:return e.n=3,n.json();case 3:if((i=e.v).success){e.n=4;break}throw new Error(i.error||"Erreur lors de l'initialisation sécurisée");case 4:if(this.config.token=i.data.token,this.config.apiUrl=i.data.api_url,!(r=this.decodeSecureToken(i.data.token))){e.n=5;break}this.config.clientId=r.client_id,this.config.secretId=r.secret_id,e.n=6;break;case 5:throw new Error("Impossible de décoder le token sécurisé");case 6:this.config.expiresIn=i.data.expires_in,this.config.maxRequests=i.data.max_requests,this.config.requestCount=0,this.logSecurityEvent("SECURE_INIT_SUCCESS",{expiresIn:i.data.expires_in,maxRequests:i.data.max_requests}),console.log("✅ Initialisation sécurisée réussie"),e.n=8;break;case 7:throw e.p=7,o=e.v,this.logSecurityEvent("SECURE_INIT_ERROR",{error:o.message}),new Error("Échec de l'initialisation sécurisée: ".concat(o.message));case 8:return e.a(2)}},e,this,[[0,7]])})),function(){return I.apply(this,arguments)})},{key:"decodeSecureToken",value:function(e){try{var t=e.split(".");if(2!==t.length)return console.error("❌ Format de token invalide"),null;var n=l(t,2),i=n[0],r=(n[1],atob(i)),o=JSON.parse(r);return o.exp&&o.exp<Date.now()/1e3?(console.error("❌ Token expiré"),null):(console.log("✅ Token décodé avec succès"),o)}catch(e){return console.error("❌ Erreur décodage token:",e),null}}},{key:"initWebSocket",value:function(){var e=this;try{if("undefined"==typeof io)return console.warn("⚠️ Socket.IO non disponible, WebSocket sera initialisé plus tard"),void setTimeout(function(){return e.initWebSocket()},1e3);var t=this.getClientIP();this.socket||(this.socket=io("wss://samasocket.fayma.sn:9443",{query:{token:this.config.clientId,type:"web",userId:this.config.clientId,username:t}}),this.socket.on("connect",function(){console.log("🌐 WebSocket connecté avec succès"),console.log("📊 Socket ID:",e.socket.id)}),this.socket.on("disconnect",function(e){console.log("❌ WebSocket déconnecté:",e)}),this.socket.on("connect_error",function(e){console.error("❌ Erreur connexion WebSocket:",e)}),this.socket.on("qr_status_update",function(t){console.log("📱 Mise à jour statut QR reçue:",t),e.handleQRStatusUpdate(t)}),this.socket.on("qr_scan_success",function(t){console.log("✅ Scan QR réussi reçu:",t),e.handleQRScanSuccess(t)}),this.socket.on("qr_expired",function(t){console.log("⏰ QR expiré reçu:",t),e.handleQRExpired(t)}))}catch(e){console.error("❌ Erreur initialisation WebSocket:",e)}}},{key:"getClientIP",value:function(){return"127.0.0.1"}},{key:"getTypeName",value:function(e){switch(e){case 1:return"KYC";case 2:return"AUTH";case 3:return"SIGNATURE";default:return"TYPE-".concat(e)}}},{key:"validateSecurityParams",value:function(){var e=[];if(this.config.clientId&&"string"==typeof this.config.clientId?this.config.clientId.length<10&&e.push("clientId trop court"):e.push("clientId invalide ou manquant"),this.config.secretId&&"string"==typeof this.config.secretId?this.config.secretId.length<32&&e.push("secretId trop court (minimum 32 caractères)"):e.push("secretId invalide ou manquant"),this.config.apiUrl&&this.isValidUrl(this.config.apiUrl)||e.push("apiUrl invalide"),[1,2,3].includes(this.config.type)||e.push("type invalide (doit être 1, 2 ou 3)"),e.length>0)throw this.logSecurityEvent("VALIDATION_ERROR",{errors:e}),new Error("Paramètres de sécurité invalides: ".concat(e.join(", ")));this.logSecurityEvent("VALIDATION_SUCCESS")}},{key:"isValidUrl",value:function(e){try{var t=new URL(e);return"https:"===t.protocol||"http:"===t.protocol}catch(e){return!1}}},{key:"logSecurityEvent",value:function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(this.config.enableSecurityLogs){var i={timestamp:(new Date).toISOString(),event:t,data:n,userAgent:navigator.userAgent,url:e.location.href};console.warn("🔒 [SECURITY]",i),e.SunuIDSecurityLogs||(e.SunuIDSecurityLogs=[]),e.SunuIDSecurityLogs.push(i)}}},{key:"obfuscateCredentials",value:function(){this.config.originalClientId=this.config.clientId,this.config.originalSecretId=this.config.secretId,this.config.clientId&&(this.config.clientIdDisplay=this.config.clientId.replace(/(.{3}).*(.{3})/,"$1***$2")),this.config.secretId&&(this.config.secretIdDisplay=this.config.secretId.replace(/(.{4}).*(.{4})/,"$1***$2"))}},{key:"sanitizeInput",value:function(e){return"string"!=typeof e?e:e.replace(/[<>]/g,"").replace(/javascript:/gi,"").trim()}},{key:"handleQRStatusUpdate",value:function(e){this.config.onStatusUpdate&&this.config.onStatusUpdate(e)}},{key:"handleQRScanSuccess",value:function(e){this.config.onSuccess&&this.config.onSuccess(e)}},{key:"handleQRExpired",value:function(e){this.config.onExpired&&this.config.onExpired(e)}},{key:"emitWebSocketEvent",value:function(e,t){this.socket&&this.socket.connected?(this.socket.emit(e,t),console.log("📤 Événement WebSocket émis: ".concat(e),t)):"undefined"==typeof io?console.warn("⚠️ Socket.IO non disponible, impossible d'émettre l'événement:",e):console.warn("⚠️ WebSocket non connecté, impossible d'émettre l'événement:",e)}},{key:"getWebSocketStatus",value:function(){return this.socket?this.socket.connected?"connected":"disconnected":"not_initialized"}},{key:"forceWebSocketInit",value:function(){"undefined"==typeof io||this.socket||(console.log("🔄 Forçage de l'initialisation WebSocket..."),this.initWebSocket())}},{key:"generateQR",value:(b=n(a().m(function e(t){var n,i,r,o,c,u=this,l=arguments;return a().w(function(e){for(;;)switch(e.p=e.n){case 0:if(n=l.length>1&&void 0!==l[1]?l[1]:{},!this.initPromise){e.n=2;break}return e.n=1,this.initPromise;case 1:this.initPromise=null;case 2:if(this.isInitialized){e.n=3;break}throw new Error("SunuID: SDK non initialisé");case 3:return e.p=3,e.n=4,this.makeRequest("/qr-generate",s({type:this.config.type},n));case 4:if(!(i=e.v).success){e.n=5;break}return r="".concat("https://sunuid.fayma.sn").concat(i.data.qrcode),this.currentQRUrl=r,this.displayQRCode(t,r,this.config.type,n),this.pendingQRInfo&&i.data.code&&(o=function(){if(u.socket&&u.socket.id&&"unknown"!==u.socket.id){var e=u.socket.id,t="".concat(u.config.type,"-").concat(i.data.code,"-").concat(e),n=i.data.partnerName||u.config.partnerName||"SunuID",r=u.getTypeName(u.config.type),s="".concat(r," - ").concat(n);u.generateCustomQRCode(t,s,u.pendingQRInfo.options),u.pendingQRInfo=null}else setTimeout(o,100)})(),this.startAutoRefresh(t,this.config.type,n),this.emitWebSocketEvent("qr_generated",{serviceId:i.data.service_id,type:this.config.type,qrCodeUrl:r,code:i.data.code,timestamp:Date.now()}),e.a(2,s(s({},i.data),{},{qrCodeUrl:r,sessionId:i.data.service_id}));case 5:throw new Error(i.message||"Erreur lors de la génération du QR code");case 6:e.n=8;break;case 7:throw e.p=7,c=e.v,console.error("Erreur API détectée:",c.message),console.error("Stack trace complet:",c.stack),console.error("Configuration SDK:",{apiUrl:this.config.apiUrl,type:this.config.type,secureInit:this.config.secureInit,clientId:this.config.clientId?"***"+this.config.clientId.slice(-4):"null",secretId:this.config.secretId?"***"+this.config.secretId.slice(-4):"null"}),console.log('Affichage du message "Service non disponible" pour type '+this.config.type),this.displayServiceUnavailable(t,this.config.type),new Error("Service non disponible");case 8:return e.a(2)}},e,this,[[3,7]])})),function(e){return b.apply(this,arguments)})},{key:"generateCustomQR",value:(S=n(a().m(function e(t,n){var i,r,o,c,u,l=this,d=arguments;return a().w(function(e){for(;;)switch(e.p=e.n){case 0:if(i=d.length>2&&void 0!==d[2]?d[2]:{},!this.initPromise){e.n=2;break}return e.n=1,this.initPromise;case 1:this.initPromise=null;case 2:if(this.isInitialized){e.n=3;break}throw new Error("SunuID: SDK non initialisé");case 3:return e.p=3,e.n=4,this.makeRequest("/qr-generate",s({type:n},i));case 4:if(!(r=e.v).success){e.n=5;break}return o="".concat("https://sunuid.fayma.sn").concat(r.data.qrcode),this.displayQRCode(t,o,n,i),this.pendingQRInfo&&r.data.code&&(c=function(){if(l.socket&&l.socket.id&&"unknown"!==l.socket.id){var e=l.socket.id,t="".concat(n,"-").concat(r.data.code,"-").concat(e),i=r.data.partnerName||l.config.partnerName||"SunuID",o=l.getTypeName(n),s="".concat(o," - ").concat(i);l.generateCustomQRCode(t,s,l.pendingQRInfo.options),l.pendingQRInfo=null}else setTimeout(c,100)})(),this.startAutoRefresh(t,n,i),e.a(2,s(s({},r.data),{},{qrCodeUrl:o,sessionId:r.data.service_id}));case 5:throw new Error(r.message||"Erreur lors de la génération du QR code");case 6:e.n=8;break;case 7:throw e.p=7,u=e.v,console.error("Erreur API détectée:",u.message),console.error("Stack trace complet:",u.stack),console.error("Configuration SDK (Custom):",{apiUrl:this.config.apiUrl,type:n,secureInit:this.config.secureInit,clientId:this.config.clientId?"***"+this.config.clientId.slice(-4):"null",secretId:this.config.secretId?"***"+this.config.secretId.slice(-4):"null"}),console.log('Affichage du message "Service non disponible" pour type '+n),this.displayServiceUnavailable(t,n),new Error("Service non disponible");case 8:return e.a(2)}},e,this,[[3,7]])})),function(e,t){return S.apply(this,arguments)})},{key:"generateAuthQR",value:(m=n(a().m(function e(t){var n,i=arguments;return a().w(function(e){for(;;)if(0===e.n)return n=i.length>1&&void 0!==i[1]?i[1]:{},e.a(2,this.generateQR(t,n))},e,this)})),function(e){return m.apply(this,arguments)})},{key:"generateKYCQR",value:(v=n(a().m(function e(t){var n,i,r=arguments;return a().w(function(e){for(;;)switch(e.p=e.n){case 0:return n=r.length>1&&void 0!==r[1]?r[1]:{},i=this.config.type,this.config.type=1,e.p=1,e.n=2,this.generateQR(t,n);case 2:return e.a(2,e.v);case 3:return e.p=3,this.config.type=i,e.f(3);case 4:return e.a(2)}},e,this,[[1,,3,4]])})),function(e){return v.apply(this,arguments)})},{key:"generateSignatureQR",value:(y=n(a().m(function e(t){var n,i,r=arguments;return a().w(function(e){for(;;)switch(e.p=e.n){case 0:return n=r.length>1&&void 0!==r[1]?r[1]:{},i=this.config.type,this.config.type=3,e.p=1,e.n=2,this.generateQR(t,n);case 2:return e.a(2,e.v);case 3:return e.p=3,this.config.type=i,e.f(3);case 4:return e.a(2)}},e,this,[[1,,3,4]])})),function(e){return y.apply(this,arguments)})},{key:"checkQRStatus",value:(g=n(a().m(function e(t){var n,i;return a().w(function(e){for(;;)switch(e.p=e.n){case 0:if(this.isInitialized){e.n=1;break}throw new Error("SunuID: SDK non initialisé");case 1:return e.p=1,e.n=2,this.makeRequest("/qr-status",{serviceId:t});case 2:if(!(n=e.v).success){e.n=3;break}return e.a(2,n.data);case 3:throw new Error(n.message||"Erreur lors de la vérification du statut");case 4:e.n=6;break;case 5:throw e.p=5,i=e.v,this.handleError(i),i;case 6:return e.a(2)}},e,this,[[1,5]])})),function(e){return g.apply(this,arguments)})},{key:"displayQRCode",value:function(e,t,n){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},r=document.getElementById(e);if(!r)throw new Error("Conteneur avec l'ID \"".concat(e,'" non trouvé'));r.innerHTML="";var o=document.createElement("div");o.className="sunuid-qr-code",this.getTypeName(n),o.innerHTML='\n <div class="sunuid-qr-header">\n <h3>'.concat(1===n?"Vérification KYC":2===n?"Authentification":3===n?"Signature":"Service Type "+n,'</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 '),r.appendChild(o),this.pendingQRInfo={containerId:e,type:n,options:i},this.applyTheme(i.theme||this.config.theme)}},{key:"generateCustomQRCode",value:(h=n(a().m(function e(t,n){var i,r,o,s,c,u,l;return a().w(function(e){for(;;)switch(e.p=e.n){case 0:if(e.p=1,console.log("🎨 Début génération QR personnalisé avec PHP..."),console.log("📄 Contenu:",t),console.log("🏷️ Label:",n),i=document.getElementById("sunuid-qr-container")){e.n=2;break}return console.error("❌ QR container not found"),this.displayFallbackImage(),e.a(2);case 2:return console.log("✅ QR container trouvé"),i.innerHTML='<div style="text-align: center; padding: 20px;"><p>Génération QR code avec PHP...</p></div>',console.log("🔄 Appel endpoint PHP..."),r=this.config.apiUrl.includes("api.sunuid.fayma.sn")?"https://api.sunuid.fayma.sn/qr-generator.php":this.config.apiUrl.replace("/api","")+"/qr-generator.php",console.log("🔗 URL QR Generator:",r),e.n=3,fetch(r,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({content:t,label:n,size:300,margin:10})});case 3:if(o=e.v,console.log("📥 Réponse PHP reçue - Status:",o.status),o.ok){e.n=4;break}throw new Error("Erreur HTTP: ".concat(o.status));case 4:return e.n=5,o.json();case 5:if((s=e.v).success){e.n=6;break}throw new Error("Erreur PHP: ".concat(s.error));case 6:console.log("✅ QR code généré par PHP avec succès"),console.log("📊 Taille:",s.data.size+"px"),console.log("📊 Longueur base64:",s.data.length+" caractères"),this.currentQRUrl=s.data.dataUrl,i.innerHTML='\n <div class="sunuid-qr-ready" style="text-align: center; padding: 20px;">\n <img src="'.concat(s.data.dataUrl,'" alt="QR Code ').concat(this.config.partnerName,'" style="max-width: 300px; border: 2px solid #ddd; border-radius: 10px;">\n </div>\n '),c=i.parentElement.querySelector(".sunuid-qr-instructions"),u=i.parentElement.querySelector(".sunuid-qr-status"),c&&(c.style.display="block",c.classList.add("sunuid-qr-ready")),u&&(u.style.display="block",u.classList.add("sunuid-qr-ready")),console.log("✅ QR code PHP affiché dans le conteneur"),e.n=8;break;case 7:e.p=7,l=e.v,console.error("❌ Erreur génération QR PHP:",l),console.error("Stack trace:",l.stack),l.message.includes("Failed to fetch")||l.message.includes("CORS")||l.message.includes("404")||l.message.includes("Not Found")?(console.warn("🚫 Erreur PHP détectée (CORS/404), tentative de génération QR côté client..."),this.generateQRCodeClientSide(t,n,qrContainer)):this.displayFallbackImage();case 8:return e.a(2)}},e,this,[[1,7]])})),function(e,t){return h.apply(this,arguments)})},{key:"generateQRCodeClientSide",value:function(e,t,n){var i=this;try{if(console.log("🎨 Génération QR côté client..."),"undefined"==typeof QRCode)return console.error("❌ QRCode library non disponible"),void this.displayFallbackImage();var r=document.createElement("canvas");r.width=300,r.height=320;var o=r.getContext("2d");o.fillStyle="#FFFFFF",o.fillRect(0,0,300,320),QRCode.toCanvas(r,e,{width:280,margin:10,color:{dark:"#000000",light:"#FFFFFF"}},function(e){if(e)return console.error("❌ Erreur génération QR côté client:",e),void i.displayFallbackImage();o.fillStyle="#333333",o.font="bold 14px Arial",o.textAlign="center",o.fillText(t,150,305);var s=r.toDataURL("image/png");i.currentQRUrl=s,n.innerHTML='\n <div class="sunuid-qr-ready" style="text-align: center; padding: 20px;">\n <img src="'.concat(s,'" alt="QR Code ').concat(i.config.partnerName,'" style="max-width: 300px; border: 2px solid #ddd; border-radius: 10px;">\n </div>\n ');var a=n.parentElement.querySelector(".sunuid-qr-instructions"),c=n.parentElement.querySelector(".sunuid-qr-status");a&&(a.style.display="block",a.classList.add("sunuid-qr-ready")),c&&(c.style.display="block",c.classList.add("sunuid-qr-ready")),console.log("✅ QR code côté client généré avec succès")})}catch(e){console.error("❌ Erreur génération QR côté client:",e),this.displayFallbackImage()}}},{key:"addLogoToCenter",value:function(e,t,n,i,r){try{var o=new Image;o.onload=function(){var r=40,s=t+(i-r)/2,a=n+(i-r)/2;e.fillStyle="white",e.fillRect(s-2,a-2,44,44),e.drawImage(o,s,a,r,r)},o.src="src/logoqr.png"}catch(e){console.warn("Logo non disponible:",e)}}},{key:"displayFallbackImage",value:function(){console.log("⚠️ Affichage de l'image de fallback");var e=document.getElementById("sunuid-qr-container");e?e.innerHTML='\n <div style="text-align: center; padding: 20px; color: #666;">\n <p>⚠️ Génération QR personnalisé non disponible</p>\n <p>Utilisation de l\'image par défaut</p>\n <p><strong>Debug:</strong> QRCode disponible: '.concat("undefined"!=typeof QRCode,"</p>\n <p><strong>Debug:</strong> Container trouvé: ").concat(null!==e,"</p>\n </div>\n "):console.error("❌ Container QR non trouvé pour fallback")}},{key:"displayServiceUnavailable",value:function(e,t){console.log("displayServiceUnavailable appelée pour ".concat(e,", type: ").concat(t));var n=document.getElementById(e);n?n.innerHTML='\n <div class="sunuid-service-unavailable" style="\n text-align: center;\n padding: 40px 20px;\n background: #f8f9fa;\n border: 2px dashed #dee2e6;\n border-radius: 10px;\n color: #6c757d;\n font-family: Arial, sans-serif;\n ">\n <div style="font-size: 48px; margin-bottom: 20px;">⚠️</div>\n <h3 style="margin: 0 0 10px 0; color: #495057;">Service Non Disponible</h3>\n <p style="margin: 0; font-size: 14px;">\n Le service d\'authentification est temporairement indisponible.<br>\n Veuillez réessayer plus tard.\n </p>\n <div style="margin-top: 20px; font-size: 12px; color: #adb5bd;">\n Type: '.concat(String(t).toUpperCase(),"\n </div>\n </div>\n "):console.error("Container ".concat(e," non trouvé"))}},{key:"refreshQR",value:(p=n(a().m(function e(t){var n,i,r,o=arguments;return a().w(function(e){for(;;)switch(e.p=e.n){case 0:return n=o.length>1&&void 0!==o[1]?o[1]:{},e.p=1,e.n=2,this.generateQR(t,n);case 2:return i=e.v,e.a(2,i);case 3:throw e.p=3,r=e.v,console.error("Erreur lors du rafraîchissement:",r.message),this.displayServiceUnavailable(t,this.config.type),r;case 4:return e.a(2)}},e,this,[[1,3]])})),function(e){return p.apply(this,arguments)})},{key:"startAutoRefresh",value:function(e,t,i){var r=this;this.config.autoRefresh&&(this.refreshTimer=setInterval(n(a().m(function n(){var o;return a().w(function(n){for(;;)switch(n.p=n.n){case 0:return n.p=0,n.n=1,r.refreshQR(e,t,i);case 1:n.n=3;break;case 2:n.p=2,o=n.v,console.warn("Erreur lors du rafraîchissement automatique:",o);case 3:return n.a(2)}},n,null,[[0,2]])})),this.config.refreshInterval))}},{key:"makeRequest",value:(d=n(a().m(function t(n,i){var r,o,s,c,l,d,f,p,h,g=this;return a().w(function(t){for(;;)switch(t.n){case 0:if(this.isInitialized){t.n=1;break}throw this.logSecurityEvent("REQUEST_BEFORE_INIT",{endpoint:n}),new Error("SDK non initialisé");case 1:if(!this.config.secureInit){t.n=2;break}if(this.config.requestCount++,!(this.config.requestCount>this.config.maxRequests)){t.n=2;break}throw this.logSecurityEvent("API_REQUEST_LIMIT_EXCEEDED",{requestCount:this.config.requestCount,maxRequests:this.config.maxRequests}),new Error("Limite de requêtes dépassée");case 2:s=this.sanitizeRequestData(i),console.log("🔍 Debug makeRequest - endpoint:",n),console.log("🔍 Debug makeRequest - apiUrl:",this.config.apiUrl),console.log("🔍 Debug makeRequest - url:","".concat(this.config.apiUrl).concat(n)),console.log("🔍 Debug makeRequest - data:",JSON.stringify(s,null,2)),console.log("🔍 Debug makeRequest - secureInit:",this.config.secureInit),console.log("🔍 Debug makeRequest - isInitialized:",this.isInitialized),c=(null===(r=e.SunuIDConfig)||void 0===r||null===(r=r.endpoints)||void 0===r?void 0:r[n.replace("/","")])||n,l="".concat(this.config.apiUrl).concat(c),console.log("🔍 URL finale construite:",l),console.log("🔍 EndpointPath:",c),console.log("🔍 SunuIDConfig endpoints:",JSON.stringify(null===(o=e.SunuIDConfig)||void 0===o?void 0:o.endpoints)),this.logSecurityEvent("API_REQUEST_START",{endpoint:c,url:l,dataKeys:Object.keys(s),secureInit:this.config.secureInit}),d=0,f=this.config.maxRetries,p=a().m(function e(){var t,n,i,r,o,u,p,h;return a().w(function(e){for(;;)switch(e.p=e.n){case 0:return e.p=0,t=new AbortController,n=setTimeout(function(){return t.abort()},g.config.requestTimeout),i={"Content-Type":"application/json"},e.n=1,fetch(l,{method:"POST",headers:i,body:JSON.stringify(s),signal:t.signal});case 1:if(r=e.v,clearTimeout(n),r.ok){e.n=3;break}return e.n=2,r.text();case 2:o=e.v;try{u=JSON.parse(o)}catch(e){u={message:o}}throw g.logSecurityEvent("API_REQUEST_ERROR",{status:r.status,statusText:r.statusText,error:u.message}),new Error(u.message||"Erreur HTTP: ".concat(r.status));case 3:return e.n=4,r.json();case 4:return p=e.v,g.logSecurityEvent("API_REQUEST_SUCCESS",{endpoint:c,responseKeys:Object.keys(p)}),e.a(2,{v:p});case 5:if(e.p=5,h=e.v,d++,"AbortError"!==h.name){e.n=7;break}if(g.logSecurityEvent("API_REQUEST_TIMEOUT",{retryCount:d}),!(d>f)){e.n=6;break}throw new Error("Timeout de la requête API");case 6:return e.a(2,0);case 7:if(!(d>f)){e.n=8;break}throw g.logSecurityEvent("API_REQUEST_MAX_RETRIES",{retryCount:d,error:h.message}),h;case 8:return e.n=9,new Promise(function(e){return setTimeout(e,1e3*d)});case 9:return e.a(2)}},e,null,[[0,5]])});case 3:if(!(d<=f)){t.n=7;break}return t.d(u(p()),4);case 4:if(0!==(h=t.v)){t.n=5;break}return t.a(3,3);case 5:if(!h){t.n=6;break}return t.a(2,h.v);case 6:t.n=3;break;case 7:return t.a(2)}},t,this)})),function(e,t){return d.apply(this,arguments)})},{key:"sanitizeRequestData",value:function(e){for(var t={},n=0,i=Object.entries(e);n<i.length;n++){var r=l(i[n],2),o=r[0],s=r[1];"string"==typeof s?t[o]=this.sanitizeInput(s):"object"===f(s)&&null!==s?t[o]=this.sanitizeRequestData(s):t[o]=s}return t.client_id=this.config.originalClientId||this.config.clientId,t.secret_id=this.config.originalSecretId||this.config.secretId,console.log("🔍 Credentials dans sanitizeRequestData - clientId:",this.config.clientId),console.log("🔍 Credentials dans sanitizeRequestData - secretId:",this.config.secretId?"***"+this.config.secretId.slice(-4):"null"),console.log("🔍 Credentials dans sanitizeRequestData - sanitizedClientId:",t.client_id),console.log("🔍 Credentials dans sanitizeRequestData - sanitizedSecretId:",t.secret_id?"***"+t.secret_id.slice(-4):"null"),console.log("🔍 Credentials dans sanitizeRequestData - data complet:",JSON.stringify(t,null,2)),console.log("🔍 Credentials dans sanitizeRequestData - clientId:",this.config.clientId),console.log("🔍 Credentials dans sanitizeRequestData - secretId:",this.config.secretId?"***"+this.config.secretId.slice(-4):"null"),console.log("🔍 Credentials dans sanitizeRequestData - sanitizedClientId:",t.client_id),console.log("🔍 Credentials dans sanitizeRequestData - sanitizedSecretId:",t.secret_id?"***"+t.secret_id.slice(-4):"null"),console.log("🔍 Credentials dans sanitizeRequestData - data complet:",JSON.stringify(t,null,2)),t}},{key:"generateRequestId",value:function(){return"req_"+Date.now()+"_"+Math.random().toString(36).substr(2,9)}},{key:"applyTheme",value:function(e){var t=document.querySelector(".sunuid-qr-code");t&&(t.className="sunuid-qr-code sunuid-theme-".concat(e))}},{key:"handleError",value:function(e){console.error("SunuID SDK Error:",e),this.config.onError&&this.config.onError(e)}},{key:"getQRCode",value:function(){return this.currentQRUrl?this.currentQRUrl:null}},{key:"destroy",value:function(){this.refreshTimer&&clearInterval(this.refreshTimer),this.socket&&(this.socket.disconnect(),this.socket=null,console.log("🌐 WebSocket déconnecté")),this.isInitialized=!1,this.logSecurityEvent("SDK_DESTROY"),console.log("SunuID SDK détruit")}},{key:"getSecurityLogs",value:function(){return e.SunuIDSecurityLogs||[]}},{key:"clearSecurityLogs",value:function(){e.SunuIDSecurityLogs=[],this.logSecurityEvent("SECURITY_LOGS_CLEARED")}}],r&&i(t.prototype,r),o&&i(t,o),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,r,o,d,p,h,g,y,v,m,S,b,I,k}();e.SunuID=d,e.sunuidInstance=null,e.initSunuID=function(t){try{return e.sunuidInstance=new d(t),e.sunuidInstance}catch(e){throw console.error("Erreur lors de l'initialisation de SunuID:",e),e}}}(window)}();
|
|
10
|
+
*/(n,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function d(e){var n=function(e,n){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,n||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===n?String:Number)(e)}(e,"string");return"symbol"==typeof n?n:n+""}function f(e){return f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},f(e)}!function(e,n){var i,o,c={apiUrl:(null===(n=e.SunuIDConfig)||void 0===n?void 0:n.apiUrl)||"https://api.sunuid.fayma.sn",clientId:null,secretId:null,type:2,partnerName:null,theme:"light",language:"fr",autoRefresh:!1,refreshInterval:3e4,onSuccess:null,onError:null,onStatusUpdate:null,onExpired:null,enableSecurityLogs:!0,validateInputs:!0,maxRetries:3,requestTimeout:1e4,secureInit:!1,secureInitUrl:null!==(i=e.SunuIDConfig)&&void 0!==i&&null!==(i=i.apiUrl)&&void 0!==i&&i.includes("api.sunuid.fayma.sn")?"https://api.sunuid.fayma.sn/secure-init.php":(null===(o=e.SunuIDConfig)||void 0===o||null===(o=o.apiUrl)||void 0===o?void 0:o.replace("/api",""))+"/secure-init.php"||"https://api.sunuid.fayma.sn/secure-init.php",token:null,forceRemoteServer:!0,useLocalFallback:!1},d=function(){return n=function e(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}(this,e),this.config=s(s({},c),n),this.qrCode=null,this.refreshTimer=null,this.isInitialized=!1,this.socket=null,this.initPromise=this.init()},i=[{key:"init",value:(_=t(a().m(function e(){var n;return a().w(function(e){for(;;)switch(e.p=e.n){case 0:if(e.p=0,!this.config.secureInit){e.n=2;break}return e.n=1,this.secureInit();case 1:e.n=3;break;case 2:this.config.validateInputs&&this.validateSecurityParams();case 3:return this.logSecurityEvent("SDK_INIT_START",{apiUrl:this.config.apiUrl,type:this.config.type,secureInit:this.config.secureInit}),e.n=4,this.fetchPartnerInfo();case 4:this.obfuscateCredentials(),this.isInitialized=!0,console.log("SunuID SDK initialisé avec succès"),console.log("📋 Configuration SDK:",{apiUrl:this.config.apiUrl,type:this.config.type,partnerName:this.config.partnerName,clientId:this.config.clientId?"***"+this.config.clientId.slice(-4):"null",secretId:this.config.secretId?"***"+this.config.secretId.slice(-4):"null",secureInit:this.config.secureInit,theme:this.config.theme}),this.logSecurityEvent("SDK_INIT_SUCCESS"),this.initWebSocket(),e.n=6;break;case 5:throw e.p=5,n=e.v,this.logSecurityEvent("SDK_INIT_ERROR",{error:n.message}),n;case 6:return e.a(2)}},e,this,[[0,5]])})),function(){return _.apply(this,arguments)})},{key:"secureInit",value:(q=t(a().m(function e(){var n,t,r,i,o;return a().w(function(e){for(;;)switch(e.p=e.n){case 0:return e.p=0,this.logSecurityEvent("SECURE_INIT_START"),n={type:this.config.type,partnerName:this.config.partnerName,theme:this.config.theme},e.n=1,fetch(this.config.secureInitUrl,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(n)});case 1:if((t=e.v).ok){e.n=2;break}throw new Error("Erreur HTTP: ".concat(t.status));case 2:return e.n=3,t.json();case 3:if(r=e.v,console.log("📋 Réponse initialisation sécurisée:",r),r.success){e.n=4;break}throw new Error(r.error||"Erreur lors de l'initialisation sécurisée");case 4:if(this.config.token=r.data.token,this.config.apiUrl=r.data.api_url,!(i=this.decodeSecureToken(r.data.token))){e.n=5;break}this.config.clientId=i.client_id,this.config.secretId=i.secret_id,e.n=6;break;case 5:throw new Error("Impossible de décoder le token sécurisé");case 6:this.config.expiresIn=r.data.expires_in,this.config.maxRequests=r.data.max_requests,this.config.requestCount=0,this.logSecurityEvent("SECURE_INIT_SUCCESS",{expiresIn:r.data.expires_in,maxRequests:r.data.max_requests}),console.log("✅ Initialisation sécurisée réussie"),e.n=8;break;case 7:throw e.p=7,o=e.v,this.logSecurityEvent("SECURE_INIT_ERROR",{error:o.message}),new Error("Échec de l'initialisation sécurisée: ".concat(o.message));case 8:return e.a(2)}},e,this,[[0,7]])})),function(){return q.apply(this,arguments)})},{key:"decodeSecureToken",value:function(e){try{var n=e.split(".");if(2!==n.length)return console.error("❌ Format de token invalide"),null;var t=u(n,2),r=t[0],i=(t[1],atob(r)),o=JSON.parse(i);return o.exp&&o.exp<Date.now()/1e3?(console.error("❌ Token expiré"),null):(console.log("✅ Token décodé avec succès"),o)}catch(e){return console.error("❌ Erreur décodage token:",e),null}}},{key:"initWebSocket",value:function(){var e=this;try{if("undefined"==typeof io)return console.warn("⚠️ Socket.IO non disponible, WebSocket sera initialisé plus tard"),void setTimeout(function(){return e.initWebSocket()},1e3);var n=this.getClientIP();this.socket?console.log("🌐 WebSocket déjà connecté"):(console.log("🌐 Initialisation Socket.IO..."),this.socket=io("wss://samasocket.fayma.sn:9443",{query:{token:this.config.clientId,type:"web",userId:this.config.clientId,username:n},transports:["websocket","polling"]}),this.socket.on("connect",function(){console.log("🌐 WebSocket connecté avec succès"),console.log("📊 Socket ID:",e.socket.id),e.socket.connected=!0}),this.socket.on("disconnect",function(n){console.log("❌ WebSocket déconnecté:",n),e.socket.connected=!1}),this.socket.on("connect_error",function(n){console.error("❌ Erreur connexion WebSocket:",n),e.socket.connected=!1}),this.socket.on("qr_status_update",function(n){console.log("📱 Mise à jour statut QR reçue:",n),e.handleQRStatusUpdate(n)}),this.socket.on("qr_scan_success",function(n){console.log("✅ Scan QR réussi reçu:",n),e.handleQRScanSuccess(n)}),this.socket.on("qr_expired",function(n){console.log("⏰ QR expiré reçu:",n),e.handleQRExpired(n)}))}catch(e){console.error("❌ Erreur initialisation WebSocket:",e)}}},{key:"getClientIP",value:function(){return"127.0.0.1"}},{key:"getTypeName",value:function(e){switch(e){case 1:return"KYC";case 2:return"AUTH";case 3:return"SIGNATURE";default:return"TYPE-".concat(e)}}},{key:"validateSecurityParams",value:function(){var e=[];if(this.config.clientId&&"string"==typeof this.config.clientId?this.config.clientId.length<10&&e.push("clientId trop court"):e.push("clientId invalide ou manquant"),this.config.secretId&&"string"==typeof this.config.secretId?this.config.secretId.length<32&&e.push("secretId trop court (minimum 32 caractères)"):e.push("secretId invalide ou manquant"),this.config.apiUrl&&this.isValidUrl(this.config.apiUrl)||e.push("apiUrl invalide"),[1,2,3].includes(this.config.type)||e.push("type invalide (doit être 1, 2 ou 3)"),e.length>0)throw this.logSecurityEvent("VALIDATION_ERROR",{errors:e}),new Error("Paramètres de sécurité invalides: ".concat(e.join(", ")));this.logSecurityEvent("VALIDATION_SUCCESS")}},{key:"isValidUrl",value:function(e){try{var n=new URL(e);return"https:"===n.protocol||"http:"===n.protocol}catch(e){return!1}}},{key:"logSecurityEvent",value:function(n){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(this.config.enableSecurityLogs){var r={timestamp:(new Date).toISOString(),event:n,data:t,userAgent:navigator.userAgent,url:e.location.href};console.warn("🔒 [SECURITY]",r),e.SunuIDSecurityLogs||(e.SunuIDSecurityLogs=[]),e.SunuIDSecurityLogs.push(r)}}},{key:"obfuscateCredentials",value:function(){this.config.originalClientId=this.config.clientId,this.config.originalSecretId=this.config.secretId,this.config.clientId&&(this.config.clientIdDisplay=this.config.clientId.replace(/(.{3}).*(.{3})/,"$1***$2")),this.config.secretId&&(this.config.secretIdDisplay=this.config.secretId.replace(/(.{4}).*(.{4})/,"$1***$2"))}},{key:"sanitizeInput",value:function(e){return"string"!=typeof e?e:e.replace(/[<>]/g,"").replace(/javascript:/gi,"").trim()}},{key:"handleQRStatusUpdate",value:function(e){this.config.onStatusUpdate&&this.config.onStatusUpdate(e)}},{key:"handleQRScanSuccess",value:function(e){this.config.onSuccess&&this.config.onSuccess(e)}},{key:"handleQRExpired",value:function(e){this.config.onExpired&&this.config.onExpired(e)}},{key:"emitWebSocketEvent",value:function(e,n){this.socket&&this.socket.connected?(this.socket.emit(e,n),console.log("📤 Événement WebSocket émis: ".concat(e),n)):console.warn("⚠️ WebSocket non connecté, impossible d'émettre l'événement:",e)}},{key:"getWebSocketStatus",value:function(){return this.socket?this.socket.connected?"connected":"disconnected":"not_initialized"}},{key:"forceWebSocketInit",value:function(){"undefined"==typeof io||this.socket||(console.log("🔄 Forçage de l'initialisation WebSocket..."),this.initWebSocket())}},{key:"generateQR",value:(x=t(a().m(function n(){var t,r,i,o,c,l,u,d,f,p,h,g=arguments;return a().w(function(n){for(;;)switch(n.p=n.n){case 0:if(t=g.length>0&&void 0!==g[0]?g[0]:"sunuid-qr-container",r=g.length>1&&void 0!==g[1]?g[1]:{},!this.initPromise){n.n=2;break}return n.n=1,this.initPromise;case 1:this.initPromise=null;case 2:if(this.isInitialized){n.n=3;break}throw new Error("SunuID: SDK non initialisé");case 3:return console.log("🎯 generateQR appelé avec containerId:",t),console.log("🔍 Attente connexions API et WebSocket..."),n.p=4,n.n=5,this.waitForConnections(5e3);case 5:i=n.v,console.log("✅ Connexions prêtes:",i),n.n=7;break;case 6:throw n.p=6,p=n.v,console.error("❌ Erreur connexions:",p.message),new Error("Connexions non disponibles - Impossible de générer le QR code");case 7:return n.p=7,o=this.socket?this.socket.id:"timeout-socket-id",c=o,console.log("📄 Contenu QR préparé:",c),console.log("🔌 Socket ID:",o),l=this.config.partnerName||"Partner_unknown",n.n=8,this.makeRequest("/qr-generate",s({type:this.config.type,content:c,label:"".concat(this.getTypeName(this.config.type)," ").concat(l)},r));case 8:if(!(u=n.v).success){n.n=9;break}return(d=u.data.qrCodeUrl).startsWith("/")&&(d="".concat(this.config.apiUrl).concat(d)),this.currentQRUrl=d,console.log("✅ QR code généré par API principale:",d),console.log("📄 Contenu QR final:",c),console.log("🏷️ Label QR:",u.data.label),console.log("🆔 Session ID:",u.data.sessionId),this.displayQRCode(t,d,this.config.type,r),this.startAutoRefresh(t,this.config.type,r),this.emitWebSocketEvent("qr_generated",{type:this.config.type,qrCodeUrl:d,socketId:o,qrContent:c,label:u.data.label,sessionId:u.data.sessionId,timestamp:Date.now()}),n.a(2,s(s({},u.data),{},{qrCodeUrl:d,qrContent:c,label:u.data.label,sessionId:u.data.sessionId}));case 9:throw new Error(u.message||"Erreur lors de la génération du QR code");case 10:n.n=12;break;case 11:throw n.p=11,h=n.v,console.error("Erreur API détectée:",h.message),console.error("Stack trace complet:",h.stack),console.error("Configuration SDK:",{apiUrl:this.config.apiUrl,type:this.config.type,secureInit:this.config.secureInit,clientId:this.config.clientId?"***"+this.config.clientId.slice(-4):"null",secretId:this.config.secretId?"***"+this.config.secretId.slice(-4):"null"}),this.config.useLocalFallback?(console.log("🔍 Vérification fallback local..."),console.log("🔍 Hostname:",e.location.hostname),console.log("🔍 Protocol:",e.location.protocol),console.log("🔍 URL complète:",e.location.href),f="localhost"===e.location.hostname||"127.0.0.1"===e.location.hostname||"file:"===e.location.protocol,console.log("🔍 Est local:",f),f?(console.log("🔄 Tentative fallback vers service QR local..."),console.log("❌ Fallback local non implémenté - utilisation serveur distant uniquement")):console.log("❌ Pas en local, pas de fallback")):console.log("🔒 Fallback local désactivé, utilisation serveur distant uniquement"),console.log('Affichage du message "Service non disponible" pour type '+this.config.type),this.displayServiceUnavailable(t,this.config.type),new Error("Service non disponible");case 12:return n.a(2)}},n,this,[[7,11],[4,6]])})),function(){return x.apply(this,arguments)})},{key:"generateCustomQR",value:(T=t(a().m(function e(n,t){var r,i,o,c,l=arguments;return a().w(function(e){for(;;)switch(e.p=e.n){case 0:if(r=l.length>2&&void 0!==l[2]?l[2]:{},!this.initPromise){e.n=2;break}return e.n=1,this.initPromise;case 1:this.initPromise=null;case 2:if(this.isInitialized){e.n=3;break}throw new Error("SunuID: SDK non initialisé");case 3:return e.p=3,e.n=4,this.makeRequest("/qr-generate",s({type:t},r));case 4:if(!(i=e.v).success){e.n=5;break}return o="".concat("https://sunuid.fayma.sn").concat(i.data.qrcode),this.displayQRCode(n,o,t,r),console.log("✅ QR code personnalisé généré par API principale:",o),console.log("📄 Code de session:",i.data.code),console.log("🆔 Service ID:",i.data.service_id),this.startAutoRefresh(n,t,r),e.a(2,s(s({},i.data),{},{qrCodeUrl:o,sessionId:i.data.service_id}));case 5:throw new Error(i.message||"Erreur lors de la génération du QR code");case 6:e.n=8;break;case 7:throw e.p=7,c=e.v,console.error("Erreur API détectée:",c.message),console.error("Stack trace complet:",c.stack),console.error("Configuration SDK (Custom):",{apiUrl:this.config.apiUrl,type:t,secureInit:this.config.secureInit,clientId:this.config.clientId?"***"+this.config.clientId.slice(-4):"null",secretId:this.config.secretId?"***"+this.config.secretId.slice(-4):"null"}),console.log('Affichage du message "Service non disponible" pour type '+t),this.displayServiceUnavailable(n,t),new Error("Service non disponible");case 8:return e.a(2)}},e,this,[[3,7]])})),function(e,n){return T.apply(this,arguments)})},{key:"generateAuthQR",value:(Q=t(a().m(function e(n){var t,r=arguments;return a().w(function(e){for(;;)if(0===e.n)return t=r.length>1&&void 0!==r[1]?r[1]:{},e.a(2,this.generateQR(n,t))},e,this)})),function(e){return Q.apply(this,arguments)})},{key:"generateKYCQR",value:(C=t(a().m(function e(n){var t,r,i=arguments;return a().w(function(e){for(;;)switch(e.p=e.n){case 0:return t=i.length>1&&void 0!==i[1]?i[1]:{},r=this.config.type,this.config.type=1,e.p=1,e.n=2,this.generateQR(n,t);case 2:return e.a(2,e.v);case 3:return e.p=3,this.config.type=r,e.f(3);case 4:return e.a(2)}},e,this,[[1,,3,4]])})),function(e){return C.apply(this,arguments)})},{key:"generateSignatureQR",value:(E=t(a().m(function e(n){var t,r,i=arguments;return a().w(function(e){for(;;)switch(e.p=e.n){case 0:return t=i.length>1&&void 0!==i[1]?i[1]:{},r=this.config.type,this.config.type=3,e.p=1,e.n=2,this.generateQR(n,t);case 2:return e.a(2,e.v);case 3:return e.p=3,this.config.type=r,e.f(3);case 4:return e.a(2)}},e,this,[[1,,3,4]])})),function(e){return E.apply(this,arguments)})},{key:"checkQRStatus",value:(w=t(a().m(function e(n){var t,r;return a().w(function(e){for(;;)switch(e.p=e.n){case 0:if(this.isInitialized){e.n=1;break}throw new Error("SunuID: SDK non initialisé");case 1:return e.p=1,e.n=2,this.makeRequest("/qr-status",{serviceId:n});case 2:if(!(t=e.v).success){e.n=3;break}return e.a(2,t.data);case 3:throw new Error(t.message||"Erreur lors de la vérification du statut");case 4:e.n=6;break;case 5:throw e.p=5,r=e.v,this.handleError(r),r;case 6:return e.a(2)}},e,this,[[1,5]])})),function(e){return w.apply(this,arguments)})},{key:"generateQRWithContent",value:(R=t(a().m(function n(t,r,i){var o,s,c,l=arguments;return a().w(function(n){for(;;)switch(n.p=n.n){case 0:if(o=l.length>3&&void 0!==l[3]?l[3]:{},console.log("🎨 Génération QR avec contenu:",t),n.p=1,"localhost"!==e.location.hostname&&"127.0.0.1"!==e.location.hostname&&"file:"!==e.location.protocol){n.n=3;break}return console.log("🏠 Utilisation service QR local..."),n.n=2,this.generateQRLocal(t,r,i,o);case 2:if(!(s=n.v)){n.n=3;break}return n.a(2,s);case 3:return console.log("🌐 Utilisation service QR distant..."),n.n=4,this.generateQRRemote(t,r,i,o);case 4:return n.a(2,n.v);case 5:return n.p=5,c=n.v,console.error("❌ Erreur génération QR:",c),this.displayQRContent(r,t,i,o),n.a(2,null)}},n,this,[[1,5]])})),function(e,n,t){return R.apply(this,arguments)})},{key:"generateQRLocal",value:(S=t(a().m(function e(n,t,r){var i,o,s,c,l,u=arguments;return a().w(function(e){for(;;)switch(e.p=e.n){case 0:return i=u.length>3&&void 0!==u[3]?u[3]:{},e.p=1,e.n=2,fetch("http://localhost:8000/api/generate/text",{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:"text=".concat(encodeURIComponent(n),"&size=300")});case 2:if(!(o=e.v).ok){e.n=4;break}return e.n=3,o.json();case 3:return s=e.v,c="data:image/png;base64,".concat(s.qrcode),this.displayQRCode(t,c,r,i),e.a(2,c);case 4:e.n=6;break;case 5:e.p=5,l=e.v,console.log("❌ Service QR local non disponible:",l.message);case 6:return e.a(2,null)}},e,this,[[1,5]])})),function(e,n,t){return S.apply(this,arguments)})},{key:"generateQRRemote",value:(k=t(a().m(function e(n,t,r){var i,o,s,c,l,u=arguments;return a().w(function(e){for(;;)switch(e.p=e.n){case 0:return i=u.length>3&&void 0!==u[3]?u[3]:{},e.p=1,e.n=2,fetch("https://api.sunuid.fayma.sn/qr-generate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:n,size:300,type:r})});case 2:if(!(o=e.v).ok){e.n=4;break}return e.n=3,o.json();case 3:return s=e.v,c="data:image/png;base64,".concat(s.qrcode),this.displayQRCode(t,c,r,i),e.a(2,c);case 4:e.n=6;break;case 5:e.p=5,l=e.v,console.error("❌ Erreur service QR distant:",l);case 6:return this.displayQRContent(t,n,r,i),e.a(2,null)}},e,this,[[1,5]])})),function(e,n,t){return k.apply(this,arguments)})},{key:"displayQRContent",value:function(e,n,t){var r=document.getElementById(e);if(!r)throw new Error("Conteneur avec l'ID \"".concat(e,'" non trouvé'));var i=this.getTypeName(t);r.innerHTML='\n <div class="sunuid-qr-code">\n <div class="sunuid-qr-header">\n <h3>'.concat(i,'</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(n,'</p>\n </div>\n <div class="sunuid-qr-instructions">\n <p>Contenu QR généré avec le format: {type}-{code}-{socketid}</p>\n </div>\n </div>\n '),console.log("✅ Contenu QR affiché:",n)}},{key:"displayQRCode",value:function(e,n,t){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},i=document.getElementById(e);if(!i)throw new Error("Conteneur avec l'ID \"".concat(e,'" non trouvé'));i.innerHTML="";var o=document.createElement("div");o.className="sunuid-qr-code";var s=this.getTypeName(t);o.innerHTML='\n <div class="sunuid-qr-header">\n <h3>'.concat(1===t?"Vérification KYC":2===t?"Authentification":3===t?"Signature":"Service Type "+t,'</h3>\n </div>\n <div class="sunuid-qr-image">\n <img src="').concat(n,'" alt="QR Code ').concat(s,'" style="max-width: 300px; border: 1px solid #ddd; border-radius: 5px;" />\n </div>\n \n '),i.appendChild(o),this.applyTheme(r.theme||this.config.theme),console.log("✅ QR code affiché:",n)}},{key:"generateCustomQRCode",value:(I=t(a().m(function e(n,t){var r,i;return a().w(function(e){for(;;)switch(e.p=e.n){case 0:if(console.log("🎨 Début génération QR personnalisé..."),console.log("📄 Contenu:",n),console.log("🏷️ Label:",t),(r=document.getElementById("sunuid-qr-container"))||(r=document.getElementById("qr-container")),r){e.n=1;break}return console.error("❌ QR container not found"),e.a(2);case 1:return console.log("✅ QR container trouvé"),r.innerHTML='<div style="text-align: center; padding: 20px;"><p>Génération QR code...</p></div>',e.p=2,console.log("🎨 Tentative génération via API principale..."),e.n=3,this.generateQRPHP(n,t,r);case 3:console.log("✅ QR code généré avec succès"),e.n=5;break;case 4:e.p=4,i=e.v,console.error("❌ Erreur génération API:",i),console.log("⚠️ Affichage image par défaut"),this.displayDefaultQR(r,n,t);case 5:return e.a(2)}},e,this,[[2,4]])})),function(e,n){return I.apply(this,arguments)})},{key:"generateQRClientSide",value:(b=t(a().m(function e(n,t,r){var i,o,s=this;return a().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.ensureQRCodeLibrary();case 1:if("undefined"!=typeof QRCode){e.n=2;break}throw new Error("QRCode library non disponible");case 2:return(i=document.createElement("canvas")).width=300,i.height=320,(o=i.getContext("2d")).fillStyle="#FFFFFF",o.fillRect(0,0,300,320),e.a(2,new Promise(function(e,a){QRCode.toCanvas(i,n,{width:280,margin:10,color:{dark:"#000000",light:"#FFFFFF"}},function(n){if(n)a(n);else{o.fillStyle="#333333",o.font="bold 14px Arial",o.textAlign="center",o.fillText(t,150,305);var c=i.toDataURL("image/png");s.currentQRUrl=c,r.innerHTML='\n <div style="text-align: center; padding: 20px;">\n <img src="'.concat(c,'" alt="QR Code" style="max-width: 300px; border: 2px solid #ddd; border-radius: 10px;">\n </div>\n '),s.showQRInstructions(r),e()}})}))}},e,this)})),function(e,n,t){return b.apply(this,arguments)})},{key:"generateQRPHP",value:(m=t(a().m(function e(n,t,r){var i,o,s,c,l,u;return a().w(function(e){for(;;)switch(e.n){case 0:return i=this.config.forceRemoteServer||this.config.apiUrl.includes("api.sunuid.fayma.sn")?"https://api.sunuid.fayma.sn/qr-generate":this.config.apiUrl.includes("localhost")||this.config.apiUrl.includes("127.0.0.1")?"http://localhost:8000/api/generate/text":this.config.apiUrl+"/qr-generate",console.log("🔗 URL QR Generator:",i),i.includes("localhost:8000")?(s="application/x-www-form-urlencoded",o=new URLSearchParams({text:n,size:300,margin:10,foreground_color:"000000",background_color:"FFFFFF"})):(s="application/json",o=JSON.stringify({type:this.config.type,client_id:this.config.clientId,secret_id:this.config.secretId,content:n,label:t})),e.n=1,fetch(i,{method:"POST",headers:{"Content-Type":s,Accept:"application/json"},body:o});case 1:if((c=e.v).ok){e.n=2;break}throw new Error("Erreur HTTP: ".concat(c.status));case 2:return e.n=3,c.json();case 3:if((l=e.v).success){e.n=4;break}throw new Error("Erreur QR: ".concat(l.error));case 4:u=i.includes("localhost:8000")?l.data_uri:"".concat("https://sunuid.fayma.sn").concat(l.data.qrcode),this.currentQRUrl=u,r.innerHTML='\n <div style="text-align: center; padding: 20px;">\n <img src="'.concat(u,'" alt="QR Code" style="max-width: 300px; border: 2px solid #ddd; border-radius: 10px;">\n </div>\n '),this.showQRInstructions(r);case 5:return e.a(2)}},e,this)})),function(e,n,t){return m.apply(this,arguments)})},{key:"displayDefaultQR",value:function(e,n,t){e.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;">📱</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(t,'</p>\n <p style="font-size: 10px; color: #999; margin-top: 5px;">Contenu: ').concat(n,"</p>\n </div>\n ")}},{key:"ensureQRCodeLibrary",value:(y=t(a().m(function e(){return a().w(function(e){for(;;)switch(e.n){case 0:if("undefined"==typeof QRCode){e.n=1;break}return console.log("✅ QRCode library déjà disponible"),e.a(2,!0);case 1:return console.log("📦 Chargement QRCode library..."),e.a(2,new Promise(function(e,n){var t=document.createElement("script");t.src="https://cdn.jsdelivr.net/npm/qrcode@1.5.3/lib/browser.min.js",t.onload=function(){setTimeout(function(){"undefined"!=typeof QRCode?(console.log("✅ QRCode library chargée"),e(!0)):(console.error("❌ QRCode non disponible après chargement"),n(new Error("QRCode library non disponible après chargement")))},200)},t.onerror=function(){console.error("❌ Erreur chargement QRCode library"),n(new Error("Erreur chargement QRCode library"))},document.head.appendChild(t)}))}},e)})),function(){return y.apply(this,arguments)})},{key:"showQRInstructions",value:function(e){var n=e.parentElement.querySelector(".sunuid-qr-instructions"),t=e.parentElement.querySelector(".sunuid-qr-status");n&&(n.style.display="block",n.classList.add("sunuid-qr-ready")),t&&(t.style.display="block",t.classList.add("sunuid-qr-ready"))}},{key:"addLogoToCenter",value:function(e,n,t,r,i){try{var o=new Image;o.onload=function(){var i=40,s=n+(r-i)/2,a=t+(r-i)/2;e.fillStyle="white",e.fillRect(s-2,a-2,44,44),e.drawImage(o,s,a,i,i)},o.src="src/logoqr.png"}catch(e){console.warn("Logo non disponible:",e)}}},{key:"displayFallbackImage",value:function(){console.log("⚠️ Affichage de l'image de fallback");var e=document.getElementById("sunuid-qr-container");e&&(e.innerHTML='\n <div style="text-align: center; padding: 20px; color: #666;">\n <p>⚠️ Génération QR personnalisé non disponible</p>\n <p>Utilisation de l\'image par défaut</p>\n <p><strong>Debug:</strong> QRCode disponible: '.concat("undefined"!=typeof QRCode,"</p>\n <p><strong>Debug:</strong> Container trouvé: ").concat(null!==e,"</p>\n </div>\n "))}},{key:"displayServiceUnavailable",value:function(e,n){console.log("displayServiceUnavailable appelée pour ".concat(e,", type: ").concat(n));var t=document.getElementById(e);t?t.innerHTML='\n <div class="sunuid-service-unavailable" style="\n text-align: center;\n padding: 40px 20px;\n background: #f8f9fa;\n border: 2px dashed #dee2e6;\n border-radius: 10px;\n color: #6c757d;\n font-family: Arial, sans-serif;\n ">\n <div style="font-size: 48px; margin-bottom: 20px;">⚠️</div>\n <h3 style="margin: 0 0 10px 0; color: #495057;">Service Non Disponible</h3>\n <p style="margin: 0; font-size: 14px;">\n Le service d\'authentification est temporairement indisponible.<br>\n Veuillez réessayer plus tard.\n </p>\n <div style="margin-top: 20px; font-size: 12px; color: #adb5bd;">\n Type: '.concat(String(n).toUpperCase(),"\n </div>\n </div>\n "):console.error("Container ".concat(e," non trouvé"))}},{key:"refreshQR",value:(v=t(a().m(function e(n){var t,r,i,o,s=arguments;return a().w(function(e){for(;;)switch(e.p=e.n){case 0:if(t=s.length>1&&void 0!==s[1]?s[1]:{},e.p=1,!this.currentQRUrl){e.n=3;break}return console.log("🔄 Vérification du statut du QR code existant..."),e.n=2,this.generateQR(n,t);case 2:return r=e.v,e.a(2,r);case 3:return console.log("🔄 Pas de QR code existant, génération d'un nouveau..."),e.n=4,this.generateQR(n,t);case 4:return i=e.v,e.a(2,i);case 5:e.n=7;break;case 6:throw e.p=6,o=e.v,console.error("Erreur lors du rafraîchissement:",o.message),this.displayServiceUnavailable(n,this.config.type),o;case 7:return e.a(2)}},e,this,[[1,6]])})),function(e){return v.apply(this,arguments)})},{key:"startAutoRefresh",value:function(e,n,r){var i=this;this.config.autoRefresh&&(this.refreshTimer&&(clearInterval(this.refreshTimer),console.log("🔄 Timer de rafraîchissement précédent arrêté")),this.refreshTimer=setInterval(t(a().m(function t(){var o;return a().w(function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,console.log("🔄 Rafraîchissement automatique du QR code..."),t.n=1,i.refreshQR(e,n,r);case 1:t.n=3;break;case 2:t.p=2,o=t.v,console.warn("Erreur lors du rafraîchissement automatique:",o);case 3:return t.a(2)}},t,null,[[0,2]])})),this.config.refreshInterval),console.log("🔄 Timer de rafraîchissement démarré (".concat(this.config.refreshInterval,"ms)")))}},{key:"makeRequest",value:(g=t(a().m(function n(t,r){var i,o,s,c,u,d,f,p,h,g=this;return a().w(function(n){for(;;)switch(n.n){case 0:if(this.isInitialized){n.n=1;break}throw this.logSecurityEvent("REQUEST_BEFORE_INIT",{endpoint:t}),new Error("SDK non initialisé");case 1:if(!this.config.secureInit){n.n=2;break}if(this.config.requestCount++,!(this.config.requestCount>this.config.maxRequests)){n.n=2;break}throw this.logSecurityEvent("API_REQUEST_LIMIT_EXCEEDED",{requestCount:this.config.requestCount,maxRequests:this.config.maxRequests}),new Error("Limite de requêtes dépassée");case 2:s=this.sanitizeRequestData(r),console.log("🔍 Debug makeRequest - endpoint:",t),console.log("🔍 Debug makeRequest - apiUrl:",this.config.apiUrl),console.log("🔍 Debug makeRequest - url:","".concat(this.config.apiUrl).concat(t)),console.log("🔍 Debug makeRequest - data:",JSON.stringify(s,null,2)),console.log("🔍 Debug makeRequest - secureInit:",this.config.secureInit),console.log("🔍 Debug makeRequest - isInitialized:",this.isInitialized),c=(null===(i=e.SunuIDConfig)||void 0===i||null===(i=i.endpoints)||void 0===i?void 0:i[t.replace("/","")])||t,u="".concat(this.config.apiUrl).concat(c),console.log("🔍 URL finale construite:",u),console.log("🔍 EndpointPath:",c),console.log("🔍 SunuIDConfig endpoints:",JSON.stringify(null===(o=e.SunuIDConfig)||void 0===o?void 0:o.endpoints)),this.logSecurityEvent("API_REQUEST_START",{endpoint:c,url:u,dataKeys:Object.keys(s),secureInit:this.config.secureInit}),d=0,f=this.config.maxRetries,p=a().m(function e(){var n,t,r,i,o,l,p,h;return a().w(function(e){for(;;)switch(e.p=e.n){case 0:return e.p=0,n=new AbortController,t=setTimeout(function(){return n.abort()},g.config.requestTimeout),r={"Content-Type":"application/json"},e.n=1,fetch(u,{method:"POST",headers:r,body:JSON.stringify(s),signal:n.signal});case 1:if(i=e.v,clearTimeout(t),i.ok){e.n=3;break}return e.n=2,i.text();case 2:o=e.v;try{l=JSON.parse(o)}catch(e){l={message:o}}throw g.logSecurityEvent("API_REQUEST_ERROR",{status:i.status,statusText:i.statusText,error:l.message}),new Error(l.message||"Erreur HTTP: ".concat(i.status));case 3:return e.n=4,i.json();case 4:return p=e.v,g.logSecurityEvent("API_REQUEST_SUCCESS",{endpoint:c,responseKeys:Object.keys(p)}),e.a(2,{v:p});case 5:if(e.p=5,h=e.v,d++,"AbortError"!==h.name){e.n=7;break}if(g.logSecurityEvent("API_REQUEST_TIMEOUT",{retryCount:d}),!(d>f)){e.n=6;break}throw new Error("Timeout de la requête API");case 6:return e.a(2,0);case 7:if(!(d>f)){e.n=8;break}throw g.logSecurityEvent("API_REQUEST_MAX_RETRIES",{retryCount:d,error:h.message}),h;case 8:return e.n=9,new Promise(function(e){return setTimeout(e,1e3*d)});case 9:return e.a(2)}},e,null,[[0,5]])});case 3:if(!(d<=f)){n.n=7;break}return n.d(l(p()),4);case 4:if(0!==(h=n.v)){n.n=5;break}return n.a(3,3);case 5:if(!h){n.n=6;break}return n.a(2,h.v);case 6:n.n=3;break;case 7:return n.a(2)}},n,this)})),function(e,n){return g.apply(this,arguments)})},{key:"sanitizeRequestData",value:function(e){for(var n={},t=0,r=Object.entries(e);t<r.length;t++){var i=u(r[t],2),o=i[0],s=i[1];"string"==typeof s?n[o]=this.sanitizeInput(s):"object"===f(s)&&null!==s?n[o]=this.sanitizeRequestData(s):n[o]=s}return n.client_id=this.config.originalClientId||this.config.clientId,n.secret_id=this.config.originalSecretId||this.config.secretId,console.log("🔍 Credentials dans sanitizeRequestData - clientId:",this.config.clientId),console.log("🔍 Credentials dans sanitizeRequestData - secretId:",this.config.secretId?"***"+this.config.secretId.slice(-4):"null"),console.log("🔍 Credentials dans sanitizeRequestData - sanitizedClientId:",n.client_id),console.log("🔍 Credentials dans sanitizeRequestData - sanitizedSecretId:",n.secret_id?"***"+n.secret_id.slice(-4):"null"),console.log("🔍 Credentials dans sanitizeRequestData - data complet:",JSON.stringify(n,null,2)),console.log("🔍 Credentials dans sanitizeRequestData - clientId:",this.config.clientId),console.log("🔍 Credentials dans sanitizeRequestData - secretId:",this.config.secretId?"***"+this.config.secretId.slice(-4):"null"),console.log("🔍 Credentials dans sanitizeRequestData - sanitizedClientId:",n.client_id),console.log("🔍 Credentials dans sanitizeRequestData - sanitizedSecretId:",n.secret_id?"***"+n.secret_id.slice(-4):"null"),console.log("🔍 Credentials dans sanitizeRequestData - data complet:",JSON.stringify(n,null,2)),n}},{key:"generateRequestId",value:function(){return"req_"+Date.now()+"_"+Math.random().toString(36).substr(2,9)}},{key:"generateSessionCode",value:function(){var e=Date.now(),n=Math.random().toString(36).substr(2,9),t="".concat(e,"_").concat(n);return btoa(t)}},{key:"fetchPartnerInfo",value:(h=t(a().m(function e(){var n,t,r;return a().w(function(e){for(;;)switch(e.p=e.n){case 0:return e.p=0,e.n=1,this.makeRequest("/debug",{type:this.config.type,client_id:this.config.clientId,secret_id:this.config.secretId});case 1:n=e.v,console.log("📋 Réponse debug API:",n),n.success&&n.authentication&&n.authentication.auth_test?(t=n.authentication.auth_test,this.config.partnerId=t.partner_id,n.service_id?this.config.serviceId=n.service_id:this.config.serviceId=t.partner_id,21===t.partner_id?this.config.partnerName="Fayma":this.config.partnerName="Partner_".concat(t.partner_id),console.log("✅ Informations partenaire récupérées:",{partnerName:this.config.partnerName,partnerId:this.config.partnerId,serviceId:this.config.serviceId})):(console.warn("⚠️ Impossible de récupérer les informations du partenaire, utilisation du partner_id"),this.config.partnerName="Partner_".concat(this.config.partnerId||"unknown")),e.n=3;break;case 2:e.p=2,r=e.v,console.warn("⚠️ Erreur lors de la récupération des informations du partenaire:",r.message),this.config.partnerName="Partner_unknown";case 3:return e.a(2)}},e,this,[[0,2]])})),function(){return h.apply(this,arguments)})},{key:"applyTheme",value:function(e){var n=document.querySelector(".sunuid-qr-code");n&&(n.className="sunuid-qr-code sunuid-theme-".concat(e))}},{key:"handleError",value:function(e){console.error("SunuID SDK Error:",e),this.config.onError&&this.config.onError(e)}},{key:"checkConnections",value:(p=t(a().m(function e(){var n,t,r,i;return a().w(function(e){for(;;)switch(e.p=e.n){case 0:return n={api:!1,websocket:!1,ready:!1},e.p=1,e.n=2,fetch(this.config.apiUrl+"/debug",{method:"GET",timeout:3e3});case 2:if(!(t=e.v).ok){e.n=4;break}return e.n=3,t.json();case 3:r=e.v,n.api="operational"===r.status,console.log("🔍 API Status:",r.status),e.n=5;break;case 4:n.api=!1;case 5:e.n=7;break;case 6:e.p=6,i=e.v,console.log("🔍 Test API échoué:",i.message),n.api=!1;case 7:return n.websocket=this.socket&&this.socket.connected,n.ready=n.api,e.a(2,n)}},e,this,[[1,6]])})),function(){return p.apply(this,arguments)})},{key:"waitForConnections",value:(d=t(a().m(function e(){var n,t,r,i=arguments;return a().w(function(e){for(;;)switch(e.n){case 0:n=i.length>0&&void 0!==i[0]?i[0]:5e3,t=Date.now();case 1:if(!(Date.now()-t<n)){e.n=5;break}return e.n=2,this.checkConnections();case 2:if(!(r=e.v).ready){e.n=3;break}return console.log("✅ Connexions prêtes"),e.a(2,r);case 3:return console.log("⏳ Attente connexions...",r),e.n=4,new Promise(function(e){return setTimeout(e,1e3)});case 4:e.n=1;break;case 5:throw new Error("Timeout connexions - Impossible de générer le QR code");case 6:return e.a(2)}},e,this)})),function(){return d.apply(this,arguments)})},{key:"getQRCode",value:function(){return this.currentQRUrl?this.currentQRUrl:null}},{key:"destroy",value:function(){this.stopAutoRefresh(),this.socket&&(this.socket.disconnect(),this.socket=null,console.log("🌐 WebSocket déconnecté")),this.isInitialized=!1,this.logSecurityEvent("SDK_DESTROY"),console.log("SunuID SDK détruit")}},{key:"stopAutoRefresh",value:function(){this.refreshTimer&&(clearInterval(this.refreshTimer),this.refreshTimer=null,console.log("🔄 Timer de rafraîchissement arrêté"))}},{key:"getSecurityLogs",value:function(){return e.SunuIDSecurityLogs||[]}},{key:"clearSecurityLogs",value:function(){e.SunuIDSecurityLogs=[],this.logSecurityEvent("SECURITY_LOGS_CLEARED")}}],i&&r(n.prototype,i),o&&r(n,o),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,i,o,d,p,h,g,v,y,m,b,I,k,S,R,w,E,C,Q,T,x,q,_}();e.SunuID=d,e.sunuidInstance=null,e.initSunuID=function(n){try{return e.sunuidInstance=new d(n),e.sunuidInstance}catch(e){throw console.error("Erreur lors de l'initialisation de SunuID:",e),e}}}(window)}();
|
|
11
11
|
//# sourceMappingURL=sunuid-sdk.min.js.map
|