sunuid-sdk 1.0.18 → 1.0.19

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.
@@ -207,6 +207,8 @@
207
207
  apiUrl: ((_window$SunuIDConfig = window.SunuIDConfig) === null || _window$SunuIDConfig === void 0 ? void 0 : _window$SunuIDConfig.apiUrl) || 'https://api.sunuid.fayma.sn',
208
208
  clientId: null,
209
209
  secretId: null,
210
+ type: 1,
211
+ // Type par défaut (1 = authentification)
210
212
  theme: 'light',
211
213
  language: 'fr',
212
214
  autoRefresh: true,
@@ -244,12 +246,12 @@
244
246
  }
245
247
 
246
248
  /**
247
- * Générer un QR code d'authentification
249
+ * Générer un QR code avec le type configuré
248
250
  */
249
251
  }, {
250
- key: "generateAuthQR",
252
+ key: "generateQR",
251
253
  value: (function () {
252
- var _generateAuthQR = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(containerId) {
254
+ var _generateQR = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(containerId) {
253
255
  var options,
254
256
  response,
255
257
  imageBaseUrl,
@@ -269,7 +271,7 @@
269
271
  _context.p = 1;
270
272
  _context.n = 2;
271
273
  return this.makeRequest('/qr-generate', _objectSpread2({
272
- type: 1
274
+ type: this.config.type
273
275
  }, options));
274
276
  case 2:
275
277
  response = _context.v;
@@ -280,8 +282,8 @@
280
282
  // Construire l'URL complète de l'image QR avec la base URL pour les images
281
283
  imageBaseUrl = 'https://sunuid.fayma.sn';
282
284
  qrImageUrl = "".concat(imageBaseUrl).concat(response.data.qrcode);
283
- this.displayQRCode(containerId, qrImageUrl, 'auth', options);
284
- this.startAutoRefresh(containerId, 'auth', options);
285
+ this.displayQRCode(containerId, qrImageUrl, this.config.type, options);
286
+ this.startAutoRefresh(containerId, this.config.type, options);
285
287
  return _context.a(2, _objectSpread2(_objectSpread2({}, response.data), {}, {
286
288
  qrCodeUrl: qrImageUrl,
287
289
  sessionId: response.data.service_id
@@ -295,27 +297,27 @@
295
297
  _context.p = 5;
296
298
  _t = _context.v;
297
299
  console.error('Erreur API détectée:', _t.message);
298
- console.log('Affichage du message "Service non disponible" pour auth');
299
- this.displayServiceUnavailable(containerId, 'auth');
300
+ console.log('Affichage du message "Service non disponible" pour type ' + this.config.type);
301
+ this.displayServiceUnavailable(containerId, this.config.type);
300
302
  throw new Error('Service non disponible');
301
303
  case 6:
302
304
  return _context.a(2);
303
305
  }
304
306
  }, _callee, this, [[1, 5]]);
305
307
  }));
306
- function generateAuthQR(_x) {
307
- return _generateAuthQR.apply(this, arguments);
308
+ function generateQR(_x) {
309
+ return _generateQR.apply(this, arguments);
308
310
  }
309
- return generateAuthQR;
311
+ return generateQR;
310
312
  }()
311
313
  /**
312
- * Générer un QR code KYC
314
+ * Générer un QR code avec un type personnalisé
313
315
  */
314
316
  )
315
317
  }, {
316
- key: "generateKYCQR",
318
+ key: "generateCustomQR",
317
319
  value: (function () {
318
- var _generateKYCQR = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(containerId) {
320
+ var _generateCustomQR = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(containerId, type) {
319
321
  var options,
320
322
  response,
321
323
  imageBaseUrl,
@@ -325,7 +327,7 @@
325
327
  return _regenerator().w(function (_context2) {
326
328
  while (1) switch (_context2.p = _context2.n) {
327
329
  case 0:
328
- options = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : {};
330
+ options = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : {};
329
331
  if (this.isInitialized) {
330
332
  _context2.n = 1;
331
333
  break;
@@ -335,7 +337,7 @@
335
337
  _context2.p = 1;
336
338
  _context2.n = 2;
337
339
  return this.makeRequest('/qr-generate', _objectSpread2({
338
- type: 2
340
+ type: type
339
341
  }, options));
340
342
  case 2:
341
343
  response = _context2.v;
@@ -346,14 +348,14 @@
346
348
  // Construire l'URL complète de l'image QR avec la base URL pour les images
347
349
  imageBaseUrl = 'https://sunuid.fayma.sn';
348
350
  qrImageUrl = "".concat(imageBaseUrl).concat(response.data.qrcode);
349
- this.displayQRCode(containerId, qrImageUrl, 'kyc', options);
350
- this.startAutoRefresh(containerId, 'kyc', options);
351
+ this.displayQRCode(containerId, qrImageUrl, type, options);
352
+ this.startAutoRefresh(containerId, type, options);
351
353
  return _context2.a(2, _objectSpread2(_objectSpread2({}, response.data), {}, {
352
354
  qrCodeUrl: qrImageUrl,
353
355
  sessionId: response.data.service_id
354
356
  }));
355
357
  case 3:
356
- throw new Error(response.message || 'Erreur lors de la génération du QR code KYC');
358
+ throw new Error(response.message || 'Erreur lors de la génération du QR code');
357
359
  case 4:
358
360
  _context2.n = 6;
359
361
  break;
@@ -361,131 +363,118 @@
361
363
  _context2.p = 5;
362
364
  _t2 = _context2.v;
363
365
  console.error('Erreur API détectée:', _t2.message);
364
- console.log('Affichage du message "Service non disponible" pour kyc');
365
- this.displayServiceUnavailable(containerId, 'kyc');
366
+ console.log('Affichage du message "Service non disponible" pour type ' + type);
367
+ this.displayServiceUnavailable(containerId, type);
366
368
  throw new Error('Service non disponible');
367
369
  case 6:
368
370
  return _context2.a(2);
369
371
  }
370
372
  }, _callee2, this, [[1, 5]]);
371
373
  }));
372
- function generateKYCQR(_x2) {
373
- return _generateKYCQR.apply(this, arguments);
374
+ function generateCustomQR(_x2, _x3) {
375
+ return _generateCustomQR.apply(this, arguments);
374
376
  }
375
- return generateKYCQR;
376
- }()
377
- /**
378
- * Générer un QR code avec un type personnalisé
379
- */
377
+ return generateCustomQR;
378
+ }() // Alias pour maintenir la compatibilité
380
379
  )
381
380
  }, {
382
- key: "generateCustomQR",
383
- value: (function () {
384
- var _generateCustomQR = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(containerId, type) {
381
+ key: "generateAuthQR",
382
+ value: function () {
383
+ var _generateAuthQR = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(containerId) {
385
384
  var options,
386
- response,
387
- imageBaseUrl,
388
- qrImageUrl,
389
- _args3 = arguments,
390
- _t3;
385
+ _args3 = arguments;
391
386
  return _regenerator().w(function (_context3) {
392
- while (1) switch (_context3.p = _context3.n) {
387
+ while (1) switch (_context3.n) {
393
388
  case 0:
394
- options = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : {};
395
- if (this.isInitialized) {
396
- _context3.n = 1;
397
- break;
398
- }
399
- throw new Error('SunuID: SDK non initialisé');
400
- case 1:
401
- _context3.p = 1;
402
- _context3.n = 2;
403
- return this.makeRequest('/qr-generate', _objectSpread2({
404
- type: type
405
- }, options));
389
+ options = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : {};
390
+ return _context3.a(2, this.generateQR(containerId, options));
391
+ }
392
+ }, _callee3, this);
393
+ }));
394
+ function generateAuthQR(_x4) {
395
+ return _generateAuthQR.apply(this, arguments);
396
+ }
397
+ return generateAuthQR;
398
+ }()
399
+ }, {
400
+ key: "generateKYCQR",
401
+ value: function () {
402
+ var _generateKYCQR = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(containerId) {
403
+ var options,
404
+ originalType,
405
+ _args4 = arguments;
406
+ return _regenerator().w(function (_context4) {
407
+ while (1) switch (_context4.p = _context4.n) {
408
+ case 0:
409
+ options = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : {};
410
+ // Sauvegarder le type actuel
411
+ originalType = this.config.type; // Changer temporairement le type pour KYC
412
+ this.config.type = 2;
413
+ _context4.p = 1;
414
+ _context4.n = 2;
415
+ return this.generateQR(containerId, options);
406
416
  case 2:
407
- response = _context3.v;
408
- if (!response.success) {
409
- _context3.n = 3;
410
- break;
411
- }
412
- // Construire l'URL complète de l'image QR avec la base URL pour les images
413
- imageBaseUrl = 'https://sunuid.fayma.sn';
414
- qrImageUrl = "".concat(imageBaseUrl).concat(response.data.qrcode);
415
- this.displayQRCode(containerId, qrImageUrl, type, options);
416
- this.startAutoRefresh(containerId, type, options);
417
- return _context3.a(2, _objectSpread2(_objectSpread2({}, response.data), {}, {
418
- qrCodeUrl: qrImageUrl,
419
- sessionId: response.data.service_id
420
- }));
417
+ return _context4.a(2, _context4.v);
421
418
  case 3:
422
- throw new Error(response.message || 'Erreur lors de la génération du QR code');
419
+ _context4.p = 3;
420
+ // Restaurer le type original
421
+ this.config.type = originalType;
422
+ return _context4.f(3);
423
423
  case 4:
424
- _context3.n = 6;
425
- break;
426
- case 5:
427
- _context3.p = 5;
428
- _t3 = _context3.v;
429
- console.error('Erreur API détectée:', _t3.message);
430
- console.log('Affichage du message "Service non disponible" pour type ' + type);
431
- this.displayServiceUnavailable(containerId, type);
432
- throw new Error('Service non disponible');
433
- case 6:
434
- return _context3.a(2);
424
+ return _context4.a(2);
435
425
  }
436
- }, _callee3, this, [[1, 5]]);
426
+ }, _callee4, this, [[1,, 3, 4]]);
437
427
  }));
