@authme/util 2.4.8 → 2.4.11
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 +66 -330
- package/index.js +66 -328
- package/package.json +1 -6
- package/src/index.d.ts +0 -1
- package/src/lib/authme-log.d.ts +7 -27
- package/src/lib/common/index.d.ts +1 -1
- package/src/ui/error-message.d.ts +5 -8
- package/src/lib/background-request-process.d.ts +0 -1
- package/src/lib/file-saver.d.ts +0 -11
package/index.cjs
CHANGED
|
@@ -11,22 +11,20 @@ require('core-js/modules/es.typed-array.sort.js');
|
|
|
11
11
|
require('core-js/modules/es.typed-array.to-locale-string.js');
|
|
12
12
|
require('core-js/modules/es.promise.js');
|
|
13
13
|
require('core-js/modules/es.regexp.exec.js');
|
|
14
|
-
require('core-js/modules/es.string.match.js');
|
|
15
|
-
require('core-js/modules/es.string.replace.js');
|
|
16
14
|
require('core-js/modules/es.regexp.to-string.js');
|
|
17
15
|
require('core-js/modules/web.dom-collections.iterator.js');
|
|
18
16
|
require('core-js/modules/es.object.assign.js');
|
|
19
17
|
require('core-js/modules/es.number.parse-int.js');
|
|
20
18
|
var jwt_decode = require('jwt-decode');
|
|
19
|
+
require('core-js/modules/es.string.match.js');
|
|
20
|
+
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
|
-
require('core-js/modules/es.array.includes.js');
|
|
25
|
-
require('core-js/modules/es.string.includes.js');
|
|
26
|
-
var fileSaver = require('file-saver');
|
|
27
|
-
var JSZip = require('jszip');
|
|
28
24
|
var Lottie = require('lottie-web');
|
|
29
25
|
require('core-js/modules/es.array.sort.js');
|
|
26
|
+
require('core-js/modules/es.array.includes.js');
|
|
27
|
+
require('core-js/modules/es.string.includes.js');
|
|
30
28
|
require('core-js/modules/es.parse-int.js');
|
|
31
29
|
require('core-js/modules/es.string.trim.js');
|
|
32
30
|
require('core-js/modules/es.string.starts-with.js');
|
|
@@ -35,7 +33,6 @@ require('core-js/modules/es.symbol.description.js');
|
|
|
35
33
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
36
34
|
|
|
37
35
|
var jwt_decode__default = /*#__PURE__*/_interopDefaultLegacy(jwt_decode);
|
|
38
|
-
var JSZip__default = /*#__PURE__*/_interopDefaultLegacy(JSZip);
|
|
39
36
|
var Lottie__default = /*#__PURE__*/_interopDefaultLegacy(Lottie);
|
|
40
37
|
|
|
41
38
|
const GLOBAL_KEY = '_AuthmeConfig';
|
|
@@ -388,6 +385,9 @@ function retryPromiseWithCondition(promiseFactory, conditionFactory) {
|
|
|
388
385
|
}
|
|
389
386
|
});
|
|
390
387
|
}
|
|
388
|
+
function getUserAgent() {
|
|
389
|
+
return `platform: ${navigator === null || navigator === void 0 ? void 0 : navigator.platform}`;
|
|
390
|
+
}
|
|
391
391
|
function isMobileOrTablet() {
|
|
392
392
|
return function (a) {
|
|
393
393
|
return !!(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55\/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk\/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-|your|zeto|zte-/i.test(a.substr(0, 4)) || /Android|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) || navigator.maxTouchPoints && navigator.maxTouchPoints > 2);
|
|
@@ -398,25 +398,6 @@ function isMobile() {
|
|
|
398
398
|
return !!(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55\/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk\/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-|your|zeto|zte-/i.test(a.substr(0, 4)) || /Android|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
|
|
399
399
|
}(navigator.userAgent || navigator.vendor || window.opera);
|
|
400
400
|
}
|
|
401
|
-
function osVersion() {
|
|
402
|
-
let version = '';
|
|
403
|
-
const android = navigator.userAgent.match(/Android\s+([\d\\.]+)/i);
|
|
404
|
-
if (android) {
|
|
405
|
-
version = android[0];
|
|
406
|
-
}
|
|
407
|
-
const ios = navigator.userAgent.match(/OS\s+([\d\\_]+)/i);
|
|
408
|
-
if (ios) {
|
|
409
|
-
version = ios[0].replace('OS ', 'iOS');
|
|
410
|
-
}
|
|
411
|
-
const win = navigator.userAgent.match(/Windows NT (\d+\.\d+)/);
|
|
412
|
-
if (win) {
|
|
413
|
-
version = win[0];
|
|
414
|
-
}
|
|
415
|
-
if (!version) {
|
|
416
|
-
version = navigator.platform;
|
|
417
|
-
}
|
|
418
|
-
return version;
|
|
419
|
-
}
|
|
420
401
|
function splitResult(result) {
|
|
421
402
|
if (result.address) {
|
|
422
403
|
const originAddress = result.address;
|
|
@@ -499,44 +480,6 @@ const isIphone14proOrProMax = () => {
|
|
|
499
480
|
return isIphone() && (screen.width === 430 && screen.height === 932 || screen.width === 393 && screen.height === 852);
|
|
500
481
|
};
|
|
501
482
|
|
|
502
|
-
function fileSaverService() {
|
|
503
|
-
const filesQueue = [];
|
|
504
|
-
function pushFile(file) {
|
|
505
|
-
filesQueue.push(file);
|
|
506
|
-
}
|
|
507
|
-
function popAllFiles() {
|
|
508
|
-
filesQueue.splice(0, filesQueue.length);
|
|
509
|
-
}
|
|
510
|
-
function saveFiles(fileName, json) {
|
|
511
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
512
|
-
const zip = new JSZip__default["default"]();
|
|
513
|
-
filesQueue.forEach(fileItem => {
|
|
514
|
-
zip.file(fileItem.name, fileItem.file);
|
|
515
|
-
});
|
|
516
|
-
if (json) zip.file('data.json', JSON.stringify(json));
|
|
517
|
-
const content = yield zip.generateAsync({
|
|
518
|
-
type: 'blob'
|
|
519
|
-
});
|
|
520
|
-
fileSaver.saveAs(content, `${fileName}.zip`);
|
|
521
|
-
popAllFiles();
|
|
522
|
-
});
|
|
523
|
-
}
|
|
524
|
-
return {
|
|
525
|
-
pushFile,
|
|
526
|
-
saveFiles
|
|
527
|
-
};
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
const {
|
|
531
|
-
saveFiles,
|
|
532
|
-
pushFile
|
|
533
|
-
} = fileSaverService();
|
|
534
|
-
exports.RUN_FUNCTION_NAME = void 0;
|
|
535
|
-
(function (RUN_FUNCTION_NAME) {
|
|
536
|
-
RUN_FUNCTION_NAME["RECOGNITION"] = "service.recognition";
|
|
537
|
-
RUN_FUNCTION_NAME["ANTI_FARUD_RECOGNITION"] = "antiFraudInstance.recognition";
|
|
538
|
-
RUN_FUNCTION_NAME["API_REQUEST"] = "api.request";
|
|
539
|
-
})(exports.RUN_FUNCTION_NAME || (exports.RUN_FUNCTION_NAME = {}));
|
|
540
483
|
function debugLog(message, ...others) {
|
|
541
484
|
if (new URLSearchParams(location.search).get('authme-debug') === 'true') {
|
|
542
485
|
console.log(message, ...others);
|
|
@@ -558,49 +501,35 @@ function generateUniqueId(length = 32) {
|
|
|
558
501
|
}
|
|
559
502
|
return result;
|
|
560
503
|
}
|
|
561
|
-
function
|
|
562
|
-
const
|
|
563
|
-
|
|
564
|
-
const
|
|
504
|
+
function downloadObjectAsJson(exportObj, exportName) {
|
|
505
|
+
const dataStr = `data:application/octet-stream;headers=Content-Disposition%3A%20attachment%3B%20filename=${exportName}.json,${encodeURIComponent(JSON.stringify(exportObj, null, 4))}`;
|
|
506
|
+
//'data:text/json;charset=utf-8,' +
|
|
507
|
+
const downloadAnchorNode = document.createElement('a');
|
|
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) {
|
|
565
515
|
const debugLogs = [];
|
|
566
|
-
const logInfo = {
|
|
567
|
-
userAgent: navigator.userAgent,
|
|
568
|
-
token: '',
|
|
569
|
-
message: ''
|
|
570
|
-
};
|
|
571
516
|
let currentRoundId = generateUniqueId(8);
|
|
572
517
|
let currentType = null;
|
|
573
|
-
const interiaTimeObj = {};
|
|
574
518
|
function pushNewDebugLog(logParams) {
|
|
575
519
|
var _a;
|
|
576
|
-
if (!debugMode) return;
|
|
520
|
+
if (!config.debugMode) return;
|
|
577
521
|
const now = new Date();
|
|
578
522
|
const _logParams = JSON.parse(JSON.stringify(logParams));
|
|
579
523
|
if (_logParams.result) {
|
|
580
524
|
(_a = _logParams.result) === null || _a === void 0 ? true : delete _a.imageData;
|
|
581
525
|
}
|
|
582
|
-
const newDebugLog = Object.assign(
|
|
526
|
+
const newDebugLog = Object.assign({
|
|
527
|
+
time: now.getTime(),
|
|
583
528
|
dateTime: now.toLocaleString(),
|
|
584
529
|
roundId: currentRoundId,
|
|
585
530
|
type: currentType !== null && currentType !== void 0 ? currentType : undefined
|
|
586
|
-
}, _logParams)
|
|
587
|
-
time: now.getTime(),
|
|
588
|
-
_id: generateUniqueId()
|
|
589
|
-
});
|
|
531
|
+
}, _logParams);
|
|
590
532
|
debugLogs.push(newDebugLog);
|
|
591
|
-
return newDebugLog;
|
|
592
|
-
}
|
|
593
|
-
function pushNewDebugImage(image, log, options) {
|
|
594
|
-
var _a, _b;
|
|
595
|
-
if (!debugMode) return;
|
|
596
|
-
const newLog = pushNewDebugLog(log);
|
|
597
|
-
const recognitionFunctions = [exports.RUN_FUNCTION_NAME.ANTI_FARUD_RECOGNITION, exports.RUN_FUNCTION_NAME.RECOGNITION];
|
|
598
|
-
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));
|
|
599
|
-
const imageStatus = (_a = currentRoundRecognitionResultItem === null || currentRoundRecognitionResultItem === void 0 ? void 0 : currentRoundRecognitionResultItem.result) === null || _a === void 0 ? void 0 : _a.eStatus;
|
|
600
|
-
pushFile({
|
|
601
|
-
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`,
|
|
602
|
-
file: image
|
|
603
|
-
});
|
|
604
533
|
}
|
|
605
534
|
function functionLogging(func, logParams) {
|
|
606
535
|
return new Promise((resolve, reject) => {
|
|
@@ -624,209 +553,28 @@ function debugTools() {
|
|
|
624
553
|
});
|
|
625
554
|
});
|
|
626
555
|
}
|
|
627
|
-
function renderDebugTips() {
|
|
628
|
-
if (document.getElementById('debug-tips')) {
|
|
629
|
-
return;
|
|
630
|
-
}
|
|
631
|
-
const debugTips = document.createElement('div');
|
|
632
|
-
debugTips.style.position = 'fixed';
|
|
633
|
-
debugTips.style.top = '50px';
|
|
634
|
-
debugTips.style.right = '0';
|
|
635
|
-
debugTips.style.zIndex = '999';
|
|
636
|
-
debugTips.innerHTML = 'Debug Mode';
|
|
637
|
-
debugTips.style.color = 'red';
|
|
638
|
-
debugTips.style.fontWeight = 'bold';
|
|
639
|
-
debugTips.setAttribute('id', 'debug-tips');
|
|
640
|
-
document.body.appendChild(debugTips);
|
|
641
|
-
}
|
|
642
|
-
function renderDebugUI() {
|
|
643
|
-
if (document.getElementById('debug-ui')) {
|
|
644
|
-
return;
|
|
645
|
-
}
|
|
646
|
-
const debugUI = document.createElement('div');
|
|
647
|
-
debugUI.style.position = 'fixed';
|
|
648
|
-
debugUI.style.top = '0';
|
|
649
|
-
debugUI.style.right = '0';
|
|
650
|
-
debugUI.style.zIndex = '777';
|
|
651
|
-
debugUI.style.backgroundColor = 'black';
|
|
652
|
-
debugUI.style.color = 'white';
|
|
653
|
-
debugUI.style.padding = '10px';
|
|
654
|
-
debugUI.style.paddingRight = '150px';
|
|
655
|
-
debugUI.style.fontSize = '12px';
|
|
656
|
-
debugUI.style.opacity = '0.7';
|
|
657
|
-
debugUI.style.boxSizing = 'border-box';
|
|
658
|
-
debugUI.style.width = '100%';
|
|
659
|
-
debugUI.style.maxHeight = '50vh';
|
|
660
|
-
debugUI.style.overflow = 'auto';
|
|
661
|
-
debugUI.setAttribute('id', 'debug-ui');
|
|
662
|
-
const closeUI = document.createElement('button');
|
|
663
|
-
closeUI.style.position = 'fixed';
|
|
664
|
-
closeUI.style.top = '0';
|
|
665
|
-
closeUI.style.right = '100px';
|
|
666
|
-
closeUI.innerHTML = 'close';
|
|
667
|
-
closeUI.addEventListener('click', () => {
|
|
668
|
-
debugUI.style.display = 'none';
|
|
669
|
-
});
|
|
670
|
-
debugUI.appendChild(closeUI);
|
|
671
|
-
const accordionUI = document.createElement('button');
|
|
672
|
-
accordionUI.style.position = 'fixed';
|
|
673
|
-
accordionUI.style.top = '0';
|
|
674
|
-
accordionUI.style.right = '0';
|
|
675
|
-
accordionUI.innerHTML = '收合/展開';
|
|
676
|
-
accordionUI.addEventListener('click', () => {
|
|
677
|
-
if (debugUI.style.maxHeight === '50vh') {
|
|
678
|
-
debugUI.style.maxHeight = '5vh';
|
|
679
|
-
} else {
|
|
680
|
-
debugUI.style.maxHeight = '50vh';
|
|
681
|
-
}
|
|
682
|
-
});
|
|
683
|
-
debugUI.appendChild(accordionUI);
|
|
684
|
-
document.body.appendChild(debugUI);
|
|
685
|
-
}
|
|
686
|
-
function setTimeStart(behavior) {
|
|
687
|
-
if (!debugModeUI) {
|
|
688
|
-
return;
|
|
689
|
-
}
|
|
690
|
-
const dStart = new Date();
|
|
691
|
-
const nStart = dStart.getTime();
|
|
692
|
-
if (interiaTimeObj && interiaTimeObj[behavior]) {
|
|
693
|
-
console.error('debugmode: setTimeStart duplicate', behavior);
|
|
694
|
-
return false;
|
|
695
|
-
}
|
|
696
|
-
interiaTimeObj[behavior] = {
|
|
697
|
-
behavior,
|
|
698
|
-
start: nStart / 1000,
|
|
699
|
-
duration: 0,
|
|
700
|
-
end: 0
|
|
701
|
-
};
|
|
702
|
-
// console.log(interiaTimeObj[behavior])
|
|
703
|
-
renderTimeInfo(behavior);
|
|
704
|
-
return interiaTimeObj[behavior];
|
|
705
|
-
}
|
|
706
|
-
function setTimeEnd(behavior) {
|
|
707
|
-
if (!debugModeUI) {
|
|
708
|
-
return;
|
|
709
|
-
}
|
|
710
|
-
const dEnd = new Date();
|
|
711
|
-
const nEnd = dEnd.getTime();
|
|
712
|
-
if (!interiaTimeObj[behavior]) {
|
|
713
|
-
console.error('debugmode: setTimeEnd not found', behavior);
|
|
714
|
-
return false;
|
|
715
|
-
}
|
|
716
|
-
interiaTimeObj[behavior].end = nEnd / 1000;
|
|
717
|
-
interiaTimeObj[behavior].duration = interiaTimeObj[behavior].end - interiaTimeObj[behavior].start;
|
|
718
|
-
// console.log(interiaTimeObj[behavior])
|
|
719
|
-
renderTimeInfo(behavior);
|
|
720
|
-
return interiaTimeObj[behavior];
|
|
721
|
-
}
|
|
722
|
-
function setTimeDuration(behavior) {
|
|
723
|
-
const ts = Date.now();
|
|
724
|
-
setTimeStart(`${behavior}_${ts}`);
|
|
725
|
-
return {
|
|
726
|
-
end: () => {
|
|
727
|
-
setTimeEnd(`${behavior}_${ts}`);
|
|
728
|
-
}
|
|
729
|
-
};
|
|
730
|
-
}
|
|
731
|
-
function renderTimeInfo(behavior) {
|
|
732
|
-
const dom = document.querySelector(`#debug-ui-${behavior}`);
|
|
733
|
-
const info = `{"behavior":<span style="color:green;">"${behavior}"</span>, "start": ${interiaTimeObj[behavior].start}, "duration": ${interiaTimeObj[behavior].duration}, "end": ${interiaTimeObj[behavior].end}}`;
|
|
734
|
-
// const info = `<span style="color:green;">${behavior}</span>: Duration: ${interiaTimeObj[behavior].duration}s`;
|
|
735
|
-
if (dom) {
|
|
736
|
-
dom.innerHTML = info;
|
|
737
|
-
return;
|
|
738
|
-
}
|
|
739
|
-
const debugUI = document.getElementById('debug-ui');
|
|
740
|
-
const div = document.createElement('div');
|
|
741
|
-
div.setAttribute('class', 'debug-ui-item');
|
|
742
|
-
div.setAttribute('id', `debug-ui-${behavior}`);
|
|
743
|
-
div.innerHTML = info;
|
|
744
|
-
debugUI.appendChild(div);
|
|
745
|
-
}
|
|
746
|
-
function functionRunTime() {
|
|
747
|
-
const arr = [];
|
|
748
|
-
const items = document.querySelectorAll('.debug-ui-item');
|
|
749
|
-
items.forEach(item => {
|
|
750
|
-
arr.push(JSON.parse(item.innerText));
|
|
751
|
-
});
|
|
752
|
-
return arr;
|
|
753
|
-
}
|
|
754
|
-
if (debugMode) {
|
|
755
|
-
renderDebugTips();
|
|
756
|
-
// setRequestLoggingFunc(functionLogging)
|
|
757
|
-
}
|
|
758
|
-
|
|
759
|
-
if (debugModeUI) {
|
|
760
|
-
console.log('debugModeUI Init');
|
|
761
|
-
renderDebugUI();
|
|
762
|
-
}
|
|
763
|
-
function saveDebugImage({
|
|
764
|
-
getDebugImageData,
|
|
765
|
-
data,
|
|
766
|
-
width,
|
|
767
|
-
height,
|
|
768
|
-
result,
|
|
769
|
-
type
|
|
770
|
-
}) {
|
|
771
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
772
|
-
if (!debugMode || !shouldGetDebugImage) return;
|
|
773
|
-
const debugImage = yield getDebugImageData(data);
|
|
774
|
-
// 創建一個虛擬的 canvas
|
|
775
|
-
const canvas = document.createElement('canvas');
|
|
776
|
-
const ctx = canvas.getContext('2d');
|
|
777
|
-
// 設置 canvas 的尺寸
|
|
778
|
-
canvas.width = width;
|
|
779
|
-
canvas.height = height;
|
|
780
|
-
// 使用 Uint8ClampedArray 將圖像數據繪製到 canvas 上
|
|
781
|
-
const imgData = ctx === null || ctx === void 0 ? void 0 : ctx.createImageData(width, height);
|
|
782
|
-
if (imgData) {
|
|
783
|
-
imgData.data.set(debugImage);
|
|
784
|
-
ctx === null || ctx === void 0 ? void 0 : ctx.putImageData(imgData, 0, 0);
|
|
785
|
-
canvas.toBlob(blob => {
|
|
786
|
-
if (blob) {
|
|
787
|
-
pushNewDebugImage(blob, {
|
|
788
|
-
result: result,
|
|
789
|
-
status: 'recognition',
|
|
790
|
-
type: type
|
|
791
|
-
}, {
|
|
792
|
-
prefix: 'debugImage_'
|
|
793
|
-
});
|
|
794
|
-
}
|
|
795
|
-
}, 'image/jpeg');
|
|
796
|
-
}
|
|
797
|
-
});
|
|
798
|
-
}
|
|
799
556
|
return {
|
|
800
|
-
debugMode,
|
|
801
|
-
debugModeUI,
|
|
802
557
|
pushNewDebugLog,
|
|
803
558
|
getDebugLogs: () => debugLogs,
|
|
804
559
|
getDebugLogsLength: () => debugLogs.length,
|
|
805
560
|
modifyDeubgLog: (index, logParams) => {
|
|
806
|
-
if (!debugMode) return;
|
|
561
|
+
if (!config.debugMode) return;
|
|
807
562
|
debugLogs[index] = Object.assign(Object.assign({}, debugLogs[index]), logParams);
|
|
808
563
|
},
|
|
809
564
|
downloadDebugLogs: () => {
|
|
810
|
-
if (!debugMode) return;
|
|
811
|
-
|
|
812
|
-
info: logInfo,
|
|
813
|
-
logs: debugLogs,
|
|
814
|
-
functionRunTime: functionRunTime()
|
|
815
|
-
});
|
|
565
|
+
if (!config.debugMode) return;
|
|
566
|
+
downloadObjectAsJson(debugLogs, `debugLog${new Date().getTime().toString()}`);
|
|
816
567
|
},
|
|
817
568
|
functionLogging,
|
|
818
569
|
nextDebugRound: type => {
|
|
819
|
-
if (!debugMode) return;
|
|
570
|
+
if (!config.debugMode) return;
|
|
820
571
|
currentRoundId = generateUniqueId(8);
|
|
821
572
|
if (type) currentType = type;
|
|
822
573
|
},
|
|
823
574
|
modifyDebugType: type => {
|
|
824
|
-
if (!debugMode) return;
|
|
575
|
+
if (!config.debugMode) return;
|
|
825
576
|
currentType = type;
|
|
826
|
-
}
|
|
827
|
-
pushNewDebugImage,
|
|
828
|
-
setTimeDuration: setTimeDuration,
|
|
829
|
-
saveDebugImage
|
|
577
|
+
}
|
|
830
578
|
};
|
|
831
579
|
}
|
|
832
580
|
|
|
@@ -1019,9 +767,8 @@ function showErrorMessage(text, showRetryBtn, callback, buttonText, _titleText)
|
|
|
1019
767
|
errorMessagePanel.appendChild(retryText);
|
|
1020
768
|
if (callback) {
|
|
1021
769
|
retryText.addEventListener('click', e => {
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
});
|
|
770
|
+
target.removeChild(errorMessagePanel);
|
|
771
|
+
callback(e);
|
|
1025
772
|
});
|
|
1026
773
|
}
|
|
1027
774
|
}
|
|
@@ -1084,12 +831,13 @@ function asyncShowErrorMessage(text, showRetryBtn, options) {
|
|
|
1084
831
|
function asyncOnLineShowErrorMessage(text, showRetryBtn) {
|
|
1085
832
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1086
833
|
return new Promise((res, rej) => {
|
|
1087
|
-
|
|
834
|
+
const callback = () => {
|
|
1088
835
|
if (window.navigator.onLine) {
|
|
1089
836
|
res(true);
|
|
1090
|
-
|
|
837
|
+
hideErrorMessage();
|
|
1091
838
|
}
|
|
1092
|
-
}
|
|
839
|
+
};
|
|
840
|
+
showErrorMessage(text, showRetryBtn, callback);
|
|
1093
841
|
});
|
|
1094
842
|
});
|
|
1095
843
|
}
|
|
@@ -1157,8 +905,6 @@ var BROWSER_CAMERA_ERRORS;
|
|
|
1157
905
|
BROWSER_CAMERA_ERRORS["NO_CAMERA"] = "NO_CAMERA";
|
|
1158
906
|
BROWSER_CAMERA_ERRORS["NOT_ALLOWED_ERROR"] = "NotAllowedError";
|
|
1159
907
|
BROWSER_CAMERA_ERRORS["NOT_FOUND_ERROR"] = "NotFoundError";
|
|
1160
|
-
BROWSER_CAMERA_ERRORS["NOT_READABLE_ERROR"] = "NotReadableError";
|
|
1161
|
-
BROWSER_CAMERA_ERRORS["ABORT_ERROR"] = "AbortError";
|
|
1162
908
|
})(BROWSER_CAMERA_ERRORS || (BROWSER_CAMERA_ERRORS = {}));
|
|
1163
909
|
let stream;
|
|
1164
910
|
const videoConstraintsFactory = (isPC, facingMode) => {
|
|
@@ -1371,6 +1117,9 @@ function isOverconstrainedError(error) {
|
|
|
1371
1117
|
}
|
|
1372
1118
|
return 'constraint' in error;
|
|
1373
1119
|
}
|
|
1120
|
+
function sleep(ms) {
|
|
1121
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
1122
|
+
}
|
|
1374
1123
|
function requestCamera({
|
|
1375
1124
|
video,
|
|
1376
1125
|
facingMode,
|
|
@@ -1379,7 +1128,29 @@ function requestCamera({
|
|
|
1379
1128
|
}) {
|
|
1380
1129
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1381
1130
|
try {
|
|
1382
|
-
|
|
1131
|
+
let perm = yield navigator.permissions.query({
|
|
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
|
+
}
|
|
1383
1154
|
} catch (error) {
|
|
1384
1155
|
if (error === BROWSER_CAMERA_ERRORS.NOT_SUPPORT) {
|
|
1385
1156
|
showMessage(translate('camera.error.notFound'));
|
|
@@ -1393,15 +1164,6 @@ function requestCamera({
|
|
|
1393
1164
|
showMessage(translate('camera.error.notFound'));
|
|
1394
1165
|
throw new AuthmeError(exports.ErrorCode.CAMERA_NOT_SUPPORT, error);
|
|
1395
1166
|
}
|
|
1396
|
-
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) {
|
|
1397
|
-
showMessage(translate('camera.error.notFound'));
|
|
1398
|
-
/* NOT_READABLE_ERROR,ABORT_ERROR 這兩個錯誤是用戶授權了,但在呼叫裝置時出現錯誤,
|
|
1399
|
-
* 常發生在APP webview ,例如: 手機開啟 web 使用 sdk,儘管在 webview 層級上授權了,但手機在設定層級沒有授權 app 使用相機,會導致此問題。
|
|
1400
|
-
* 但每個 android 手機的在這方面的實作不一致,不是每個手機在這種情況下都會拋出錯誤。
|
|
1401
|
-
* 參考 https://developer.mozilla.org/zh-CN/docs/Web/API/MediaDevices/getUserMedia#notreadableerror
|
|
1402
|
-
*/
|
|
1403
|
-
throw new AuthmeError(exports.ErrorCode.CAMERA_NOT_SUPPORT, error);
|
|
1404
|
-
}
|
|
1405
1167
|
if (isOverconstrainedError(error)) {
|
|
1406
1168
|
showMessage(translate('camera.error.lowResolution'));
|
|
1407
1169
|
throw new AuthmeError(exports.ErrorCode.CAMERA_NOT_SUPPORT, error);
|
|
@@ -2397,40 +2159,15 @@ function RGBToLottieColor(color) {
|
|
|
2397
2159
|
return color.map(c => c / 255);
|
|
2398
2160
|
}
|
|
2399
2161
|
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
requstQueue.shift();
|
|
2405
|
-
}
|
|
2406
|
-
requstQueue.push(request);
|
|
2407
|
-
}
|
|
2408
|
-
function clearRequest() {
|
|
2409
|
-
requstQueue.splice(0, requstQueue.length);
|
|
2410
|
-
}
|
|
2411
|
-
function backgroundRequest(request) {
|
|
2412
|
-
const requestPromise = request();
|
|
2413
|
-
requestPromise.catch(err => {
|
|
2414
|
-
if (err._code === exports.ErrorCode.NETWORK_ERROR) {
|
|
2415
|
-
pushRequest(request);
|
|
2416
|
-
}
|
|
2417
|
-
});
|
|
2418
|
-
}
|
|
2419
|
-
window.ononline = () => {
|
|
2420
|
-
const tasks = [...requstQueue];
|
|
2421
|
-
clearRequest();
|
|
2422
|
-
tasks.forEach(request => {
|
|
2423
|
-
backgroundRequest(request);
|
|
2424
|
-
});
|
|
2162
|
+
var name = "@authme/util";
|
|
2163
|
+
var version$1 = "2.4.11";
|
|
2164
|
+
var peerDependencies = {
|
|
2165
|
+
"core-js": "^3.6.0"
|
|
2425
2166
|
};
|
|
2426
|
-
|
|
2427
|
-
var name = "authme/sdk";
|
|
2428
|
-
var version$1 = "2.4.8";
|
|
2429
|
-
var date = "2023-12-20T07:24:47+0000";
|
|
2430
2167
|
var packageInfo = {
|
|
2431
2168
|
name: name,
|
|
2432
2169
|
version: version$1,
|
|
2433
|
-
|
|
2170
|
+
peerDependencies: peerDependencies
|
|
2434
2171
|
};
|
|
2435
2172
|
|
|
2436
2173
|
var _a;
|
|
@@ -2446,7 +2183,6 @@ exports.UintArrayToBlob = UintArrayToBlob;
|
|
|
2446
2183
|
exports.asyncOnLineShowErrorMessage = asyncOnLineShowErrorMessage;
|
|
2447
2184
|
exports.asyncShowErrorMessage = asyncShowErrorMessage;
|
|
2448
2185
|
exports.asyncShowPopup = asyncShowPopup;
|
|
2449
|
-
exports.backgroundRequest = backgroundRequest;
|
|
2450
2186
|
exports.checkOnlineStatus = checkOnlineStatus;
|
|
2451
2187
|
exports.clearCanvas = clearCanvas;
|
|
2452
2188
|
exports.colorStringToRGB = colorStringToRGB;
|
|
@@ -2462,6 +2198,7 @@ exports.getCssVariable = getCssVariable;
|
|
|
2462
2198
|
exports.getDeviceInfo = getDeviceInfo;
|
|
2463
2199
|
exports.getImageData = getImageData;
|
|
2464
2200
|
exports.getSystemInfo = getSystemInfo;
|
|
2201
|
+
exports.getUserAgent = getUserAgent;
|
|
2465
2202
|
exports.hexToRGB = hexToRGB;
|
|
2466
2203
|
exports.hideElement = hideElement;
|
|
2467
2204
|
exports.hideErrorMessage = hideErrorMessage;
|
|
@@ -2469,7 +2206,6 @@ exports.hidePopup = hidePopup;
|
|
|
2469
2206
|
exports.isIphone14proOrProMax = isIphone14proOrProMax;
|
|
2470
2207
|
exports.isMobile = isMobile;
|
|
2471
2208
|
exports.isMobileOrTablet = isMobileOrTablet;
|
|
2472
|
-
exports.osVersion = osVersion;
|
|
2473
2209
|
exports.requestCamera = requestCamera;
|
|
2474
2210
|
exports.resize = resize;
|
|
2475
2211
|
exports.retryPromiseWithCondition = retryPromiseWithCondition;
|
package/index.js
CHANGED
|
@@ -7,22 +7,20 @@ import 'core-js/modules/es.typed-array.sort.js';
|
|
|
7
7
|
import 'core-js/modules/es.typed-array.to-locale-string.js';
|
|
8
8
|
import 'core-js/modules/es.promise.js';
|
|
9
9
|
import 'core-js/modules/es.regexp.exec.js';
|
|
10
|
-
import 'core-js/modules/es.string.match.js';
|
|
11
|
-
import 'core-js/modules/es.string.replace.js';
|
|
12
10
|
import 'core-js/modules/es.regexp.to-string.js';
|
|
13
11
|
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
14
12
|
import 'core-js/modules/es.object.assign.js';
|
|
15
13
|
import 'core-js/modules/es.number.parse-int.js';
|
|
16
14
|
import jwt_decode from 'jwt-decode';
|
|
15
|
+
import 'core-js/modules/es.string.match.js';
|
|
16
|
+
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 'core-js/modules/es.array.includes.js';
|
|
21
|
-
import 'core-js/modules/es.string.includes.js';
|
|
22
|
-
import { saveAs } from 'file-saver';
|
|
23
|
-
import JSZip from 'jszip';
|
|
24
20
|
import Lottie from 'lottie-web';
|
|
25
21
|
import 'core-js/modules/es.array.sort.js';
|
|
22
|
+
import 'core-js/modules/es.array.includes.js';
|
|
23
|
+
import 'core-js/modules/es.string.includes.js';
|
|
26
24
|
import 'core-js/modules/es.parse-int.js';
|
|
27
25
|
import 'core-js/modules/es.string.trim.js';
|
|
28
26
|
import 'core-js/modules/es.string.starts-with.js';
|
|
@@ -378,6 +376,9 @@ function retryPromiseWithCondition(promiseFactory, conditionFactory) {
|
|
|
378
376
|
}
|
|
379
377
|
});
|
|
380
378
|
}
|
|
379
|
+
function getUserAgent() {
|
|
380
|
+
return `platform: ${navigator === null || navigator === void 0 ? void 0 : navigator.platform}`;
|
|
381
|
+
}
|
|
381
382
|
function isMobileOrTablet() {
|
|
382
383
|
return function (a) {
|
|
383
384
|
return !!(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55\/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk\/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-|your|zeto|zte-/i.test(a.substr(0, 4)) || /Android|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) || navigator.maxTouchPoints && navigator.maxTouchPoints > 2);
|
|
@@ -388,25 +389,6 @@ function isMobile() {
|
|
|
388
389
|
return !!(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55\/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk\/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-|your|zeto|zte-/i.test(a.substr(0, 4)) || /Android|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
|
|
389
390
|
}(navigator.userAgent || navigator.vendor || window.opera);
|
|
390
391
|
}
|
|
391
|
-
function osVersion() {
|
|
392
|
-
let version = '';
|
|
393
|
-
const android = navigator.userAgent.match(/Android\s+([\d\\.]+)/i);
|
|
394
|
-
if (android) {
|
|
395
|
-
version = android[0];
|
|
396
|
-
}
|
|
397
|
-
const ios = navigator.userAgent.match(/OS\s+([\d\\_]+)/i);
|
|
398
|
-
if (ios) {
|
|
399
|
-
version = ios[0].replace('OS ', 'iOS');
|
|
400
|
-
}
|
|
401
|
-
const win = navigator.userAgent.match(/Windows NT (\d+\.\d+)/);
|
|
402
|
-
if (win) {
|
|
403
|
-
version = win[0];
|
|
404
|
-
}
|
|
405
|
-
if (!version) {
|
|
406
|
-
version = navigator.platform;
|
|
407
|
-
}
|
|
408
|
-
return version;
|
|
409
|
-
}
|
|
410
392
|
function splitResult(result) {
|
|
411
393
|
if (result.address) {
|
|
412
394
|
const originAddress = result.address;
|
|
@@ -489,44 +471,6 @@ const isIphone14proOrProMax = () => {
|
|
|
489
471
|
return isIphone() && (screen.width === 430 && screen.height === 932 || screen.width === 393 && screen.height === 852);
|
|
490
472
|
};
|
|
491
473
|
|
|
492
|
-
function fileSaverService() {
|
|
493
|
-
const filesQueue = [];
|
|
494
|
-
function pushFile(file) {
|
|
495
|
-
filesQueue.push(file);
|
|
496
|
-
}
|
|
497
|
-
function popAllFiles() {
|
|
498
|
-
filesQueue.splice(0, filesQueue.length);
|
|
499
|
-
}
|
|
500
|
-
function saveFiles(fileName, json) {
|
|
501
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
502
|
-
const zip = new JSZip();
|
|
503
|
-
filesQueue.forEach(fileItem => {
|
|
504
|
-
zip.file(fileItem.name, fileItem.file);
|
|
505
|
-
});
|
|
506
|
-
if (json) zip.file('data.json', JSON.stringify(json));
|
|
507
|
-
const content = yield zip.generateAsync({
|
|
508
|
-
type: 'blob'
|
|
509
|
-
});
|
|
510
|
-
saveAs(content, `${fileName}.zip`);
|
|
511
|
-
popAllFiles();
|
|
512
|
-
});
|
|
513
|
-
}
|
|
514
|
-
return {
|
|
515
|
-
pushFile,
|
|
516
|
-
saveFiles
|
|
517
|
-
};
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
const {
|
|
521
|
-
saveFiles,
|
|
522
|
-
pushFile
|
|
523
|
-
} = fileSaverService();
|
|
524
|
-
var RUN_FUNCTION_NAME;
|
|
525
|
-
(function (RUN_FUNCTION_NAME) {
|
|
526
|
-
RUN_FUNCTION_NAME["RECOGNITION"] = "service.recognition";
|
|
527
|
-
RUN_FUNCTION_NAME["ANTI_FARUD_RECOGNITION"] = "antiFraudInstance.recognition";
|
|
528
|
-
RUN_FUNCTION_NAME["API_REQUEST"] = "api.request";
|
|
529
|
-
})(RUN_FUNCTION_NAME || (RUN_FUNCTION_NAME = {}));
|
|
530
474
|
function debugLog(message, ...others) {
|
|
531
475
|
if (new URLSearchParams(location.search).get('authme-debug') === 'true') {
|
|
532
476
|
console.log(message, ...others);
|
|
@@ -548,49 +492,35 @@ function generateUniqueId(length = 32) {
|
|
|
548
492
|
}
|
|
549
493
|
return result;
|
|
550
494
|
}
|
|
551
|
-
function
|
|
552
|
-
const
|
|
553
|
-
|
|
554
|
-
const
|
|
495
|
+
function downloadObjectAsJson(exportObj, exportName) {
|
|
496
|
+
const dataStr = `data:application/octet-stream;headers=Content-Disposition%3A%20attachment%3B%20filename=${exportName}.json,${encodeURIComponent(JSON.stringify(exportObj, null, 4))}`;
|
|
497
|
+
//'data:text/json;charset=utf-8,' +
|
|
498
|
+
const downloadAnchorNode = document.createElement('a');
|
|
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) {
|
|
555
506
|
const debugLogs = [];
|
|
556
|
-
const logInfo = {
|
|
557
|
-
userAgent: navigator.userAgent,
|
|
558
|
-
token: '',
|
|
559
|
-
message: ''
|
|
560
|
-
};
|
|
561
507
|
let currentRoundId = generateUniqueId(8);
|
|
562
508
|
let currentType = null;
|
|
563
|
-
const interiaTimeObj = {};
|
|
564
509
|
function pushNewDebugLog(logParams) {
|
|
565
510
|
var _a;
|
|
566
|
-
if (!debugMode) return;
|
|
511
|
+
if (!config.debugMode) return;
|
|
567
512
|
const now = new Date();
|
|
568
513
|
const _logParams = JSON.parse(JSON.stringify(logParams));
|
|
569
514
|
if (_logParams.result) {
|
|
570
515
|
(_a = _logParams.result) === null || _a === void 0 ? true : delete _a.imageData;
|
|
571
516
|
}
|
|
572
|
-
const newDebugLog = Object.assign(
|
|
517
|
+
const newDebugLog = Object.assign({
|
|
518
|
+
time: now.getTime(),
|
|
573
519
|
dateTime: now.toLocaleString(),
|
|
574
520
|
roundId: currentRoundId,
|
|
575
521
|
type: currentType !== null && currentType !== void 0 ? currentType : undefined
|
|
576
|
-
}, _logParams)
|
|
577
|
-
time: now.getTime(),
|
|
578
|
-
_id: generateUniqueId()
|
|
579
|
-
});
|
|
522
|
+
}, _logParams);
|
|
580
523
|
debugLogs.push(newDebugLog);
|
|
581
|
-
return newDebugLog;
|
|
582
|
-
}
|
|
583
|
-
function pushNewDebugImage(image, log, options) {
|
|
584
|
-
var _a, _b;
|
|
585
|
-
if (!debugMode) return;
|
|
586
|
-
const newLog = pushNewDebugLog(log);
|
|
587
|
-
const recognitionFunctions = [RUN_FUNCTION_NAME.ANTI_FARUD_RECOGNITION, RUN_FUNCTION_NAME.RECOGNITION];
|
|
588
|
-
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));
|
|
589
|
-
const imageStatus = (_a = currentRoundRecognitionResultItem === null || currentRoundRecognitionResultItem === void 0 ? void 0 : currentRoundRecognitionResultItem.result) === null || _a === void 0 ? void 0 : _a.eStatus;
|
|
590
|
-
pushFile({
|
|
591
|
-
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`,
|
|
592
|
-
file: image
|
|
593
|
-
});
|
|
594
524
|
}
|
|
595
525
|
function functionLogging(func, logParams) {
|
|
596
526
|
return new Promise((resolve, reject) => {
|
|
@@ -614,209 +544,28 @@ function debugTools() {
|
|
|
614
544
|
});
|
|
615
545
|
});
|
|
616
546
|
}
|
|
617
|
-
function renderDebugTips() {
|
|
618
|
-
if (document.getElementById('debug-tips')) {
|
|
619
|
-
return;
|
|
620
|
-
}
|
|
621
|
-
const debugTips = document.createElement('div');
|
|
622
|
-
debugTips.style.position = 'fixed';
|
|
623
|
-
debugTips.style.top = '50px';
|
|
624
|
-
debugTips.style.right = '0';
|
|
625
|
-
debugTips.style.zIndex = '999';
|
|
626
|
-
debugTips.innerHTML = 'Debug Mode';
|
|
627
|
-
debugTips.style.color = 'red';
|
|
628
|
-
debugTips.style.fontWeight = 'bold';
|
|
629
|
-
debugTips.setAttribute('id', 'debug-tips');
|
|
630
|
-
document.body.appendChild(debugTips);
|
|
631
|
-
}
|
|
632
|
-
function renderDebugUI() {
|
|
633
|
-
if (document.getElementById('debug-ui')) {
|
|
634
|
-
return;
|
|
635
|
-
}
|
|
636
|
-
const debugUI = document.createElement('div');
|
|
637
|
-
debugUI.style.position = 'fixed';
|
|
638
|
-
debugUI.style.top = '0';
|
|
639
|
-
debugUI.style.right = '0';
|
|
640
|
-
debugUI.style.zIndex = '777';
|
|
641
|
-
debugUI.style.backgroundColor = 'black';
|
|
642
|
-
debugUI.style.color = 'white';
|
|
643
|
-
debugUI.style.padding = '10px';
|
|
644
|
-
debugUI.style.paddingRight = '150px';
|
|
645
|
-
debugUI.style.fontSize = '12px';
|
|
646
|
-
debugUI.style.opacity = '0.7';
|
|
647
|
-
debugUI.style.boxSizing = 'border-box';
|
|
648
|
-
debugUI.style.width = '100%';
|
|
649
|
-
debugUI.style.maxHeight = '50vh';
|
|
650
|
-
debugUI.style.overflow = 'auto';
|
|
651
|
-
debugUI.setAttribute('id', 'debug-ui');
|
|
652
|
-
const closeUI = document.createElement('button');
|
|
653
|
-
closeUI.style.position = 'fixed';
|
|
654
|
-
closeUI.style.top = '0';
|
|
655
|
-
closeUI.style.right = '100px';
|
|
656
|
-
closeUI.innerHTML = 'close';
|
|
657
|
-
closeUI.addEventListener('click', () => {
|
|
658
|
-
debugUI.style.display = 'none';
|
|
659
|
-
});
|
|
660
|
-
debugUI.appendChild(closeUI);
|
|
661
|
-
const accordionUI = document.createElement('button');
|
|
662
|
-
accordionUI.style.position = 'fixed';
|
|
663
|
-
accordionUI.style.top = '0';
|
|
664
|
-
accordionUI.style.right = '0';
|
|
665
|
-
accordionUI.innerHTML = '收合/展開';
|
|
666
|
-
accordionUI.addEventListener('click', () => {
|
|
667
|
-
if (debugUI.style.maxHeight === '50vh') {
|
|
668
|
-
debugUI.style.maxHeight = '5vh';
|
|
669
|
-
} else {
|
|
670
|
-
debugUI.style.maxHeight = '50vh';
|
|
671
|
-
}
|
|
672
|
-
});
|
|
673
|
-
debugUI.appendChild(accordionUI);
|
|
674
|
-
document.body.appendChild(debugUI);
|
|
675
|
-
}
|
|
676
|
-
function setTimeStart(behavior) {
|
|
677
|
-
if (!debugModeUI) {
|
|
678
|
-
return;
|
|
679
|
-
}
|
|
680
|
-
const dStart = new Date();
|
|
681
|
-
const nStart = dStart.getTime();
|
|
682
|
-
if (interiaTimeObj && interiaTimeObj[behavior]) {
|
|
683
|
-
console.error('debugmode: setTimeStart duplicate', behavior);
|
|
684
|
-
return false;
|
|
685
|
-
}
|
|
686
|
-
interiaTimeObj[behavior] = {
|
|
687
|
-
behavior,
|
|
688
|
-
start: nStart / 1000,
|
|
689
|
-
duration: 0,
|
|
690
|
-
end: 0
|
|
691
|
-
};
|
|
692
|
-
// console.log(interiaTimeObj[behavior])
|
|
693
|
-
renderTimeInfo(behavior);
|
|
694
|
-
return interiaTimeObj[behavior];
|
|
695
|
-
}
|
|
696
|
-
function setTimeEnd(behavior) {
|
|
697
|
-
if (!debugModeUI) {
|
|
698
|
-
return;
|
|
699
|
-
}
|
|
700
|
-
const dEnd = new Date();
|
|
701
|
-
const nEnd = dEnd.getTime();
|
|
702
|
-
if (!interiaTimeObj[behavior]) {
|
|
703
|
-
console.error('debugmode: setTimeEnd not found', behavior);
|
|
704
|
-
return false;
|
|
705
|
-
}
|
|
706
|
-
interiaTimeObj[behavior].end = nEnd / 1000;
|
|
707
|
-
interiaTimeObj[behavior].duration = interiaTimeObj[behavior].end - interiaTimeObj[behavior].start;
|
|
708
|
-
// console.log(interiaTimeObj[behavior])
|
|
709
|
-
renderTimeInfo(behavior);
|
|
710
|
-
return interiaTimeObj[behavior];
|
|
711
|
-
}
|
|
712
|
-
function setTimeDuration(behavior) {
|
|
713
|
-
const ts = Date.now();
|
|
714
|
-
setTimeStart(`${behavior}_${ts}`);
|
|
715
|
-
return {
|
|
716
|
-
end: () => {
|
|
717
|
-
setTimeEnd(`${behavior}_${ts}`);
|
|
718
|
-
}
|
|
719
|
-
};
|
|
720
|
-
}
|
|
721
|
-
function renderTimeInfo(behavior) {
|
|
722
|
-
const dom = document.querySelector(`#debug-ui-${behavior}`);
|
|
723
|
-
const info = `{"behavior":<span style="color:green;">"${behavior}"</span>, "start": ${interiaTimeObj[behavior].start}, "duration": ${interiaTimeObj[behavior].duration}, "end": ${interiaTimeObj[behavior].end}}`;
|
|
724
|
-
// const info = `<span style="color:green;">${behavior}</span>: Duration: ${interiaTimeObj[behavior].duration}s`;
|
|
725
|
-
if (dom) {
|
|
726
|
-
dom.innerHTML = info;
|
|
727
|
-
return;
|
|
728
|
-
}
|
|
729
|
-
const debugUI = document.getElementById('debug-ui');
|
|
730
|
-
const div = document.createElement('div');
|
|
731
|
-
div.setAttribute('class', 'debug-ui-item');
|
|
732
|
-
div.setAttribute('id', `debug-ui-${behavior}`);
|
|
733
|
-
div.innerHTML = info;
|
|
734
|
-
debugUI.appendChild(div);
|
|
735
|
-
}
|
|
736
|
-
function functionRunTime() {
|
|
737
|
-
const arr = [];
|
|
738
|
-
const items = document.querySelectorAll('.debug-ui-item');
|
|
739
|
-
items.forEach(item => {
|
|
740
|
-
arr.push(JSON.parse(item.innerText));
|
|
741
|
-
});
|
|
742
|
-
return arr;
|
|
743
|
-
}
|
|
744
|
-
if (debugMode) {
|
|
745
|
-
renderDebugTips();
|
|
746
|
-
// setRequestLoggingFunc(functionLogging)
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
if (debugModeUI) {
|
|
750
|
-
console.log('debugModeUI Init');
|
|
751
|
-
renderDebugUI();
|
|
752
|
-
}
|
|
753
|
-
function saveDebugImage({
|
|
754
|
-
getDebugImageData,
|
|
755
|
-
data,
|
|
756
|
-
width,
|
|
757
|
-
height,
|
|
758
|
-
result,
|
|
759
|
-
type
|
|
760
|
-
}) {
|
|
761
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
762
|
-
if (!debugMode || !shouldGetDebugImage) return;
|
|
763
|
-
const debugImage = yield getDebugImageData(data);
|
|
764
|
-
// 創建一個虛擬的 canvas
|
|
765
|
-
const canvas = document.createElement('canvas');
|
|
766
|
-
const ctx = canvas.getContext('2d');
|
|
767
|
-
// 設置 canvas 的尺寸
|
|
768
|
-
canvas.width = width;
|
|
769
|
-
canvas.height = height;
|
|
770
|
-
// 使用 Uint8ClampedArray 將圖像數據繪製到 canvas 上
|
|
771
|
-
const imgData = ctx === null || ctx === void 0 ? void 0 : ctx.createImageData(width, height);
|
|
772
|
-
if (imgData) {
|
|
773
|
-
imgData.data.set(debugImage);
|
|
774
|
-
ctx === null || ctx === void 0 ? void 0 : ctx.putImageData(imgData, 0, 0);
|
|
775
|
-
canvas.toBlob(blob => {
|
|
776
|
-
if (blob) {
|
|
777
|
-
pushNewDebugImage(blob, {
|
|
778
|
-
result: result,
|
|
779
|
-
status: 'recognition',
|
|
780
|
-
type: type
|
|
781
|
-
}, {
|
|
782
|
-
prefix: 'debugImage_'
|
|
783
|
-
});
|
|
784
|
-
}
|
|
785
|
-
}, 'image/jpeg');
|
|
786
|
-
}
|
|
787
|
-
});
|
|
788
|
-
}
|
|
789
547
|
return {
|
|
790
|
-
debugMode,
|
|
791
|
-
debugModeUI,
|
|
792
548
|
pushNewDebugLog,
|
|
793
549
|
getDebugLogs: () => debugLogs,
|
|
794
550
|
getDebugLogsLength: () => debugLogs.length,
|
|
795
551
|
modifyDeubgLog: (index, logParams) => {
|
|
796
|
-
if (!debugMode) return;
|
|
552
|
+
if (!config.debugMode) return;
|
|
797
553
|
debugLogs[index] = Object.assign(Object.assign({}, debugLogs[index]), logParams);
|
|
798
554
|
},
|
|
799
555
|
downloadDebugLogs: () => {
|
|
800
|
-
if (!debugMode) return;
|
|
801
|
-
|
|
802
|
-
info: logInfo,
|
|
803
|
-
logs: debugLogs,
|
|
804
|
-
functionRunTime: functionRunTime()
|
|
805
|
-
});
|
|
556
|
+
if (!config.debugMode) return;
|
|
557
|
+
downloadObjectAsJson(debugLogs, `debugLog${new Date().getTime().toString()}`);
|
|
806
558
|
},
|
|
807
559
|
functionLogging,
|
|
808
560
|
nextDebugRound: type => {
|
|
809
|
-
if (!debugMode) return;
|
|
561
|
+
if (!config.debugMode) return;
|
|
810
562
|
currentRoundId = generateUniqueId(8);
|
|
811
563
|
if (type) currentType = type;
|
|
812
564
|
},
|
|
813
565
|
modifyDebugType: type => {
|
|
814
|
-
if (!debugMode) return;
|
|
566
|
+
if (!config.debugMode) return;
|
|
815
567
|
currentType = type;
|
|
816
|
-
}
|
|
817
|
-
pushNewDebugImage,
|
|
818
|
-
setTimeDuration: setTimeDuration,
|
|
819
|
-
saveDebugImage
|
|
568
|
+
}
|
|
820
569
|
};
|
|
821
570
|
}
|
|
822
571
|
|
|
@@ -1009,9 +758,8 @@ function showErrorMessage(text, showRetryBtn, callback, buttonText, _titleText)
|
|
|
1009
758
|
errorMessagePanel.appendChild(retryText);
|
|
1010
759
|
if (callback) {
|
|
1011
760
|
retryText.addEventListener('click', e => {
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
});
|
|
761
|
+
target.removeChild(errorMessagePanel);
|
|
762
|
+
callback(e);
|
|
1015
763
|
});
|
|
1016
764
|
}
|
|
1017
765
|
}
|
|
@@ -1074,12 +822,13 @@ function asyncShowErrorMessage(text, showRetryBtn, options) {
|
|
|
1074
822
|
function asyncOnLineShowErrorMessage(text, showRetryBtn) {
|
|
1075
823
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1076
824
|
return new Promise((res, rej) => {
|
|
1077
|
-
|
|
825
|
+
const callback = () => {
|
|
1078
826
|
if (window.navigator.onLine) {
|
|
1079
827
|
res(true);
|
|
1080
|
-
|
|
828
|
+
hideErrorMessage();
|
|
1081
829
|
}
|
|
1082
|
-
}
|
|
830
|
+
};
|
|
831
|
+
showErrorMessage(text, showRetryBtn, callback);
|
|
1083
832
|
});
|
|
1084
833
|
});
|
|
1085
834
|
}
|
|
@@ -1147,8 +896,6 @@ var BROWSER_CAMERA_ERRORS;
|
|
|
1147
896
|
BROWSER_CAMERA_ERRORS["NO_CAMERA"] = "NO_CAMERA";
|
|
1148
897
|
BROWSER_CAMERA_ERRORS["NOT_ALLOWED_ERROR"] = "NotAllowedError";
|
|
1149
898
|
BROWSER_CAMERA_ERRORS["NOT_FOUND_ERROR"] = "NotFoundError";
|
|
1150
|
-
BROWSER_CAMERA_ERRORS["NOT_READABLE_ERROR"] = "NotReadableError";
|
|
1151
|
-
BROWSER_CAMERA_ERRORS["ABORT_ERROR"] = "AbortError";
|
|
1152
899
|
})(BROWSER_CAMERA_ERRORS || (BROWSER_CAMERA_ERRORS = {}));
|
|
1153
900
|
let stream;
|
|
1154
901
|
const videoConstraintsFactory = (isPC, facingMode) => {
|
|
@@ -1361,6 +1108,9 @@ function isOverconstrainedError(error) {
|
|
|
1361
1108
|
}
|
|
1362
1109
|
return 'constraint' in error;
|
|
1363
1110
|
}
|
|
1111
|
+
function sleep(ms) {
|
|
1112
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
1113
|
+
}
|
|
1364
1114
|
function requestCamera({
|
|
1365
1115
|
video,
|
|
1366
1116
|
facingMode,
|
|
@@ -1369,7 +1119,29 @@ function requestCamera({
|
|
|
1369
1119
|
}) {
|
|
1370
1120
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1371
1121
|
try {
|
|
1372
|
-
|
|
1122
|
+
let perm = yield navigator.permissions.query({
|
|
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
|
+
}
|
|
1373
1145
|
} catch (error) {
|
|
1374
1146
|
if (error === BROWSER_CAMERA_ERRORS.NOT_SUPPORT) {
|
|
1375
1147
|
showMessage(translate('camera.error.notFound'));
|
|
@@ -1383,15 +1155,6 @@ function requestCamera({
|
|
|
1383
1155
|
showMessage(translate('camera.error.notFound'));
|
|
1384
1156
|
throw new AuthmeError(ErrorCode.CAMERA_NOT_SUPPORT, error);
|
|
1385
1157
|
}
|
|
1386
|
-
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) {
|
|
1387
|
-
showMessage(translate('camera.error.notFound'));
|
|
1388
|
-
/* NOT_READABLE_ERROR,ABORT_ERROR 這兩個錯誤是用戶授權了,但在呼叫裝置時出現錯誤,
|
|
1389
|
-
* 常發生在APP webview ,例如: 手機開啟 web 使用 sdk,儘管在 webview 層級上授權了,但手機在設定層級沒有授權 app 使用相機,會導致此問題。
|
|
1390
|
-
* 但每個 android 手機的在這方面的實作不一致,不是每個手機在這種情況下都會拋出錯誤。
|
|
1391
|
-
* 參考 https://developer.mozilla.org/zh-CN/docs/Web/API/MediaDevices/getUserMedia#notreadableerror
|
|
1392
|
-
*/
|
|
1393
|
-
throw new AuthmeError(ErrorCode.CAMERA_NOT_SUPPORT, error);
|
|
1394
|
-
}
|
|
1395
1158
|
if (isOverconstrainedError(error)) {
|
|
1396
1159
|
showMessage(translate('camera.error.lowResolution'));
|
|
1397
1160
|
throw new AuthmeError(ErrorCode.CAMERA_NOT_SUPPORT, error);
|
|
@@ -2387,40 +2150,15 @@ function RGBToLottieColor(color) {
|
|
|
2387
2150
|
return color.map(c => c / 255);
|
|
2388
2151
|
}
|
|
2389
2152
|
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
requstQueue.shift();
|
|
2395
|
-
}
|
|
2396
|
-
requstQueue.push(request);
|
|
2397
|
-
}
|
|
2398
|
-
function clearRequest() {
|
|
2399
|
-
requstQueue.splice(0, requstQueue.length);
|
|
2400
|
-
}
|
|
2401
|
-
function backgroundRequest(request) {
|
|
2402
|
-
const requestPromise = request();
|
|
2403
|
-
requestPromise.catch(err => {
|
|
2404
|
-
if (err._code === ErrorCode.NETWORK_ERROR) {
|
|
2405
|
-
pushRequest(request);
|
|
2406
|
-
}
|
|
2407
|
-
});
|
|
2408
|
-
}
|
|
2409
|
-
window.ononline = () => {
|
|
2410
|
-
const tasks = [...requstQueue];
|
|
2411
|
-
clearRequest();
|
|
2412
|
-
tasks.forEach(request => {
|
|
2413
|
-
backgroundRequest(request);
|
|
2414
|
-
});
|
|
2153
|
+
var name = "@authme/util";
|
|
2154
|
+
var version$1 = "2.4.11";
|
|
2155
|
+
var peerDependencies = {
|
|
2156
|
+
"core-js": "^3.6.0"
|
|
2415
2157
|
};
|
|
2416
|
-
|
|
2417
|
-
var name = "authme/sdk";
|
|
2418
|
-
var version$1 = "2.4.8";
|
|
2419
|
-
var date = "2023-12-20T07:24:47+0000";
|
|
2420
2158
|
var packageInfo = {
|
|
2421
2159
|
name: name,
|
|
2422
2160
|
version: version$1,
|
|
2423
|
-
|
|
2161
|
+
peerDependencies: peerDependencies
|
|
2424
2162
|
};
|
|
2425
2163
|
|
|
2426
2164
|
var _a;
|
|
@@ -2429,4 +2167,4 @@ const version = packageInfo.version;
|
|
|
2429
2167
|
(_a = (_b = window)[_c = Symbol.for('authme-sdk')]) !== null && _a !== void 0 ? _a : _b[_c] = {};
|
|
2430
2168
|
window[Symbol.for('authme-sdk')][packageInfo.name] = version;
|
|
2431
2169
|
|
|
2432
|
-
export { AuthmeError, ErrorCode, Icon, RGBToLottieColor,
|
|
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 };
|
package/package.json
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@authme/util",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.11",
|
|
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",
|
|
10
8
|
"lottie-web": "5.9.6"
|
|
11
9
|
},
|
|
12
|
-
"devDependencies": {
|
|
13
|
-
"@types/file-saver": "^2.0.5"
|
|
14
|
-
},
|
|
15
10
|
"module": "./index.js",
|
|
16
11
|
"main": "./index.cjs",
|
|
17
12
|
"type": "module",
|
package/src/index.d.ts
CHANGED
package/src/lib/authme-log.d.ts
CHANGED
|
@@ -1,34 +1,22 @@
|
|
|
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
|
-
}
|
|
14
1
|
export declare function debugLog(message?: any, ...others: any[]): void;
|
|
15
2
|
export interface DebugLog<T> {
|
|
3
|
+
image?: string;
|
|
4
|
+
resultOcrImg?: string;
|
|
16
5
|
result?: any;
|
|
17
6
|
report?: any;
|
|
18
7
|
status?: 'recognition' | 'confirm' | 'run-start' | 'run-end' | 'run-error';
|
|
19
|
-
runFunction?:
|
|
8
|
+
runFunction?: string;
|
|
20
9
|
roundId?: string;
|
|
21
|
-
_id: string;
|
|
22
10
|
type?: T;
|
|
23
|
-
time
|
|
11
|
+
time?: number;
|
|
24
12
|
dateTime?: string;
|
|
25
13
|
message?: any;
|
|
26
14
|
isAntiFraud?: boolean;
|
|
27
15
|
}
|
|
28
|
-
export declare function debugTools<T>(
|
|
16
|
+
export declare function debugTools<T>(config: {
|
|
29
17
|
debugMode: boolean;
|
|
30
|
-
|
|
31
|
-
pushNewDebugLog: (logParams:
|
|
18
|
+
}): {
|
|
19
|
+
pushNewDebugLog: (logParams: DebugLog<T>) => void;
|
|
32
20
|
getDebugLogs: () => DebugLog<T>[];
|
|
33
21
|
getDebugLogsLength: () => number;
|
|
34
22
|
modifyDeubgLog: (index: number, logParams: Partial<DebugLog<T>>) => void;
|
|
@@ -36,12 +24,4 @@ export declare function debugTools<T>(): {
|
|
|
36
24
|
functionLogging: <P>(func: () => Promise<P>, logParams?: Partial<DebugLog<T>>) => Promise<P>;
|
|
37
25
|
nextDebugRound: (type?: T) => void;
|
|
38
26
|
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>;
|
|
46
27
|
};
|
|
47
|
-
export {};
|
|
@@ -5,9 +5,9 @@ export declare function dataURItoBlob(dataURI: string): Blob;
|
|
|
5
5
|
export declare function UintArrayToBlob(width: number, height: number, data: Uint8Array | Uint8ClampedArray, canvasEle?: HTMLCanvasElement, imageFormat?: 'jpg' | 'png'): Blob;
|
|
6
6
|
export declare function waitTime(ms: number): Promise<void>;
|
|
7
7
|
export declare function retryPromiseWithCondition<T>(promiseFactory: () => Promise<T>, conditionFactory: (...args: any[]) => Promise<any>): Promise<T>;
|
|
8
|
+
export declare function getUserAgent(): string;
|
|
8
9
|
export declare function isMobileOrTablet(): boolean;
|
|
9
10
|
export declare function isMobile(): boolean;
|
|
10
|
-
export declare function osVersion(): string;
|
|
11
11
|
export declare function splitResult(result: any): any;
|
|
12
12
|
export declare function combineResult(result: any): any;
|
|
13
13
|
export declare const isIphone14proOrProMax: () => boolean;
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
export declare
|
|
2
|
-
export declare
|
|
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>;
|
|
1
|
+
export declare function showErrorMessage(text: string, showRetryBtn?: boolean, callback?: (e: Event) => void, buttonText?: string, _titleText?: string): Promise<void>;
|
|
2
|
+
export declare function showErrorMessageEventName(text: string, showRetryBtn?: boolean, callback?: (e: Event) => void, buttonText?: string, titleText?: string): Promise<void>;
|
|
7
3
|
export declare function hideErrorMessage(): void;
|
|
8
4
|
export declare function asyncShowErrorMessage(text: string, showRetryBtn?: boolean, options?: {
|
|
9
|
-
callback?:
|
|
5
|
+
callback?: (e: Event) => void;
|
|
10
6
|
buttonText?: string;
|
|
11
7
|
titleText?: string;
|
|
12
|
-
|
|
8
|
+
errorTextHandler?: (text: Error) => string;
|
|
9
|
+
showErrorMessageHandler?: (text: string) => void;
|
|
13
10
|
}): Promise<boolean>;
|
|
14
11
|
export declare function asyncOnLineShowErrorMessage(text: string, showRetryBtn?: boolean): Promise<boolean>;
|
|
15
12
|
export declare function checkOnlineStatus(msg: string): Promise<void>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function backgroundRequest<T = unknown>(request: () => Promise<T>): void;
|
package/src/lib/file-saver.d.ts
DELETED