@authme/engine 2.8.42 → 2.8.44

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.
@@ -1,54 +1,45 @@
1
1
  import 'core-js/modules/es.array.iterator.js';
2
+ import 'core-js/modules/es.array.push.js';
3
+ import 'core-js/modules/es.array.sort.js';
4
+ import 'core-js/modules/es.array-buffer.constructor.js';
5
+ import 'core-js/modules/es.array-buffer.slice.js';
6
+ import 'core-js/modules/es.array-buffer.detached.js';
7
+ import 'core-js/modules/es.array-buffer.transfer.js';
8
+ import 'core-js/modules/es.array-buffer.transfer-to-fixed-length.js';
9
+ import 'core-js/modules/es.json.stringify.js';
10
+ import 'core-js/modules/es.object.assign.js';
2
11
  import 'core-js/modules/es.object.from-entries.js';
12
+ import 'core-js/modules/es.parse-int.js';
13
+ import 'core-js/modules/es.promise.js';
3
14
  import 'core-js/modules/es.regexp.exec.js';
4
- import 'core-js/modules/es.array-buffer.slice.js';
15
+ import 'core-js/modules/es.regexp.test.js';
16
+ import 'core-js/modules/es.regexp.to-string.js';
5
17
  import 'core-js/modules/es.typed-array.uint8-array.js';
18
+ import 'core-js/modules/es.typed-array.at.js';
6
19
  import 'core-js/modules/es.typed-array.fill.js';
20
+ import 'core-js/modules/es.typed-array.find-last.js';
21
+ import 'core-js/modules/es.typed-array.find-last-index.js';
7
22
  import 'core-js/modules/es.typed-array.set.js';
8
23
  import 'core-js/modules/es.typed-array.sort.js';
9
24
  import 'core-js/modules/es.typed-array.to-locale-string.js';
25
+ import 'core-js/modules/es.typed-array.to-reversed.js';
26
+ import 'core-js/modules/es.typed-array.to-sorted.js';
27
+ import 'core-js/modules/es.typed-array.with.js';
28
+ import 'core-js/modules/esnext.iterator.constructor.js';
29
+ import 'core-js/modules/esnext.iterator.filter.js';
30
+ import 'core-js/modules/esnext.iterator.map.js';
31
+ import 'core-js/modules/esnext.uint8-array.to-base64.js';
32
+ import 'core-js/modules/esnext.uint8-array.to-hex.js';
10
33
  import 'core-js/modules/web.dom-collections.iterator.js';
11
34
  import 'core-js/modules/web.url.js';
35
+ import 'core-js/modules/web.url.to-json.js';
12
36
  import 'core-js/modules/web.url-search-params.js';
13
- import 'core-js/modules/es.promise.js';
14
- import 'core-js/modules/es.parse-int.js';
15
- import 'core-js/modules/es.object.assign.js';
16
- import 'core-js/modules/es.regexp.to-string.js';
17
- import 'core-js/modules/es.array.sort.js';
37
+ import 'core-js/modules/web.url-search-params.delete.js';
38
+ import 'core-js/modules/web.url-search-params.has.js';
39
+ import 'core-js/modules/web.url-search-params.size.js';
18
40
  import { sendRequest, AuthmeError, ErrorCode } from '@authme/core';
19
- import { debugTools, isMobile, Storage } from '@authme/util';
41
+ import { Storage, debugTools, isMobile } from '@authme/util';
20
42
  import { firstValueFrom, filter, map, tap, fromEvent, shareReplay, from, mergeAll, concatMap, of, reduce, defer, concatAll, mergeMap } from 'rxjs';
21
- import 'core-js/modules/es.symbol.description.js';
22
-
23
- /******************************************************************************
24
- Copyright (c) Microsoft Corporation.
25
-
26
- Permission to use, copy, modify, and/or distribute this software for any
27
- purpose with or without fee is hereby granted.
28
-
29
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
30
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
31
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
32
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
33
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
34
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
35
- PERFORMANCE OF THIS SOFTWARE.
36
- ***************************************************************************** */
37
-
38
- function __awaiter(thisArg, _arguments, P, generator) {
39
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
40
- return new (P || (P = Promise))(function (resolve, reject) {
41
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
42
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
43
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
44
- step((generator = generator.apply(thisArg, _arguments || [])).next());
45
- });
46
- }
47
-
48
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
49
- var e = new Error(message);
50
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
51
- };
52
43
 
53
44
  var EngineModule;
54
45
  (function (EngineModule) {
@@ -67,8 +58,8 @@ var EAuthMeEngineReturnCode;
67
58
  })(EAuthMeEngineReturnCode || (EAuthMeEngineReturnCode = {}));
68
59
 
69
60
  var authEnumModule = /*#__PURE__*/Object.freeze({
70
- __proto__: null,
71
- get EAuthMeEngineReturnCode () { return EAuthMeEngineReturnCode; }
61
+ __proto__: null,
62
+ get EAuthMeEngineReturnCode () { return EAuthMeEngineReturnCode; }
72
63
  });
73
64
 
74
65
  var EAuthMeCardClass;
@@ -76,7 +67,7 @@ var EAuthMeCardClass;
76
67
  EAuthMeCardClass["Invalid"] = "EAuthMeCardClass_Invalid";
77
68
  EAuthMeCardClass["Unknown"] = "EAuthMeCardClass_UnknownCard";
78
69
  EAuthMeCardClass["Passport"] = "EAuthMeCardClass_Passport";
