@authme/util 2.4.4-rc.7 → 2.4.5
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/index.cjs +311 -57
- package/index.js +310 -58
- package/package.json +6 -1
- package/src/index.d.ts +1 -0
- package/src/lib/authme-log.d.ts +27 -7
- package/src/lib/background-request-process.d.ts +1 -0
- package/src/lib/file-saver.d.ts +11 -0
- package/src/ui/error-message.d.ts +8 -5
package/index.cjs
CHANGED
|
@@ -21,10 +21,12 @@ require('core-js/modules/es.string.replace.js');
|
|
|
21
21
|
require('core-js/modules/web.url-search-params.js');
|
|
22
22
|
require('core-js/modules/es.string.search.js');
|
|
23
23
|
require('core-js/modules/es.typed-array.uint32-array.js');
|
|
24
|
-
var Lottie = require('lottie-web');
|
|
25
|
-
require('core-js/modules/es.array.sort.js');
|
|
26
24
|
require('core-js/modules/es.array.includes.js');
|
|
27
25
|
require('core-js/modules/es.string.includes.js');
|
|
26
|
+
var fileSaver = require('file-saver');
|
|
27
|
+
var JSZip = require('jszip');
|
|
28
|
+
var Lottie = require('lottie-web');
|
|
29
|
+
require('core-js/modules/es.array.sort.js');
|
|
28
30
|
require('core-js/modules/es.parse-int.js');
|
|
29
31
|
require('core-js/modules/es.string.trim.js');
|
|
30
32
|
require('core-js/modules/es.string.starts-with.js');
|
|
@@ -33,6 +35,7 @@ require('core-js/modules/es.symbol.description.js');
|
|
|
33
35
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
34
36
|
|
|
35
37
|
var jwt_decode__default = /*#__PURE__*/_interopDefaultLegacy(jwt_decode);
|
|
38
|
+
var JSZip__default = /*#__PURE__*/_interopDefaultLegacy(JSZip);
|
|
36
39
|
var Lottie__default = /*#__PURE__*/_interopDefaultLegacy(Lottie);
|
|
37
40
|
|
|
38
41
|
const GLOBAL_KEY = '_AuthmeConfig';
|
|
@@ -480,6 +483,44 @@ const isIphone14proOrProMax = () => {
|
|
|
480
483
|
return isIphone() && (screen.width === 430 && screen.height === 932 || screen.width === 393 && screen.height === 852);
|
|
481
484
|
};
|
|
482
485
|
|
|
486
|
+
function fileSaverService() {
|
|
487
|
+
const filesQueue = [];
|
|
488
|
+
function pushFile(file) {
|
|
489
|
+
filesQueue.push(file);
|
|
490
|
+
}
|
|
491
|
+
function popAllFiles() {
|
|
492
|
+
filesQueue.splice(0, filesQueue.length);
|
|
493
|
+
}
|
|
494
|
+
function saveFiles(fileName, json) {
|
|
495
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
496
|
+
const zip = new JSZip__default["default"]();
|
|
497
|
+
filesQueue.forEach(fileItem => {
|
|
498
|
+
zip.file(fileItem.name, fileItem.file);
|
|
499
|
+
});
|
|
500
|
+
if (json) zip.file('data.json', JSON.stringify(json));
|
|
501
|
+
const content = yield zip.generateAsync({
|
|
502
|
+
type: 'blob'
|
|
503
|
+
});
|
|
504
|
+
fileSaver.saveAs(content, `${fileName}.zip`);
|
|
505
|
+
popAllFiles();
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
return {
|
|
509
|
+
pushFile,
|
|
510
|
+
saveFiles
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
const {
|
|
515
|
+
saveFiles,
|
|
516
|
+
pushFile
|
|
517
|
+
} = fileSaverService();
|
|
518
|
+
exports.RUN_FUNCTION_NAME = void 0;
|
|
519
|
+
(function (RUN_FUNCTION_NAME) {
|
|
520
|
+
RUN_FUNCTION_NAME["RECOGNITION"] = "service.recognition";
|
|
521
|
+
RUN_FUNCTION_NAME["ANTI_FARUD_RECOGNITION"] = "antiFraudInstance.recognition";
|
|
522
|
+
RUN_FUNCTION_NAME["API_REQUEST"] = "api.request";
|
|
523
|
+
})(exports.RUN_FUNCTION_NAME || (exports.RUN_FUNCTION_NAME = {}));
|
|
483
524
|
function debugLog(message, ...others) {
|
|
484
525
|
if (new URLSearchParams(location.search).get('authme-debug') === 'true') {
|
|
485
526
|
console.log(message, ...others);
|
|
@@ -501,35 +542,49 @@ function generateUniqueId(length = 32) {
|
|
|
501
542
|
}
|
|
502
543
|
return result;
|
|
503
544
|
}
|
|
504
|
-
function
|
|
505
|
-
const
|
|
506
|
-
|
|
507
|
-
const
|
|
508
|
-
downloadAnchorNode.setAttribute('href', dataStr);
|
|
509
|
-
downloadAnchorNode.setAttribute('download', exportName + '.json');
|
|
510
|
-
document.body.appendChild(downloadAnchorNode); // required for firefox
|
|
511
|
-
downloadAnchorNode.click();
|
|
512
|
-
downloadAnchorNode.remove();
|
|
513
|
-
}
|
|
514
|
-
function debugTools(config) {
|
|
545
|
+
function debugTools() {
|
|
546
|
+
const debugMode = new URLSearchParams(location.search).get('authme-debug') === 'true';
|
|
547
|
+
const debugModeUI = new URLSearchParams(location.search).get('authme-debug-info') === 'true';
|
|
548
|
+
const shouldGetDebugImage = new URLSearchParams(location.search).get('authme-debug-get-image') === 'true';
|
|
515
549
|
const debugLogs = [];
|
|
550
|
+
const logInfo = {
|
|
551
|
+
userAgent: navigator.userAgent,
|
|
552
|
+
token: '',
|
|
553
|
+
message: ''
|
|
554
|
+
};
|
|
516
555
|
let currentRoundId = generateUniqueId(8);
|
|
517
556
|
let currentType = null;
|
|
557
|
+
const interiaTimeObj = {};
|
|
518
558
|
function pushNewDebugLog(logParams) {
|
|
519
559
|
var _a;
|
|
520
|
-
if (!
|
|
560
|
+
if (!debugMode) return;
|
|
521
561
|
const now = new Date();
|
|
522
562
|
const _logParams = JSON.parse(JSON.stringify(logParams));
|
|
523
563
|
if (_logParams.result) {
|
|
524
564
|
(_a = _logParams.result) === null || _a === void 0 ? true : delete _a.imageData;
|
|
525
565
|
}
|
|
526
|
-
const newDebugLog = Object.assign({
|
|
527
|
-
time: now.getTime(),
|
|
566
|
+
const newDebugLog = Object.assign(Object.assign({
|
|
528
567
|
dateTime: now.toLocaleString(),
|
|
529
568
|
roundId: currentRoundId,
|
|
530
569
|
type: currentType !== null && currentType !== void 0 ? currentType : undefined
|
|
531
|
-
}, _logParams)
|
|
570
|
+
}, _logParams), {
|
|
571
|
+
time: now.getTime(),
|
|
572
|
+
_id: generateUniqueId()
|
|
573
|
+
});
|
|
532
574
|
debugLogs.push(newDebugLog);
|
|
575
|
+
return newDebugLog;
|
|
576
|
+
}
|
|
577
|
+
function pushNewDebugImage(image, log, options) {
|
|
578
|
+
var _a, _b;
|
|
579
|
+
if (!debugMode) return;
|
|
580
|
+
const newLog = pushNewDebugLog(log);
|
|
581
|
+
const recognitionFunctions = [exports.RUN_FUNCTION_NAME.ANTI_FARUD_RECOGNITION, exports.RUN_FUNCTION_NAME.RECOGNITION];
|
|
582
|
+
const currentRoundRecognitionResultItem = debugLogs.find(item => item.roundId === (newLog === null || newLog === void 0 ? void 0 : newLog.roundId) && item.status === 'run-end' && (item.runFunction ? recognitionFunctions.includes(item.runFunction) : false));
|
|
583
|
+
const imageStatus = (_a = currentRoundRecognitionResultItem === null || currentRoundRecognitionResultItem === void 0 ? void 0 : currentRoundRecognitionResultItem.result) === null || _a === void 0 ? void 0 : _a.eStatus;
|
|
584
|
+
pushFile({
|
|
585
|
+
name: `${(_b = options === null || options === void 0 ? void 0 : options.prefix) !== null && _b !== void 0 ? _b : ''}${newLog === null || newLog === void 0 ? void 0 : newLog.time}-${newLog === null || newLog === void 0 ? void 0 : newLog._id}${imageStatus ? `__${imageStatus}` : ''}.jpeg`,
|
|
586
|
+
file: image
|
|
587
|
+
});
|
|
533
588
|
}
|
|
534
589
|
function functionLogging(func, logParams) {
|
|
535
590
|
return new Promise((resolve, reject) => {
|
|
@@ -553,28 +608,209 @@ function debugTools(config) {
|
|
|
553
608
|
});
|
|
554
609
|
});
|
|
555
610
|
}
|
|
611
|
+
function renderDebugTips() {
|
|
612
|
+
if (document.getElementById('debug-tips')) {
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
const debugTips = document.createElement('div');
|
|
616
|
+
debugTips.style.position = 'fixed';
|
|
617
|
+
debugTips.style.top = '50px';
|
|
618
|
+
debugTips.style.right = '0';
|
|
619
|
+
debugTips.style.zIndex = '999';
|
|
620
|
+
debugTips.innerHTML = 'Debug Mode';
|
|
621
|
+
debugTips.style.color = 'red';
|
|
622
|
+
debugTips.style.fontWeight = 'bold';
|
|
623
|
+
debugTips.setAttribute('id', 'debug-tips');
|
|
624
|
+
document.body.appendChild(debugTips);
|
|
625
|
+
}
|
|
626
|
+
function renderDebugUI() {
|
|
627
|
+
if (document.getElementById('debug-ui')) {
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
630
|
+
const debugUI = document.createElement('div');
|
|
631
|
+
debugUI.style.position = 'fixed';
|
|
632
|
+
debugUI.style.top = '0';
|
|
633
|
+
debugUI.style.right = '0';
|
|
634
|
+
debugUI.style.zIndex = '777';
|
|
635
|
+
debugUI.style.backgroundColor = 'black';
|
|
636
|
+
debugUI.style.color = 'white';
|
|
637
|
+
debugUI.style.padding = '10px';
|
|
638
|
+
debugUI.style.paddingRight = '150px';
|
|
639
|
+
debugUI.style.fontSize = '12px';
|
|
640
|
+
debugUI.style.opacity = '0.7';
|
|
641
|
+
debugUI.style.boxSizing = 'border-box';
|
|
642
|
+
debugUI.style.width = '100%';
|
|
643
|
+
debugUI.style.maxHeight = '50vh';
|
|
644
|
+
debugUI.style.overflow = 'auto';
|
|
645
|
+
debugUI.setAttribute('id', 'debug-ui');
|
|
646
|
+
const closeUI = document.createElement('button');
|
|
647
|
+
closeUI.style.position = 'fixed';
|
|
648
|
+
closeUI.style.top = '0';
|
|
649
|
+
closeUI.style.right = '100px';
|
|
650
|
+
closeUI.innerHTML = 'close';
|
|
651
|
+
closeUI.addEventListener('click', () => {
|
|
652
|
+
debugUI.style.display = 'none';
|
|
653
|
+
});
|
|
654
|
+
debugUI.appendChild(closeUI);
|
|
655
|
+
const accordionUI = document.createElement('button');
|
|
656
|
+
accordionUI.style.position = 'fixed';
|
|
657
|
+
accordionUI.style.top = '0';
|
|
658
|
+
accordionUI.style.right = '0';
|
|
659
|
+
accordionUI.innerHTML = '收合/展開';
|
|
660
|
+
accordionUI.addEventListener('click', () => {
|
|
661
|
+
if (debugUI.style.maxHeight === '50vh') {
|
|
662
|
+
debugUI.style.maxHeight = '5vh';
|
|
663
|
+
} else {
|
|
664
|
+
debugUI.style.maxHeight = '50vh';
|
|
665
|
+
}
|
|
666
|
+
});
|
|
667
|
+
debugUI.appendChild(accordionUI);
|
|
668
|
+
document.body.appendChild(debugUI);
|
|
669
|
+
}
|
|
670
|
+
function setTimeStart(behavior) {
|
|
671
|
+
if (!debugModeUI) {
|
|
672
|
+
return;
|
|
673
|
+
}
|
|
674
|
+
const dStart = new Date();
|
|
675
|
+
const nStart = dStart.getTime();
|
|
676
|
+
if (interiaTimeObj && interiaTimeObj[behavior]) {
|
|
677
|
+
console.error('debugmode: setTimeStart duplicate', behavior);
|
|
678
|
+
return false;
|
|
679
|
+
}
|
|
680
|
+
interiaTimeObj[behavior] = {
|
|
681
|
+
behavior,
|
|
682
|
+
start: nStart / 1000,
|
|
683
|
+
duration: 0,
|
|
684
|
+
end: 0
|
|
685
|
+
};
|
|
686
|
+
// console.log(interiaTimeObj[behavior])
|
|
687
|
+
renderTimeInfo(behavior);
|
|
688
|
+
return interiaTimeObj[behavior];
|
|
689
|
+
}
|
|
690
|
+
function setTimeEnd(behavior) {
|
|
691
|
+
if (!debugModeUI) {
|
|
692
|
+
return;
|
|
693
|
+
}
|
|
694
|
+
const dEnd = new Date();
|
|
695
|
+
const nEnd = dEnd.getTime();
|
|
696
|
+
if (!interiaTimeObj[behavior]) {
|
|
697
|
+
console.error('debugmode: setTimeEnd not found', behavior);
|
|
698
|
+
return false;
|
|
699
|
+
}
|
|
700
|
+
interiaTimeObj[behavior].end = nEnd / 1000;
|
|
701
|
+
interiaTimeObj[behavior].duration = interiaTimeObj[behavior].end - interiaTimeObj[behavior].start;
|
|
702
|
+
// console.log(interiaTimeObj[behavior])
|
|
703
|
+
renderTimeInfo(behavior);
|
|
704
|
+
return interiaTimeObj[behavior];
|
|
705
|
+
}
|
|
706
|
+
function setTimeDuration(behavior) {
|
|
707
|
+
const ts = Date.now();
|
|
708
|
+
setTimeStart(`${behavior}_${ts}`);
|
|
709
|
+
return {
|
|
710
|
+
end: () => {
|
|
711
|
+
setTimeEnd(`${behavior}_${ts}`);
|
|
712
|
+
}
|
|
713
|
+
};
|
|
714
|
+
}
|
|
715
|
+
function renderTimeInfo(behavior) {
|
|
716
|
+
const dom = document.querySelector(`#debug-ui-${behavior}`);
|
|
717
|
+
const info = `{"behavior":<span style="color:green;">"${behavior}"</span>, "start": ${interiaTimeObj[behavior].start}, "duration": ${interiaTimeObj[behavior].duration}, "end": ${interiaTimeObj[behavior].end}}`;
|
|
718
|
+
// const info = `<span style="color:green;">${behavior}</span>: Duration: ${interiaTimeObj[behavior].duration}s`;
|
|
719
|
+
if (dom) {
|
|
720
|
+
dom.innerHTML = info;
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
723
|
+
const debugUI = document.getElementById('debug-ui');
|
|
724
|
+
const div = document.createElement('div');
|
|
725
|
+
div.setAttribute('class', 'debug-ui-item');
|
|
726
|
+
div.setAttribute('id', `debug-ui-${behavior}`);
|
|
727
|
+
div.innerHTML = info;
|
|
728
|
+
debugUI.appendChild(div);
|
|
729
|
+
}
|
|
730
|
+
function functionRunTime() {
|
|
731
|
+
const arr = [];
|
|
732
|
+
const items = document.querySelectorAll('.debug-ui-item');
|
|
733
|
+
items.forEach(item => {
|
|
734
|
+
arr.push(JSON.parse(item.innerText));
|
|
735
|
+
});
|
|
736
|
+
return arr;
|
|
737
|
+
}
|
|
738
|
+
if (debugMode) {
|
|
739
|
+
renderDebugTips();
|
|
740
|
+
// setRequestLoggingFunc(functionLogging)
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
if (debugModeUI) {
|
|
744
|
+
console.log('debugModeUI Init');
|
|
745
|
+
renderDebugUI();
|
|
746
|
+
}
|
|
747
|
+
function saveDebugImage({
|
|
748
|
+
getDebugImageData,
|
|
749
|
+
data,
|
|
750
|
+
width,
|
|
751
|
+
height,
|
|
752
|
+
result,
|
|
753
|
+
type
|
|
754
|
+
}) {
|
|
755
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
756
|
+
if (!debugMode || !shouldGetDebugImage) return;
|
|
757
|
+
const debugImage = yield getDebugImageData(data);
|
|
758
|
+
// 創建一個虛擬的 canvas
|
|
759
|
+
const canvas = document.createElement('canvas');
|
|
760
|
+
const ctx = canvas.getContext('2d');
|
|
761
|
+
// 設置 canvas 的尺寸
|
|
762
|
+
canvas.width = width;
|
|
763
|
+
canvas.height = height;
|
|
764
|
+
// 使用 Uint8ClampedArray 將圖像數據繪製到 canvas 上
|
|
765
|
+
const imgData = ctx === null || ctx === void 0 ? void 0 : ctx.createImageData(width, height);
|
|
766
|
+
if (imgData) {
|
|
767
|
+
imgData.data.set(debugImage);
|
|
768
|
+
ctx === null || ctx === void 0 ? void 0 : ctx.putImageData(imgData, 0, 0);
|
|
769
|
+
canvas.toBlob(blob => {
|
|
770
|
+
if (blob) {
|
|
771
|
+
pushNewDebugImage(blob, {
|
|
772
|
+
result: result,
|
|
773
|
+
status: 'recognition',
|
|
774
|
+
type: type
|
|
775
|
+
}, {
|
|
776
|
+
prefix: 'debugImage_'
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
}, 'image/jpeg');
|
|
780
|
+
}
|
|
781
|
+
});
|
|
782
|
+
}
|
|
556
783
|
return {
|
|
784
|
+
debugMode,
|
|
785
|
+
debugModeUI,
|
|
557
786
|
pushNewDebugLog,
|
|
558
787
|
getDebugLogs: () => debugLogs,
|
|
559
788
|
getDebugLogsLength: () => debugLogs.length,
|
|
560
789
|
modifyDeubgLog: (index, logParams) => {
|
|
561
|
-
if (!
|
|
790
|
+
if (!debugMode) return;
|
|
562
791
|
debugLogs[index] = Object.assign(Object.assign({}, debugLogs[index]), logParams);
|
|
563
792
|
},
|
|
564
793
|
downloadDebugLogs: () => {
|
|
565
|
-
if (!
|
|
566
|
-
|
|
794
|
+
if (!debugMode) return;
|
|
795
|
+
saveFiles(`debugLog${new Date().getTime().toString()}`, {
|
|
796
|
+
info: logInfo,
|
|
797
|
+
logs: debugLogs,
|
|
798
|
+
functionRunTime: functionRunTime()
|
|
799
|
+
});
|
|
567
800
|
},
|
|
568
801
|
functionLogging,
|
|
569
802
|
nextDebugRound: type => {
|
|
570
|
-
if (!
|
|
803
|
+
if (!debugMode) return;
|
|
571
804
|
currentRoundId = generateUniqueId(8);
|
|
572
805
|
if (type) currentType = type;
|
|
573
806
|
},
|
|
574
807
|
modifyDebugType: type => {
|
|
575
|
-
if (!
|
|
808
|
+
if (!debugMode) return;
|
|
576
809
|
currentType = type;
|
|
577
|
-
}
|
|
810
|
+
},
|
|
811
|
+
pushNewDebugImage,
|
|
812
|
+
setTimeDuration: setTimeDuration,
|
|
813
|
+
saveDebugImage
|
|
578
814
|
};
|
|
579
815
|
}
|
|
580
816
|
|
|
@@ -767,8 +1003,9 @@ function showErrorMessage(text, showRetryBtn, callback, buttonText, _titleText)
|
|
|
767
1003
|
errorMessagePanel.appendChild(retryText);
|
|
768
1004
|
if (callback) {
|
|
769
1005
|
retryText.addEventListener('click', e => {
|
|
770
|
-
|
|
771
|
-
|
|
1006
|
+
callback(e, {
|
|
1007
|
+
hideErrorMessage
|
|
1008
|
+
});
|
|
772
1009
|
});
|
|
773
1010
|
}
|
|
774
1011
|
}
|
|
@@ -831,13 +1068,12 @@ function asyncShowErrorMessage(text, showRetryBtn, options) {
|
|
|
831
1068
|
function asyncOnLineShowErrorMessage(text, showRetryBtn) {
|
|
832
1069
|
return __awaiter(this, void 0, void 0, function* () {
|
|
833
1070
|
return new Promise((res, rej) => {
|
|
834
|
-
|
|
1071
|
+
showErrorMessage(text, showRetryBtn, (_, tools) => {
|
|
835
1072
|
if (window.navigator.onLine) {
|
|
836
1073
|
res(true);
|
|
837
|
-
hideErrorMessage();
|
|
1074
|
+
tools === null || tools === void 0 ? void 0 : tools.hideErrorMessage();
|
|
838
1075
|
}
|
|
839
|
-
};
|
|
840
|
-
showErrorMessage(text, showRetryBtn, callback);
|
|
1076
|
+
});
|
|
841
1077
|
});
|
|
842
1078
|
});
|
|
843
1079
|
}
|
|
@@ -905,6 +1141,8 @@ var BROWSER_CAMERA_ERRORS;
|
|
|
905
1141
|
BROWSER_CAMERA_ERRORS["NO_CAMERA"] = "NO_CAMERA";
|
|
906
1142
|
BROWSER_CAMERA_ERRORS["NOT_ALLOWED_ERROR"] = "NotAllowedError";
|
|
907
1143
|
BROWSER_CAMERA_ERRORS["NOT_FOUND_ERROR"] = "NotFoundError";
|
|
1144
|
+
BROWSER_CAMERA_ERRORS["NOT_READABLE_ERROR"] = "NotReadableError";
|
|
1145
|
+
BROWSER_CAMERA_ERRORS["ABORT_ERROR"] = "AbortError";
|
|
908
1146
|
})(BROWSER_CAMERA_ERRORS || (BROWSER_CAMERA_ERRORS = {}));
|
|
909
1147
|
let stream;
|
|
910
1148
|
const videoConstraintsFactory = (isPC, facingMode) => {
|
|
@@ -1117,9 +1355,6 @@ function isOverconstrainedError(error) {
|
|
|
1117
1355
|
}
|
|
1118
1356
|
return 'constraint' in error;
|
|
1119
1357
|
}
|
|
1120
|
-
function sleep(ms) {
|
|
1121
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
1122
|
-
}
|
|
1123
1358
|
function requestCamera({
|
|
1124
1359
|
video,
|
|
1125
1360
|
facingMode,
|
|
@@ -1128,29 +1363,7 @@ function requestCamera({
|
|
|
1128
1363
|
}) {
|
|
1129
1364
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1130
1365
|
try {
|
|
1131
|
-
|
|
1132
|
-
name: 'camera'
|
|
1133
|
-
});
|
|
1134
|
-
if (perm.state == 'prompt') {
|
|
1135
|
-
for (let i = 0; i < 5; ++i) {
|
|
1136
|
-
try {
|
|
1137
|
-
//for ios 17.4.1 hack, if you call getUserMedia too early will only get not allowed.
|
|
1138
|
-
yield sleep(1000);
|
|
1139
|
-
return yield _requestCamera(video, facingMode);
|
|
1140
|
-
} catch (error) {
|
|
1141
|
-
if ((error === null || error === void 0 ? void 0 : error.name) === BROWSER_CAMERA_ERRORS.NOT_ALLOWED_ERROR) {
|
|
1142
|
-
perm = yield navigator.permissions.query({
|
|
1143
|
-
name: 'camera'
|
|
1144
|
-
});
|
|
1145
|
-
} else {
|
|
1146
|
-
throw error;
|
|
1147
|
-
}
|
|
1148
|
-
}
|
|
1149
|
-
}
|
|
1150
|
-
return yield _requestCamera(video, facingMode);
|
|
1151
|
-
} else {
|
|
1152
|
-
return yield _requestCamera(video, facingMode);
|
|
1153
|
-
}
|
|
1366
|
+
return yield _requestCamera(video, facingMode);
|
|
1154
1367
|
} catch (error) {
|
|
1155
1368
|
if (error === BROWSER_CAMERA_ERRORS.NOT_SUPPORT) {
|
|
1156
1369
|
showMessage(translate('camera.error.notFound'));
|
|
@@ -1164,6 +1377,15 @@ function requestCamera({
|
|
|
1164
1377
|
showMessage(translate('camera.error.notFound'));
|
|
1165
1378
|
throw new AuthmeError(exports.ErrorCode.CAMERA_NOT_SUPPORT, error);
|
|
1166
1379
|
}
|
|
1380
|
+
if ((error === null || error === void 0 ? void 0 : error.name) === BROWSER_CAMERA_ERRORS.NOT_READABLE_ERROR || (error === null || error === void 0 ? void 0 : error.name) === BROWSER_CAMERA_ERRORS.ABORT_ERROR) {
|
|
1381
|
+
showMessage(translate('camera.error.notFound'));
|
|
1382
|
+
/* NOT_READABLE_ERROR,ABORT_ERROR 這兩個錯誤是用戶授權了,但在呼叫裝置時出現錯誤,
|
|
1383
|
+
* 常發生在APP webview ,例如: 手機開啟 web 使用 sdk,儘管在 webview 層級上授權了,但手機在設定層級沒有授權 app 使用相機,會導致此問題。
|
|
1384
|
+
* 但每個 android 手機的在這方面的實作不一致,不是每個手機在這種情況下都會拋出錯誤。
|
|
1385
|
+
* 參考 https://developer.mozilla.org/zh-CN/docs/Web/API/MediaDevices/getUserMedia#notreadableerror
|
|
1386
|
+
*/
|
|
1387
|
+
throw new AuthmeError(exports.ErrorCode.CAMERA_NOT_SUPPORT, error);
|
|
1388
|
+
}
|
|
1167
1389
|
if (isOverconstrainedError(error)) {
|
|
1168
1390
|
showMessage(translate('camera.error.lowResolution'));
|
|
1169
1391
|
throw new AuthmeError(exports.ErrorCode.CAMERA_NOT_SUPPORT, error);
|
|
@@ -2159,15 +2381,46 @@ function RGBToLottieColor(color) {
|
|
|
2159
2381
|
return color.map(c => c / 255);
|
|
2160
2382
|
}
|
|
2161
2383
|
|
|
2384
|
+
const QUEUE_LENGTH = 10;
|
|
2385
|
+
const requstQueue = [];
|
|
2386
|
+
function pushRequest(request) {
|
|
2387
|
+
if (requstQueue.length > QUEUE_LENGTH - 1) {
|
|
2388
|
+
requstQueue.shift();
|
|
2389
|
+
}
|
|
2390
|
+
requstQueue.push(request);
|
|
2391
|
+
}
|
|
2392
|
+
function clearRequest() {
|
|
2393
|
+
requstQueue.splice(0, requstQueue.length);
|
|
2394
|
+
}
|
|
2395
|
+
function backgroundRequest(request) {
|
|
2396
|
+
const requestPromise = request();
|
|
2397
|
+
requestPromise.catch(err => {
|
|
2398
|
+
if (err._code === exports.ErrorCode.NETWORK_ERROR) {
|
|
2399
|
+
pushRequest(request);
|
|
2400
|
+
}
|
|
2401
|
+
});
|
|
2402
|
+
}
|
|
2403
|
+
window.ononline = () => {
|
|
2404
|
+
const tasks = [...requstQueue];
|
|
2405
|
+
clearRequest();
|
|
2406
|
+
tasks.forEach(request => {
|
|
2407
|
+
backgroundRequest(request);
|
|
2408
|
+
});
|
|
2409
|
+
};
|
|
2410
|
+
|
|
2162
2411
|
var name = "@authme/util";
|
|
2163
|
-
var version$1 = "2.4.
|
|
2412
|
+
var version$1 = "2.4.5";
|
|
2164
2413
|
var peerDependencies = {
|
|
2165
2414
|
"core-js": "^3.6.0"
|
|
2166
2415
|
};
|
|
2416
|
+
var devDependencies = {
|
|
2417
|
+
"@types/file-saver": "^2.0.5"
|
|
2418
|
+
};
|
|
2167
2419
|
var packageInfo = {
|
|
2168
2420
|
name: name,
|
|
2169
2421
|
version: version$1,
|
|
2170
|
-
peerDependencies: peerDependencies
|
|
2422
|
+
peerDependencies: peerDependencies,
|
|
2423
|
+
devDependencies: devDependencies
|
|
2171
2424
|
};
|
|
2172
2425
|
|
|
2173
2426
|
var _a;
|
|
@@ -2183,6 +2436,7 @@ exports.UintArrayToBlob = UintArrayToBlob;
|
|
|
2183
2436
|
exports.asyncOnLineShowErrorMessage = asyncOnLineShowErrorMessage;
|
|
2184
2437
|
exports.asyncShowErrorMessage = asyncShowErrorMessage;
|
|
2185
2438
|
exports.asyncShowPopup = asyncShowPopup;
|
|
2439
|
+
exports.backgroundRequest = backgroundRequest;
|
|
2186
2440
|
exports.checkOnlineStatus = checkOnlineStatus;
|
|
2187
2441
|
exports.clearCanvas = clearCanvas;
|
|
2188
2442
|
exports.colorStringToRGB = colorStringToRGB;
|
package/index.js
CHANGED
|
@@ -17,10 +17,12 @@ import 'core-js/modules/es.string.replace.js';
|
|
|
17
17
|
import 'core-js/modules/web.url-search-params.js';
|
|
18
18
|
import 'core-js/modules/es.string.search.js';
|
|
19
19
|
import 'core-js/modules/es.typed-array.uint32-array.js';
|
|
20
|
-
import Lottie from 'lottie-web';
|
|
21
|
-
import 'core-js/modules/es.array.sort.js';
|
|
22
20
|
import 'core-js/modules/es.array.includes.js';
|
|
23
21
|
import 'core-js/modules/es.string.includes.js';
|
|
22
|
+
import { saveAs } from 'file-saver';
|
|
23
|
+
import JSZip from 'jszip';
|
|
24
|
+
import Lottie from 'lottie-web';
|
|
25
|
+
import 'core-js/modules/es.array.sort.js';
|
|
24
26
|
import 'core-js/modules/es.parse-int.js';
|
|
25
27
|
import 'core-js/modules/es.string.trim.js';
|
|
26
28
|
import 'core-js/modules/es.string.starts-with.js';
|
|
@@ -471,6 +473,44 @@ const isIphone14proOrProMax = () => {
|
|
|
471
473
|
return isIphone() && (screen.width === 430 && screen.height === 932 || screen.width === 393 && screen.height === 852);
|
|
472
474
|
};
|
|
473
475
|
|
|
476
|
+
function fileSaverService() {
|
|
477
|
+
const filesQueue = [];
|
|
478
|
+
function pushFile(file) {
|
|
479
|
+
filesQueue.push(file);
|
|
480
|
+
}
|
|
481
|
+
function popAllFiles() {
|
|
482
|
+
filesQueue.splice(0, filesQueue.length);
|
|
483
|
+
}
|
|
484
|
+
function saveFiles(fileName, json) {
|
|
485
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
486
|
+
const zip = new JSZip();
|
|
487
|
+
filesQueue.forEach(fileItem => {
|
|
488
|
+
zip.file(fileItem.name, fileItem.file);
|
|
489
|
+
});
|
|
490
|
+
if (json) zip.file('data.json', JSON.stringify(json));
|
|
491
|
+
const content = yield zip.generateAsync({
|
|
492
|
+
type: 'blob'
|
|
493
|
+
});
|
|
494
|
+
saveAs(content, `${fileName}.zip`);
|
|
495
|
+
popAllFiles();
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
return {
|
|
499
|
+
pushFile,
|
|
500
|
+
saveFiles
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
const {
|
|
505
|
+
saveFiles,
|
|
506
|
+
pushFile
|
|
507
|
+
} = fileSaverService();
|
|
508
|
+
var RUN_FUNCTION_NAME;
|
|
509
|
+
(function (RUN_FUNCTION_NAME) {
|
|
510
|
+
RUN_FUNCTION_NAME["RECOGNITION"] = "service.recognition";
|
|
511
|
+
RUN_FUNCTION_NAME["ANTI_FARUD_RECOGNITION"] = "antiFraudInstance.recognition";
|
|
512
|
+
RUN_FUNCTION_NAME["API_REQUEST"] = "api.request";
|
|
513
|
+
})(RUN_FUNCTION_NAME || (RUN_FUNCTION_NAME = {}));
|
|
474
514
|
function debugLog(message, ...others) {
|
|
475
515
|
if (new URLSearchParams(location.search).get('authme-debug') === 'true') {
|
|
476
516
|
console.log(message, ...others);
|
|
@@ -492,35 +532,49 @@ function generateUniqueId(length = 32) {
|
|
|
492
532
|
}
|
|
493
533
|
return result;
|
|
494
534
|
}
|
|
495
|
-
function
|
|
496
|
-
const
|
|
497
|
-
|
|
498
|
-
const
|
|
499
|
-
downloadAnchorNode.setAttribute('href', dataStr);
|
|
500
|
-
downloadAnchorNode.setAttribute('download', exportName + '.json');
|
|
501
|
-
document.body.appendChild(downloadAnchorNode); // required for firefox
|
|
502
|
-
downloadAnchorNode.click();
|
|
503
|
-
downloadAnchorNode.remove();
|
|
504
|
-
}
|
|
505
|
-
function debugTools(config) {
|
|
535
|
+
function debugTools() {
|
|
536
|
+
const debugMode = new URLSearchParams(location.search).get('authme-debug') === 'true';
|
|
537
|
+
const debugModeUI = new URLSearchParams(location.search).get('authme-debug-info') === 'true';
|
|
538
|
+
const shouldGetDebugImage = new URLSearchParams(location.search).get('authme-debug-get-image') === 'true';
|
|
506
539
|
const debugLogs = [];
|
|
540
|
+
const logInfo = {
|
|
541
|
+
userAgent: navigator.userAgent,
|
|
542
|
+
token: '',
|
|
543
|
+
message: ''
|
|
544
|
+
};
|
|
507
545
|
let currentRoundId = generateUniqueId(8);
|
|
508
546
|
let currentType = null;
|
|
547
|
+
const interiaTimeObj = {};
|
|
509
548
|
function pushNewDebugLog(logParams) {
|
|
510
549
|
var _a;
|
|
511
|
-
if (!
|
|
550
|
+
if (!debugMode) return;
|
|
512
551
|
const now = new Date();
|
|
513
552
|
const _logParams = JSON.parse(JSON.stringify(logParams));
|
|
514
553
|
if (_logParams.result) {
|
|
515
554
|
(_a = _logParams.result) === null || _a === void 0 ? true : delete _a.imageData;
|
|
516
555
|
}
|
|
517
|
-
const newDebugLog = Object.assign({
|
|
518
|
-
time: now.getTime(),
|
|
556
|
+
const newDebugLog = Object.assign(Object.assign({
|
|
519
557
|
dateTime: now.toLocaleString(),
|
|
520
558
|
roundId: currentRoundId,
|
|
521
559
|
type: currentType !== null && currentType !== void 0 ? currentType : undefined
|
|
522
|
-
}, _logParams)
|
|
560
|
+
}, _logParams), {
|
|
561
|
+
time: now.getTime(),
|
|
562
|
+
_id: generateUniqueId()
|
|
563
|
+
});
|
|
523
564
|
debugLogs.push(newDebugLog);
|
|
565
|
+
return newDebugLog;
|
|
566
|
+
}
|
|
567
|
+
function pushNewDebugImage(image, log, options) {
|
|
568
|
+
var _a, _b;
|
|
569
|
+
if (!debugMode) return;
|
|
570
|
+
const newLog = pushNewDebugLog(log);
|
|
571
|
+
const recognitionFunctions = [RUN_FUNCTION_NAME.ANTI_FARUD_RECOGNITION, RUN_FUNCTION_NAME.RECOGNITION];
|
|
572
|
+
const currentRoundRecognitionResultItem = debugLogs.find(item => item.roundId === (newLog === null || newLog === void 0 ? void 0 : newLog.roundId) && item.status === 'run-end' && (item.runFunction ? recognitionFunctions.includes(item.runFunction) : false));
|
|
573
|
+
const imageStatus = (_a = currentRoundRecognitionResultItem === null || currentRoundRecognitionResultItem === void 0 ? void 0 : currentRoundRecognitionResultItem.result) === null || _a === void 0 ? void 0 : _a.eStatus;
|
|
574
|
+
pushFile({
|
|
575
|
+
name: `${(_b = options === null || options === void 0 ? void 0 : options.prefix) !== null && _b !== void 0 ? _b : ''}${newLog === null || newLog === void 0 ? void 0 : newLog.time}-${newLog === null || newLog === void 0 ? void 0 : newLog._id}${imageStatus ? `__${imageStatus}` : ''}.jpeg`,
|
|
576
|
+
file: image
|
|
577
|
+
});
|
|
524
578
|
}
|
|
525
579
|
function functionLogging(func, logParams) {
|
|
526
580
|
return new Promise((resolve, reject) => {
|
|
@@ -544,28 +598,209 @@ function debugTools(config) {
|
|
|
544
598
|
});
|
|
545
599
|
});
|
|
546
600
|
}
|
|
601
|
+
function renderDebugTips() {
|
|
602
|
+
if (document.getElementById('debug-tips')) {
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
const debugTips = document.createElement('div');
|
|
606
|
+
debugTips.style.position = 'fixed';
|
|
607
|
+
debugTips.style.top = '50px';
|
|
608
|
+
debugTips.style.right = '0';
|
|
609
|
+
debugTips.style.zIndex = '999';
|
|
610
|
+
debugTips.innerHTML = 'Debug Mode';
|
|
611
|
+
debugTips.style.color = 'red';
|
|
612
|
+
debugTips.style.fontWeight = 'bold';
|
|
613
|
+
debugTips.setAttribute('id', 'debug-tips');
|
|
614
|
+
document.body.appendChild(debugTips);
|
|
615
|
+
}
|
|
616
|
+
function renderDebugUI() {
|
|
617
|
+
if (document.getElementById('debug-ui')) {
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
620
|
+
const debugUI = document.createElement('div');
|
|
621
|
+
debugUI.style.position = 'fixed';
|
|
622
|
+
debugUI.style.top = '0';
|
|
623
|
+
debugUI.style.right = '0';
|
|
624
|
+
debugUI.style.zIndex = '777';
|
|
625
|
+
debugUI.style.backgroundColor = 'black';
|
|
626
|
+
debugUI.style.color = 'white';
|
|
627
|
+
debugUI.style.padding = '10px';
|
|
628
|
+
debugUI.style.paddingRight = '150px';
|
|
629
|
+
debugUI.style.fontSize = '12px';
|
|
630
|
+
debugUI.style.opacity = '0.7';
|
|
631
|
+
debugUI.style.boxSizing = 'border-box';
|
|
632
|
+
debugUI.style.width = '100%';
|
|
633
|
+
debugUI.style.maxHeight = '50vh';
|
|
634
|
+
debugUI.style.overflow = 'auto';
|
|
635
|
+
debugUI.setAttribute('id', 'debug-ui');
|
|
636
|
+
const closeUI = document.createElement('button');
|
|
637
|
+
closeUI.style.position = 'fixed';
|
|
638
|
+
closeUI.style.top = '0';
|
|
639
|
+
closeUI.style.right = '100px';
|
|
640
|
+
closeUI.innerHTML = 'close';
|
|
641
|
+
closeUI.addEventListener('click', () => {
|
|
642
|
+
debugUI.style.display = 'none';
|
|
643
|
+
});
|
|
644
|
+
debugUI.appendChild(closeUI);
|
|
645
|
+
const accordionUI = document.createElement('button');
|
|
646
|
+
accordionUI.style.position = 'fixed';
|
|
647
|
+
accordionUI.style.top = '0';
|
|
648
|
+
accordionUI.style.right = '0';
|
|
649
|
+
accordionUI.innerHTML = '收合/展開';
|
|
650
|
+
accordionUI.addEventListener('click', () => {
|
|
651
|
+
if (debugUI.style.maxHeight === '50vh') {
|
|
652
|
+
debugUI.style.maxHeight = '5vh';
|
|
653
|
+
} else {
|
|
654
|
+
debugUI.style.maxHeight = '50vh';
|
|
655
|
+
}
|
|
656
|
+
});
|
|
657
|
+
debugUI.appendChild(accordionUI);
|
|
658
|
+
document.body.appendChild(debugUI);
|
|
659
|
+
}
|
|
660
|
+
function setTimeStart(behavior) {
|
|
661
|
+
if (!debugModeUI) {
|
|
662
|
+
return;
|
|
663
|
+
}
|
|
664
|
+
const dStart = new Date();
|
|
665
|
+
const nStart = dStart.getTime();
|
|
666
|
+
if (interiaTimeObj && interiaTimeObj[behavior]) {
|
|
667
|
+
console.error('debugmode: setTimeStart duplicate', behavior);
|
|
668
|
+
return false;
|
|
669
|
+
}
|
|
670
|
+
interiaTimeObj[behavior] = {
|
|
671
|
+
behavior,
|
|
672
|
+
start: nStart / 1000,
|
|
673
|
+
duration: 0,
|
|
674
|
+
end: 0
|
|
675
|
+
};
|
|
676
|
+
// console.log(interiaTimeObj[behavior])
|
|
677
|
+
renderTimeInfo(behavior);
|
|
678
|
+
return interiaTimeObj[behavior];
|
|
679
|
+
}
|
|
680
|
+
function setTimeEnd(behavior) {
|
|
681
|
+
if (!debugModeUI) {
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
const dEnd = new Date();
|
|
685
|
+
const nEnd = dEnd.getTime();
|
|
686
|
+
if (!interiaTimeObj[behavior]) {
|
|
687
|
+
console.error('debugmode: setTimeEnd not found', behavior);
|
|
688
|
+
return false;
|
|
689
|
+
}
|
|
690
|
+
interiaTimeObj[behavior].end = nEnd / 1000;
|
|
691
|
+
interiaTimeObj[behavior].duration = interiaTimeObj[behavior].end - interiaTimeObj[behavior].start;
|
|
692
|
+
// console.log(interiaTimeObj[behavior])
|
|
693
|
+
renderTimeInfo(behavior);
|
|
694
|
+
return interiaTimeObj[behavior];
|
|
695
|
+
}
|
|
696
|
+
function setTimeDuration(behavior) {
|
|
697
|
+
const ts = Date.now();
|
|
698
|
+
setTimeStart(`${behavior}_${ts}`);
|
|
699
|
+
return {
|
|
700
|
+
end: () => {
|
|
701
|
+
setTimeEnd(`${behavior}_${ts}`);
|
|
702
|
+
}
|
|
703
|
+
};
|
|
704
|
+
}
|
|
705
|
+
function renderTimeInfo(behavior) {
|
|
706
|
+
const dom = document.querySelector(`#debug-ui-${behavior}`);
|
|
707
|
+
const info = `{"behavior":<span style="color:green;">"${behavior}"</span>, "start": ${interiaTimeObj[behavior].start}, "duration": ${interiaTimeObj[behavior].duration}, "end": ${interiaTimeObj[behavior].end}}`;
|
|
708
|
+
// const info = `<span style="color:green;">${behavior}</span>: Duration: ${interiaTimeObj[behavior].duration}s`;
|
|
709
|
+
if (dom) {
|
|
710
|
+
dom.innerHTML = info;
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
const debugUI = document.getElementById('debug-ui');
|
|
714
|
+
const div = document.createElement('div');
|
|
715
|
+
div.setAttribute('class', 'debug-ui-item');
|
|
716
|
+
div.setAttribute('id', `debug-ui-${behavior}`);
|
|
717
|
+
div.innerHTML = info;
|
|
718
|
+
debugUI.appendChild(div);
|
|
719
|
+
}
|
|
720
|
+
function functionRunTime() {
|
|
721
|
+
const arr = [];
|
|
722
|
+
const items = document.querySelectorAll('.debug-ui-item');
|
|
723
|
+
items.forEach(item => {
|
|
724
|
+
arr.push(JSON.parse(item.innerText));
|
|
725
|
+
});
|
|
726
|
+
return arr;
|
|
727
|
+
}
|
|
728
|
+
if (debugMode) {
|
|
729
|
+
renderDebugTips();
|
|
730
|
+
// setRequestLoggingFunc(functionLogging)
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
if (debugModeUI) {
|
|
734
|
+
console.log('debugModeUI Init');
|
|
735
|
+
renderDebugUI();
|
|
736
|
+
}
|
|
737
|
+
function saveDebugImage({
|
|
738
|
+
getDebugImageData,
|
|
739
|
+
data,
|
|
740
|
+
width,
|
|
741
|
+
height,
|
|
742
|
+
result,
|
|
743
|
+
type
|
|
744
|
+
}) {
|
|
745
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
746
|
+
if (!debugMode || !shouldGetDebugImage) return;
|
|
747
|
+
const debugImage = yield getDebugImageData(data);
|
|
748
|
+
// 創建一個虛擬的 canvas
|
|
749
|
+
const canvas = document.createElement('canvas');
|
|
750
|
+
const ctx = canvas.getContext('2d');
|
|
751
|
+
// 設置 canvas 的尺寸
|
|
752
|
+
canvas.width = width;
|
|
753
|
+
canvas.height = height;
|
|
754
|
+
// 使用 Uint8ClampedArray 將圖像數據繪製到 canvas 上
|
|
755
|
+
const imgData = ctx === null || ctx === void 0 ? void 0 : ctx.createImageData(width, height);
|
|
756
|
+
if (imgData) {
|
|
757
|
+
imgData.data.set(debugImage);
|
|
758
|
+
ctx === null || ctx === void 0 ? void 0 : ctx.putImageData(imgData, 0, 0);
|
|
759
|
+
canvas.toBlob(blob => {
|
|
760
|
+
if (blob) {
|
|
761
|
+
pushNewDebugImage(blob, {
|
|
762
|
+
result: result,
|
|
763
|
+
status: 'recognition',
|
|
764
|
+
type: type
|
|
765
|
+
}, {
|
|
766
|
+
prefix: 'debugImage_'
|
|
767
|
+
});
|
|
768
|
+
}
|
|
769
|
+
}, 'image/jpeg');
|
|
770
|
+
}
|
|
771
|
+
});
|
|
772
|
+
}
|
|
547
773
|
return {
|
|
774
|
+
debugMode,
|
|
775
|
+
debugModeUI,
|
|
548
776
|
pushNewDebugLog,
|
|
549
777
|
getDebugLogs: () => debugLogs,
|
|
550
778
|
getDebugLogsLength: () => debugLogs.length,
|
|
551
779
|
modifyDeubgLog: (index, logParams) => {
|
|
552
|
-
if (!
|
|
780
|
+
if (!debugMode) return;
|
|
553
781
|
debugLogs[index] = Object.assign(Object.assign({}, debugLogs[index]), logParams);
|
|
554
782
|
},
|
|
555
783
|
downloadDebugLogs: () => {
|
|
556
|
-
if (!
|
|
557
|
-
|
|
784
|
+
if (!debugMode) return;
|
|
785
|
+
saveFiles(`debugLog${new Date().getTime().toString()}`, {
|
|
786
|
+
info: logInfo,
|
|
787
|
+
logs: debugLogs,
|
|
788
|
+
functionRunTime: functionRunTime()
|
|
789
|
+
});
|
|
558
790
|
},
|
|
559
791
|
functionLogging,
|
|
560
792
|
nextDebugRound: type => {
|
|
561
|
-
if (!
|
|
793
|
+
if (!debugMode) return;
|
|
562
794
|
currentRoundId = generateUniqueId(8);
|
|
563
795
|
if (type) currentType = type;
|
|
564
796
|
},
|
|
565
797
|
modifyDebugType: type => {
|
|
566
|
-
if (!
|
|
798
|
+
if (!debugMode) return;
|
|
567
799
|
currentType = type;
|
|
568
|
-
}
|
|
800
|
+
},
|
|
801
|
+
pushNewDebugImage,
|
|
802
|
+
setTimeDuration: setTimeDuration,
|
|
803
|
+
saveDebugImage
|
|
569
804
|
};
|
|
570
805
|
}
|
|
571
806
|
|
|
@@ -758,8 +993,9 @@ function showErrorMessage(text, showRetryBtn, callback, buttonText, _titleText)
|
|
|
758
993
|
errorMessagePanel.appendChild(retryText);
|
|
759
994
|
if (callback) {
|
|
760
995
|
retryText.addEventListener('click', e => {
|
|
761
|
-
|
|
762
|
-
|
|
996
|
+
callback(e, {
|
|
997
|
+
hideErrorMessage
|
|
998
|
+
});
|
|
763
999
|
});
|
|
764
1000
|
}
|
|
765
1001
|
}
|
|
@@ -822,13 +1058,12 @@ function asyncShowErrorMessage(text, showRetryBtn, options) {
|
|
|
822
1058
|
function asyncOnLineShowErrorMessage(text, showRetryBtn) {
|
|
823
1059
|
return __awaiter(this, void 0, void 0, function* () {
|
|
824
1060
|
return new Promise((res, rej) => {
|
|
825
|
-
|
|
1061
|
+
showErrorMessage(text, showRetryBtn, (_, tools) => {
|
|
826
1062
|
if (window.navigator.onLine) {
|
|
827
1063
|
res(true);
|
|
828
|
-
hideErrorMessage();
|
|
1064
|
+
tools === null || tools === void 0 ? void 0 : tools.hideErrorMessage();
|
|
829
1065
|
}
|
|
830
|
-
};
|
|
831
|
-
showErrorMessage(text, showRetryBtn, callback);
|
|
1066
|
+
});
|
|
832
1067
|
});
|
|
833
1068
|
});
|
|
834
1069
|
}
|
|
@@ -896,6 +1131,8 @@ var BROWSER_CAMERA_ERRORS;
|
|
|
896
1131
|
BROWSER_CAMERA_ERRORS["NO_CAMERA"] = "NO_CAMERA";
|
|
897
1132
|
BROWSER_CAMERA_ERRORS["NOT_ALLOWED_ERROR"] = "NotAllowedError";
|
|
898
1133
|
BROWSER_CAMERA_ERRORS["NOT_FOUND_ERROR"] = "NotFoundError";
|
|
1134
|
+
BROWSER_CAMERA_ERRORS["NOT_READABLE_ERROR"] = "NotReadableError";
|
|
1135
|
+
BROWSER_CAMERA_ERRORS["ABORT_ERROR"] = "AbortError";
|
|
899
1136
|
})(BROWSER_CAMERA_ERRORS || (BROWSER_CAMERA_ERRORS = {}));
|
|
900
1137
|
let stream;
|
|
901
1138
|
const videoConstraintsFactory = (isPC, facingMode) => {
|
|
@@ -1108,9 +1345,6 @@ function isOverconstrainedError(error) {
|
|
|
1108
1345
|
}
|
|
1109
1346
|
return 'constraint' in error;
|
|
1110
1347
|
}
|
|
1111
|
-
function sleep(ms) {
|
|
1112
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
1113
|
-
}
|
|
1114
1348
|
function requestCamera({
|
|
1115
1349
|
video,
|
|
1116
1350
|
facingMode,
|
|
@@ -1119,29 +1353,7 @@ function requestCamera({
|
|
|
1119
1353
|
}) {
|
|
1120
1354
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1121
1355
|
try {
|
|
1122
|
-
|
|
1123
|
-
name: 'camera'
|
|
1124
|
-
});
|
|
1125
|
-
if (perm.state == 'prompt') {
|
|
1126
|
-
for (let i = 0; i < 5; ++i) {
|
|
1127
|
-
try {
|
|
1128
|
-
//for ios 17.4.1 hack, if you call getUserMedia too early will only get not allowed.
|
|
1129
|
-
yield sleep(1000);
|
|
1130
|
-
return yield _requestCamera(video, facingMode);
|
|
1131
|
-
} catch (error) {
|
|
1132
|
-
if ((error === null || error === void 0 ? void 0 : error.name) === BROWSER_CAMERA_ERRORS.NOT_ALLOWED_ERROR) {
|
|
1133
|
-
perm = yield navigator.permissions.query({
|
|
1134
|
-
name: 'camera'
|
|
1135
|
-
});
|
|
1136
|
-
} else {
|
|
1137
|
-
throw error;
|
|
1138
|
-
}
|
|
1139
|
-
}
|
|
1140
|
-
}
|
|
1141
|
-
return yield _requestCamera(video, facingMode);
|
|
1142
|
-
} else {
|
|
1143
|
-
return yield _requestCamera(video, facingMode);
|
|
1144
|
-
}
|
|
1356
|
+
return yield _requestCamera(video, facingMode);
|
|
1145
1357
|
} catch (error) {
|
|
1146
1358
|
if (error === BROWSER_CAMERA_ERRORS.NOT_SUPPORT) {
|
|
1147
1359
|
showMessage(translate('camera.error.notFound'));
|
|
@@ -1155,6 +1367,15 @@ function requestCamera({
|
|
|
1155
1367
|
showMessage(translate('camera.error.notFound'));
|
|
1156
1368
|
throw new AuthmeError(ErrorCode.CAMERA_NOT_SUPPORT, error);
|
|
1157
1369
|
}
|
|
1370
|
+
if ((error === null || error === void 0 ? void 0 : error.name) === BROWSER_CAMERA_ERRORS.NOT_READABLE_ERROR || (error === null || error === void 0 ? void 0 : error.name) === BROWSER_CAMERA_ERRORS.ABORT_ERROR) {
|
|
1371
|
+
showMessage(translate('camera.error.notFound'));
|
|
1372
|
+
/* NOT_READABLE_ERROR,ABORT_ERROR 這兩個錯誤是用戶授權了,但在呼叫裝置時出現錯誤,
|
|
1373
|
+
* 常發生在APP webview ,例如: 手機開啟 web 使用 sdk,儘管在 webview 層級上授權了,但手機在設定層級沒有授權 app 使用相機,會導致此問題。
|
|
1374
|
+
* 但每個 android 手機的在這方面的實作不一致,不是每個手機在這種情況下都會拋出錯誤。
|
|
1375
|
+
* 參考 https://developer.mozilla.org/zh-CN/docs/Web/API/MediaDevices/getUserMedia#notreadableerror
|
|
1376
|
+
*/
|
|
1377
|
+
throw new AuthmeError(ErrorCode.CAMERA_NOT_SUPPORT, error);
|
|
1378
|
+
}
|
|
1158
1379
|
if (isOverconstrainedError(error)) {
|
|
1159
1380
|
showMessage(translate('camera.error.lowResolution'));
|
|
1160
1381
|
throw new AuthmeError(ErrorCode.CAMERA_NOT_SUPPORT, error);
|
|
@@ -2150,15 +2371,46 @@ function RGBToLottieColor(color) {
|
|
|
2150
2371
|
return color.map(c => c / 255);
|
|
2151
2372
|
}
|
|
2152
2373
|
|
|
2374
|
+
const QUEUE_LENGTH = 10;
|
|
2375
|
+
const requstQueue = [];
|
|
2376
|
+
function pushRequest(request) {
|
|
2377
|
+
if (requstQueue.length > QUEUE_LENGTH - 1) {
|
|
2378
|
+
requstQueue.shift();
|
|
2379
|
+
}
|
|
2380
|
+
requstQueue.push(request);
|
|
2381
|
+
}
|
|
2382
|
+
function clearRequest() {
|
|
2383
|
+
requstQueue.splice(0, requstQueue.length);
|
|
2384
|
+
}
|
|
2385
|
+
function backgroundRequest(request) {
|
|
2386
|
+
const requestPromise = request();
|
|
2387
|
+
requestPromise.catch(err => {
|
|
2388
|
+
if (err._code === ErrorCode.NETWORK_ERROR) {
|
|
2389
|
+
pushRequest(request);
|
|
2390
|
+
}
|
|
2391
|
+
});
|
|
2392
|
+
}
|
|
2393
|
+
window.ononline = () => {
|
|
2394
|
+
const tasks = [...requstQueue];
|
|
2395
|
+
clearRequest();
|
|
2396
|
+
tasks.forEach(request => {
|
|
2397
|
+
backgroundRequest(request);
|
|
2398
|
+
});
|
|
2399
|
+
};
|
|
2400
|
+
|
|
2153
2401
|
var name = "@authme/util";
|
|
2154
|
-
var version$1 = "2.4.
|
|
2402
|
+
var version$1 = "2.4.5";
|
|
2155
2403
|
var peerDependencies = {
|
|
2156
2404
|
"core-js": "^3.6.0"
|
|
2157
2405
|
};
|
|
2406
|
+
var devDependencies = {
|
|
2407
|
+
"@types/file-saver": "^2.0.5"
|
|
2408
|
+
};
|
|
2158
2409
|
var packageInfo = {
|
|
2159
2410
|
name: name,
|
|
2160
2411
|
version: version$1,
|
|
2161
|
-
peerDependencies: peerDependencies
|
|
2412
|
+
peerDependencies: peerDependencies,
|
|
2413
|
+
devDependencies: devDependencies
|
|
2162
2414
|
};
|
|
2163
2415
|
|
|
2164
2416
|
var _a;
|
|
@@ -2167,4 +2419,4 @@ const version = packageInfo.version;
|
|
|
2167
2419
|
(_a = (_b = window)[_c = Symbol.for('authme-sdk')]) !== null && _a !== void 0 ? _a : _b[_c] = {};
|
|
2168
2420
|
window[Symbol.for('authme-sdk')][packageInfo.name] = version;
|
|
2169
2421
|
|
|
2170
|
-
export { AuthmeError, ErrorCode, Icon, RGBToLottieColor, STORAGE_KEY, Storage, TIME_UNIT, UintArrayToBlob, asyncOnLineShowErrorMessage, asyncShowErrorMessage, asyncShowPopup, checkOnlineStatus, clearCanvas, colorStringToRGB, colorToRGB, combineResult, cropByRatio, dataURItoBlob, debugLog, debugTools, decodeToken, getCanvasSize, getCssVariable, getDeviceInfo, getImageData, getSystemInfo, getUserAgent, hexToRGB, hideElement, hideErrorMessage, hidePopup, isIphone14proOrProMax, isMobile, isMobileOrTablet, requestCamera, resize, retryPromiseWithCondition, showElement, showErrorMessage, showErrorMessageEventName, showPopup, splitResult, startLoadingSDK, startSpinner, stopLoadingSDK, stopSpinner, switchCamera, useState, version, videoConstraintsFactory, waitTime };
|
|
2422
|
+
export { AuthmeError, ErrorCode, Icon, RGBToLottieColor, RUN_FUNCTION_NAME, STORAGE_KEY, Storage, TIME_UNIT, UintArrayToBlob, asyncOnLineShowErrorMessage, asyncShowErrorMessage, asyncShowPopup, backgroundRequest, checkOnlineStatus, clearCanvas, colorStringToRGB, colorToRGB, combineResult, cropByRatio, dataURItoBlob, debugLog, debugTools, decodeToken, getCanvasSize, getCssVariable, getDeviceInfo, getImageData, getSystemInfo, getUserAgent, hexToRGB, hideElement, hideErrorMessage, hidePopup, isIphone14proOrProMax, isMobile, isMobileOrTablet, requestCamera, resize, retryPromiseWithCondition, showElement, showErrorMessage, showErrorMessageEventName, showPopup, splitResult, startLoadingSDK, startSpinner, stopLoadingSDK, stopSpinner, switchCamera, useState, version, videoConstraintsFactory, waitTime };
|
package/package.json
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@authme/util",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.5",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"core-js": "^3.6.0",
|
|
6
6
|
"jwt-decode": "3.1.2",
|
|
7
7
|
"rxjs": "7.5.7",
|
|
8
|
+
"file-saver": "2.0.5",
|
|
9
|
+
"jszip": "3.10.1",
|
|
8
10
|
"lottie-web": "5.9.6"
|
|
9
11
|
},
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"@types/file-saver": "^2.0.5"
|
|
14
|
+
},
|
|
10
15
|
"module": "./index.js",
|
|
11
16
|
"main": "./index.cjs",
|
|
12
17
|
"type": "module",
|
package/src/index.d.ts
CHANGED
package/src/lib/authme-log.d.ts
CHANGED
|
@@ -1,22 +1,34 @@
|
|
|
1
|
+
export declare enum RUN_FUNCTION_NAME {
|
|
2
|
+
RECOGNITION = "service.recognition",
|
|
3
|
+
ANTI_FARUD_RECOGNITION = "antiFraudInstance.recognition",
|
|
4
|
+
API_REQUEST = "api.request"
|
|
5
|
+
}
|
|
6
|
+
interface GetDebugImageParams<T> {
|
|
7
|
+
data: Uint8ClampedArray;
|
|
8
|
+
type?: T;
|
|
9
|
+
getDebugImageData: (data: Uint8ClampedArray | Uint8Array) => Promise<Uint8Array>;
|
|
10
|
+
result: any;
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
}
|
|
1
14
|
export declare function debugLog(message?: any, ...others: any[]): void;
|
|
2
15
|
export interface DebugLog<T> {
|
|
3
|
-
image?: string;
|
|
4
|
-
resultOcrImg?: string;
|
|
5
16
|
result?: any;
|
|
6
17
|
report?: any;
|
|
7
18
|
status?: 'recognition' | 'confirm' | 'run-start' | 'run-end' | 'run-error';
|
|
8
|
-
runFunction?:
|
|
19
|
+
runFunction?: RUN_FUNCTION_NAME;
|
|
9
20
|
roundId?: string;
|
|
21
|
+
_id: string;
|
|
10
22
|
type?: T;
|
|
11
|
-
time
|
|
23
|
+
time: number;
|
|
12
24
|
dateTime?: string;
|
|
13
25
|
message?: any;
|
|
14
26
|
isAntiFraud?: boolean;
|
|
15
27
|
}
|
|
16
|
-
export declare function debugTools<T>(
|
|
28
|
+
export declare function debugTools<T>(): {
|
|
17
29
|
debugMode: boolean;
|
|
18
|
-
|
|
19
|
-
pushNewDebugLog: (logParams: DebugLog<T
|
|
30
|
+
debugModeUI: boolean;
|
|
31
|
+
pushNewDebugLog: (logParams: Partial<DebugLog<T>>) => DebugLog<T> | undefined;
|
|
20
32
|
getDebugLogs: () => DebugLog<T>[];
|
|
21
33
|
getDebugLogsLength: () => number;
|
|
22
34
|
modifyDeubgLog: (index: number, logParams: Partial<DebugLog<T>>) => void;
|
|
@@ -24,4 +36,12 @@ export declare function debugTools<T>(config: {
|
|
|
24
36
|
functionLogging: <P>(func: () => Promise<P>, logParams?: Partial<DebugLog<T>>) => Promise<P>;
|
|
25
37
|
nextDebugRound: (type?: T) => void;
|
|
26
38
|
modifyDebugType: (type: T) => void;
|
|
39
|
+
pushNewDebugImage: (image: Blob, log: Partial<DebugLog<T>>, options?: {
|
|
40
|
+
prefix?: string;
|
|
41
|
+
}) => void;
|
|
42
|
+
setTimeDuration: (behavior: string) => {
|
|
43
|
+
end: () => void;
|
|
44
|
+
};
|
|
45
|
+
saveDebugImage: ({ getDebugImageData, data, width, height, result, type, }: GetDebugImageParams<T>) => Promise<void>;
|
|
27
46
|
};
|
|
47
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function backgroundRequest<T = unknown>(request: () => Promise<T>): void;
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
export declare
|
|
2
|
-
export declare
|
|
1
|
+
export declare type ShowErrorMessageHandler = (text: string, showRetryBtn?: boolean, callback?: CallBackType, buttonText?: string, titleText?: string) => void;
|
|
2
|
+
export declare type CallBackType = (e: Event, tools?: {
|
|
3
|
+
hideErrorMessage: () => void;
|
|
4
|
+
}) => void;
|
|
5
|
+
export declare function showErrorMessage(text: string, showRetryBtn?: boolean, callback?: CallBackType, buttonText?: string, _titleText?: string): Promise<void>;
|
|
6
|
+
export declare function showErrorMessageEventName(text: string, showRetryBtn?: boolean, callback?: CallBackType, buttonText?: string, titleText?: string): Promise<void>;
|
|
3
7
|
export declare function hideErrorMessage(): void;
|
|
4
8
|
export declare function asyncShowErrorMessage(text: string, showRetryBtn?: boolean, options?: {
|
|
5
|
-
callback?:
|
|
9
|
+
callback?: CallBackType;
|
|
6
10
|
buttonText?: string;
|
|
7
11
|
titleText?: string;
|
|
8
|
-
|
|
9
|
-
showErrorMessageHandler?: (text: string) => void;
|
|
12
|
+
showErrorMessageHandler?: ShowErrorMessageHandler;
|
|
10
13
|
}): Promise<boolean>;
|
|
11
14
|
export declare function asyncOnLineShowErrorMessage(text: string, showRetryBtn?: boolean): Promise<boolean>;
|
|
12
15
|
export declare function checkOnlineStatus(msg: string): Promise<void>;
|