@authme/engine 2.8.41 → 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";
@@ -105,10 +96,11 @@ var EAuthMeCardOCRStatus;
105
96
  EAuthMeCardOCRStatus["WrongCardType"] = "EAuthMeCardOCRStatus_WrongCardType";
106
97
  EAuthMeCardOCRStatus["PositionNotMatch"] = "EAuthMeCardOCRStatus_PositionNotMatch";
107
98
  EAuthMeCardOCRStatus["Reflective"] = "EAuthMeCardOCRStatus_Reflective";
99
+ EAuthMeCardOCRStatus["Gray"] = "EAuthMeCardOCRStatus_Gray";
108
100
  EAuthMeCardOCRStatus["Blur"] = "EAuthMeCardOCRStatus_Blur";
109
- EAuthMeCardOCRStatus["Motion"] = "EAuthMeCardOCRStatus_Motion";
110
101
  EAuthMeCardOCRStatus["Pass"] = "EAuthMeCardOCRStatus_Pass";
111
102
  EAuthMeCardOCRStatus["Error"] = "EAuthMeCardOCRStatus_Error";
103
+ EAuthMeCardOCRStatus["Motion"] = "EAuthMeCardOCRStatus_Motion";
112
104
  })(EAuthMeCardOCRStatus || (EAuthMeCardOCRStatus = {}));
113
105
  var EAuthMeIDCardAntiFraudStatus;
114
106
  (function (EAuthMeIDCardAntiFraudStatus) {
@@ -134,6 +126,7 @@ var EAuthMeIDCardAntiFraudStatus;
134
126
  EAuthMeIDCardAntiFraudStatus["NeedHoldCard"] = "EAuthMeIDCardAntiFraudStatus_NeedHoldCard";
135
127
  EAuthMeIDCardAntiFraudStatus["StagePass"] = "EAuthMeIDCardAntiFraudStatus_StagePass";
136
128
  EAuthMeIDCardAntiFraudStatus["CardThicknessFailed"] = "EAuthMeIDCardAntiFraudStatus_CardThicknessFailed";
129
+ EAuthMeIDCardAntiFraudStatus["Undefined"] = "EAuthMeIDCardAntiFraudStatus_Undefined";
137
130
  })(EAuthMeIDCardAntiFraudStatus || (EAuthMeIDCardAntiFraudStatus = {}));
138
131
  var EAuthMeMRZRecogStatus;
139
132
  (function (EAuthMeMRZRecogStatus) {
@@ -142,13 +135,15 @@ var EAuthMeMRZRecogStatus;
142
135
  })(EAuthMeMRZRecogStatus || (EAuthMeMRZRecogStatus = {}));
143
136
  var EAuthMeMRZServiceStatus;
144
137
  (function (EAuthMeMRZServiceStatus) {
145
- EAuthMeMRZServiceStatus["Success"] = "EAuthMeMRZServiceStatus_Success";
146
138
  EAuthMeMRZServiceStatus["NotFound"] = "EAuthMeMRZServiceStatus_NotFound";
147
- EAuthMeMRZServiceStatus["RecogFailed"] = "EAuthMeMRZServiceStatus_RecogFailed";
148
- EAuthMeMRZServiceStatus["WrongCardType"] = "EAuthMeMRZServiceStatus_WrongCardType";
149
- EAuthMeMRZServiceStatus["Error"] = "EAuthMeMRZServiceStatus_Error";
150
139
  EAuthMeMRZServiceStatus["NotAligned"] = "EAuthMeMRZServiceStatus_NotAligned";
151
140
  EAuthMeMRZServiceStatus["Reflective"] = "EAuthMeMRZServiceStatus_Reflective";
141
+ EAuthMeMRZServiceStatus["Blur"] = "EAuthMeMRZServiceStatus_Blur";
142
+ EAuthMeMRZServiceStatus["WrongCardType"] = "EAuthMeMRZServiceStatus_WrongCardType";
143
+ EAuthMeMRZServiceStatus["MRZNotFound"] = "EAuthMeMRZServiceStatus_MRZNotFound";
144
+ EAuthMeMRZServiceStatus["RecogFailed"] = "EAuthMeMRZServiceStatus_RecogFailed";
145
+ EAuthMeMRZServiceStatus["Success"] = "EAuthMeMRZServiceStatus_Success";
146
+ EAuthMeMRZServiceStatus["Error"] = "EAuthMeMRZServiceStatus_Error";
152
147
  })(EAuthMeMRZServiceStatus || (EAuthMeMRZServiceStatus = {}));
