@authme/util 2.4.2 → 2.4.7
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 +494 -54
- package/index.js +489 -54
- package/package.json +6 -1
- package/src/index.d.ts +1 -0
- package/src/lib/authme-error.d.ts +2 -1
- package/src/lib/authme-log.d.ts +46 -0
- package/src/lib/background-request-process.d.ts +1 -0
- package/src/lib/common/index.d.ts +1 -1
- package/src/lib/file-saver.d.ts +11 -0
- package/src/ui/camera.d.ts +19 -1
- package/src/ui/error-message.d.ts +12 -2
- package/src/ui/spinner.d.ts +1 -1
package/index.js
CHANGED
|
@@ -7,19 +7,22 @@ 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';
|
|
10
12
|
import 'core-js/modules/es.regexp.to-string.js';
|
|
11
13
|
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
12
14
|
import 'core-js/modules/es.object.assign.js';
|
|
13
15
|
import 'core-js/modules/es.number.parse-int.js';
|
|
14
16
|
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
|
-
import
|
|
20
|
-
import 'core-js/modules/es.array.sort.js';
|
|
19
|
+
import 'core-js/modules/es.typed-array.uint32-array.js';
|
|
21
20
|
import 'core-js/modules/es.array.includes.js';
|
|
22
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';
|
|
23
26
|
import 'core-js/modules/es.parse-int.js';
|
|
24
27
|
import 'core-js/modules/es.string.trim.js';
|
|
25
28
|
import 'core-js/modules/es.string.starts-with.js';
|
|
@@ -176,6 +179,7 @@ var ErrorCode;
|
|
|
176
179
|
ErrorCode[ErrorCode["USER_CANCEL"] = 903] = "USER_CANCEL";
|
|
177
180
|
ErrorCode[ErrorCode["CAMERA_NOT_SUPPORT"] = 904] = "CAMERA_NOT_SUPPORT";
|
|
178
181
|
ErrorCode[ErrorCode["SERVER_ERROR"] = 905] = "SERVER_ERROR";
|
|
182
|
+
ErrorCode[ErrorCode["EVENT_NAME_WRONG"] = 906] = "EVENT_NAME_WRONG";
|
|
179
183
|
})(ErrorCode || (ErrorCode = {}));
|
|
180
184
|
|
|
181
185
|
function decodeToken(token) {
|
|
@@ -374,9 +378,6 @@ function retryPromiseWithCondition(promiseFactory, conditionFactory) {
|
|
|
374
378
|
}
|
|
375
379
|
});
|
|
376
380
|
}
|
|
377
|
-
function getUserAgent() {
|
|
378
|
-
return `platform: ${navigator === null || navigator === void 0 ? void 0 : navigator.platform}`;
|
|
379
|
-
}
|
|
380
381
|
function isMobileOrTablet() {
|
|
381
382
|
return function (a) {
|
|
382
383
|
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);
|
|
@@ -387,6 +388,25 @@ function isMobile() {
|
|
|
387
388
|
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));
|
|
388
389
|
}(navigator.userAgent || navigator.vendor || window.opera);
|
|
389
390
|
}
|
|
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
|
+
}
|
|
390
410
|
function splitResult(result) {
|
|
391
411
|
if (result.address) {
|
|
392
412
|
const originAddress = result.address;
|
|
@@ -469,11 +489,336 @@ const isIphone14proOrProMax = () => {
|
|
|
469
489
|
return isIphone() && (screen.width === 430 && screen.height === 932 || screen.width === 393 && screen.height === 852);
|
|
470
490
|
};
|
|
471
491
|
|
|
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 = {}));
|
|
472
530
|
function debugLog(message, ...others) {
|
|
473
531
|
if (new URLSearchParams(location.search).get('authme-debug') === 'true') {
|
|
474
532
|
console.log(message, ...others);
|
|
475
533
|
}
|
|
476
534
|
}
|
|
535
|
+
function generateUniqueId(length = 32) {
|
|
536
|
+
if (length <= 0) {
|
|
537
|
+
throw new Error('Length should be a positive integer.');
|
|
538
|
+
}
|
|
539
|
+
// 定義可能的字元
|
|
540
|
+
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
541
|
+
const charactersLength = characters.length;
|
|
542
|
+
const randomValues = new Uint32Array(length);
|
|
543
|
+
// 使用window.crypto.getRandomValues取得真正的隨機值
|
|
544
|
+
window.crypto.getRandomValues(randomValues);
|
|
545
|
+
let result = '';
|
|
546
|
+
for (let i = 0; i < length; i++) {
|
|
547
|
+
result += characters[randomValues[i] % charactersLength];
|
|
548
|
+
}
|
|
549
|
+
return result;
|
|
550
|
+
}
|
|
551
|
+
function debugTools() {
|
|
552
|
+
const debugMode = new URLSearchParams(location.search).get('authme-debug') === 'true';
|
|
553
|
+
const debugModeUI = new URLSearchParams(location.search).get('authme-debug-info') === 'true';
|
|
554
|
+
const shouldGetDebugImage = new URLSearchParams(location.search).get('authme-debug-get-image') === 'true';
|
|
555
|
+
const debugLogs = [];
|
|
556
|
+
const logInfo = {
|
|
557
|
+
userAgent: navigator.userAgent,
|
|
558
|
+
token: '',
|
|
559
|
+
message: ''
|
|
560
|
+
};
|
|
561
|
+
let currentRoundId = generateUniqueId(8);
|
|
562
|
+
let currentType = null;
|
|
563
|
+
const interiaTimeObj = {};
|
|
564
|
+
function pushNewDebugLog(logParams) {
|
|
565
|
+
var _a;
|
|
566
|
+
if (!debugMode) return;
|
|
567
|
+
const now = new Date();
|
|
568
|
+
const _logParams = JSON.parse(JSON.stringify(logParams));
|
|
569
|
+
if (_logParams.result) {
|
|
570
|
+
(_a = _logParams.result) === null || _a === void 0 ? true : delete _a.imageData;
|
|
571
|
+
}
|
|
572
|
+
const newDebugLog = Object.assign(Object.assign({
|
|
573
|
+
dateTime: now.toLocaleString(),
|
|
574
|
+
roundId: currentRoundId,
|
|
575
|
+
type: currentType !== null && currentType !== void 0 ? currentType : undefined
|
|
576
|
+
}, _logParams), {
|
|
577
|
+
time: now.getTime(),
|
|
578
|
+
_id: generateUniqueId()
|
|
579
|
+
});
|
|
580
|
+
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
|
+
}
|
|
595
|
+
function functionLogging(func, logParams) {
|
|
596
|
+
return new Promise((resolve, reject) => {
|
|
597
|
+
pushNewDebugLog(Object.assign(Object.assign({}, logParams), {
|
|
598
|
+
status: 'run-start'
|
|
599
|
+
}));
|
|
600
|
+
func().then(result => {
|
|
601
|
+
pushNewDebugLog(Object.assign(Object.assign({}, logParams), {
|
|
602
|
+
status: 'run-end',
|
|
603
|
+
roundId: currentRoundId,
|
|
604
|
+
result
|
|
605
|
+
}));
|
|
606
|
+
resolve(result);
|
|
607
|
+
}).catch(error => {
|
|
608
|
+
pushNewDebugLog(Object.assign(Object.assign({}, logParams), {
|
|
609
|
+
status: 'run-error',
|
|
610
|
+
roundId: currentRoundId,
|
|
611
|
+
result: error
|
|
612
|
+
}));
|
|
613
|
+
reject(error);
|
|
614
|
+
});
|
|
615
|
+
});
|
|
616
|
+
}
|
|
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
|
+
return {
|
|
790
|
+
debugMode,
|
|
791
|
+
debugModeUI,
|
|
792
|
+
pushNewDebugLog,
|
|
793
|
+
getDebugLogs: () => debugLogs,
|
|
794
|
+
getDebugLogsLength: () => debugLogs.length,
|
|
795
|
+
modifyDeubgLog: (index, logParams) => {
|
|
796
|
+
if (!debugMode) return;
|
|
797
|
+
debugLogs[index] = Object.assign(Object.assign({}, debugLogs[index]), logParams);
|
|
798
|
+
},
|
|
799
|
+
downloadDebugLogs: () => {
|
|
800
|
+
if (!debugMode) return;
|
|
801
|
+
saveFiles(`debugLog${new Date().getTime().toString()}`, {
|
|
802
|
+
info: logInfo,
|
|
803
|
+
logs: debugLogs,
|
|
804
|
+
functionRunTime: functionRunTime()
|
|
805
|
+
});
|
|
806
|
+
},
|
|
807
|
+
functionLogging,
|
|
808
|
+
nextDebugRound: type => {
|
|
809
|
+
if (!debugMode) return;
|
|
810
|
+
currentRoundId = generateUniqueId(8);
|
|
811
|
+
if (type) currentType = type;
|
|
812
|
+
},
|
|
813
|
+
modifyDebugType: type => {
|
|
814
|
+
if (!debugMode) return;
|
|
815
|
+
currentType = type;
|
|
816
|
+
},
|
|
817
|
+
pushNewDebugImage,
|
|
818
|
+
setTimeDuration: setTimeDuration,
|
|
819
|
+
saveDebugImage
|
|
820
|
+
};
|
|
821
|
+
}
|
|
477
822
|
|
|
478
823
|
var TIME_UNIT;
|
|
479
824
|
(function (TIME_UNIT) {
|
|
@@ -578,7 +923,7 @@ function cropByRatio(width, height, ratio) {
|
|
|
578
923
|
};
|
|
579
924
|
}
|
|
580
925
|
|
|
581
|
-
function startSpinner(text) {
|
|
926
|
+
function startSpinner(text, backgroundOpaque) {
|
|
582
927
|
const loadingLottie = Storage.getItem(STORAGE_KEY.LOADING_LOTTIE);
|
|
583
928
|
const body = document.querySelector('.authme-container');
|
|
584
929
|
if (loadingLottie) {
|
|
@@ -602,6 +947,9 @@ function startSpinner(text) {
|
|
|
602
947
|
loadingSDKText.textContent = text;
|
|
603
948
|
loadingSDKContent.appendChild(loadingSDKText);
|
|
604
949
|
}
|
|
950
|
+
if (backgroundOpaque) {
|
|
951
|
+
loadingSDKOuter.classList.add('authme-loading-sdk-outer--opaque');
|
|
952
|
+
}
|
|
605
953
|
return;
|
|
606
954
|
}
|
|
607
955
|
const spinnerOuter = document.createElement('div');
|
|
@@ -615,6 +963,9 @@ function startSpinner(text) {
|
|
|
615
963
|
spinnerText.textContent = text;
|
|
616
964
|
spinnerOuter.appendChild(spinnerText);
|
|
617
965
|
}
|
|
966
|
+
if (backgroundOpaque) {
|
|
967
|
+
spinnerOuter.classList.add('loading-outer--opaque');
|
|
968
|
+
}
|
|
618
969
|
body === null || body === void 0 ? void 0 : body.appendChild(spinnerOuter);
|
|
619
970
|
}
|
|
620
971
|
function stopSpinner() {
|
|
@@ -635,7 +986,7 @@ var Icon;
|
|
|
635
986
|
Icon["PictureIcon"] = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFAAAABQCAYAAACOEfKtAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAt9SURBVHgB7VxdTFRJFq7q23/Q0NC6IKDGhrgiG4mSGAejmyDoToxri5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TVAQ6POW3VC/7PxX5C8GlLbwYKriOgSuyiSoyqanQYdH2315b2sBn9EQCRe/fubS8pKalPtSLjEQehCnjbMl90yT+N984mErIoIalDJ9SUCJmd31WVnPnRrFc9VAdMu6qqaqfZbN6SzKETHo9nlDqHPlijVCIOAIE/xK6Kh04sU3kRJH/sSfgIAPmi0rEn7/S6uz+UmS7HIhIAWa+Q3Lh69WpQpgkywJSOPQHC6NL7KN0ZHIENINifUSMNEEt1YYdB6JjXm9zxeWk/eAfUCCViUOWkZNbpABDX/NppW+MN2mD+rnDJyjl4J4JwBrvk7cIa1KH0OxA5r9MOJqLI5SIB4sJBMsR5K+roJxZhk5bouBjr8DFJM/TKpL87XGwcSpZM2DGETa8yT7Axahmeh506ixPJmqyItJ0fGPbSGr5cVgmgTI+kGXXpNSPvDNpRSKt1aZHK8XfIBOkWpkCo3OwL1ZiD8pb4x9+Fx7rzKGjsTpXqWKT3AEaouQui44kQmXqkl7gIMnaGKpTP/lRC1oTSi4Hwfg7dkkgncRFkjMAIwqoMoabUkUnCiQCZJI1FxgkUAXNrJMnboMBnsYyAxpNQKaB0DHIY5Ck1zbFwEpRMBlDAZM80aXnkkUceeSzif3+l5taU5LriAAAAAElFTkSuQmCC";
|
|
636
987
|
})(Icon || (Icon = {}));
|
|
637
988
|
|
|
638
|
-
function showErrorMessage(text, showRetryBtn, callback) {
|
|
989
|
+
function showErrorMessage(text, showRetryBtn, callback, buttonText, _titleText) {
|
|
639
990
|
return __awaiter(this, void 0, void 0, function* () {
|
|
640
991
|
const target = document.querySelector('.authme-container');
|
|
641
992
|
if (!target) {
|
|
@@ -654,7 +1005,40 @@ function showErrorMessage(text, showRetryBtn, callback) {
|
|
|
654
1005
|
if (showRetryBtn) {
|
|
655
1006
|
const retryText = document.createElement('div');
|
|
656
1007
|
retryText.className = 'retry-text';
|
|
657
|
-
retryText.textContent = '重試';
|
|
1008
|
+
retryText.textContent = buttonText !== null && buttonText !== void 0 ? buttonText : '重試';
|
|
1009
|
+
errorMessagePanel.appendChild(retryText);
|
|
1010
|
+
if (callback) {
|
|
1011
|
+
retryText.addEventListener('click', e => {
|
|
1012
|
+
callback(e, {
|
|
1013
|
+
hideErrorMessage
|
|
1014
|
+
});
|
|
1015
|
+
});
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
target === null || target === void 0 ? void 0 : target.appendChild(errorMessagePanel);
|
|
1019
|
+
});
|
|
1020
|
+
}
|
|
1021
|
+
function showErrorMessageEventName(text, showRetryBtn, callback, buttonText, titleText) {
|
|
1022
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1023
|
+
const target = document.querySelector('.authme-container');
|
|
1024
|
+
if (!target) {
|
|
1025
|
+
return;
|
|
1026
|
+
}
|
|
1027
|
+
const errorMessagePanel = document.createElement('div');
|
|
1028
|
+
errorMessagePanel.classList.add('error-message-panel');
|
|
1029
|
+
errorMessagePanel.classList.add('event-name');
|
|
1030
|
+
const errorText = document.createElement('div');
|
|
1031
|
+
errorText.className = 'error-text';
|
|
1032
|
+
errorText.textContent = text;
|
|
1033
|
+
const title = document.createElement('div');
|
|
1034
|
+
title.className = 'error-title';
|
|
1035
|
+
title.textContent = titleText !== null && titleText !== void 0 ? titleText : 'error';
|
|
1036
|
+
errorMessagePanel.appendChild(title);
|
|
1037
|
+
errorMessagePanel.appendChild(errorText);
|
|
1038
|
+
if (showRetryBtn) {
|
|
1039
|
+
const retryText = document.createElement('div');
|
|
1040
|
+
retryText.className = 'retry-text';
|
|
1041
|
+
retryText.textContent = buttonText !== null && buttonText !== void 0 ? buttonText : '重試';
|
|
658
1042
|
errorMessagePanel.appendChild(retryText);
|
|
659
1043
|
if (callback) {
|
|
660
1044
|
retryText.addEventListener('click', e => {
|
|
@@ -673,27 +1057,29 @@ function hideErrorMessage() {
|
|
|
673
1057
|
body === null || body === void 0 ? void 0 : body.removeChild(errorMessagePanel);
|
|
674
1058
|
}
|
|
675
1059
|
}
|
|
676
|
-
function asyncShowErrorMessage(text, showRetryBtn) {
|
|
1060
|
+
function asyncShowErrorMessage(text, showRetryBtn, options) {
|
|
1061
|
+
var _a;
|
|
677
1062
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1063
|
+
const _showErrorMessage = (_a = options === null || options === void 0 ? void 0 : options.showErrorMessageHandler) !== null && _a !== void 0 ? _a : showErrorMessage;
|
|
678
1064
|
return new Promise((res, rej) => {
|
|
1065
|
+
var _a;
|
|
679
1066
|
const callback = () => {
|
|
680
1067
|
res(true);
|
|
681
1068
|
hideErrorMessage();
|
|
682
1069
|
};
|
|
683
|
-
|
|
1070
|
+
_showErrorMessage(text, showRetryBtn, (_a = options === null || options === void 0 ? void 0 : options.callback) !== null && _a !== void 0 ? _a : callback, options === null || options === void 0 ? void 0 : options.buttonText, options === null || options === void 0 ? void 0 : options.titleText);
|
|
684
1071
|
});
|
|
685
1072
|
});
|
|
686
1073
|
}
|
|
687
1074
|
function asyncOnLineShowErrorMessage(text, showRetryBtn) {
|
|
688
1075
|
return __awaiter(this, void 0, void 0, function* () {
|
|
689
1076
|
return new Promise((res, rej) => {
|
|
690
|
-
|
|
1077
|
+
showErrorMessage(text, showRetryBtn, (_, tools) => {
|
|
691
1078
|
if (window.navigator.onLine) {
|
|
692
1079
|
res(true);
|
|
693
|
-
hideErrorMessage();
|
|
1080
|
+
tools === null || tools === void 0 ? void 0 : tools.hideErrorMessage();
|
|
694
1081
|
}
|
|
695
|
-
};
|
|
696
|
-
showErrorMessage(text, showRetryBtn, callback);
|
|
1082
|
+
});
|
|
697
1083
|
});
|
|
698
1084
|
});
|
|
699
1085
|
}
|
|
@@ -761,7 +1147,10 @@ var BROWSER_CAMERA_ERRORS;
|
|
|
761
1147
|
BROWSER_CAMERA_ERRORS["NO_CAMERA"] = "NO_CAMERA";
|
|
762
1148
|
BROWSER_CAMERA_ERRORS["NOT_ALLOWED_ERROR"] = "NotAllowedError";
|
|
763
1149
|
BROWSER_CAMERA_ERRORS["NOT_FOUND_ERROR"] = "NotFoundError";
|
|
1150
|
+
BROWSER_CAMERA_ERRORS["NOT_READABLE_ERROR"] = "NotReadableError";
|
|
1151
|
+
BROWSER_CAMERA_ERRORS["ABORT_ERROR"] = "AbortError";
|
|
764
1152
|
})(BROWSER_CAMERA_ERRORS || (BROWSER_CAMERA_ERRORS = {}));
|
|
1153
|
+
let stream;
|
|
765
1154
|
const videoConstraintsFactory = (isPC, facingMode) => {
|
|
766
1155
|
return isPC ? {
|
|
767
1156
|
video: {
|
|
@@ -842,6 +1231,43 @@ function arrayFromAsync(asyncIterable) {
|
|
|
842
1231
|
return result;
|
|
843
1232
|
});
|
|
844
1233
|
}
|
|
1234
|
+
function switchCamera(deviceId, video) {
|
|
1235
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1236
|
+
try {
|
|
1237
|
+
if (stream) {
|
|
1238
|
+
stream.getTracks().forEach(track => track.stop());
|
|
1239
|
+
}
|
|
1240
|
+
const constraints = {
|
|
1241
|
+
video: {
|
|
1242
|
+
// 推測依然需要使用 width & height 的限制條件,
|
|
1243
|
+
// 否則即使是高解析度相機,也有可能拿到低解析度的圖片。(待驗證)
|
|
1244
|
+
width: {
|
|
1245
|
+
min: 1280,
|
|
1246
|
+
ideal: 1920,
|
|
1247
|
+
max: 1920
|
|
1248
|
+
},
|
|
1249
|
+
height: {
|
|
1250
|
+
min: 720,
|
|
1251
|
+
ideal: 1080,
|
|
1252
|
+
max: 1080
|
|
1253
|
+
},
|
|
1254
|
+
focusMode: 'auto',
|
|
1255
|
+
deviceId: deviceId
|
|
1256
|
+
}
|
|
1257
|
+
};
|
|
1258
|
+
stream = yield navigator.mediaDevices.getUserMedia(constraints);
|
|
1259
|
+
video.srcObject = stream;
|
|
1260
|
+
yield video.play();
|
|
1261
|
+
// Note: Fix Safari 15 video not showing bug
|
|
1262
|
+
video.srcObject = null;
|
|
1263
|
+
setTimeout(() => {
|
|
1264
|
+
video.srcObject = stream;
|
|
1265
|
+
}, 10);
|
|
1266
|
+
} catch (e) {
|
|
1267
|
+
throw new AuthmeError(ErrorCode.CAMERA_NOT_SUPPORT, e);
|
|
1268
|
+
}
|
|
1269
|
+
});
|
|
1270
|
+
}
|
|
845
1271
|
function _requestCamera(video, facingMode) {
|
|
846
1272
|
var _a;
|
|
847
1273
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -916,39 +1342,14 @@ function _requestCamera(video, facingMode) {
|
|
|
916
1342
|
if (!deviceId) {
|
|
917
1343
|
throw BROWSER_CAMERA_ERRORS.NO_CAMERA;
|
|
918
1344
|
}
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
max: 1920
|
|
927
|
-
},
|
|
928
|
-
height: {
|
|
929
|
-
min: 720,
|
|
930
|
-
ideal: 1080,
|
|
931
|
-
max: 1080
|
|
932
|
-
},
|
|
933
|
-
focusMode: 'auto',
|
|
934
|
-
deviceId: {
|
|
935
|
-
exact: deviceId
|
|
936
|
-
}
|
|
937
|
-
}
|
|
1345
|
+
if (stream) {
|
|
1346
|
+
stream.getTracks().forEach(track => track.stop());
|
|
1347
|
+
}
|
|
1348
|
+
yield switchCamera(deviceId, video);
|
|
1349
|
+
return {
|
|
1350
|
+
facingMode: firstDevice.meta.facingMode,
|
|
1351
|
+
deviceMetas: deviceMetas
|
|
938
1352
|
};
|
|
939
|
-
debugLog('camera info', {
|
|
940
|
-
firstDevice,
|
|
941
|
-
deviceMetas
|
|
942
|
-
});
|
|
943
|
-
const stream = yield navigator.mediaDevices.getUserMedia(constraints);
|
|
944
|
-
video.srcObject = stream;
|
|
945
|
-
yield video.play();
|
|
946
|
-
// Note: Fix Safari 15 video not showing bug
|
|
947
|
-
video.srcObject = null;
|
|
948
|
-
setTimeout(() => {
|
|
949
|
-
video.srcObject = stream;
|
|
950
|
-
}, 10);
|
|
951
|
-
return firstDevice.meta.facingMode;
|
|
952
1353
|
});
|
|
953
1354
|
}
|
|
954
1355
|
function isOverconstrainedError(error) {
|
|
@@ -982,6 +1383,15 @@ function requestCamera({
|
|
|
982
1383
|
showMessage(translate('camera.error.notFound'));
|
|
983
1384
|
throw new AuthmeError(ErrorCode.CAMERA_NOT_SUPPORT, error);
|
|
984
1385
|
}
|
|
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
|
+
}
|
|
985
1395
|
if (isOverconstrainedError(error)) {
|
|
986
1396
|
showMessage(translate('camera.error.lowResolution'));
|
|
987
1397
|
throw new AuthmeError(ErrorCode.CAMERA_NOT_SUPPORT, error);
|
|
@@ -1977,15 +2387,40 @@ function RGBToLottieColor(color) {
|
|
|
1977
2387
|
return color.map(c => c / 255);
|
|
1978
2388
|
}
|
|
1979
2389
|
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
2390
|
+
const QUEUE_LENGTH = 10;
|
|
2391
|
+
const requstQueue = [];
|
|
2392
|
+
function pushRequest(request) {
|
|
2393
|
+
if (requstQueue.length > QUEUE_LENGTH - 1) {
|
|
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
|
+
});
|
|
1984
2415
|
};
|
|
2416
|
+
|
|
2417
|
+
var name = "authme/sdk";
|
|
2418
|
+
var version$1 = "2.4.7";
|
|
2419
|
+
var date = "2023-12-14T08:29:41+0000";
|
|
1985
2420
|
var packageInfo = {
|
|
1986
2421
|
name: name,
|
|
1987
2422
|
version: version$1,
|
|
1988
|
-
|
|
2423
|
+
date: date
|
|
1989
2424
|
};
|
|
1990
2425
|
|
|
1991
2426
|
var _a;
|
|
@@ -1994,4 +2429,4 @@ const version = packageInfo.version;
|
|
|
1994
2429
|
(_a = (_b = window)[_c = Symbol.for('authme-sdk')]) !== null && _a !== void 0 ? _a : _b[_c] = {};
|
|
1995
2430
|
window[Symbol.for('authme-sdk')][packageInfo.name] = version;
|
|
1996
2431
|
|
|
1997
|
-
export { AuthmeError, ErrorCode, Icon, RGBToLottieColor, STORAGE_KEY, Storage, TIME_UNIT, UintArrayToBlob, asyncOnLineShowErrorMessage, asyncShowErrorMessage, asyncShowPopup, checkOnlineStatus, clearCanvas, colorStringToRGB, colorToRGB, combineResult, cropByRatio, dataURItoBlob, debugLog, decodeToken, getCanvasSize, getCssVariable, getDeviceInfo, getImageData, getSystemInfo,
|
|
2432
|
+
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, hexToRGB, hideElement, hideErrorMessage, hidePopup, isIphone14proOrProMax, isMobile, isMobileOrTablet, osVersion, requestCamera, resize, retryPromiseWithCondition, showElement, showErrorMessage, showErrorMessageEventName, showPopup, splitResult, startLoadingSDK, startSpinner, stopLoadingSDK, stopSpinner, switchCamera, useState, version, videoConstraintsFactory, waitTime };
|