438
- function generateCustomQR(_x3, _x4) {
439
- return _generateCustomQR.apply(this, arguments);
428
+ function generateKYCQR(_x5) {
429
+ return _generateKYCQR.apply(this, arguments);
440
430
  }
441
- return generateCustomQR;
431
+ return generateKYCQR;
442
432
  }()
443
433
  /**
444
434
  * Vérifier le statut d'un QR code
445
435
  */
446
- )
447
436
  }, {
448
437
  key: "checkQRStatus",
449
438
  value: (function () {
450
- var _checkQRStatus = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(sessionId) {
451
- var response, _t4;
452
- return _regenerator().w(function (_context4) {
453
- while (1) switch (_context4.p = _context4.n) {
439
+ var _checkQRStatus = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(sessionId) {
440
+ var response, _t3;
441
+ return _regenerator().w(function (_context5) {
442
+ while (1) switch (_context5.p = _context5.n) {
454
443
  case 0:
455
444
  if (this.isInitialized) {
456
- _context4.n = 1;
445
+ _context5.n = 1;
457
446
  break;
458
447
  }
459
448
  throw new Error('SunuID: SDK non initialisé');
460
449
  case 1:
461
- _context4.p = 1;
462
- _context4.n = 2;
450
+ _context5.p = 1;
451
+ _context5.n = 2;
463
452
  return this.makeRequest('/qr-status', {
464
453
  serviceId: sessionId
465
454
  });
466
455
  case 2:
467
- response = _context4.v;
456
+ response = _context5.v;
468
457
  if (!response.success) {
469
- _context4.n = 3;
458
+ _context5.n = 3;
470
459
  break;
471
460
  }
472
- return _context4.a(2, response.data);
461
+ return _context5.a(2, response.data);
473
462
  case 3:
474
463
  throw new Error(response.message || 'Erreur lors de la vérification du statut');
475
464
  case 4:
476
- _context4.n = 6;
465
+ _context5.n = 6;
477
466
  break;
478
467
  case 5:
479
- _context4.p = 5;
480
- _t4 = _context4.v;
481
- this.handleError(_t4);
482
- throw _t4;
468
+ _context5.p = 5;
469
+ _t3 = _context5.v;
470
+ this.handleError(_t3);
471
+ throw _t3;
483
472
  case 6:
484
- return _context4.a(2);
473
+ return _context5.a(2);
485
474
  }
486
- }, _callee4, this, [[1, 5]]);
475
+ }, _callee5, this, [[1, 5]]);
487
476
  }));
488
- function checkQRStatus(_x5) {
477
+ function checkQRStatus(_x6) {
489
478
  return _checkQRStatus.apply(this, arguments);
490
479
  }
491
480
  return checkQRStatus;
@@ -509,7 +498,7 @@
509
498
  // Créer l'élément QR code
510
499
  var qrElement = document.createElement('div');
511
500
  qrElement.className = 'sunuid-qr-code';
512
- qrElement.innerHTML = "\n <div class=\"sunuid-qr-header\">\n <h3>".concat(type === 1 ? 'Authentification' : type === 2 ? 'Vérification KYC' : 'Service Type ' + type, "</h3>\n </div>\n <div class=\"sunuid-qr-image\">\n <img src=\"").concat(qrUrl, "\" alt=\"QR Code SunuID\" style=\"max-width: 300px; height: auto;\">\n </div>\n <div class=\"sunuid-qr-instructions\">\n <p>Scannez ce QR code avec l'application SunuID pour vous connecter</p>\n </div>\n <div class=\"sunuid-qr-status\" id=\"sunuid-status\">\n <p>En attente de scan...</p>\n </div>\n ");
501
+ qrElement.innerHTML = "\n <div class=\"sunuid-qr-header\">\n <h3>".concat(type === 1 ? 'Authentification' : type === 2 ? 'Vérification KYC' : type === 3 ? 'Service Type 3' : 'Service Type ' + type, "</h3>\n </div>\n <div class=\"sunuid-qr-image\">\n <img src=\"").concat(qrUrl, "\" alt=\"QR Code SunuID\" style=\"max-width: 300px; height: auto;\">\n </div>\n <div class=\"sunuid-qr-instructions\">\n <p>Scannez ce QR code avec l'application SunuID pour vous connecter</p>\n </div>\n <div class=\"sunuid-qr-status\" id=\"sunuid-status\">\n <p>En attente de scan...</p>\n </div>\n ");
513
502
  container.appendChild(qrElement);
514
503
 
515
504
  // Appliquer le thème
@@ -537,61 +526,33 @@
537
526
  }, {
538
527
  key: "refreshQR",
539
528
  value: (function () {
540
- var _refreshQR = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(containerId, type) {
529
+ var _refreshQR = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(containerId) {
541
530
  var options,
542
531
  result,
543
- _args5 = arguments,
544
- _t5,
545
- _t6,
546
- _t7;
547
- return _regenerator().w(function (_context5) {
548
- while (1) switch (_context5.p = _context5.n) {
532
+ _args6 = arguments,
533
+ _t4;
534
+ return _regenerator().w(function (_context6) {
535
+ while (1) switch (_context6.p = _context6.n) {
549
536
  case 0:
550
- options = _args5.length > 2 && _args5[2] !== undefined ? _args5[2] : {};
551
- _context5.p = 1;
552
- if (!(type === 1)) {
553
- _context5.n = 3;
554
- break;
555
- }
556
- _context5.n = 2;
557
- return this.generateAuthQR(containerId, options);
537
+ options = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : {};
538
+ _context6.p = 1;
539
+ _context6.n = 2;
540
+ return this.generateQR(containerId, options);
558
541
  case 2:
559
- _t5 = _context5.v;
560
- _context5.n = 8;
561
- break;
542
+ result = _context6.v;
543
+ return _context6.a(2, result);
562
544
  case 3:
563
- if (!(type === 2)) {
564
- _context5.n = 5;
565
- break;
566
- }
567
- _context5.n = 4;
568
- return this.generateKYCQR(containerId, options);
545
+ _context6.p = 3;
546
+ _t4 = _context6.v;
547
+ console.error('Erreur lors du rafraîchissement:', _t4.message);
548
+ this.displayServiceUnavailable(containerId, this.config.type);
549
+ throw _t4;
569
550
  case 4:
570
- _t6 = _context5.v;
571
- _context5.n = 7;
572
- break;
573
- case 5:
574
- _context5.n = 6;
575
- return this.generateCustomQR(containerId, type, options);
576
- case 6:
577
- _t6 = _context5.v;
578
- case 7:
579
- _t5 = _t6;
580
- case 8:
581
- result = _t5;
582
- return _context5.a(2, result);
583
- case 9:
584
- _context5.p = 9;
585
- _t7 = _context5.v;
586
- console.error('Erreur lors du rafraîchissement:', _t7.message);
587
- this.displayServiceUnavailable(containerId, type);
588
- throw _t7;
589
- case 10:
590
- return _context5.a(2);
551
+ return _context6.a(2);
591
552
  }
592
- }, _callee5, this, [[1, 9]]);
553
+ }, _callee6, this, [[1, 3]]);
593
554
  }));
594
- function refreshQR(_x6, _x7) {
555
+ function refreshQR(_x7) {
595
556
  return _refreshQR.apply(this, arguments);
596
557
  }
597
558
  return refreshQR;
@@ -605,25 +566,25 @@
605
566
  value: function startAutoRefresh(containerId, type, options) {
606
567
  var _this = this;
607
568
  if (!this.config.autoRefresh) return;
608
- this.refreshTimer = setInterval(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6() {
609
- var _t8;
610
- return _regenerator().w(function (_context6) {
611
- while (1) switch (_context6.p = _context6.n) {
569
+ this.refreshTimer = setInterval(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7() {
570
+ var _t5;
571
+ return _regenerator().w(function (_context7) {
572
+ while (1) switch (_context7.p = _context7.n) {
612
573
  case 0:
613
- _context6.p = 0;
614
- _context6.n = 1;
574
+ _context7.p = 0;
575
+ _context7.n = 1;
615
576
  return _this.refreshQR(containerId, type, options);
616
577
  case 1:
617
- _context6.n = 3;
578
+ _context7.n = 3;
618
579
  break;
619
580
  case 2:
620
- _context6.p = 2;
621
- _t8 = _context6.v;
622
- console.warn('Erreur lors du rafraîchissement automatique:', _t8);
581
+ _context7.p = 2;
582
+ _t5 = _context7.v;
583
+ console.warn('Erreur lors du rafraîchissement automatique:', _t5);
623
584
  case 3:
624
- return _context6.a(2);
585
+ return _context7.a(2);
625
586
  }
626
- }, _callee6, null, [[0, 2]]);
587
+ }, _callee7, null, [[0, 2]]);
627
588
  })), this.config.refreshInterval);
628
589
  }
629
590
 
@@ -637,17 +598,17 @@
637
598
  }, {
638
599
  key: "makeRequest",
639
600
  value: (function () {
640
- var _makeRequest = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(endpoint, data) {
601
+ var _makeRequest = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(endpoint, data) {
641
602
  var _window$SunuIDConfig2;
642
- var endpointPath, url, response, errorText, errorData, result, _t9;
643
- return _regenerator().w(function (_context7) {
644
- while (1) switch (_context7.p = _context7.n) {
603
+ var endpointPath, url, response, errorText, errorData, result, _t6;
604
+ return _regenerator().w(function (_context8) {
605
+ while (1) switch (_context8.p = _context8.n) {
645
606
  case 0:
646
607
  // Utiliser l'endpoint depuis la configuration si disponible
647
608
  endpointPath = ((_window$SunuIDConfig2 = window.SunuIDConfig) === null || _window$SunuIDConfig2 === void 0 || (_window$SunuIDConfig2 = _window$SunuIDConfig2.endpoints) === null || _window$SunuIDConfig2 === void 0 ? void 0 : _window$SunuIDConfig2[endpoint.replace('/', '')]) || endpoint;
648
609
  url = "".concat(this.config.apiUrl).concat(endpointPath);
649
- _context7.p = 1;
650
- _context7.n = 2;
610
+ _context8.p = 1;
611
+ _context8.n = 2;
651
612
  return fetch(url, {
652
613
  method: 'POST',
653
614
  headers: {
@@ -661,15 +622,15 @@
661
622
  }))
662
623
  });
663
624
  case 2:
664
- response = _context7.v;
625
+ response = _context8.v;
665
626
  if (response.ok) {
666
- _context7.n = 4;
627
+ _context8.n = 4;
667
628
  break;
668
629
  }
669
- _context7.n = 3;
630
+ _context8.n = 3;
670
631
  return response.text();
671
632
  case 3:
672
- errorText = _context7.v;
633
+ errorText = _context8.v;
673
634
  try {
674
635
  errorData = JSON.parse(errorText);
675
636
  } catch (e) {
@@ -679,20 +640,20 @@
679
640
  }
680
641
  throw new Error(errorData.message || "Erreur HTTP: ".concat(response.status));
681
642
  case 4:
682
- _context7.n = 5;
643
+ _context8.n = 5;
683
644
  return response.json();
684
645
  case 5:
685
- result = _context7.v;
686
- return _context7.a(2, result);
646
+ result = _context8.v;
647
+ return _context8.a(2, result);
687
648
  case 6:
688
- _context7.p = 6;
689
- _t9 = _context7.v;
690
- console.error('Erreur API SunuID:', _t9);
691
- throw _t9;
649
+ _context8.p = 6;
650
+ _t6 = _context8.v;
651
+ console.error('Erreur API SunuID:', _t6);
652
+ throw _t6;
692
653
  case 7:
693
- return _context7.a(2);
654
+ return _context8.a(2);
694
655
  }
695
- }, _callee7, this, [[1, 6]]);
656
+ }, _callee8, this, [[1, 6]]);
696
657
  }));
697
658
  function makeRequest(_x8, _x9) {
698
659
  return _makeRequest.apply(this, arguments);