153
148
  var EAuthMeIDCardAntiFraudStage;
154
149
  (function (EAuthMeIDCardAntiFraudStage) {
@@ -162,15 +157,15 @@ var EAuthMeIDCardAntiFraudStage;
162
157
  })(EAuthMeIDCardAntiFraudStage || (EAuthMeIDCardAntiFraudStage = {}));
163
158
 
164
159
  var idRecognitionEnumModule = /*#__PURE__*/Object.freeze({
165
- __proto__: null,
166
- get EAuthMeCardClass () { return EAuthMeCardClass; },
167
- get EAuthMeIDCardMetalTagStatus () { return EAuthMeIDCardMetalTagStatus; },
168
- get EAuthMeCardMatchStatus () { return EAuthMeCardMatchStatus; },
169
- get EAuthMeCardOCRStatus () { return EAuthMeCardOCRStatus; },
170
- get EAuthMeIDCardAntiFraudStatus () { return EAuthMeIDCardAntiFraudStatus; },
171
- get EAuthMeMRZRecogStatus () { return EAuthMeMRZRecogStatus; },
172
- get EAuthMeMRZServiceStatus () { return EAuthMeMRZServiceStatus; },
173
- 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; }
174
169
  });
175
170
 
176
171
  var EAuthMeFASServiceStatus;
@@ -230,13 +225,13 @@ var EAuthMeFaceAntiSpoofingStatus;
230
225
  })(EAuthMeFaceAntiSpoofingStatus || (EAuthMeFaceAntiSpoofingStatus = {}));
231
226
 
232
227
  var fasRecognitionEnumModule = /*#__PURE__*/Object.freeze({
233
- __proto__: null,
234
- get EAuthMeFASServiceStatus () { return EAuthMeFASServiceStatus; },
235
- get EAuthMeFASServiceStage () { return EAuthMeFASServiceStage; },
236
- get EAuthMeEyeStatus () { return EAuthMeEyeStatus; },
237
- get EAuthMeMouthStatus () { return EAuthMeMouthStatus; },
238
- get EAuthMeFacePose () { return EAuthMeFacePose; },
239
- 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; }
240
235
  });
241
236
 
242
237
  const defaultMlEngineConfig = {
@@ -249,18 +244,14 @@ const defaultMlEngineConfig = {
249
244
  };
250
245
 
251
246
  var name = "authme/sdk";
252
- var version$1 = "2.8.41";
253
- var date = "2026-01-30T10:27:23+0000";
247
+ var version$1 = "2.8.44";
254
248
  var sdkInfo = {
255
249
  name: name,
256
- version: version$1,
257
- date: date
258
- };
250
+ version: version$1};
259
251
 
260
- var _a;
261
- var _b, _c;
252
+ var _window, _Symbol$for, _window$_Symbol$for;
262
253
  const version = sdkInfo.version;
263
- (_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] = {};
264
255
  window[Symbol.for('authme-sdk')][sdkInfo.name] = version;
265
256
 
266
257
  function logCollect(message, stackTrace) {
@@ -277,17 +268,36 @@ function logCollect(message, stackTrace) {
277
268
  });
278
269
  }
279
270
 
271
+ var _MlEngine, _AuthmeEngineModuleBase;
280
272
  const getDownloadOrder = function () {
281
273
  // model 越大,在後續 worker service 載入與解密的時間越長,
282
274
  // 所以盡可能讓越大的檔案排在越前面下載,以便讓耗費時間長的任務先排在背景執行。
283
275
  //
284
276
  // 但由於 api server 目前沒有提供檔案大小的相關資訊,
285
277
  // 所以將順序相關的資訊寫死在 sdk 裡。
286
- 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
287
297
  ].map((key, index) => [key, index]));
288
298
  return function getDownloadOrder(key) {
289
- var _a;
290
- 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;
291
301
  };
292
302
  }();
293
303
  function isSimdSupported() {
@@ -319,54 +329,46 @@ function getJsContentAsync(url) {
319
329
  sdkInfo: null
320
330
  });
321
331
  }
322
- function createWorkerWithObjectUrlAsync(url) {
323
- return __awaiter(this, void 0, void 0, function* () {
324
- const scriptContent = yield getJsContentAsync(url);
325
- const objectUrl = URL.createObjectURL(new Blob([scriptContent], {
326
- type: 'text/javascript'
327
- }));
328
- const worker = new Worker(objectUrl);
329
- URL.revokeObjectURL(objectUrl);
330
- return worker;
331
- });
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;
332
340
  }