79
- EAuthMeCardClass["ALL_PASSPORT_CONTENT"] = "EAuthMeCardClass_Passport";
70
+ EAuthMeCardClass["ALL_PASSPORT_CONTENT"] = "EAuthMeCardClass_ALL_PASSPORT_CONTENT";
80
71
  EAuthMeCardClass["TWN_IDCard_Front"] = "EAuthMeCardClass_TWN_IDCard_Front";
81
72
  EAuthMeCardClass["TWN_IDCard_Back"] = "EAuthMeCardClass_TWN_IDCard_Back";
82
73
  EAuthMeCardClass["TWN_DriverLicense_Front"] = "EAuthMeCardClass_TWN_DriverLicense_Front";
@@ -166,15 +157,15 @@ var EAuthMeIDCardAntiFraudStage;
166
157
  })(EAuthMeIDCardAntiFraudStage || (EAuthMeIDCardAntiFraudStage = {}));
167
158
 
168
159
  var idRecognitionEnumModule = /*#__PURE__*/Object.freeze({
169
- __proto__: null,
170
- get EAuthMeCardClass () { return EAuthMeCardClass; },
171
- get EAuthMeIDCardMetalTagStatus () { return EAuthMeIDCardMetalTagStatus; },
172
- get EAuthMeCardMatchStatus () { return EAuthMeCardMatchStatus; },
173
- get EAuthMeCardOCRStatus () { return EAuthMeCardOCRStatus; },
174
- get EAuthMeIDCardAntiFraudStatus () { return EAuthMeIDCardAntiFraudStatus; },
175
- get EAuthMeMRZRecogStatus () { return EAuthMeMRZRecogStatus; },
176
- get EAuthMeMRZServiceStatus () { return EAuthMeMRZServiceStatus; },
177
- get EAuthMeIDCardAntiFraudStage () { return EAuthMeIDCardAntiFraudStage; }
160
+ __proto__: null,
161
+ get EAuthMeCardClass () { return EAuthMeCardClass; },
162
+ get EAuthMeCardMatchStatus () { return EAuthMeCardMatchStatus; },
163
+ get EAuthMeCardOCRStatus () { return EAuthMeCardOCRStatus; },
164
+ get EAuthMeIDCardAntiFraudStage () { return EAuthMeIDCardAntiFraudStage; },
165
+ get EAuthMeIDCardAntiFraudStatus () { return EAuthMeIDCardAntiFraudStatus; },
166
+ get EAuthMeIDCardMetalTagStatus () { return EAuthMeIDCardMetalTagStatus; },
167
+ get EAuthMeMRZRecogStatus () { return EAuthMeMRZRecogStatus; },
168
+ get EAuthMeMRZServiceStatus () { return EAuthMeMRZServiceStatus; }
178
169
  });
179
170
 
180
171
  var EAuthMeFASServiceStatus;
@@ -234,13 +225,13 @@ var EAuthMeFaceAntiSpoofingStatus;
234
225
  })(EAuthMeFaceAntiSpoofingStatus || (EAuthMeFaceAntiSpoofingStatus = {}));
235
226
 
236
227
  var fasRecognitionEnumModule = /*#__PURE__*/Object.freeze({
237
- __proto__: null,
238
- get EAuthMeFASServiceStatus () { return EAuthMeFASServiceStatus; },
239
- get EAuthMeFASServiceStage () { return EAuthMeFASServiceStage; },
240
- get EAuthMeEyeStatus () { return EAuthMeEyeStatus; },
241
- get EAuthMeMouthStatus () { return EAuthMeMouthStatus; },
242
- get EAuthMeFacePose () { return EAuthMeFacePose; },
243
- get EAuthMeFaceAntiSpoofingStatus () { return EAuthMeFaceAntiSpoofingStatus; }
228
+ __proto__: null,
229
+ get EAuthMeEyeStatus () { return EAuthMeEyeStatus; },
230
+ get EAuthMeFASServiceStage () { return EAuthMeFASServiceStage; },
231
+ get EAuthMeFASServiceStatus () { return EAuthMeFASServiceStatus; },
232
+ get EAuthMeFaceAntiSpoofingStatus () { return EAuthMeFaceAntiSpoofingStatus; },
233
+ get EAuthMeFacePose () { return EAuthMeFacePose; },
234
+ get EAuthMeMouthStatus () { return EAuthMeMouthStatus; }
244
235
  });
245
236
 
246
237
  const defaultMlEngineConfig = {
@@ -253,18 +244,14 @@ const defaultMlEngineConfig = {
253
244
  };
254
245
 
255
246
  var name = "authme/sdk";
256
- var version$1 = "2.8.42";
257
- var date = "2026-02-03T09:36:05+0000";
247
+ var version$1 = "2.8.44";
258
248
  var sdkInfo = {
259
249
  name: name,
260
- version: version$1,
261
- date: date
262
- };
250
+ version: version$1};
263
251
 
264
- var _a;
265
- var _b, _c;
252
+ var _window, _Symbol$for, _window$_Symbol$for;
266
253
  const version = sdkInfo.version;
267
- (_a = (_b = window)[_c = Symbol.for('authme-sdk')]) !== null && _a !== void 0 ? _a : _b[_c] = {};
254
+ (_window$_Symbol$for = (_window = window)[_Symbol$for = Symbol.for('authme-sdk')]) != null ? _window$_Symbol$for : _window[_Symbol$for] = {};
268
255
  window[Symbol.for('authme-sdk')][sdkInfo.name] = version;
