@authme/util 2.3.1-rc.3 → 2.4.4-rc.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 +553 -97
- package/index.js +542 -97
- package/package.json +3 -1
- package/src/lib/authme-error.d.ts +3 -1
- package/src/lib/authme-log.d.ts +26 -0
- package/src/lib/common/client-info.service.d.ts +2 -0
- package/src/lib/common/index.d.ts +6 -0
- package/src/lib/common/jwt-decode.service.d.ts +19 -0
- package/src/lib/common/state.service.d.ts +4 -0
- package/src/lib/storage/storage.d.ts +7 -0
- package/src/ui/camera.d.ts +19 -1
- package/src/ui/error-message.d.ts +9 -2
- package/src/ui/spinner.d.ts +1 -1
package/index.js
CHANGED
|
@@ -7,35 +7,49 @@ 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.regexp.to-string.js';
|
|
10
11
|
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
12
|
+
import 'core-js/modules/es.object.assign.js';
|
|
13
|
+
import 'core-js/modules/es.number.parse-int.js';
|
|
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';
|
|
11
17
|
import 'core-js/modules/web.url-search-params.js';
|
|
12
18
|
import 'core-js/modules/es.string.search.js';
|
|
13
|
-
import 'core-js/modules/es.
|
|
19
|
+
import 'core-js/modules/es.typed-array.uint32-array.js';
|
|
20
|
+
import Lottie from 'lottie-web';
|
|
14
21
|
import 'core-js/modules/es.array.sort.js';
|
|
15
22
|
import 'core-js/modules/es.array.includes.js';
|
|
16
23
|
import 'core-js/modules/es.string.includes.js';
|
|
17
|
-
import lottie from 'lottie-web';
|
|
18
|
-
import 'core-js/modules/es.string.replace.js';
|
|
19
24
|
import 'core-js/modules/es.parse-int.js';
|
|
20
25
|
import 'core-js/modules/es.string.trim.js';
|
|
21
26
|
import 'core-js/modules/es.string.starts-with.js';
|
|
22
27
|
import 'core-js/modules/es.symbol.description.js';
|
|
23
28
|
|
|
24
29
|
const GLOBAL_KEY = '_AuthmeConfig';
|
|
30
|
+
const _storage = {};
|
|
31
|
+
var STORAGE_KEY;
|
|
32
|
+
(function (STORAGE_KEY) {
|
|
33
|
+
STORAGE_KEY["LOADING_LOTTIE"] = "loadingLottie";
|
|
34
|
+
STORAGE_KEY["OCR_IDCARD_RESULT_FORMAT"] = "ocrIdcardResultFormat";
|
|
35
|
+
STORAGE_KEY["ENABLE_EVENT_TRACKING"] = "enableEventTracking";
|
|
36
|
+
STORAGE_KEY["EVENT_TRACK_URL"] = "eventTrackUrl";
|
|
37
|
+
STORAGE_KEY["API_BASE_URL"] = "apiBaseUrl";
|
|
38
|
+
})(STORAGE_KEY || (STORAGE_KEY = {}));
|
|
25
39
|
function getItem(key) {
|
|
26
|
-
return
|
|
40
|
+
return _storage[GLOBAL_KEY][key];
|
|
27
41
|
}
|
|
28
42
|
function setItem(key, val) {
|
|
29
|
-
if (!
|
|
30
|
-
|
|
43
|
+
if (!_storage[GLOBAL_KEY]) {
|
|
44
|
+
_storage[GLOBAL_KEY] = {};
|
|
31
45
|
}
|
|
32
|
-
return
|
|
46
|
+
return _storage[GLOBAL_KEY][key] = val;
|
|
33
47
|
}
|
|
34
48
|
function removeItem(key) {
|
|
35
|
-
return delete
|
|
49
|
+
return delete _storage[GLOBAL_KEY][key];
|
|
36
50
|
}
|
|
37
51
|
function clear() {
|
|
38
|
-
|
|
52
|
+
_storage[GLOBAL_KEY] = {};
|
|
39
53
|
}
|
|
40
54
|
const Storage = {
|
|
41
55
|
getItem,
|
|
@@ -59,6 +73,18 @@ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
59
73
|
PERFORMANCE OF THIS SOFTWARE.
|
|
60
74
|
***************************************************************************** */
|
|
61
75
|
|
|
76
|
+
function __rest(s, e) {
|
|
77
|
+
var t = {};
|
|
78
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
79
|
+
t[p] = s[p];
|
|
80
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
81
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
82
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
83
|
+
t[p[i]] = s[p[i]];
|
|
84
|
+
}
|
|
85
|
+
return t;
|
|
86
|
+
}
|
|
87
|
+
|
|
62
88
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
63
89
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
64
90
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -105,6 +131,188 @@ function __asyncValues(o) {
|
|
|
105
131
|
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
106
132
|
}
|
|
107
133
|
|
|
134
|
+
class AuthmeError {
|
|
135
|
+
constructor(code, cause = null) {
|
|
136
|
+
this._cause = null;
|
|
137
|
+
this._code = null;
|
|
138
|
+
this._code = code;
|
|
139
|
+
this._cause = cause;
|
|
140
|
+
}
|
|
141
|
+
get message() {
|
|
142
|
+
return '[Authme SDK Error] Code: ' + this.code;
|
|
143
|
+
}
|
|
144
|
+
setCode(code) {
|
|
145
|
+
this._code = code;
|
|
146
|
+
}
|
|
147
|
+
get code() {
|
|
148
|
+
return this._code;
|
|
149
|
+
}
|
|
150
|
+
get cause() {
|
|
151
|
+
return this._cause;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
var ErrorCode;
|
|
155
|
+
(function (ErrorCode) {
|
|
156
|
+
// 1XX for engine
|
|
157
|
+
ErrorCode[ErrorCode["BROWSER_NOT_SUPPORT"] = 100] = "BROWSER_NOT_SUPPORT";
|
|
158
|
+
ErrorCode[ErrorCode["ENGINE_INIT_ERROR"] = 101] = "ENGINE_INIT_ERROR";
|
|
159
|
+
ErrorCode[ErrorCode["ENGINE_MODULE_IS_INITIALIZING"] = 102] = "ENGINE_MODULE_IS_INITIALIZING";
|
|
160
|
+
ErrorCode[ErrorCode["ENGINE_MODULE_INIT_ERROR"] = 103] = "ENGINE_MODULE_INIT_ERROR";
|
|
161
|
+
ErrorCode[ErrorCode["RECOGNITION_NOT_AVAILABLE"] = 104] = "RECOGNITION_NOT_AVAILABLE";
|
|
162
|
+
ErrorCode[ErrorCode["RECOGNITION_ERROR"] = 105] = "RECOGNITION_ERROR";
|
|
163
|
+
ErrorCode[ErrorCode["INVALID_AUTH_ERROR"] = 106] = "INVALID_AUTH_ERROR";
|
|
164
|
+
ErrorCode[ErrorCode["SCREEN_RESOLUTION_TOO_LOW"] = 107] = "SCREEN_RESOLUTION_TOO_LOW";
|
|
165
|
+
ErrorCode[ErrorCode["SCREEN_SIZE_CHANGED"] = 108] = "SCREEN_SIZE_CHANGED";
|
|
166
|
+
// 2 for LIVENESS
|
|
167
|
+
ErrorCode[ErrorCode["LIVENESS_NOT_PASSED"] = 201] = "LIVENESS_NOT_PASSED";
|
|
168
|
+
// 3 for ID-Recognition
|
|
169
|
+
ErrorCode[ErrorCode["ID_RECOGNITION_CONFIRM_INFO_ERROR"] = 301] = "ID_RECOGNITION_CONFIRM_INFO_ERROR";
|
|
170
|
+
ErrorCode[ErrorCode["ID_RECOGNITION_TIMEOUT"] = 302] = "ID_RECOGNITION_TIMEOUT";
|
|
171
|
+
// 4 for Anti-fraud
|
|
172
|
+
ErrorCode[ErrorCode["ID_RECOGNITION_ANTI_FRAUD_NOT_PASSED"] = 401] = "ID_RECOGNITION_ANTI_FRAUD_NOT_PASSED";
|
|
173
|
+
// 9 for common
|
|
174
|
+
ErrorCode[ErrorCode["SDK_INTERNAL_ERROR"] = 900] = "SDK_INTERNAL_ERROR";
|
|
175
|
+
ErrorCode[ErrorCode["NETWORK_ERROR"] = 901] = "NETWORK_ERROR";
|
|
176
|
+
ErrorCode[ErrorCode["HTTP_ERROR_RESPONSE"] = 902] = "HTTP_ERROR_RESPONSE";
|
|
177
|
+
ErrorCode[ErrorCode["USER_CANCEL"] = 903] = "USER_CANCEL";
|
|
178
|
+
ErrorCode[ErrorCode["CAMERA_NOT_SUPPORT"] = 904] = "CAMERA_NOT_SUPPORT";
|
|
179
|
+
ErrorCode[ErrorCode["SERVER_ERROR"] = 905] = "SERVER_ERROR";
|
|
180
|
+
ErrorCode[ErrorCode["EVENT_NAME_WRONG"] = 906] = "EVENT_NAME_WRONG";
|
|
181
|
+
})(ErrorCode || (ErrorCode = {}));
|
|
182
|
+
|
|
183
|
+
function decodeToken(token) {
|
|
184
|
+
const decoded = jwt_decode(token);
|
|
185
|
+
const {
|
|
186
|
+
exp,
|
|
187
|
+
iat
|
|
188
|
+
} = decoded;
|
|
189
|
+
return {
|
|
190
|
+
payload: decoded,
|
|
191
|
+
exp: typeof exp === 'number' ? exp : 0,
|
|
192
|
+
iat: typeof iat === 'number' ? iat : 0
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function getDeviceInfo() {
|
|
197
|
+
const userAgent = window.navigator.userAgent;
|
|
198
|
+
const deviceType = getDeviceType(userAgent);
|
|
199
|
+
const browserType = getBrowserType(userAgent);
|
|
200
|
+
return `${deviceType} (${browserType})`;
|
|
201
|
+
}
|
|
202
|
+
function getDeviceType(userAgent) {
|
|
203
|
+
if (userAgent.match(/iPad/i) || userAgent.match(/iPhone/i)) {
|
|
204
|
+
return 'iPad/iPhone';
|
|
205
|
+
} else if (userAgent.match(/Android/i)) {
|
|
206
|
+
return 'Android';
|
|
207
|
+
} else if (userAgent.match(/Windows Phone/i)) {
|
|
208
|
+
return 'Windows Phone';
|
|
209
|
+
} else if (userAgent.match(/Windows NT/i)) {
|
|
210
|
+
return 'Windows PC';
|
|
211
|
+
} else if (userAgent.match(/Mac OS/i)) {
|
|
212
|
+
return 'Mac';
|
|
213
|
+
} else if (userAgent.match(/Linux/i)) {
|
|
214
|
+
return 'Linux';
|
|
215
|
+
} else {
|
|
216
|
+
return 'Unknown Device';
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
function getBrowserType(userAgent) {
|
|
220
|
+
if (userAgent.match(/Chrome/i)) {
|
|
221
|
+
return 'Chrome';
|
|
222
|
+
} else if (userAgent.match(/Firefox/i)) {
|
|
223
|
+
return 'Firefox';
|
|
224
|
+
} else if (userAgent.match(/Edge/i)) {
|
|
225
|
+
return 'Edge';
|
|
226
|
+
} else if (userAgent.match(/Safari/i)) {
|
|
227
|
+
return 'Safari';
|
|
228
|
+
} else if (userAgent.match(/MSIE/i) || userAgent.match(/Trident/i)) {
|
|
229
|
+
return 'IE';
|
|
230
|
+
} else {
|
|
231
|
+
return 'Unknown Browser';
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
function getSystemInfo() {
|
|
235
|
+
const userAgent = window.navigator.userAgent;
|
|
236
|
+
const os = getOs(userAgent);
|
|
237
|
+
const osVersion = getOsVersion(userAgent);
|
|
238
|
+
return `${os} (${osVersion})`;
|
|
239
|
+
}
|
|
240
|
+
function getOs(userAgent) {
|
|
241
|
+
if (userAgent.match(/Windows NT 10/i)) {
|
|
242
|
+
return 'Windows 10';
|
|
243
|
+
} else if (userAgent.match(/Windows NT 6.3/i)) {
|
|
244
|
+
return 'Windows 8.1';
|
|
245
|
+
} else if (userAgent.match(/Windows NT 6.2/i)) {
|
|
246
|
+
return 'Windows 8';
|
|
247
|
+
} else if (userAgent.match(/Windows NT 6.1/i)) {
|
|
248
|
+
return 'Windows 7';
|
|
249
|
+
} else if (userAgent.match(/Windows NT 6.0/i)) {
|
|
250
|
+
return 'Windows Vista';
|
|
251
|
+
} else if (userAgent.match(/Windows NT 5.1/i)) {
|
|
252
|
+
return 'Windows XP';
|
|
253
|
+
} else if (userAgent.match(/Windows NT 5.0/i)) {
|
|
254
|
+
return 'Windows 2000';
|
|
255
|
+
} else if (userAgent.match(/Mac/i)) {
|
|
256
|
+
return 'Mac OS';
|
|
257
|
+
} else if (userAgent.match(/Linux/i)) {
|
|
258
|
+
return 'Linux';
|
|
259
|
+
} else {
|
|
260
|
+
return 'Unknown OS';
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
function getOsVersion(userAgent) {
|
|
264
|
+
if (userAgent.match(/Windows NT/i)) {
|
|
265
|
+
const matches = userAgent.match(/Windows NT ([\d\\.]+)/i);
|
|
266
|
+
if (matches) {
|
|
267
|
+
return matches[1];
|
|
268
|
+
} else {
|
|
269
|
+
return '';
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
if (userAgent.match(/Mac/i)) {
|
|
273
|
+
const matches = userAgent.match(/Mac OS X ([\d_.]+)/i);
|
|
274
|
+
if (matches) {
|
|
275
|
+
return matches[1].replace(/_/g, '.');
|
|
276
|
+
} else {
|
|
277
|
+
return '';
|
|
278
|
+
}
|
|
279
|
+
} else if (userAgent.match(/Android/i)) {
|
|
280
|
+
const matches = userAgent.match(/Android ([\d.]+)/i);
|
|
281
|
+
if (matches) {
|
|
282
|
+
return matches[1];
|
|
283
|
+
} else {
|
|
284
|
+
return '';
|
|
285
|
+
}
|
|
286
|
+
} else {
|
|
287
|
+
return '';
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
class State {
|
|
292
|
+
constructor(initialValue = null) {
|
|
293
|
+
this._value = initialValue;
|
|
294
|
+
}
|
|
295
|
+
getValue() {
|
|
296
|
+
return this._value;
|
|
297
|
+
}
|
|
298
|
+
setValue(newValue) {
|
|
299
|
+
this._value = newValue;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
function useState(initialValue = null, subscription) {
|
|
303
|
+
const state = new State(initialValue);
|
|
304
|
+
function getValue() {
|
|
305
|
+
return state.getValue();
|
|
306
|
+
}
|
|
307
|
+
function setValue(newValue) {
|
|
308
|
+
if (subscription && newValue !== state.getValue()) {
|
|
309
|
+
subscription.next(newValue);
|
|
310
|
+
}
|
|
311
|
+
state.setValue(newValue);
|
|
312
|
+
}
|
|
313
|
+
return [getValue, setValue];
|
|
314
|
+
}
|
|
315
|
+
|
|
108
316
|
function dataURItoBlob(dataURI) {
|
|
109
317
|
// convert base64/URLEncoded data component to raw binary data held in a string
|
|
110
318
|
const byteString = atob(dataURI.split(',')[1]);
|
|
@@ -156,7 +364,9 @@ function retryPromiseWithCondition(promiseFactory, conditionFactory) {
|
|
|
156
364
|
const res = yield promiseFactory();
|
|
157
365
|
return res;
|
|
158
366
|
} catch (e) {
|
|
159
|
-
|
|
367
|
+
if ((e === null || e === void 0 ? void 0 : e._code) === ErrorCode.SERVER_ERROR) {
|
|
368
|
+
throw e;
|
|
369
|
+
}
|
|
160
370
|
const retry = yield conditionFactory(e);
|
|
161
371
|
if (retry) {
|
|
162
372
|
return retryPromiseWithCondition(promiseFactory, conditionFactory);
|
|
@@ -179,59 +389,185 @@ function isMobile() {
|
|
|
179
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));
|
|
180
390
|
}(navigator.userAgent || navigator.vendor || window.opera);
|
|
181
391
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
392
|
+
function splitResult(result) {
|
|
393
|
+
if (result.address) {
|
|
394
|
+
const originAddress = result.address;
|
|
395
|
+
const address1Index = checkCity(originAddress);
|
|
396
|
+
result.address1 = address1Index === -1 ? '' : originAddress.slice(0, 3);
|
|
397
|
+
const address2 = address1Index === -1 ? originAddress : originAddress.slice(3);
|
|
398
|
+
const address2Index = checkZone(address2);
|
|
399
|
+
result.address2 = address2Index === -1 ? '' : address2.slice(0, address2Index + 1);
|
|
400
|
+
result.address3 = address2Index === -1 ? address2 : address2.slice(address2Index + 1);
|
|
189
401
|
}
|
|
190
|
-
|
|
191
|
-
|
|
402
|
+
if (result.dateOfBirth) {
|
|
403
|
+
const splitDateOfBirth = result.dateOfBirth.split('-');
|
|
404
|
+
const dateOfBirthY = (+splitDateOfBirth[0] - 1911).toString();
|
|
405
|
+
result.dateOfBirthY = dateOfBirthY.length < 3 ? '0' + dateOfBirthY : dateOfBirthY;
|
|
406
|
+
result.dateOfBirthM = splitDateOfBirth[1];
|
|
407
|
+
result.dateOfBirthD = splitDateOfBirth[2];
|
|
192
408
|
}
|
|
193
|
-
|
|
194
|
-
|
|
409
|
+
if (result.dateOfIssue) {
|
|
410
|
+
const splitDateOfIssue = result.dateOfIssue.split('-');
|
|
411
|
+
const dateOfIssueY = (+splitDateOfIssue[0] - 1911).toString();
|
|
412
|
+
result.dateOfIssueY = dateOfIssueY.length < 3 ? '0' + dateOfIssueY : dateOfIssueY;
|
|
413
|
+
result.dateOfIssueM = splitDateOfIssue[1];
|
|
414
|
+
result.dateOfIssueD = splitDateOfIssue[2];
|
|
195
415
|
}
|
|
196
|
-
|
|
197
|
-
|
|
416
|
+
return result;
|
|
417
|
+
}
|
|
418
|
+
function checkCity(address) {
|
|
419
|
+
const citys = ['臺北市', '臺中市', '基隆市', '臺南市', '高雄市', '新北市', '宜蘭縣', '桃園市', '嘉義市', '新竹縣', '苗栗縣', '南投縣', '彰化縣', '新竹市', '雲林縣', '嘉義縣', '屏東縣', '花蓮縣', '臺東縣', '金門縣', '澎湖縣', '連江縣', '臺中縣', '臺南縣', '高雄縣'];
|
|
420
|
+
for (const city of citys) {
|
|
421
|
+
if (address.indexOf(city) !== -1) {
|
|
422
|
+
return address.indexOf(city);
|
|
423
|
+
}
|
|
198
424
|
}
|
|
199
|
-
|
|
200
|
-
|
|
425
|
+
return -1;
|
|
426
|
+
}
|
|
427
|
+
function checkZone(address) {
|
|
428
|
+
const zones = ['鄉', '鎮', '市', '區'];
|
|
429
|
+
for (const zone of zones) {
|
|
430
|
+
if (address.indexOf(zone) !== -1) {
|
|
431
|
+
return address.indexOf(zone);
|
|
432
|
+
}
|
|
201
433
|
}
|
|
434
|
+
return -1;
|
|
202
435
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
//
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
436
|
+
function notEmpty(value) {
|
|
437
|
+
return typeof value !== 'undefined' && value !== null && value !== '';
|
|
438
|
+
}
|
|
439
|
+
function combineResult(result) {
|
|
440
|
+
const {
|
|
441
|
+
address1,
|
|
442
|
+
address2,
|
|
443
|
+
address3,
|
|
444
|
+
dateOfBirthY,
|
|
445
|
+
dateOfBirthM,
|
|
446
|
+
dateOfBirthD,
|
|
447
|
+
dateOfIssueY,
|
|
448
|
+
dateOfIssueM,
|
|
449
|
+
dateOfIssueD
|
|
450
|
+
} = result,
|
|
451
|
+
others = __rest(result, ["address1", "address2", "address3", "dateOfBirthY", "dateOfBirthM", "dateOfBirthD", "dateOfIssueY", "dateOfIssueM", "dateOfIssueD"]);
|
|
452
|
+
// 由於呼叫函數的情境包含 confirmOCRResult,
|
|
453
|
+
// confirmOCRResult 並不會知道目前是什麼卡片類型,
|
|
454
|
+
// 所以會以分割出的欄位來判斷是否進行欄位合併與覆寫。
|
|
455
|
+
const newResult = Object.assign({}, others);
|
|
456
|
+
if ([address1, address2, address3].every(notEmpty)) {
|
|
457
|
+
newResult.address = `${address1}${address2}${address3}`;
|
|
458
|
+
}
|
|
459
|
+
if ([dateOfBirthY, dateOfBirthM, dateOfBirthD].every(notEmpty)) {
|
|
460
|
+
newResult.dateOfBirth = `${1911 + Number.parseInt(dateOfBirthY || '0')}-${dateOfBirthM}-${dateOfBirthD}`;
|
|
461
|
+
}
|
|
462
|
+
if ([dateOfIssueY, dateOfIssueM, dateOfIssueD].every(notEmpty)) {
|
|
463
|
+
newResult.dateOfIssue = `${1911 + Number.parseInt(dateOfIssueY || '0')}-${dateOfIssueM}-${dateOfIssueD}`;
|
|
464
|
+
}
|
|
465
|
+
return newResult;
|
|
466
|
+
}
|
|
467
|
+
const isIphone14proOrProMax = () => {
|
|
468
|
+
const isIphone = () => {
|
|
469
|
+
return /iPhone|iPad|iPod/i.test(navigator.userAgent);
|
|
470
|
+
};
|
|
471
|
+
return isIphone() && (screen.width === 430 && screen.height === 932 || screen.width === 393 && screen.height === 852);
|
|
472
|
+
};
|
|
229
473
|
|
|
230
474
|
function debugLog(message, ...others) {
|
|
231
475
|
if (new URLSearchParams(location.search).get('authme-debug') === 'true') {
|
|
232
476
|
console.log(message, ...others);
|
|
233
477
|
}
|
|
234
478
|
}
|
|
479
|
+
function generateUniqueId(length = 32) {
|
|
480
|
+
if (length <= 0) {
|
|
481
|
+
throw new Error('Length should be a positive integer.');
|
|
482
|
+
}
|
|
483
|
+
// 定義可能的字元
|
|
484
|
+
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
485
|
+
const charactersLength = characters.length;
|
|
486
|
+
const randomValues = new Uint32Array(length);
|
|
487
|
+
// 使用window.crypto.getRandomValues取得真正的隨機值
|
|
488
|
+
window.crypto.getRandomValues(randomValues);
|
|
489
|
+
let result = '';
|
|
490
|
+
for (let i = 0; i < length; i++) {
|
|
491
|
+
result += characters[randomValues[i] % charactersLength];
|
|
492
|
+
}
|
|
493
|
+
return result;
|
|
494
|
+
}
|
|
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) {
|
|
506
|
+
const debugLogs = [];
|
|
507
|
+
let currentRoundId = generateUniqueId(8);
|
|
508
|
+
let currentType = null;
|
|
509
|
+
function pushNewDebugLog(logParams) {
|
|
510
|
+
var _a;
|
|
511
|
+
if (!config.debugMode) return;
|
|
512
|
+
const now = new Date();
|
|
513
|
+
const _logParams = JSON.parse(JSON.stringify(logParams));
|
|
514
|
+
if (_logParams.result) {
|
|
515
|
+
(_a = _logParams.result) === null || _a === void 0 ? true : delete _a.imageData;
|
|
516
|
+
}
|
|
517
|
+
const newDebugLog = Object.assign({
|
|
518
|
+
time: now.getTime(),
|
|
519
|
+
dateTime: now.toLocaleString(),
|
|
520
|
+
roundId: currentRoundId,
|
|
521
|
+
type: currentType !== null && currentType !== void 0 ? currentType : undefined
|
|
522
|
+
}, _logParams);
|
|
523
|
+
debugLogs.push(newDebugLog);
|
|
524
|
+
}
|
|
525
|
+
function functionLogging(func, logParams) {
|
|
526
|
+
return new Promise((resolve, reject) => {
|
|
527
|
+
pushNewDebugLog(Object.assign(Object.assign({}, logParams), {
|
|
528
|
+
status: 'run-start'
|
|
529
|
+
}));
|
|
530
|
+
func().then(result => {
|
|
531
|
+
pushNewDebugLog(Object.assign(Object.assign({}, logParams), {
|
|
532
|
+
status: 'run-end',
|
|
533
|
+
roundId: currentRoundId,
|
|
534
|
+
result
|
|
535
|
+
}));
|
|
536
|
+
resolve(result);
|
|
537
|
+
}).catch(error => {
|
|
538
|
+
pushNewDebugLog(Object.assign(Object.assign({}, logParams), {
|
|
539
|
+
status: 'run-error',
|
|
540
|
+
roundId: currentRoundId,
|
|
541
|
+
result: error
|
|
542
|
+
}));
|
|
543
|
+
reject(error);
|
|
544
|
+
});
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
return {
|
|
548
|
+
pushNewDebugLog,
|
|
549
|
+
getDebugLogs: () => debugLogs,
|
|
550
|
+
getDebugLogsLength: () => debugLogs.length,
|
|
551
|
+
modifyDeubgLog: (index, logParams) => {
|
|
552
|
+
if (!config.debugMode) return;
|
|
553
|
+
debugLogs[index] = Object.assign(Object.assign({}, debugLogs[index]), logParams);
|
|
554
|
+
},
|
|
555
|
+
downloadDebugLogs: () => {
|
|
556
|
+
if (!config.debugMode) return;
|
|
557
|
+
downloadObjectAsJson(debugLogs, `debugLog${new Date().getTime().toString()}`);
|
|
558
|
+
},
|
|
559
|
+
functionLogging,
|
|
560
|
+
nextDebugRound: type => {
|
|
561
|
+
if (!config.debugMode) return;
|
|
562
|
+
currentRoundId = generateUniqueId(8);
|
|
563
|
+
if (type) currentType = type;
|
|
564
|
+
},
|
|
565
|
+
modifyDebugType: type => {
|
|
566
|
+
if (!config.debugMode) return;
|
|
567
|
+
currentType = type;
|
|
568
|
+
}
|
|
569
|
+
};
|
|
570
|
+
}
|
|
235
571
|
|
|
236
572
|
var TIME_UNIT;
|
|
237
573
|
(function (TIME_UNIT) {
|
|
@@ -336,24 +672,58 @@ function cropByRatio(width, height, ratio) {
|
|
|
336
672
|
};
|
|
337
673
|
}
|
|
338
674
|
|
|
339
|
-
function startSpinner(text) {
|
|
675
|
+
function startSpinner(text, backgroundOpaque) {
|
|
676
|
+
const loadingLottie = Storage.getItem(STORAGE_KEY.LOADING_LOTTIE);
|
|
340
677
|
const body = document.querySelector('.authme-container');
|
|
678
|
+
if (loadingLottie) {
|
|
679
|
+
const loadingSDKOuter = document.createElement('div');
|
|
680
|
+
const loadingSDKContent = document.createElement('div');
|
|
681
|
+
const loadingSDKText = document.createElement('div');
|
|
682
|
+
loadingSDKOuter.classList.add('authme-loading-sdk-outer');
|
|
683
|
+
loadingSDKContent.classList.add('authme-loading-sdk-content');
|
|
684
|
+
loadingSDKOuter.appendChild(loadingSDKContent);
|
|
685
|
+
Lottie.loadAnimation({
|
|
686
|
+
container: loadingSDKContent,
|
|
687
|
+
renderer: 'svg',
|
|
688
|
+
loop: true,
|
|
689
|
+
autoplay: true,
|
|
690
|
+
name: 'spinner-loading',
|
|
691
|
+
animationData: loadingLottie
|
|
692
|
+
});
|
|
693
|
+
body === null || body === void 0 ? void 0 : body.appendChild(loadingSDKOuter);
|
|
694
|
+
if (text) {
|
|
695
|
+
loadingSDKText.classList.add('authme-loading-sdk-text');
|
|
696
|
+
loadingSDKText.textContent = text;
|
|
697
|
+
loadingSDKContent.appendChild(loadingSDKText);
|
|
698
|
+
}
|
|
699
|
+
if (backgroundOpaque) {
|
|
700
|
+
loadingSDKOuter.classList.add('authme-loading-sdk-outer--opaque');
|
|
701
|
+
}
|
|
702
|
+
return;
|
|
703
|
+
}
|
|
341
704
|
const spinnerOuter = document.createElement('div');
|
|
342
|
-
spinnerOuter.className = 'loading-outer';
|
|
343
705
|
const spinner = document.createElement('div');
|
|
344
|
-
spinner.className = 'loading';
|
|
345
706
|
const spinnerText = document.createElement('div');
|
|
346
707
|
spinnerOuter.appendChild(spinner);
|
|
708
|
+
spinnerOuter.className = 'loading-outer';
|
|
709
|
+
spinner.className = 'loading';
|
|
347
710
|
if (text) {
|
|
348
711
|
spinnerText.className = 'loading-text';
|
|
349
712
|
spinnerText.textContent = text;
|
|
350
713
|
spinnerOuter.appendChild(spinnerText);
|
|
351
714
|
}
|
|
715
|
+
if (backgroundOpaque) {
|
|
716
|
+
spinnerOuter.classList.add('loading-outer--opaque');
|
|
717
|
+
}
|
|
352
718
|
body === null || body === void 0 ? void 0 : body.appendChild(spinnerOuter);
|
|
353
719
|
}
|
|
354
720
|
function stopSpinner() {
|
|
721
|
+
const loadingLottie = Storage.getItem(STORAGE_KEY.LOADING_LOTTIE);
|
|
355
722
|
const body = document.querySelector('.authme-container');
|
|
356
|
-
|
|
723
|
+
if (loadingLottie) {
|
|
724
|
+
Lottie.destroy('spinner-loading');
|
|
725
|
+
}
|
|
726
|
+
const spinner = loadingLottie ? document.querySelector('.authme-loading-sdk-outer') : document.querySelector('.loading-outer');
|
|
357
727
|
if (spinner) {
|
|
358
728
|
body === null || body === void 0 ? void 0 : body.removeChild(spinner);
|
|
359
729
|
}
|
|
@@ -365,7 +735,7 @@ var Icon;
|
|
|
365
735
|
Icon["PictureIcon"] = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFAAAABQCAYAAACOEfKtAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAt9SURBVHgB7VxdTFRJFq7q23/Q0NC6IKDGhrgiG4mSGAejmyDoToxri5F1ZV9Gk0lWn8CnyY4Pgw9rsk+LT2M2k+juw+KOGBU3cUYjsoljNDFRA1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ubS8pKalPtSLjEQehCnjbMl90yT+N984mErIoIalDJ9SUCJmd31WVnPnRrFc9VAdMu6qqaqfZbN6SzKETHo9nlDqHPlijVCIOAIE/xK6Kh04sU3kRJH/sSfgIAPmi0rEn7/S6uz+UmS7HIhIAWa+Q3Lh69WpQpgkywJSOPQHC6NL7KN0ZHIENINifUSMNEEt1YYdB6JjXm9zxeWk/eAfUCCViUOWkZNbpABDX/NppW+MN2mD+rnDJyjl4J4JwBrvk7cIa1KH0OxA5r9MOJqLI5SIB4sJBMsR5K+roJxZhk5bouBjr8DFJM/TKpL87XGwcSpZM2DGETa8yT7Axahmeh506ixPJmqyItJ0fGPbSGr5cVgmgTI+kGXXpNSPvDNpRSKt1aZHK8XfIBOkWpkCo3OwL1ZiD8pb4x9+Fx7rzKGjsTpXqWKT3AEaouQui44kQmXqkl7gIMnaGKpTP/lRC1oTSi4Hwfg7dkkgncRFkjMAIwqoMoabUkUnCiQCZJI1FxgkUAXNrJMnboMBnsYyAxpNQKaB0DHIY5Ck1zbFwEpRMBlDAZM80aXnkkUceeSzif3+l5taU5LriAAAAAElFTkSuQmCC";
|
|
366
736
|
})(Icon || (Icon = {}));
|
|
367
737
|
|
|
368
|
-
function showErrorMessage(text, showRetryBtn, callback) {
|
|
738
|
+
function showErrorMessage(text, showRetryBtn, callback, buttonText, _titleText) {
|
|
369
739
|
return __awaiter(this, void 0, void 0, function* () {
|
|
370
740
|
const target = document.querySelector('.authme-container');
|
|
371
741
|
if (!target) {
|
|
@@ -384,7 +754,39 @@ function showErrorMessage(text, showRetryBtn, callback) {
|
|
|
384
754
|
if (showRetryBtn) {
|
|
385
755
|
const retryText = document.createElement('div');
|
|
386
756
|
retryText.className = 'retry-text';
|
|
387
|
-
retryText.textContent = '重試';
|
|
757
|
+
retryText.textContent = buttonText !== null && buttonText !== void 0 ? buttonText : '重試';
|
|
758
|
+
errorMessagePanel.appendChild(retryText);
|
|
759
|
+
if (callback) {
|
|
760
|
+
retryText.addEventListener('click', e => {
|
|
761
|
+
target.removeChild(errorMessagePanel);
|
|
762
|
+
callback(e);
|
|
763
|
+
});
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
target === null || target === void 0 ? void 0 : target.appendChild(errorMessagePanel);
|
|
767
|
+
});
|
|
768
|
+
}
|
|
769
|
+
function showErrorMessageEventName(text, showRetryBtn, callback, buttonText, titleText) {
|
|
770
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
771
|
+
const target = document.querySelector('.authme-container');
|
|
772
|
+
if (!target) {
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
const errorMessagePanel = document.createElement('div');
|
|
776
|
+
errorMessagePanel.classList.add('error-message-panel');
|
|
777
|
+
errorMessagePanel.classList.add('event-name');
|
|
778
|
+
const errorText = document.createElement('div');
|
|
779
|
+
errorText.className = 'error-text';
|
|
780
|
+
errorText.textContent = text;
|
|
781
|
+
const title = document.createElement('div');
|
|
782
|
+
title.className = 'error-title';
|
|
783
|
+
title.textContent = titleText !== null && titleText !== void 0 ? titleText : 'error';
|
|
784
|
+
errorMessagePanel.appendChild(title);
|
|
785
|
+
errorMessagePanel.appendChild(errorText);
|
|
786
|
+
if (showRetryBtn) {
|
|
787
|
+
const retryText = document.createElement('div');
|
|
788
|
+
retryText.className = 'retry-text';
|
|
789
|
+
retryText.textContent = buttonText !== null && buttonText !== void 0 ? buttonText : '重試';
|
|
388
790
|
errorMessagePanel.appendChild(retryText);
|
|
389
791
|
if (callback) {
|
|
390
792
|
retryText.addEventListener('click', e => {
|
|
@@ -403,14 +805,17 @@ function hideErrorMessage() {
|
|
|
403
805
|
body === null || body === void 0 ? void 0 : body.removeChild(errorMessagePanel);
|
|
404
806
|
}
|
|
405
807
|
}
|
|
406
|
-
function asyncShowErrorMessage(text, showRetryBtn) {
|
|
808
|
+
function asyncShowErrorMessage(text, showRetryBtn, options) {
|
|
809
|
+
var _a;
|
|
407
810
|
return __awaiter(this, void 0, void 0, function* () {
|
|
811
|
+
const _showErrorMessage = (_a = options === null || options === void 0 ? void 0 : options.showErrorMessageHandler) !== null && _a !== void 0 ? _a : showErrorMessage;
|
|
408
812
|
return new Promise((res, rej) => {
|
|
813
|
+
var _a;
|
|
409
814
|
const callback = () => {
|
|
410
815
|
res(true);
|
|
411
816
|
hideErrorMessage();
|
|
412
817
|
};
|
|
413
|
-
|
|
818
|
+
_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);
|
|
414
819
|
});
|
|
415
820
|
});
|
|
416
821
|
}
|
|
@@ -492,6 +897,7 @@ var BROWSER_CAMERA_ERRORS;
|
|
|
492
897
|
BROWSER_CAMERA_ERRORS["NOT_ALLOWED_ERROR"] = "NotAllowedError";
|
|
493
898
|
BROWSER_CAMERA_ERRORS["NOT_FOUND_ERROR"] = "NotFoundError";
|
|
494
899
|
})(BROWSER_CAMERA_ERRORS || (BROWSER_CAMERA_ERRORS = {}));
|
|
900
|
+
let stream;
|
|
495
901
|
const videoConstraintsFactory = (isPC, facingMode) => {
|
|
496
902
|
return isPC ? {
|
|
497
903
|
video: {
|
|
@@ -572,6 +978,43 @@ function arrayFromAsync(asyncIterable) {
|
|
|
572
978
|
return result;
|
|
573
979
|
});
|
|
574
980
|
}
|
|
981
|
+
function switchCamera(deviceId, video) {
|
|
982
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
983
|
+
try {
|
|
984
|
+
if (stream) {
|
|
985
|
+
stream.getTracks().forEach(track => track.stop());
|
|
986
|
+
}
|
|
987
|
+
const constraints = {
|
|
988
|
+
video: {
|
|
989
|
+
// 推測依然需要使用 width & height 的限制條件,
|
|
990
|
+
// 否則即使是高解析度相機,也有可能拿到低解析度的圖片。(待驗證)
|
|
991
|
+
width: {
|
|
992
|
+
min: 1280,
|
|
993
|
+
ideal: 1920,
|
|
994
|
+
max: 1920
|
|
995
|
+
},
|
|
996
|
+
height: {
|
|
997
|
+
min: 720,
|
|
998
|
+
ideal: 1080,
|
|
999
|
+
max: 1080
|
|
1000
|
+
},
|
|
1001
|
+
focusMode: 'auto',
|
|
1002
|
+
deviceId: deviceId
|
|
1003
|
+
}
|
|
1004
|
+
};
|
|
1005
|
+
stream = yield navigator.mediaDevices.getUserMedia(constraints);
|
|
1006
|
+
video.srcObject = stream;
|
|
1007
|
+
yield video.play();
|
|
1008
|
+
// Note: Fix Safari 15 video not showing bug
|
|
1009
|
+
video.srcObject = null;
|
|
1010
|
+
setTimeout(() => {
|
|
1011
|
+
video.srcObject = stream;
|
|
1012
|
+
}, 10);
|
|
1013
|
+
} catch (e) {
|
|
1014
|
+
throw new AuthmeError(ErrorCode.CAMERA_NOT_SUPPORT, e);
|
|
1015
|
+
}
|
|
1016
|
+
});
|
|
1017
|
+
}
|
|
575
1018
|
function _requestCamera(video, facingMode) {
|
|
576
1019
|
var _a;
|
|
577
1020
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -646,39 +1089,14 @@ function _requestCamera(video, facingMode) {
|
|
|
646
1089
|
if (!deviceId) {
|
|
647
1090
|
throw BROWSER_CAMERA_ERRORS.NO_CAMERA;
|
|
648
1091
|
}
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
max: 1920
|
|
657
|
-
},
|
|
658
|
-
height: {
|
|
659
|
-
min: 720,
|
|
660
|
-
ideal: 1080,
|
|
661
|
-
max: 1080
|
|
662
|
-
},
|
|
663
|
-
focusMode: 'auto',
|
|
664
|
-
deviceId: {
|
|
665
|
-
exact: deviceId
|
|
666
|
-
}
|
|
667
|
-
}
|
|
1092
|
+
if (stream) {
|
|
1093
|
+
stream.getTracks().forEach(track => track.stop());
|
|
1094
|
+
}
|
|
1095
|
+
yield switchCamera(deviceId, video);
|
|
1096
|
+
return {
|
|
1097
|
+
facingMode: firstDevice.meta.facingMode,
|
|
1098
|
+
deviceMetas: deviceMetas
|
|
668
1099
|
};
|
|
669
|
-
debugLog('camera info', {
|
|
670
|
-
firstDevice,
|
|
671
|
-
deviceMetas
|
|
672
|
-
});
|
|
673
|
-
const stream = yield navigator.mediaDevices.getUserMedia(constraints);
|
|
674
|
-
video.srcObject = stream;
|
|
675
|
-
yield video.play();
|
|
676
|
-
// Note: Fix Safari 15 video not showing bug
|
|
677
|
-
video.srcObject = null;
|
|
678
|
-
setTimeout(() => {
|
|
679
|
-
video.srcObject = stream;
|
|
680
|
-
}, 10);
|
|
681
|
-
return firstDevice.meta.facingMode;
|
|
682
1100
|
});
|
|
683
1101
|
}
|
|
684
1102
|
function isOverconstrainedError(error) {
|
|
@@ -690,6 +1108,9 @@ function isOverconstrainedError(error) {
|
|
|
690
1108
|
}
|
|
691
1109
|
return 'constraint' in error;
|
|
692
1110
|
}
|
|
1111
|
+
function sleep(ms) {
|
|
1112
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
1113
|
+
}
|
|
693
1114
|
function requestCamera({
|
|
694
1115
|
video,
|
|
695
1116
|
facingMode,
|
|
@@ -698,7 +1119,29 @@ function requestCamera({
|
|
|
698
1119
|
}) {
|
|
699
1120
|
return __awaiter(this, void 0, void 0, function* () {
|
|
700
1121
|
try {
|
|
701
|
-
|
|
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
|
+
}
|
|
702
1145
|
} catch (error) {
|
|
703
1146
|
if (error === BROWSER_CAMERA_ERRORS.NOT_SUPPORT) {
|
|
704
1147
|
showMessage(translate('camera.error.notFound'));
|
|
@@ -1646,25 +2089,27 @@ const sdk_loading = () => ({
|
|
|
1646
2089
|
});
|
|
1647
2090
|
|
|
1648
2091
|
function startLoadingSDK(text) {
|
|
2092
|
+
const loadingLottie = Storage.getItem(STORAGE_KEY.LOADING_LOTTIE);
|
|
1649
2093
|
const body = document.body;
|
|
1650
2094
|
const loadingSDKOuter = document.createElement('div');
|
|
1651
2095
|
const loadingSDKContent = document.createElement('div');
|
|
1652
2096
|
loadingSDKOuter.classList.add('authme-loading-sdk-outer');
|
|
1653
2097
|
loadingSDKContent.classList.add('authme-loading-sdk-content');
|
|
1654
2098
|
loadingSDKOuter.appendChild(loadingSDKContent);
|
|
1655
|
-
|
|
2099
|
+
Lottie.loadAnimation({
|
|
1656
2100
|
container: loadingSDKContent,
|
|
1657
2101
|
renderer: 'svg',
|
|
1658
2102
|
loop: true,
|
|
1659
2103
|
autoplay: true,
|
|
1660
|
-
name: '
|
|
1661
|
-
animationData: sdk_loading()
|
|
2104
|
+
name: 'init-sdk-loading',
|
|
2105
|
+
animationData: loadingLottie ? loadingLottie : sdk_loading()
|
|
1662
2106
|
});
|
|
1663
2107
|
body === null || body === void 0 ? void 0 : body.appendChild(loadingSDKOuter);
|
|
1664
2108
|
}
|
|
1665
2109
|
function stopLoadingSDK() {
|
|
1666
2110
|
const body = document.body;
|
|
1667
2111
|
const loadingSDKOuter = document.querySelector('.authme-loading-sdk-outer');
|
|
2112
|
+
Lottie.destroy('init-sdk-loading');
|
|
1668
2113
|
if (loadingSDKOuter) {
|
|
1669
2114
|
body === null || body === void 0 ? void 0 : body.removeChild(loadingSDKOuter);
|
|
1670
2115
|
}
|
|
@@ -1706,7 +2151,7 @@ function RGBToLottieColor(color) {
|
|
|
1706
2151
|
}
|
|
1707
2152
|
|
|
1708
2153
|
var name = "@authme/util";
|
|
1709
|
-
var version$1 = "2.
|
|
2154
|
+
var version$1 = "2.4.4-rc.7";
|
|
1710
2155
|
var peerDependencies = {
|
|
1711
2156
|
"core-js": "^3.6.0"
|
|
1712
2157
|
};
|
|
@@ -1722,4 +2167,4 @@ const version = packageInfo.version;
|
|
|
1722
2167
|
(_a = (_b = window)[_c = Symbol.for('authme-sdk')]) !== null && _a !== void 0 ? _a : _b[_c] = {};
|
|
1723
2168
|
window[Symbol.for('authme-sdk')][packageInfo.name] = version;
|
|
1724
2169
|
|
|
1725
|
-
export { AuthmeError, ErrorCode, Icon, RGBToLottieColor, Storage, TIME_UNIT, UintArrayToBlob, asyncOnLineShowErrorMessage, asyncShowErrorMessage, asyncShowPopup, checkOnlineStatus, clearCanvas, colorStringToRGB, colorToRGB, cropByRatio, dataURItoBlob, debugLog, getCanvasSize, getCssVariable, getImageData, getUserAgent, hexToRGB, hideElement, hideErrorMessage, hidePopup, isMobile, isMobileOrTablet, requestCamera, resize, retryPromiseWithCondition, showElement, showErrorMessage, showPopup, startLoadingSDK, startSpinner, stopLoadingSDK, stopSpinner, version, videoConstraintsFactory, waitTime };
|
|
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 };
|