@ekyc_qoobiss/qbs-ect-cmp 3.6.29 → 3.6.31

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.
@@ -2,6 +2,15 @@
2
2
 
3
3
  const index = require('./index-41696e0e.js');
4
4
 
5
+ exports.OrderStatuses = void 0;
6
+ (function (OrderStatuses) {
7
+ OrderStatuses[OrderStatuses["Capturing"] = 0] = "Capturing";
8
+ OrderStatuses[OrderStatuses["FinishedCapturing"] = 1] = "FinishedCapturing";
9
+ OrderStatuses[OrderStatuses["Waiting"] = 2] = "Waiting";
10
+ OrderStatuses[OrderStatuses["NotFound"] = 3] = "NotFound";
11
+ OrderStatuses[OrderStatuses["Aborted"] = 4] = "Aborted";
12
+ })(exports.OrderStatuses || (exports.OrderStatuses = {}));
13
+
5
14
  const appendToMap = (map, propName, value) => {
6
15
  const items = map.get(propName);
7
16
  if (!items) {
@@ -253,6 +262,7 @@ class ApiUrls {
253
262
  this.AddLog = this.uriEnv + 'validation/logs/add';
254
263
  this.AddStep = this.uriEnv + 'validation/logs/step';
255
264
  this.AbortRequest = this.uriEnv + 'validation/identity/abort';
265
+ this.Translations = this.uriEnv + 'validation/translations/get';
256
266
  }
257
267
  }
258
268
 
@@ -301,7 +311,264 @@ onChange('phoneValidation', value => {
301
311
  sessionStorage.setItem(SessionKeys.PhoneValidationKey, String(value));
302
312
  });
303
313
 
314
+ exports.FlowSteps = void 0;
315
+ (function (FlowSteps) {
316
+ FlowSteps[FlowSteps["ComponentLoaded"] = 'component-loaded'] = "ComponentLoaded";
317
+ FlowSteps[FlowSteps["MobileRedirect"] = 'mobile-redirect'] = "MobileRedirect";
318
+ FlowSteps[FlowSteps["Landing"] = 'landing'] = "Landing";
319
+ FlowSteps[FlowSteps["Agreements"] = 'agreements'] = "Agreements";
320
+ FlowSteps[FlowSteps["OtpSend"] = 'otp-send'] = "OtpSend";
321
+ FlowSteps[FlowSteps["OtpCheck"] = 'otp-check'] = "OtpCheck";
322
+ FlowSteps[FlowSteps["CiFront"] = 'ci-front'] = "CiFront";
323
+ FlowSteps[FlowSteps["CiFrontHowTo"] = 'ci-front-how-to'] = "CiFrontHowTo";
324
+ FlowSteps[FlowSteps["CiFrontCapture"] = 'ci-front-capture'] = "CiFrontCapture";
325
+ FlowSteps[FlowSteps["CiBack"] = 'ci-back'] = "CiBack";
326
+ FlowSteps[FlowSteps["CiBackHowTo"] = 'ci-back-how-to'] = "CiBackHowTo";
327
+ FlowSteps[FlowSteps["CiBackCapture"] = 'ci-back-capture'] = "CiBackCapture";
328
+ FlowSteps[FlowSteps["CiTilt"] = 'ci-tilt'] = "CiTilt";
329
+ FlowSteps[FlowSteps["CiError"] = 'ci-error'] = "CiError";
330
+ FlowSteps[FlowSteps["SelfieHowTo"] = 'selfie-how-to'] = "SelfieHowTo";
331
+ FlowSteps[FlowSteps["SelfieTilt"] = 'selfie-tilt'] = "SelfieTilt";
332
+ FlowSteps[FlowSteps["SelfieCapture"] = 'selfie-capture'] = "SelfieCapture";
333
+ FlowSteps[FlowSteps["Selfie"] = 'selfie'] = "Selfie";
334
+ FlowSteps[FlowSteps["SelfieError"] = 'selfie-error'] = "SelfieError";
335
+ FlowSteps[FlowSteps["End"] = 'end'] = "End";
336
+ FlowSteps[FlowSteps["CameraError"] = 'camera-error'] = "CameraError";
337
+ })(exports.FlowSteps || (exports.FlowSteps = {}));
338
+ exports.FlowMoments = void 0;
339
+ (function (FlowMoments) {
340
+ FlowMoments[FlowMoments["Initialized"] = 'initialized'] = "Initialized";
341
+ FlowMoments[FlowMoments["Finalized"] = 'finalized'] = "Finalized";
342
+ FlowMoments[FlowMoments["None"] = 'none'] = "None";
343
+ })(exports.FlowMoments || (exports.FlowMoments = {}));
344
+
345
+ class ApiCall {
346
+ constructor() {
347
+ this.serviceErrors = ['Service Unavailable', 'Unauthorized'];
348
+ this.toBase64 = (file) => new Promise((resolve, reject) => {
349
+ const reader = new FileReader();
350
+ reader.readAsDataURL(file);
351
+ reader.onload = () => resolve(reader.result);
352
+ reader.onerror = error => reject(error);
353
+ });
354
+ this.urls = new ApiUrls();
355
+ }
356
+ // private async http2<T>(method: string, url: string, data: string): Promise<T> {
357
+ // return new Promise((resolve, reject) => {
358
+ // var xhr = new XMLHttpRequest();
359
+ // xhr.open(method, url);
360
+ // xhr.onload = function () {
361
+ // if (xhr.status >= 200 && xhr.status < 300) {
362
+ // resolve(xhr.response);
363
+ // } else {
364
+ // reject({
365
+ // status: xhr.status,
366
+ // statusText: xhr.statusText,
367
+ // });
368
+ // }
369
+ // };
370
+ // xhr.onerror = function () {
371
+ // reject({
372
+ // status: xhr.status,
373
+ // statusText: xhr.statusText,
374
+ // });
375
+ // };
376
+ // xhr.send(data);
377
+ // });
378
+ // }
379
+ async http(request) {
380
+ const response = await fetch(request);
381
+ if (!response.ok) {
382
+ throw new Error(response.statusText);
383
+ }
384
+ try {
385
+ // may error if there is no body
386
+ return await response.json();
387
+ }
388
+ catch (ex) {
389
+ throw new Error('No json found in response ' + ex);
390
+ }
391
+ }
392
+ async post(url, data, withRetry = true) {
393
+ var request = new Request(state.apiBaseUrl + url, {
394
+ method: 'POST',
395
+ body: data,
396
+ headers: {
397
+ 'Content-Type': 'application/json',
398
+ 'Authorization': 'IDKYC-TOKEN ' + state.token,
399
+ },
400
+ });
401
+ try {
402
+ return await this.http(request);
403
+ }
404
+ catch (ex) {
405
+ if (!withRetry || this.serviceErrors.includes(ex.message)) {
406
+ throw ex;
407
+ }
408
+ this.AddLog('Error in post ', ex);
409
+ try {
410
+ var request2 = new Request(state.apiBaseUrl + url, {
411
+ method: 'POST',
412
+ body: data,
413
+ headers: {
414
+ 'Content-Type': 'application/json',
415
+ 'Authorization': 'IDKYC-TOKEN ' + state.token,
416
+ },
417
+ });
418
+ return await this.http(request2);
419
+ }
420
+ catch (ex2) {
421
+ this.AddLog('Error in post ', ex2);
422
+ var request3 = new Request(state.apiBaseUrl + url, {
423
+ method: 'POST',
424
+ body: data,
425
+ headers: {
426
+ 'Content-Type': 'application/json',
427
+ 'Authorization': 'IDKYC-TOKEN ' + state.token,
428
+ },
429
+ });
430
+ return await this.http(request3);
431
+ }
432
+ }
433
+ }
434
+ async get(url, withRetry = true) {
435
+ var request = new Request(state.apiBaseUrl + url, {
436
+ method: 'GET',
437
+ headers: {
438
+ 'Content-Type': 'application/json',
439
+ 'Authorization': 'IDKYC-TOKEN ' + state.token,
440
+ },
441
+ });
442
+ try {
443
+ return await this.http(request);
444
+ }
445
+ catch (ex) {
446
+ if (!withRetry || this.serviceErrors.includes(ex.message)) {
447
+ throw ex;
448
+ }
449
+ this.AddLog('Error in get ', ex);
450
+ try {
451
+ var request2 = new Request(state.apiBaseUrl + url, {
452
+ method: 'GET',
453
+ headers: {
454
+ 'Content-Type': 'application/json',
455
+ 'Authorization': 'IDKYC-TOKEN ' + state.token,
456
+ },
457
+ });
458
+ return await this.http(request2);
459
+ }
460
+ catch (ex2) {
461
+ this.AddLog('Error in get ', ex2);
462
+ var request3 = new Request(state.apiBaseUrl + url, {
463
+ method: 'GET',
464
+ headers: {
465
+ 'Content-Type': 'application/json',
466
+ 'Authorization': 'IDKYC-TOKEN ' + state.token,
467
+ },
468
+ });
469
+ return await this.http(request3);
470
+ }
471
+ }
472
+ }
473
+ async SendOTPCode(requestId, phoneNumber) {
474
+ let data = { requestId: requestId, phone: phoneNumber };
475
+ let jsonResp = await this.post(this.urls.OtpSend, JSON.stringify(data));
476
+ return jsonResp.sent;
477
+ }
478
+ async CheckOTPCode(requestId, otpCode) {
479
+ let data = { requestId: requestId, otp: otpCode };
480
+ let jsonResp = await this.post(this.urls.OtpCheck, JSON.stringify(data));
481
+ return jsonResp.valid;
482
+ }
483
+ async AddIdentificationRequest(deviceInfo, version) {
484
+ if (state.debug)
485
+ console.log('Calling identity request with store:' + JSON.stringify(state));
486
+ let data = {
487
+ requestId: state.requestId,
488
+ clientDeviceInfo: JSON.stringify(deviceInfo),
489
+ redirectId: state.redirectId,
490
+ phoneNumber: state.phoneNumber,
491
+ version: version,
492
+ };
493
+ let jsonResp = await this.post(this.urls.IdentityInsert, JSON.stringify(data));
494
+ if (state.requestId == '') {
495
+ state.requestId = jsonResp.requestId;
496
+ }
497
+ state.hasIdBack = jsonResp.hasIdBack;
498
+ state.hasIdTilt = jsonResp.hasIdTilt;
499
+ state.hasSelfieGesture = jsonResp.hasSelfieGesture;
500
+ state.agreementsValidation = jsonResp.agreementsValidation;
501
+ state.phoneValidation = jsonResp.phoneValidation;
502
+ state.phoneNumber = jsonResp.phoneNumber;
503
+ return true;
504
+ }
505
+ async UploadFileForRequestB64(requestId, type, file) {
506
+ let data = {
507
+ requestId: requestId,
508
+ type: type,
509
+ data: await this.toBase64(file),
510
+ };
511
+ let respJson = await this.post(this.urls.UploadCapture, JSON.stringify(data));
512
+ if (!state.hasIdBack && type == 'IdFront') {
513
+ return respJson.isValid;
514
+ }
515
+ if (state.hasIdBack && type == 'IdBack') {
516
+ return respJson.isValid;
517
+ }
518
+ if (type == 'Selfie') {
519
+ return respJson.isValid;
520
+ }
521
+ return true;
522
+ }
523
+ async GetAgreement(agreementType) {
524
+ let resp = await this.get(this.urls.GetAgreement + '?type=' + agreementType + '&requestId=' + state.requestId);
525
+ return resp.htmlText;
526
+ }
527
+ async GenerateAgreement(agreementType) {
528
+ let data = { requestId: state.requestId, documentType: agreementType };
529
+ let resp = await this.post(this.urls.GenerateAgreement, JSON.stringify(data));
530
+ return resp.generation;
531
+ }
532
+ async GetStatus(requestId) {
533
+ let resp = await this.get(this.urls.GetStatus + '?orderId=' + requestId);
534
+ return exports.OrderStatuses[resp.status];
535
+ }
536
+ async SendLink(link, phoneNumber) {
537
+ let data = { requestId: state.requestId, link: link, phoneNumber: phoneNumber };
538
+ let resp = await this.post(this.urls.SendLink, JSON.stringify(data));
539
+ return resp.sent;
540
+ }
541
+ async AddLog(error, context) {
542
+ try {
543
+ let data = {
544
+ requestId: state.requestId,
545
+ action: exports.FlowStatus[state.flowStatus],
546
+ message: JSON.stringify({ error, context }),
547
+ };
548
+ let result = await this.post(this.urls.AddLog, JSON.stringify(data), false);
549
+ return result.saved;
550
+ }
551
+ catch (_a) { }
552
+ }
553
+ async AddStep(step, moment) {
554
+ let data = { requestId: state.requestId, redirectId: state.redirectId, step: exports.FlowSteps[step], moment: exports.FlowMoments[moment], timestamp: new Date().toISOString() };
555
+ let result = await this.post(this.urls.AddStep, JSON.stringify(data));
556
+ return result.saved;
557
+ }
558
+ async AbortRequest() {
559
+ let result = await this.post(this.urls.AbortRequest, JSON.stringify({ requestId: state.requestId }));
560
+ return result.saved;
561
+ }
562
+ async GetTranslations(langIso) {
563
+ let result = await this.get(this.urls.Translations + '?langIso=' + langIso);
564
+ return result;
565
+ }
566
+ }
567
+
304
568
  class TranslationsController {
569
+ constructor() {
570
+ this.apiCall = new ApiCall();
571
+ }
305
572
  async getValues() {
306
573
  if (this.values) {
307
574
  return this.values;
@@ -312,33 +579,31 @@ class TranslationsController {
312
579
  }
313
580
  }
314
581
  getLocale(element = document.body) {
315
- const closestElement = element.closest('[lang]');
316
- return closestElement ? closestElement.lang : state.langIso;
582
+ if (state.langIso && state.langIso != '') {
583
+ return state.langIso;
584
+ }
585
+ else {
586
+ const closestElement = element.closest('[lang]');
587
+ return closestElement ? closestElement.lang : 'ro';
588
+ }
317
589
  }
318
590
  async fetchTranslations() {
319
591
  const locale = this.getLocale();
320
- const existingTranslations = JSON.parse(sessionStorage.getItem(`i18n.${locale}`));
321
- if (existingTranslations && Object.keys(existingTranslations).length > 0) {
322
- return existingTranslations;
323
- }
324
- else {
325
- try {
326
- const result = await fetch(`/i18n/${locale}.json`);
327
- if (result.ok) {
328
- const data = await result.json();
329
- sessionStorage.setItem(`i18n.${locale}`, JSON.stringify(data));
330
- return data;
331
- }
332
- }
333
- catch (exception) {
334
- console.error(`Error loading locale: ${locale}`, exception);
592
+ try {
593
+ const result = this.apiCall.GetTranslations(locale);
594
+ if (result) {
595
+ return result;
335
596
  }
336
597
  }
598
+ catch (exception) {
599
+ console.error(`Error loading locale: ${locale}`, exception);
600
+ return null;
601
+ }
337
602
  }
338
603
  }
339
604
  const Translations = new TranslationsController();
340
605
 
341
- exports.ApiUrls = ApiUrls;
606
+ exports.ApiCall = ApiCall;
342
607
  exports.IdCaptureValues = IdCaptureValues;
343
608
  exports.SelfieCaptureValues = SelfieCaptureValues;
344
609
  exports.SessionKeys = SessionKeys;