269
256
 
270
257
  function logCollect(message, stackTrace) {
@@ -281,17 +268,36 @@ function logCollect(message, stackTrace) {
281
268
  });
282
269
  }
283
270
 
271
+ var _MlEngine, _AuthmeEngineModuleBase;
284
272
  const getDownloadOrder = function () {
285
273
  // model 越大,在後續 worker service 載入與解密的時間越長,
286
274
  // 所以盡可能讓越大的檔案排在越前面下載,以便讓耗費時間長的任務先排在背景執行。
287
275
  //
288
276
  // 但由於 api server 目前沒有提供檔案大小的相關資訊,
289
277
  // 所以將順序相關的資訊寫死在 sdk 裡。
290
- const DOWNLOAD_ORDER = Object.fromEntries(['FACE_03', 'FACE_00', 'IDCardAntiFraud_00', 'FACE_01', 'OCR_00', 'FACE_02', 'OCR_02', 'MRZ_00', 'OCR_01', 'MRZ_01' // 375k
278
+ const DOWNLOAD_ORDER = Object.fromEntries(['FACE_03',
279
+ // 3.7m
280
+ 'FACE_00',
281
+ // 1.6m
282
+ 'IDCardAntiFraud_00',
283
+ //1.5m
284
+ 'FACE_01',
285
+ // 1.4m
286
+ 'OCR_00',
287
+ // 1.4m
288
+ 'FACE_02',
289
+ // 1.3m
290
+ 'OCR_02',
291
+ // 548k
292
+ 'MRZ_00',
293
+ // 548k
294
+ 'OCR_01',
295
+ // 375k
296
+ 'MRZ_01' // 375k
291
297
  ].map((key, index) => [key, index]));
292
298
  return function getDownloadOrder(key) {
293
- var _a;
294
- return (_a = DOWNLOAD_ORDER[key]) !== null && _a !== void 0 ? _a : Number.MAX_VALUE;
299
+ var _DOWNLOAD_ORDER$key;
300
+ return (_DOWNLOAD_ORDER$key = DOWNLOAD_ORDER[key]) != null ? _DOWNLOAD_ORDER$key : Number.MAX_VALUE;
295
301
  };
296
302
  }();
297
303
  function isSimdSupported() {
@@ -323,54 +329,46 @@ function getJsContentAsync(url) {
323
329
  sdkInfo: null
324
330
  });
325
331
  }
326
- function createWorkerWithObjectUrlAsync(url) {
327
- return __awaiter(this, void 0, void 0, function* () {
328
- const scriptContent = yield getJsContentAsync(url);
329
- const objectUrl = URL.createObjectURL(new Blob([scriptContent], {
330
- type: 'text/javascript'
331
- }));
332
- const worker = new Worker(objectUrl);
333
- URL.revokeObjectURL(objectUrl);
334
- return worker;
335
- });
332
+ async function createWorkerWithObjectUrlAsync(url) {
333
+ const scriptContent = await getJsContentAsync(url);
334
+ const objectUrl = URL.createObjectURL(new Blob([scriptContent], {
335
+ type: 'text/javascript'
336
+ }));
337
+ const worker = new Worker(objectUrl);
338
+ URL.revokeObjectURL(objectUrl);
339
+ return worker;
336
340
  }
337
341
  function convertToModelQueryString(modelVersion) {
338
342
  return `models=${modelVersion.name}[${modelVersion.version}]`;
339
343
  }
340
- function fetchModelCodesAsync(modelVersions) {
341
- return __awaiter(this, void 0, void 0, function* () {
342
- const queryString = modelVersions.map(convertToModelQueryString).join('&');
343
- const response = yield sendRequest('/api/model-management/v1/model?' + queryString);
344
- return response.models;
345
- });
344
+ async function fetchModelCodesAsync(modelVersions) {
345
+ const queryString = modelVersions.map(convertToModelQueryString).join('&');
346
+ const response = await sendRequest('/api/model-management/v1/model?' + queryString);
347
+ return response.models;
346
348
  }
347
349
  function base64ToBufferAsync(base64) {
348
350
  const dataUrl = 'data:application/octet-binary;base64,' + base64;
349
351
  return fetch(dataUrl).then(res => res.arrayBuffer());
350
352
  }
351
- function fetchModelContentAsync(code, dataTransferMethod) {
352
- return __awaiter(this, void 0, void 0, function* () {
353
- const payload = yield sendRequest(`/api/model-management/v1/model/${code}${dataTransferMethod === 'binary' ? '/file' : ''}`);
354
- if (dataTransferMethod === 'binary') {
355
- return payload;
356
- } else {
357
- return yield base64ToBufferAsync(payload.data);
358
- }
359
- });
353
+ async function fetchModelContentAsync(code, dataTransferMethod) {
354
+ const payload = await sendRequest(`/api/model-management/v1/model/${code}${dataTransferMethod === 'binary' ? '/file' : ''}`);
355
+ if (dataTransferMethod === 'binary') {
356
+ return payload;
357
+ } else {
358
+ return await base64ToBufferAsync(payload.data);
359
+ }
360
360
  }
361
361
  function fetchModelContents(modelVersions, dataTransferMethod) {
362
362
  return of(modelVersions).pipe(concatMap(modelVersions => defer(() => fetchModelCodesAsync(modelVersions))), concatAll(), mergeMap(({
363
363
  name,
364
364
  version,
365
365
  code
366
- }) => defer(() => __awaiter(this, void 0, void 0, function* () {
367
- return {
368
- modelVersion: {
369
- name,
370
- version: `${parseInt(version)}`
371
- },
372
- modelArrayBuffer: yield fetchModelContentAsync(code, dataTransferMethod)
373
- };
366
+ }) => defer(async () => ({
367
+ modelVersion: {
368
+ name,
369
+ version: `${parseInt(version)}`
370
+ },
371
+ modelArrayBuffer: await fetchModelContentAsync(code, dataTransferMethod)
374
372
  })), 1
375
373
  // 下載 model 過程會分為 wait time & download time,
376
374
  // concurrent 設定越高,只能起到降低 wait time 的作用,但會拉長單一檔案完成下載的時間,
@@ -379,16 +377,13 @@ function fetchModelContents(modelVersions, dataTransferMethod) {
379
377
  // 所以 concurrent 建議設定為 1 或 2,盡量讓已下載好的 model 儘早進行載入與解密。
380
378
  ));
381
379
  }
382
-
383
380
  class AuthmeFunctionModule {
384
- init(config) {
385
- return __awaiter(this, void 0, void 0, function* () {
386
- for (const key in config) {
387
- if (Object.prototype.hasOwnProperty.call(config, key)) {
388
- Storage.setItem(key, config[key]);
389
- }
381
+ async init(config) {
382
+ for (const key in config) {
383
+ if (Object.prototype.hasOwnProperty.call(config, key)) {
384
+ Storage.setItem(key, config[key]);
390
385
  }
391
- });
386
+ }
392
387
  }
393
388
  static getVersion() {
394
389
  return version;
@@ -399,7 +394,7 @@ class MlEngine {
399
394
  this.workerAndStreamPromise = undefined;
400
395
  this.preloadPromise = undefined;
401
396
  this.debugTools = debugTools();
402
- this.config = Object.assign(Object.assign(Object.assign({}, defaultMlEngineConfig), config), {
397
+ this.config = Object.assign({}, defaultMlEngineConfig, config, {
403
398
  isMobile: isMobile()
404
399
  });
405
400
  }
@@ -416,102 +411,88 @@ class MlEngine {
416
411
  durationTimeWorker.end();
417
412
  })));
418
413
  }
419
- _makeWorkerAndStreamAsync() {
420
- var _a;
421
- return __awaiter(this, void 0, void 0, function* () {
422
- // use blobUrl to fix cross-domain problem on worker creating.
423
- // ref:
424
- // * https://stackoverflow.com/questions/25458104/can-should-html5-web-workers-use-cors-for-cross-origin
425
- // * https://web.dev/workers-basics/
426
- const worker = yield createWorkerWithObjectUrlAsync(`${(_a = this.config.scriptPath) !== null && _a !== void 0 ? _a : ''}engine-worker.js?t=${Date.now()}`);
427
- const workerMessage$ = fromEvent(worker, 'message').pipe(map(x => {
428
- var _a, _b, _c, _d;
429
- if ((_b = (_a = x.data) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.error) {
430
- logCollect('workerMessage error', JSON.stringify((_d = (_c = x.data) === null || _c === void 0 ? void 0 : _c.value) === null || _d === void 0 ? void 0 : _d.error));
431
- throw new AuthmeError(ErrorCode.SDK_INTERNAL_ERROR, 'unexpected worker error');
432
- }
433
- return x.data;
434
- }), shareReplay(1));
435
- yield this._run(worker, workerMessage$, EngineModule.Core, 'setConfig', this.config);
436
- return [worker, workerMessage$];
437
- });
438
- }
439
- _backgroundPreloadAsync() {
440
- var _a;
441
- return __awaiter(this, void 0, void 0, function* () {
442
- const [worker, workerMessage$] = yield (_a = this.workerAndStreamPromise) !== null && _a !== void 0 ? _a : this.workerAndStreamPromise = this._makeWorkerAndStreamAsync();
443
- yield this._loadEngineAsync(worker, workerMessage$);
444
- yield this._checkEnumConsistencyAsync(worker, workerMessage$);
445
- return [worker, workerMessage$];
446
- });
447
- }
448
- terminateWorkerAsync() {
449
- return __awaiter(this, void 0, void 0, function* () {
450
- if (this.workerAndStreamPromise || this.preloadPromise) {
451
- const [worker, _] = yield this._backgroundPreloadAsync();
452
- this.workerAndStreamPromise = undefined;
453
- this.preloadPromise = undefined;
454
- worker.terminate();
414
+ async _makeWorkerAndStreamAsync() {
415
+ var _this$config$scriptPa;
416
+ // use blobUrl to fix cross-domain problem on worker creating.
417
+ // ref:
418
+ // * https://stackoverflow.com/questions/25458104/can-should-html5-web-workers-use-cors-for-cross-origin
419
+ // * https://web.dev/workers-basics/
420
+ const worker = await createWorkerWithObjectUrlAsync(`${(_this$config$scriptPa = this.config.scriptPath) != null ? _this$config$scriptPa : ''}engine-worker.js?t=${Date.now()}`);
421
+ const workerMessage$ = fromEvent(worker, 'message').pipe(map(x => {
422
+ var _x$data;
423
+ if ((_x$data = x.data) != null && (_x$data = _x$data.value) != null && _x$data.error) {
424
+ var _x$data2;
425
+ logCollect('workerMessage error', JSON.stringify((_x$data2 = x.data) == null || (_x$data2 = _x$data2.value) == null ? void 0 : _x$data2.error));
426
+ throw new AuthmeError(ErrorCode.SDK_INTERNAL_ERROR, 'unexpected worker error');
455
427
  }
456
- });
428
+ return x.data;
429
+ }), shareReplay(1));
430
+ await this._run(worker, workerMessage$, EngineModule.Core, 'setConfig', this.config);
431
+ return [worker, workerMessage$];
432
+ }
433
+ async _backgroundPreloadAsync() {
434
+ var _this$workerAndStream;
435
+ const [worker, workerMessage$] = await ((_this$workerAndStream = this.workerAndStreamPromise) != null ? _this$workerAndStream : this.workerAndStreamPromise = this._makeWorkerAndStreamAsync());
436
+ await this._loadEngineAsync(worker, workerMessage$);
437
+ await this._checkEnumConsistencyAsync(worker, workerMessage$);
438
+ return [worker, workerMessage$];
439
+ }
440
+ async terminateWorkerAsync() {
441
+ if (this.workerAndStreamPromise || this.preloadPromise) {
442
+ const [worker, _] = await this._backgroundPreloadAsync();
443
+ this.workerAndStreamPromise = undefined;
444
+ this.preloadPromise = undefined;
445
+ worker.terminate();
446
+ }
457
447
  }
458
448
  _preloadAndWaitReadyAsync() {
459
- var _a;
460
- return (_a = this.preloadPromise) !== null && _a !== void 0 ? _a : this.preloadPromise = this._backgroundPreloadAsync();
461
- }
462
- _checkEnumConsistencyAsync(worker, workerMessage$) {
463
- return __awaiter(this, void 0, void 0, function* () {
464
- const problem = yield this._run(worker, workerMessage$, 'Core', 'checkEnumConsistency', Object.assign(Object.assign(Object.assign({}, authEnumModule), idRecognitionEnumModule), fasRecognitionEnumModule));
465
- if (problem.length > 0) {
466
- logCollect('enum consistency problem', JSON.stringify(problem));
467
- throw new AuthmeError(ErrorCode.SDK_INTERNAL_ERROR, {
468
- problem
469
- });
470
- }
471
- });
449
+ var _this$preloadPromise;
450
+ return (_this$preloadPromise = this.preloadPromise) != null ? _this$preloadPromise : this.preloadPromise = this._backgroundPreloadAsync();
451
+ }
452
+ async _checkEnumConsistencyAsync(worker, workerMessage$) {
453
+ const problem = await this._run(worker, workerMessage$, 'Core', 'checkEnumConsistency', Object.assign({}, authEnumModule, idRecognitionEnumModule, fasRecognitionEnumModule));
454
+ if (problem.length > 0) {
455
+ logCollect('enum consistency problem', JSON.stringify(problem));
456
+ throw new AuthmeError(ErrorCode.SDK_INTERNAL_ERROR, {
457
+ problem
458
+ });
459
+ }
472
460
  }
473
- run(module, command, value = {}) {
474
- return __awaiter(this, void 0, void 0, function* () {
475
- const [worker, workerMessage$] = yield this._preloadAndWaitReadyAsync();
476
- return yield this._run(worker, workerMessage$, module, command, value);
477
- });
461
+ async run(module, command, value = {}) {
462
+ const [worker, workerMessage$] = await this._preloadAndWaitReadyAsync();
463
+ return await this._run(worker, workerMessage$, module, command, value);
478
464
  }
479
465
  getConfig() {
480
466
  return this.config;
481
467
  }
482
- setConfig(config) {
483
- return __awaiter(this, void 0, void 0, function* () {
484
- this.config = Object.assign(Object.assign({}, this.config), config);
485
- if (this.workerAndStreamPromise) {
486
- const [worker, workerMessage$] = yield this._preloadAndWaitReadyAsync();
487
- yield this._run(worker, workerMessage$, EngineModule.Core, 'setConfig', this.config);
488
- }
489
- });
490
- }
491
- setPublicKeyForJson(pubKey) {
492
- return __awaiter(this, void 0, void 0, function* () {
493
- const [worker, workerMessage$] = yield this._preloadAndWaitReadyAsync();
494
- yield this._run(worker, workerMessage$, EngineModule.Fas, 'setPublicKeyForJson', pubKey);
495
- });
468
+ async setConfig(config) {
469
+ this.config = Object.assign({}, this.config, config);
470
+ if (this.workerAndStreamPromise) {
471
+ const [worker, workerMessage$] = await this._preloadAndWaitReadyAsync();
472
+ await this._run(worker, workerMessage$, EngineModule.Core, 'setConfig', this.config);
473
+ }
496
474
  }
497
- _loadEngineAsync(worker, workerMessage$) {
498
- var _a, _b, _c, _d, _e;
499
- return __awaiter(this, void 0, void 0, function* () {
500
- // load js/wasm outside the worker.
501
- const simdSupported = isSimdSupported();
502
- const jsUrl = simdSupported ? `${(_a = this.config.scriptPath) !== null && _a !== void 0 ? _a : ''}ml_engine_web.simd.js` : `${(_b = this.config.scriptPath) !== null && _b !== void 0 ? _b : ''}ml_engine_web.js`;
503
- const wasmUrl = simdSupported ? `${(_c = this.config.scriptPath) !== null && _c !== void 0 ? _c : ''}ml_engine_web.simd.wasm` : `${(_d = this.config.scriptPath) !== null && _d !== void 0 ? _d : ''}ml_engine_web.wasm`;
504
- const durationTimeNetworkEngine = this.debugTools.setTimeDuration('loadEngine_network');
505
- const [engineJsContent, engineWasmContent] = yield (_e = MlEngine._ENGINE_CACHE) !== null && _e !== void 0 ? _e : MlEngine._ENGINE_CACHE = Promise.all([getJsContentAsync(`${jsUrl}?t=${Date.now()}`), getWasmContentAsync(`${wasmUrl}?t=${Date.now()}`)]);
506
- durationTimeNetworkEngine.end();
507
- return yield this._run(worker, workerMessage$, EngineModule.Core, 'loadEngine', {
508
- engineJsContent,
509
- engineWasmContent
510
- });
475
+ async setPublicKeyForJson(pubKey) {
476
+ const [worker, workerMessage$] = await this._preloadAndWaitReadyAsync();
477
+ await this._run(worker, workerMessage$, EngineModule.Fas, 'setPublicKeyForJson', pubKey);
478
+ }
479
+ async _loadEngineAsync(worker, workerMessage$) {
480
+ var _this$config$scriptPa2, _this$config$scriptPa3, _this$config$scriptPa4, _this$config$scriptPa5, _MlEngine$_ENGINE_CAC;
481
+ // load js/wasm outside the worker.
482
+ const simdSupported = isSimdSupported();
483
+ const jsUrl = simdSupported ? `${(_this$config$scriptPa2 = this.config.scriptPath) != null ? _this$config$scriptPa2 : ''}ml_engine_web.simd.js` : `${(_this$config$scriptPa3 = this.config.scriptPath) != null ? _this$config$scriptPa3 : ''}ml_engine_web.js`;
484
+ const wasmUrl = simdSupported ? `${(_this$config$scriptPa4 = this.config.scriptPath) != null ? _this$config$scriptPa4 : ''}ml_engine_web.simd.wasm` : `${(_this$config$scriptPa5 = this.config.scriptPath) != null ? _this$config$scriptPa5 : ''}ml_engine_web.wasm`;
485
+ const durationTimeNetworkEngine = this.debugTools.setTimeDuration('loadEngine_network');
486
+ const [engineJsContent, engineWasmContent] = await ((_MlEngine$_ENGINE_CAC = MlEngine._ENGINE_CACHE) != null ? _MlEngine$_ENGINE_CAC : MlEngine._ENGINE_CACHE = Promise.all([getJsContentAsync(`${jsUrl}?t=${Date.now()}`), getWasmContentAsync(`${wasmUrl}?t=${Date.now()}`)]));
487
+ durationTimeNetworkEngine.end();
488
+ return await this._run(worker, workerMessage$, EngineModule.Core, 'loadEngine', {
489
+ engineJsContent,
490
+ engineWasmContent
511
491
  });
512
492
  }
513
493
  }
514
- MlEngine._ENGINE_CACHE = undefined;
494
+ _MlEngine = MlEngine;
495
+ _MlEngine._ENGINE_CACHE = undefined;
515
496
  class AuthmeEngineModuleBase {
516
497
  constructor(engine) {
517
498
  this._initPromise = undefined;
@@ -524,59 +505,57 @@ class AuthmeEngineModuleBase {
524
505
  _engineRunAsync(command, value) {
525
506
  return this.engine.run(this.moduleName, command, value);
526
507
  }
527
- _init() {
528
- var _a;
529
- return __awaiter(this, void 0, void 0, function* () {
530
- if (this.initialized) {
531
- return true;
532
- }
533
- if (this.initializing) {
534
- throw new AuthmeError(ErrorCode.ENGINE_MODULE_IS_INITIALIZING);
535
- }
536
- this.initializing = true;
537
- try {
538
- const noLoadedModelVersions = yield this._engineRunAsync('getNoLoadedModelVersions');
539
- const noCachedModelVersions = noLoadedModelVersions.filter(({
540
- name,
541
- version
542
- }) => !AuthmeEngineModuleBase._MODEL_CACHE[`${name}-${version}`]);
543
- const newCachedValues = fetchModelContents(noCachedModelVersions.sort((a, b) => getDownloadOrder(a.name) - getDownloadOrder(b.name)), (_a = this.engine.getConfig().dataTransferMethod) !== null && _a !== void 0 ? _a : 'binary').pipe(shareReplay());
544
- for (const {
545
- name,
546
- version
547
- } of noCachedModelVersions) {
548
- AuthmeEngineModuleBase._MODEL_CACHE[`${name}-${version}`] = newCachedValues.pipe(filter(({
549
- modelVersion
550
- }) => modelVersion.name === name && modelVersion.version === version));
551
- }
552
- const loadSessions$ = from(noLoadedModelVersions).pipe(map(({
553
- name,
554
- version
555
- }) => AuthmeEngineModuleBase._MODEL_CACHE[`${name}-${version}`]), mergeAll(), concatMap(({
556
- modelVersion,
557
- modelArrayBuffer
558
- }) => of(this._engineRunAsync('loadSession', {
559
- modelVersion,
560
- modelArrayBuffer
561
- }))), reduce((promises, item) => {
562
- promises.push(item);
563
- return promises;
564
- }, []), concatMap(promises => defer(() => Promise.all(promises))));
565
- yield firstValueFrom(loadSessions$);
566
- const result = yield this._engineRunAsync('init');
567
- this.initialized = true;
568
- return result;
569
- } catch (error) {
570
- logCollect('engine init error', JSON.stringify(error));
571
- throw new AuthmeError(ErrorCode.ENGINE_MODULE_INIT_ERROR, error);
572
- } finally {
573
- this.initializing = false;
508
+ async _init() {
509
+ if (this.initialized) {
510
+ return true;
511
+ }
512
+ if (this.initializing) {
513
+ throw new AuthmeError(ErrorCode.ENGINE_MODULE_IS_INITIALIZING);
514
+ }
515
+ this.initializing = true;
516
+ try {
517
+ var _this$engine$getConfi;
518
+ const noLoadedModelVersions = await this._engineRunAsync('getNoLoadedModelVersions');
519
+ const noCachedModelVersions = noLoadedModelVersions.filter(({
520
+ name,
521
+ version
522
+ }) => !AuthmeEngineModuleBase._MODEL_CACHE[`${name}-${version}`]);
523
+ const newCachedValues = fetchModelContents(noCachedModelVersions.sort((a, b) => getDownloadOrder(a.name) - getDownloadOrder(b.name)), (_this$engine$getConfi = this.engine.getConfig().dataTransferMethod) != null ? _this$engine$getConfi : 'binary').pipe(shareReplay());
524
+ for (const {
525
+ name,
526
+ version
527
+ } of noCachedModelVersions) {
528
+ AuthmeEngineModuleBase._MODEL_CACHE[`${name}-${version}`] = newCachedValues.pipe(filter(({
529
+ modelVersion
530
+ }) => modelVersion.name === name && modelVersion.version === version));
574
531
  }
575
- });
532
+ const loadSessions$ = from(noLoadedModelVersions).pipe(map(({
533
+ name,
534
+ version
535
+ }) => AuthmeEngineModuleBase._MODEL_CACHE[`${name}-${version}`]), mergeAll(), concatMap(({
536
+ modelVersion,
537
+ modelArrayBuffer
538
+ }) => of(this._engineRunAsync('loadSession', {
539
+ modelVersion,
540
+ modelArrayBuffer
541
+ }))), reduce((promises, item) => {
542
+ promises.push(item);
543
+ return promises;
544
+ }, []), concatMap(promises => defer(() => Promise.all(promises))));
545
+ await firstValueFrom(loadSessions$);
546
+ const result = await this._engineRunAsync('init');
547
+ this.initialized = true;
548
+ return result;
549
+ } catch (error) {
550
+ logCollect('engine init error', JSON.stringify(error));
551
+ throw new AuthmeError(ErrorCode.ENGINE_MODULE_INIT_ERROR, error);
552
+ } finally {
553
+ this.initializing = false;
554
+ }
576
555
  }
577
556
  init() {
578
- var _a;
579
- return (_a = this._initPromise) !== null && _a !== void 0 ? _a : this._initPromise = this._init();
557
+ var _this$_initPromise;
558
+ return (_this$_initPromise = this._initPromise) != null ? _this$_initPromise : this._initPromise = this._init();
580
559
  }
581
560
  preloadAsync() {
582
561
  return this.init();
@@ -594,66 +573,60 @@ class AuthmeEngineModuleBase {
594
573
  setOption(params) {
595
574
  return this._engineRunAsync('setOption', params);
596
575
  }
597
- recognition(data) {
598
- return __awaiter(this, void 0, void 0, function* () {
599
- // status control
600
- if (!this.received || !this.initialized || !this.setSized) {
601
- logCollect('recognition not available', JSON.stringify(ErrorCode.RECOGNITION_NOT_AVAILABLE));
602
- throw new AuthmeError(ErrorCode.RECOGNITION_NOT_AVAILABLE);
603
- }
604
- try {
605
- this.received = false;
606
- const start = performance.now();
607
- const return$ = yield this._engineRunAsync('recognition', {
608
- data
609
- });
610
- this.received = true;
611
- return Object.assign(Object.assign({}, return$), {
612
- debugInfo: {
613
- inferenceTime: performance.now() - start
614
- }
615
- });
616
- } catch (error) {
617
- this.received = true;
618
- logCollect('recognition error', JSON.stringify(error));
619
- throw new AuthmeError(ErrorCode.RECOGNITION_ERROR, error);
620
- }
621
- });
622
- }
623
- getDebugImageData(data) {
624
- return __awaiter(this, void 0, void 0, function* () {
625
- // status control
626
- if (!this.received || !this.initialized || !this.setSized) {
627
- logCollect('getDebugImageData recognition not available', JSON.stringify(ErrorCode.RECOGNITION_NOT_AVAILABLE));
628
- throw new AuthmeError(ErrorCode.RECOGNITION_NOT_AVAILABLE);
629
- }
630
- try {
631
- this.received = false;
632
- const start = performance.now();
633
- const return$ = yield this._engineRunAsync('getDebugImage', {
634
- data
635
- });
636
- this.received = true;
637
- return$.debugInfo = {
576
+ async recognition(data) {
577
+ // status control
578
+ if (!this.received || !this.initialized || !this.setSized) {
579
+ logCollect('recognition not available', JSON.stringify(ErrorCode.RECOGNITION_NOT_AVAILABLE));
580
+ throw new AuthmeError(ErrorCode.RECOGNITION_NOT_AVAILABLE);
581
+ }
582
+ try {
583
+ this.received = false;
584
+ const start = performance.now();
585
+ const return$ = await this._engineRunAsync('recognition', {
586
+ data
587
+ });
588
+ this.received = true;
589
+ return Object.assign({}, return$, {
590
+ debugInfo: {
638
591
  inferenceTime: performance.now() - start
639
- };
640
- return return$;
641
- } catch (error) {
642
- this.received = true;
643
- logCollect('getDebugImageData recognition error', JSON.stringify(error));
644
- throw new AuthmeError(ErrorCode.RECOGNITION_ERROR, error);
645
- }
646
- });
592
+ }
593
+ });
594
+ } catch (error) {
595
+ this.received = true;
596
+ logCollect('recognition error', JSON.stringify(error));
597
+ throw new AuthmeError(ErrorCode.RECOGNITION_ERROR, error);
598
+ }
647
599
  }
648
- setFrameSize(width, height) {
649
- return __awaiter(this, void 0, void 0, function* () {
650
- const result = yield this._engineRunAsync('setFrameSize', {
651
- width,
652
- height
600
+ async getDebugImageData(data) {
601
+ // status control
602
+ if (!this.received || !this.initialized || !this.setSized) {
603
+ logCollect('getDebugImageData recognition not available', JSON.stringify(ErrorCode.RECOGNITION_NOT_AVAILABLE));
604
+ throw new AuthmeError(ErrorCode.RECOGNITION_NOT_AVAILABLE);
605
+ }
606
+ try {
607
+ this.received = false;
608
+ const start = performance.now();
609
+ const return$ = await this._engineRunAsync('getDebugImage', {
610
+ data
653
611
  });
654
- this.setSized = true;
655
- return result;
612
+ this.received = true;
613
+ return$.debugInfo = {
614
+ inferenceTime: performance.now() - start
615
+ };
616
+ return return$;
617
+ } catch (error) {
618
+ this.received = true;
619
+ logCollect('getDebugImageData recognition error', JSON.stringify(error));
620
+ throw new AuthmeError(ErrorCode.RECOGNITION_ERROR, error);
621
+ }
622
+ }
623
+ async setFrameSize(width, height) {
624
+ const result = await this._engineRunAsync('setFrameSize', {
625
+ width,
626
+ height
656
627
  });
628
+ this.setSized = true;
629
+ return result;
657
630
  }
658
631
  getParams() {
659
632
  return this._engineRunAsync('getParams');
@@ -668,38 +641,30 @@ class AuthmeEngineModuleBase {
668
641
  positions
669
642
  });
670
643
  }
671
- encryptString(str, key) {
672
- return __awaiter(this, void 0, void 0, function* () {
673
- return yield this._engineRunAsync('encryptString', {
674
- string: str,
675
- key
676
- });
644
+ async encryptString(str, key) {
645
+ return await this._engineRunAsync('encryptString', {
646
+ string: str,
647
+ key
677
648
  });
678
649
  }
679
- encryptBlob(uint8Array, key) {
680
- return __awaiter(this, void 0, void 0, function* () {
681
- return yield this._engineRunAsync('encryptBlob', {
682
- uint8Array: uint8Array,
683
- key
684
- });
650
+ async encryptBlob(uint8Array, key) {
651
+ return await this._engineRunAsync('encryptBlob', {
652
+ uint8Array: uint8Array,
653
+ key
685
654
  });
686
655
  }
687
656
  // 測試圖片上傳加密用,未來實作後請刪除。
688
- _decryptString(str, key) {
689
- return __awaiter(this, void 0, void 0, function* () {
690
- return yield this._engineRunAsync('_decryptString', {
691
- string: str,
692
- key
693
- });
657
+ async _decryptString(str, key) {
658
+ return await this._engineRunAsync('_decryptString', {
659
+ string: str,
660
+ key
694
661
  });
695
662
  }
696
- destroy() {
697
- return __awaiter(this, void 0, void 0, function* () {
698
- yield this._engineRunAsync('destroy');
699
- this.initialized = false;
700
- this._initPromise = undefined;
701
- return true;
702
- });
663
+ async destroy() {
664
+ await this._engineRunAsync('destroy');
665
+ this.initialized = false;
666
+ this._initPromise = undefined;
667
+ return true;
703
668
  }
704
669
  getUIParams() {
705
670
  return this.engine.run(this.moduleName, 'getUIParams');
@@ -711,6 +676,7 @@ class AuthmeEngineModuleBase {
711
676
  this._MODEL_CACHE = {};
712
677
  }
713
678
  }
714
- AuthmeEngineModuleBase._MODEL_CACHE = {};
679
+ _AuthmeEngineModuleBase = AuthmeEngineModuleBase;
680
+ _AuthmeEngineModuleBase._MODEL_CACHE = {};
715
681
 
716
682
  export { AuthmeEngineModuleBase, AuthmeFunctionModule, EAuthMeCardClass, EAuthMeCardMatchStatus, EAuthMeCardOCRStatus, EAuthMeEngineReturnCode, EAuthMeEyeStatus, EAuthMeFASServiceStage, EAuthMeFASServiceStatus, EAuthMeFaceAntiSpoofingStatus, EAuthMeFacePose, EAuthMeIDCardAntiFraudStage, EAuthMeIDCardAntiFraudStatus, EAuthMeIDCardMetalTagStatus, EAuthMeMRZRecogStatus, EAuthMeMRZServiceStatus, EAuthMeMouthStatus, EngineModule, MlEngine, defaultMlEngineConfig, version };