sunuid-sdk 1.0.28 → 1.0.30
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/dist/sunuid-sdk.esm.js +115 -24
- package/dist/sunuid-sdk.esm.js.map +1 -1
- package/dist/sunuid-sdk.js +115 -24
- package/dist/sunuid-sdk.js.map +1 -1
- package/dist/sunuid-sdk.min.js +1 -1
- package/dist/sunuid-sdk.min.js.map +1 -1
- package/package.json +1 -1
package/dist/sunuid-sdk.js
CHANGED
|
@@ -274,7 +274,7 @@
|
|
|
274
274
|
* @license MIT
|
|
275
275
|
*/
|
|
276
276
|
|
|
277
|
-
(function (window, _window$SunuIDConfig
|
|
277
|
+
(function (window, _window$SunuIDConfig) {
|
|
278
278
|
|
|
279
279
|
// Configuration par défaut
|
|
280
280
|
var DEFAULT_CONFIG = {
|
|
@@ -302,7 +302,12 @@
|
|
|
302
302
|
// 10 secondes
|
|
303
303
|
// Options d'initialisation sécurisée
|
|
304
304
|
secureInit: false,
|
|
305
|
-
secureInitUrl:
|
|
305
|
+
secureInitUrl: function (_window$SunuIDConfig2, _window$SunuIDConfig3) {
|
|
306
|
+
if ((_window$SunuIDConfig2 = window.SunuIDConfig) !== null && _window$SunuIDConfig2 !== void 0 && (_window$SunuIDConfig2 = _window$SunuIDConfig2.apiUrl) !== null && _window$SunuIDConfig2 !== void 0 && _window$SunuIDConfig2.includes('api.sunuid.fayma.sn')) {
|
|
307
|
+
return 'https://sunuid.fayma.sn/secure-init.php';
|
|
308
|
+
}
|
|
309
|
+
return ((_window$SunuIDConfig3 = window.SunuIDConfig) === null || _window$SunuIDConfig3 === void 0 || (_window$SunuIDConfig3 = _window$SunuIDConfig3.apiUrl) === null || _window$SunuIDConfig3 === void 0 ? void 0 : _window$SunuIDConfig3.replace('/api', '')) + '/secure-init.php' || 'https://sunuid.fayma.sn/secure-init.php';
|
|
310
|
+
}(),
|
|
306
311
|
token: null
|
|
307
312
|
};
|
|
308
313
|
|
|
@@ -1187,7 +1192,7 @@
|
|
|
1187
1192
|
key: "generateCustomQRCode",
|
|
1188
1193
|
value: (function () {
|
|
1189
1194
|
var _generateCustomQRCode = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(content, label) {
|
|
1190
|
-
var
|
|
1195
|
+
var _qrContainer,
|
|
1191
1196
|
qrGeneratorUrl,
|
|
1192
1197
|
_response3,
|
|
1193
1198
|
responseData,
|
|
@@ -1201,8 +1206,8 @@
|
|
|
1201
1206
|
console.log('🎨 Début génération QR personnalisé avec PHP...');
|
|
1202
1207
|
console.log('📄 Contenu:', content);
|
|
1203
1208
|
console.log('🏷️ Label:', label);
|
|
1204
|
-
|
|
1205
|
-
if (
|
|
1209
|
+
_qrContainer = document.getElementById('sunuid-qr-container');
|
|
1210
|
+
if (_qrContainer) {
|
|
1206
1211
|
_context9.n = 2;
|
|
1207
1212
|
break;
|
|
1208
1213
|
}
|
|
@@ -1213,11 +1218,18 @@
|
|
|
1213
1218
|
console.log('✅ QR container trouvé');
|
|
1214
1219
|
|
|
1215
1220
|
// Nettoyer le conteneur
|
|
1216
|
-
|
|
1221
|
+
_qrContainer.innerHTML = '<div style="text-align: center; padding: 20px;"><p>Génération QR code avec PHP...</p></div>';
|
|
1217
1222
|
|
|
1218
1223
|
// Appeler l'endpoint PHP
|
|
1219
1224
|
console.log('🔄 Appel endpoint PHP...');
|
|
1220
|
-
|
|
1225
|
+
// Construire l'URL du QR generator de manière plus robuste
|
|
1226
|
+
|
|
1227
|
+
if (this.config.apiUrl.includes('api.sunuid.fayma.sn')) {
|
|
1228
|
+
qrGeneratorUrl = 'https://sunuid.fayma.sn/qr-generator.php';
|
|
1229
|
+
} else {
|
|
1230
|
+
qrGeneratorUrl = this.config.apiUrl.replace('/api', '') + '/qr-generator.php';
|
|
1231
|
+
}
|
|
1232
|
+
console.log('🔗 URL QR Generator:', qrGeneratorUrl);
|
|
1221
1233
|
_context9.n = 3;
|
|
1222
1234
|
return fetch(qrGeneratorUrl, {
|
|
1223
1235
|
method: 'POST',
|
|
@@ -1259,11 +1271,11 @@
|
|
|
1259
1271
|
this.currentQRUrl = responseData.data.dataUrl;
|
|
1260
1272
|
|
|
1261
1273
|
// Créer le conteneur avec le QR code PHP
|
|
1262
|
-
|
|
1274
|
+
_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 ");
|
|
1263
1275
|
|
|
1264
1276
|
// Afficher les instructions et le statut maintenant que le QR est prêt
|
|
1265
|
-
instructionsElement =
|
|
1266
|
-
statusElement =
|
|
1277
|
+
instructionsElement = _qrContainer.parentElement.querySelector('.sunuid-qr-instructions');
|
|
1278
|
+
statusElement = _qrContainer.parentElement.querySelector('.sunuid-qr-status');
|
|
1267
1279
|
if (instructionsElement) {
|
|
1268
1280
|
instructionsElement.style.display = 'block';
|
|
1269
1281
|
instructionsElement.classList.add('sunuid-qr-ready');
|
|
@@ -1280,7 +1292,14 @@
|
|
|
1280
1292
|
_t6 = _context9.v;
|
|
1281
1293
|
console.error('❌ Erreur génération QR PHP:', _t6);
|
|
1282
1294
|
console.error('Stack trace:', _t6.stack);
|
|
1283
|
-
|
|
1295
|
+
|
|
1296
|
+
// Détecter les erreurs CORS spécifiquement
|
|
1297
|
+
if (_t6.message.includes('Failed to fetch') || _t6.message.includes('CORS')) {
|
|
1298
|
+
console.warn('🚫 Erreur CORS détectée, tentative de génération QR côté client...');
|
|
1299
|
+
this.generateQRCodeClientSide(content, label, qrContainer);
|
|
1300
|
+
} else {
|
|
1301
|
+
this.displayFallbackImage();
|
|
1302
|
+
}
|
|
1284
1303
|
case 8:
|
|
1285
1304
|
return _context9.a(2);
|
|
1286
1305
|
}
|
|
@@ -1292,9 +1311,81 @@
|
|
|
1292
1311
|
return generateCustomQRCode;
|
|
1293
1312
|
}()
|
|
1294
1313
|
/**
|
|
1295
|
-
*
|
|
1314
|
+
* Générer un QR code côté client en cas d'erreur CORS
|
|
1296
1315
|
*/
|
|
1297
1316
|
)
|
|
1317
|
+
}, {
|
|
1318
|
+
key: "generateQRCodeClientSide",
|
|
1319
|
+
value: function generateQRCodeClientSide(content, label, qrContainer) {
|
|
1320
|
+
var _this4 = this;
|
|
1321
|
+
try {
|
|
1322
|
+
console.log('🎨 Génération QR côté client...');
|
|
1323
|
+
|
|
1324
|
+
// Vérifier si QRCode est disponible
|
|
1325
|
+
if (typeof QRCode === 'undefined') {
|
|
1326
|
+
console.error('❌ QRCode library non disponible');
|
|
1327
|
+
this.displayFallbackImage();
|
|
1328
|
+
return;
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
// Créer un canvas pour le QR code
|
|
1332
|
+
var canvas = document.createElement('canvas');
|
|
1333
|
+
canvas.width = 300;
|
|
1334
|
+
canvas.height = 300;
|
|
1335
|
+
var ctx = canvas.getContext('2d');
|
|
1336
|
+
|
|
1337
|
+
// Générer le QR code avec QRCode library
|
|
1338
|
+
QRCode.toCanvas(canvas, content, {
|
|
1339
|
+
width: 280,
|
|
1340
|
+
margin: 10,
|
|
1341
|
+
color: {
|
|
1342
|
+
dark: '#000000',
|
|
1343
|
+
light: '#FFFFFF'
|
|
1344
|
+
}
|
|
1345
|
+
}, function (error) {
|
|
1346
|
+
if (error) {
|
|
1347
|
+
console.error('❌ Erreur génération QR côté client:', error);
|
|
1348
|
+
_this4.displayFallbackImage();
|
|
1349
|
+
return;
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
// Ajouter le label en bas du QR code
|
|
1353
|
+
ctx.fillStyle = '#333333';
|
|
1354
|
+
ctx.font = '14px Arial';
|
|
1355
|
+
ctx.textAlign = 'center';
|
|
1356
|
+
ctx.fillText(label, 150, 295);
|
|
1357
|
+
|
|
1358
|
+
// Convertir en data URL
|
|
1359
|
+
var dataUrl = canvas.toDataURL('image/png');
|
|
1360
|
+
|
|
1361
|
+
// Stocker l'URL du QR code pour getQRCode()
|
|
1362
|
+
_this4.currentQRUrl = dataUrl;
|
|
1363
|
+
|
|
1364
|
+
// Afficher le QR code
|
|
1365
|
+
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 ");
|
|
1366
|
+
|
|
1367
|
+
// Afficher les instructions et le statut
|
|
1368
|
+
var instructionsElement = qrContainer.parentElement.querySelector('.sunuid-qr-instructions');
|
|
1369
|
+
var statusElement = qrContainer.parentElement.querySelector('.sunuid-qr-status');
|
|
1370
|
+
if (instructionsElement) {
|
|
1371
|
+
instructionsElement.style.display = 'block';
|
|
1372
|
+
instructionsElement.classList.add('sunuid-qr-ready');
|
|
1373
|
+
}
|
|
1374
|
+
if (statusElement) {
|
|
1375
|
+
statusElement.style.display = 'block';
|
|
1376
|
+
statusElement.classList.add('sunuid-qr-ready');
|
|
1377
|
+
}
|
|
1378
|
+
console.log('✅ QR code côté client généré avec succès');
|
|
1379
|
+
});
|
|
1380
|
+
} catch (error) {
|
|
1381
|
+
console.error('❌ Erreur génération QR côté client:', error);
|
|
1382
|
+
this.displayFallbackImage();
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
/**
|
|
1387
|
+
* Ajouter le logo au centre du QR code
|
|
1388
|
+
*/
|
|
1298
1389
|
}, {
|
|
1299
1390
|
key: "addLogoToCenter",
|
|
1300
1391
|
value: function addLogoToCenter(ctx, x, y, width, height) {
|
|
@@ -1393,7 +1484,7 @@
|
|
|
1393
1484
|
}, {
|
|
1394
1485
|
key: "startAutoRefresh",
|
|
1395
1486
|
value: function startAutoRefresh(containerId, type, options) {
|
|
1396
|
-
var
|
|
1487
|
+
var _this5 = this;
|
|
1397
1488
|
if (!this.config.autoRefresh) return;
|
|
1398
1489
|
this.refreshTimer = setInterval(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1() {
|
|
1399
1490
|
var _t8;
|
|
@@ -1402,7 +1493,7 @@
|
|
|
1402
1493
|
case 0:
|
|
1403
1494
|
_context1.p = 0;
|
|
1404
1495
|
_context1.n = 1;
|
|
1405
|
-
return
|
|
1496
|
+
return _this5.refreshQR(containerId, type, options);
|
|
1406
1497
|
case 1:
|
|
1407
1498
|
_context1.n = 3;
|
|
1408
1499
|
break;
|
|
@@ -1428,9 +1519,9 @@
|
|
|
1428
1519
|
key: "makeRequest",
|
|
1429
1520
|
value: (function () {
|
|
1430
1521
|
var _makeRequest = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10(endpoint, data) {
|
|
1431
|
-
var _window$
|
|
1432
|
-
_window$
|
|
1433
|
-
|
|
1522
|
+
var _window$SunuIDConfig4,
|
|
1523
|
+
_window$SunuIDConfig5,
|
|
1524
|
+
_this6 = this;
|
|
1434
1525
|
var sanitizedData, endpointPath, url, retryCount, maxRetries, _loop, _ret;
|
|
1435
1526
|
return _regenerator().w(function (_context11) {
|
|
1436
1527
|
while (1) switch (_context11.n) {
|
|
@@ -1469,11 +1560,11 @@
|
|
|
1469
1560
|
console.log('🔍 Debug makeRequest - isInitialized:', this.isInitialized);
|
|
1470
1561
|
|
|
1471
1562
|
// Utiliser l'endpoint depuis la configuration si disponible
|
|
1472
|
-
endpointPath = ((_window$
|
|
1563
|
+
endpointPath = ((_window$SunuIDConfig4 = window.SunuIDConfig) === null || _window$SunuIDConfig4 === void 0 || (_window$SunuIDConfig4 = _window$SunuIDConfig4.endpoints) === null || _window$SunuIDConfig4 === void 0 ? void 0 : _window$SunuIDConfig4[endpoint.replace('/', '')]) || endpoint;
|
|
1473
1564
|
url = "".concat(this.config.apiUrl).concat(endpointPath); // Debug: Afficher l'URL finale
|
|
1474
1565
|
console.log('🔍 URL finale construite:', url);
|
|
1475
1566
|
console.log('🔍 EndpointPath:', endpointPath);
|
|
1476
|
-
console.log('🔍 SunuIDConfig endpoints:', JSON.stringify((_window$
|
|
1567
|
+
console.log('🔍 SunuIDConfig endpoints:', JSON.stringify((_window$SunuIDConfig5 = window.SunuIDConfig) === null || _window$SunuIDConfig5 === void 0 ? void 0 : _window$SunuIDConfig5.endpoints));
|
|
1477
1568
|
|
|
1478
1569
|
// Log de sécurité pour la requête
|
|
1479
1570
|
this.logSecurityEvent('API_REQUEST_START', {
|
|
@@ -1493,7 +1584,7 @@
|
|
|
1493
1584
|
controller = new AbortController();
|
|
1494
1585
|
timeoutId = setTimeout(function () {
|
|
1495
1586
|
return controller.abort();
|
|
1496
|
-
},
|
|
1587
|
+
}, _this6.config.requestTimeout); // Headers minimaux (API SunuID n'accepte que les headers essentiels)
|
|
1497
1588
|
headers = {
|
|
1498
1589
|
'Content-Type': 'application/json'
|
|
1499
1590
|
}; // Note: En mode sécurisé, les credentials sont dans le body
|
|
@@ -1526,7 +1617,7 @@
|
|
|
1526
1617
|
message: errorText
|
|
1527
1618
|
};
|
|
1528
1619
|
}
|
|
1529
|
-
|
|
1620
|
+
_this6.logSecurityEvent('API_REQUEST_ERROR', {
|
|
1530
1621
|
status: _response4.status,
|
|
1531
1622
|
statusText: _response4.statusText,
|
|
1532
1623
|
error: errorData.message
|
|
@@ -1537,7 +1628,7 @@
|
|
|
1537
1628
|
return _response4.json();
|
|
1538
1629
|
case 4:
|
|
1539
1630
|
result = _context10.v;
|
|
1540
|
-
|
|
1631
|
+
_this6.logSecurityEvent('API_REQUEST_SUCCESS', {
|
|
1541
1632
|
endpoint: endpointPath,
|
|
1542
1633
|
responseKeys: Object.keys(result)
|
|
1543
1634
|
});
|
|
@@ -1552,7 +1643,7 @@
|
|
|
1552
1643
|
_context10.n = 7;
|
|
1553
1644
|
break;
|
|
1554
1645
|
}
|
|
1555
|
-
|
|
1646
|
+
_this6.logSecurityEvent('API_REQUEST_TIMEOUT', {
|
|
1556
1647
|
retryCount: retryCount
|
|
1557
1648
|
});
|
|
1558
1649
|
if (!(retryCount > maxRetries)) {
|
|
@@ -1567,7 +1658,7 @@
|
|
|
1567
1658
|
_context10.n = 8;
|
|
1568
1659
|
break;
|
|
1569
1660
|
}
|
|
1570
|
-
|
|
1661
|
+
_this6.logSecurityEvent('API_REQUEST_MAX_RETRIES', {
|
|
1571
1662
|
retryCount: retryCount,
|
|
1572
1663
|
error: _t9.message
|
|
1573
1664
|
});
|