333
341
  function convertToModelQueryString(modelVersion) {
334
342
  return `models=${modelVersion.name}[${modelVersion.version}]`;
335
343
  }
336
- function fetchModelCodesAsync(modelVersions) {
337
- return __awaiter(this, void 0, void 0, function* () {
338
- const queryString = modelVersions.map(convertToModelQueryString).join('&');
339
- const response = yield sendRequest('/api/model-management/v1/model?' + queryString);
340
- return response.models;
341
- });
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;
342
348
  }
343
349
  function base64ToBufferAsync(base64) {
344
350
  const dataUrl = 'data:application/octet-binary;base64,' + base64;
345
351
  return fetch(dataUrl).then(res => res.arrayBuffer());
346
352
  }
347
- function fetchModelContentAsync(code, dataTransferMethod) {
348
- return __awaiter(this, void 0, void 0, function* () {
349
- const payload = yield sendRequest(`/api/model-management/v1/model/${code}${dataTransferMethod === 'binary' ? '/file' : ''}`);
350
- if (dataTransferMethod === 'binary') {
351
- return payload;
352
- } else {
353
- return yield base64ToBufferAsync(payload.data);
354
- }
355
- });
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
+ }
356
360
  }
357
361
  function fetchModelContents(modelVersions, dataTransferMethod) {
358
362
  return of(modelVersions).pipe(concatMap(modelVersions => defer(() => fetchModelCodesAsync(modelVersions))), concatAll(), mergeMap(({
359
363
  name,
360
364
  version,
361
365
  code
362
- }) => defer(() => __awaiter(this, void 0, void 0, function* () {
363
- return {
364
- modelVersion: {
365
- name,
366
- version: `${parseInt(version)}`
367
- },
368
- modelArrayBuffer: yield fetchModelContentAsync(code, dataTransferMethod)
369
- };
366
+ }) => defer(async () => ({
367
+ modelVersion: {
368
+ name,
369
+ version: `${parseInt(version)}`
370
+ },
371
+ modelArrayBuffer: await fetchModelContentAsync(code, dataTransferMethod)
370
372
  })), 1
371
373
  // 下載 model 過程會分為 wait time & download time,
372
374
  // concurrent 設定越高,只能起到降低 wait time 的作用,但會拉長單一檔案完成下載的時間,
@@ -375,16 +377,13 @@ function fetchModelContents(modelVersions, dataTransferMethod) {
375
377
  // 所以 concurrent 建議設定為 1 或 2,盡量讓已下載好的 model 儘早進行載入與解密。
376
378
  ));
377
379
  }
378
-
379
380
  class AuthmeFunctionModule {
380
- init(config) {
381
- return __awaiter(this, void 0, void 0, function* () {
382
- for (const key in config) {
383
- if (Object.prototype.hasOwnProperty.call(config, key)) {
384
- Storage.setItem(key, config[key]);
385
- }
381
+ async init(config) {
382
+ for (const key in config) {
383
+ if (Object.prototype.hasOwnProperty.call(config, key)) {
384
+ Storage.setItem(key, config[key]);
386
385
  }
387
- });
386
+ }
388
387
  }
389
388
  static getVersion() {
390
389
  return version;
@@ -395,7 +394,7 @@ class MlEngine {
395
394
  this.workerAndStreamPromise = undefined;
396
395
  this.preloadPromise = undefined;
397
396
  this.debugTools = debugTools();
398
- this.config = Object.assign(Object.assign(Object.assign({}, defaultMlEngineConfig), config), {
397
+ this.config = Object.assign({}, defaultMlEngineConfig, config, {
399
398
  isMobile: isMobile()
400
399
  });
401
400
  }
@@ -412,102 +411,88 @@ class MlEngine {
412
411
  durationTimeWorker.end();
413
412
  })));
414
413
  }
415
- _makeWorkerAndStreamAsync() {
416
- var _a;
417
- return __awaiter(this, void 0, void 0, function* () {
418
- // use blobUrl to fix cross-domain problem on worker creating.
419
- // ref:
420
- // * https://stackoverflow.com/questions/25458104/can-should-html5-web-workers-use-cors-for-cross-origin
421
- // * https://web.dev/workers-basics/
422
- const worker = yield createWorkerWithObjectUrlAsync(`${(_a = this.config.scriptPath) !== null && _a !== void 0 ? _a : ''}engine-worker.js?t=${Date.now()}`);
423
- const workerMessage$ = fromEvent(worker, 'message').pipe(map(x => {
424
- var _a, _b, _c, _d;
425
- if ((_b = (_a = x.data) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.error) {
426
- 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));
427
- throw new AuthmeError(ErrorCode.SDK_INTERNAL_ERROR, 'unexpected worker error');
428
- }
429
- return x.data;
430
- }), shareReplay(1));
431
- yield this._run(worker, workerMessage$, EngineModule.Core, 'setConfig', this.config);
432
- return [worker, workerMessage$];
433
- });
434
- }
435
- _backgroundPreloadAsync() {
436
- var _a;
437
- return __awaiter(this, void 0, void 0, function* () {
438
- const [worker, workerMessage$] = yield (_a = this.workerAndStreamPromise) !== null && _a !== void 0 ? _a : this.workerAndStreamPromise = this._makeWorkerAndStreamAsync();
439
- yield this._loadEngineAsync(worker, workerMessage$);
440
- yield this._checkEnumConsistencyAsync(worker, workerMessage$);
441
- return [worker, workerMessage$];
442
- });
443
- }
444
- terminateWorkerAsync() {
445
- return __awaiter(this, void 0, void 0, function* () {
446
- if (this.workerAndStreamPromise || this.preloadPromise) {
447
- const [worker, _] = yield this._backgroundPreloadAsync();
448
- this.workerAndStreamPromise = undefined;
449
- this.preloadPromise = undefined;
450
- 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');
451
427
  }
452
- });
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
+ }
453
447
  }
454
448
  _preloadAndWaitReadyAsync() {
455
- var _a;
456
- return (_a = this.preloadPromise) !== null && _a !== void 0 ? _a : this.preloadPromise = this._backgroundPreloadAsync();
457
- }
458
- _checkEnumConsistencyAsync(worker, workerMessage$) {
459
- return __awaiter(this, void 0, void 0, function* () {
460
- const problem = yield this._run(worker, workerMessage$, 'Core', 'checkEnumConsistency', Object.assign(Object.assign(Object.assign({}, authEnumModule), idRecognitionEnumModule), fasRecognitionEnumModule));
461
- if (problem.length > 0) {
462
- logCollect('enum consistency problem', JSON.stringify(problem));
463
- throw new AuthmeError(ErrorCode.SDK_INTERNAL_ERROR, {
464
- problem
465
- });
466
- }
467
- });
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
+ }
468
460
  }
469
- run(module, command, value = {}) {
470
- return __awaiter(this, void 0, void 0, function* () {
471
- const [worker, workerMessage$] = yield this._preloadAndWaitReadyAsync();
472
- return yield this._run(worker, workerMessage$, module, command, value);
473
- });
461
+ async run(module, command, value = {}) {
462
+ const [worker, workerMessage$] = await this._preloadAndWaitReadyAsync();
463
+ return await this._run(worker, workerMessage$, module, command, value);
474
464
  }
475
465
  getConfig() {
476
466
  return this.config;
477
467
  }
478
- setConfig(config) {
479
- return __awaiter(this, void 0, void 0, function* () {
480
- this.config = Object.assign(Object.assign({}, this.config), config);
481
- if (this.workerAndStreamPromise) {
482
- const [worker, workerMessage$] = yield this._preloadAndWaitReadyAsync();
483
- yield this._run(worker, workerMessage$, EngineModule.Core, 'setConfig', this.config);
484
- }
485
- });
486
- }
487
- setPublicKeyForJson(pubKey) {
488
- return __awaiter(this, void 0, void 0, function* () {
489
- const [worker, workerMessage$] = yield this._preloadAndWaitReadyAsync();
490
- yield this._run(worker, workerMessage$, EngineModule.Fas, 'setPublicKeyForJson', pubKey);
491
- });
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
+ }
492
474
  }
493
- _loadEngineAsync(worker, workerMessage$) {
494
- var _a, _b, _c, _d, _e;
495
- return __awaiter(this, void 0, void 0, function* () {
496
- // load js/wasm outside the worker.
497
- const simdSupported = isSimdSupported();
498
- 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`;
499
- 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`;
500
- const durationTimeNetworkEngine = this.debugTools.setTimeDuration('loadEngine_network');
501
- 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()}`)]);
502
- durationTimeNetworkEngine.end();
503
- return yield this._run(worker, workerMessage$, EngineModule.Core, 'loadEngine', {
504
- engineJsContent,
505
- engineWasmContent
506
- });
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
507
491
  });
508
492
  }
509
493
  }
510
- MlEngine._ENGINE_CACHE = undefined;
494
+ _MlEngine = MlEngine;
495
+ _MlEngine._ENGINE_CACHE = undefined;
511
496
  class AuthmeEngineModuleBase {
512
497
  constructor(engine) {
513
498
  this._initPromise = undefined;
@@ -520,59 +505,57 @@ class AuthmeEngineModuleBase {
520
505
  _engineRunAsync(command, value) {
521
506
  return this.engine.run(this.moduleName, command, value);
522
507
  }
523
- _init() {
524
- var _a;
525
- return __awaiter(this, void 0, void 0, function* () {
526
- if (this.initialized) {
527
- return true;
528
- }
529
- if (this.initializing) {
530
- throw new AuthmeError(ErrorCode.ENGINE_MODULE_IS_INITIALIZING);
531
- }
532
- this.initializing = true;
533
- try {
534
- const noLoadedModelVersions = yield this._engineRunAsync('getNoLoadedModelVersions');
535
- const noCachedModelVersions = noLoadedModelVersions.filter(({
536
- name,
537
- version
538
- }) => !AuthmeEngineModuleBase._MODEL_CACHE[`${name}-${version}`]);
539
- 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());
540
- for (const {
541
- name,
542
- version
543
- } of noCachedModelVersions) {
544
- AuthmeEngineModuleBase._MODEL_CACHE[`${name}-${version}`] = newCachedValues.pipe(filter(({
545
- modelVersion
546
- }) => modelVersion.name === name && modelVersion.version === version));
547
- }
548
- const loadSessions$ = from(noLoadedModelVersions).pipe(map(({
549
- name,
550
- version
551
- }) => AuthmeEngineModuleBase._MODEL_CACHE[`${name}-${version}`]), mergeAll(), concatMap(({
552
- modelVersion,
553
- modelArrayBuffer
554
- }) => of(this._engineRunAsync('loadSession', {
555
- modelVersion,
556
- modelArrayBuffer
557
- }))), reduce((promises, item) => {
558
- promises.push(item);
559
- return promises;
560
- }, []), concatMap(promises => defer(() => Promise.all(promises))));
561
- yield firstValueFrom(loadSessions$);
562
- const result = yield this._engineRunAsync('init');
563
- this.initialized = true;
564
- return result;
565
- } catch (error) {
566
- logCollect('engine init error', JSON.stringify(error));
567
- throw new AuthmeError(ErrorCode.ENGINE_MODULE_INIT_ERROR, error);
568
- } finally {
569
- 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));
570
531
  }
571
- });
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
+ }
572
555
  }
573
556
  init() {
574
- var _a;
575
- 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();
576
559
  }
577
560
  preloadAsync() {
578
561
  return this.init();
@@ -590,66 +573,60 @@ class AuthmeEngineModuleBase {
590
573
  setOption(params) {
591
574
  return this._engineRunAsync('setOption', params);
592
575
  }
593
- recognition(data) {
594
- return __awaiter(this, void 0, void 0, function* () {
595
- // status control
596
- if (!this.received || !this.initialized || !this.setSized) {
597
- logCollect('recognition not available', JSON.stringify(ErrorCode.RECOGNITION_NOT_AVAILABLE));
598
- throw new AuthmeError(ErrorCode.RECOGNITION_NOT_AVAILABLE);
599
- }
600
- try {
601
- this.received = false;
602
- const start = performance.now();
603
- const return$ = yield this._engineRunAsync('recognition', {
604
- data
605
- });
606
- this.received = true;
607
- return Object.assign(Object.assign({}, return$), {
608
- debugInfo: {
609
- inferenceTime: performance.now() - start
610
- }
611
- });
612
- } catch (error) {
613
- this.received = true;
614
- logCollect('recognition error', JSON.stringify(error));
615
- throw new AuthmeError(ErrorCode.RECOGNITION_ERROR, error);
616
- }
617
- });
618
- }
619
- getDebugImageData(data) {
620
- return __awaiter(this, void 0, void 0, function* () {
621
- // status control
622
- if (!this.received || !this.initialized || !this.setSized) {
623
- logCollect('getDebugImageData recognition not available', JSON.stringify(ErrorCode.RECOGNITION_NOT_AVAILABLE));
624
- throw new AuthmeError(ErrorCode.RECOGNITION_NOT_AVAILABLE);
625
- }
626
- try {
627
- this.received = false;
628
- const start = performance.now();
629
- const return$ = yield this._engineRunAsync('getDebugImage', {
630
- data
631
- });
632
- this.received = true;
633
- 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: {
634
591
  inferenceTime: performance.now() - start
635
- };
636
- return return$;
637
- } catch (error) {
638
- this.received = true;
639
- logCollect('getDebugImageData recognition error', JSON.stringify(error));
640
- throw new AuthmeError(ErrorCode.RECOGNITION_ERROR, error);
641
- }
642
- });
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
+ }
643
599
  }
644
- setFrameSize(width, height) {
645
- return __awaiter(this, void 0, void 0, function* () {
646
- const result = yield this._engineRunAsync('setFrameSize', {
647
- width,
648
- 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
649
611
  });
650
- this.setSized = true;
651
- 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
652
627
  });
628
+ this.setSized = true;
629
+ return result;
653
630
  }
654
631
  getParams() {
655
632
  return this._engineRunAsync('getParams');
@@ -664,38 +641,30 @@ class AuthmeEngineModuleBase {
664
641
  positions
665
642
  });
666
643
  }
667
- encryptString(str, key) {
668
- return __awaiter(this, void 0, void 0, function* () {
669
- return yield this._engineRunAsync('encryptString', {
670
- string: str,
671
- key
672
- });
644
+ async encryptString(str, key) {
645
+ return await this._engineRunAsync('encryptString', {
646
+ string: str,
647
+ key
673
648
  });
674
649
  }
675
- encryptBlob(uint8Array, key) {
676
- return __awaiter(this, void 0, void 0, function* () {
677
- return yield this._engineRunAsync('encryptBlob', {
678
- uint8Array: uint8Array,
679
- key
680
- });
650
+ async encryptBlob(uint8Array, key) {
651
+ return await this._engineRunAsync('encryptBlob', {
652
+ uint8Array: uint8Array,
653
+ key
681
654
  });
682
655
  }
683
656
  // 測試圖片上傳加密用,未來實作後請刪除。
684
- _decryptString(str, key) {
685
- return __awaiter(this, void 0, void 0, function* () {
686
- return yield this._engineRunAsync('_decryptString', {
687
- string: str,
688
- key
689
- });
657
+ async _decryptString(str, key) {
658
+ return await this._engineRunAsync('_decryptString', {
659
+ string: str,
660
+ key
690
661
  });
691
662
  }
692
- destroy() {
693
- return __awaiter(this, void 0, void 0, function* () {
694
- yield this._engineRunAsync('destroy');
695
- this.initialized = false;
696
- this._initPromise = undefined;
697
- return true;
698
- });
663
+ async destroy() {
664
+ await this._engineRunAsync('destroy');
665
+ this.initialized = false;
666
+ this._initPromise = undefined;
667
+ return true;
699
668
  }
700
669
  getUIParams() {
701
670
  return this.engine.run(this.moduleName, 'getUIParams');
@@ -707,6 +676,7 @@ class AuthmeEngineModuleBase {
707
676
  this._MODEL_CACHE = {};
708
677
  }
709
678
  }
710
- AuthmeEngineModuleBase._MODEL_CACHE = {};
679
+ _AuthmeEngineModuleBase = AuthmeEngineModuleBase;
680
+ _AuthmeEngineModuleBase._MODEL_CACHE = {};
711
681
 
712
682
  export { AuthmeEngineModuleBase, AuthmeFunctionModule, EAuthMeCardClass, EAuthMeCardMatchStatus, EAuthMeCardOCRStatus, EAuthMeEngineReturnCode, EAuthMeEyeStatus, EAuthMeFASServiceStage, EAuthMeFASServiceStatus, EAuthMeFaceAntiSpoofingStatus, EAuthMeFacePose, EAuthMeIDCardAntiFraudStage, EAuthMeIDCardAntiFraudStatus, EAuthMeIDCardMetalTagStatus, EAuthMeMRZRecogStatus, EAuthMeMRZServiceStatus, EAuthMeMouthStatus, EngineModule, MlEngine, defaultMlEngineConfig, version };