@authme/engine 2.2.0 → 2.2.1-rc.1
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/CHANGELOG.md +20 -0
- package/assets/engine-worker.js +77 -24
- package/assets/ml_engine_web.js +1 -1
- package/assets/ml_engine_web.simd.js +1 -1
- package/assets/ml_engine_web.simd.wasm +0 -0
- package/assets/ml_engine_web.wasm +0 -0
- package/assets/ml_engine_web_version.txt +1 -1
- package/package.json +3 -3
- package/src/lib/engine.d.ts +22 -14
- package/src/lib/engine.js +106 -86
- package/src/lib/engine.js.map +1 -1
- package/src/lib/enum/auth.enum.d.ts +2 -2
- package/src/lib/enum/auth.enum.js +5 -5
- package/src/lib/enum/auth.enum.js.map +1 -1
- package/src/lib/enum/fas-recognition.enum.d.ts +46 -0
- package/src/lib/enum/fas-recognition.enum.js +56 -0
- package/src/lib/enum/fas-recognition.enum.js.map +1 -0
- package/src/lib/enum/id-recognition.enum.d.ts +64 -0
- package/src/lib/enum/id-recognition.enum.js +76 -0
- package/src/lib/enum/id-recognition.enum.js.map +1 -0
- package/src/lib/enum/index.d.ts +2 -0
- package/src/lib/enum/index.js +2 -0
- package/src/lib/enum/index.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
## [2.2.1-rc.1](https://github.com/AuthMe01/web-client-sdk/compare/v2.2.1-rc.0...v2.2.1-rc.1) (2022-12-28)
|
|
6
|
+
|
|
7
|
+
### Features
|
|
8
|
+
|
|
9
|
+
- upgrade engine to 5.1.0 ([26e2128](https://github.com/AuthMe01/web-client-sdk/commit/26e2128026edf36c4b54efdf61b339a2f755a528))
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
- inconsistency enum (or remove unused) ([b716f14](https://github.com/AuthMe01/web-client-sdk/commit/b716f142fa20d2eebf0af66ff27f858ef1e825b0))
|
|
14
|
+
|
|
15
|
+
## [2.2.1-rc.0](https://github.com/AuthMe01/web-client-sdk/compare/v2.2.0...v2.2.1-rc.0) (2022-12-22)
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
- implement preloadBackground feature ([4b58a16](https://github.com/AuthMe01/web-client-sdk/commit/4b58a16dbdd506d48ce9f9671d8154997f4b9839))
|
|
20
|
+
|
|
21
|
+
### Bug Fixes
|
|
22
|
+
|
|
23
|
+
- engine destroy fail problem ([e2ffc84](https://github.com/AuthMe01/web-client-sdk/commit/e2ffc843cafb2c414535be6d735957e1a04b7146))
|
|
24
|
+
|
|
5
25
|
## [2.2.0](https://github.com/AuthMe01/web-client-sdk/compare/v2.2.0-rc.13...v2.2.0) (2022-12-19)
|
|
6
26
|
|
|
7
27
|
## [2.2.0-rc.13](https://github.com/AuthMe01/web-client-sdk/compare/v2.2.0-rc.12...v2.2.0-rc.13) (2022-12-19)
|
package/assets/engine-worker.js
CHANGED
|
@@ -68,8 +68,14 @@
|
|
|
68
68
|
|
|
69
69
|
// Base
|
|
70
70
|
const baseFunctions = {
|
|
71
|
-
instance
|
|
72
|
-
|
|
71
|
+
// 由於不同 service 間的 _loadedSessions instance 是隔離開來的,
|
|
72
|
+
// 所以不能將 _loadedSessions: {} 直接放到這裡,
|
|
73
|
+
// 否則會造成 destroy 異常。
|
|
74
|
+
// 更好的做法會是用 class 替代現在的做法,只是改的幅度偏大,
|
|
75
|
+
// 所以暫時保留現有的做法。
|
|
76
|
+
_getLoadedModelKey({ modelVersion: { name, version } }) {
|
|
77
|
+
return `${name}#${version}`;
|
|
78
|
+
},
|
|
73
79
|
_getModelVersions(constructorName) {
|
|
74
80
|
const versionVector =
|
|
75
81
|
self.EngineLib[constructorName]['getModelVersion']();
|
|
@@ -83,27 +89,34 @@
|
|
|
83
89
|
}
|
|
84
90
|
return models;
|
|
85
91
|
},
|
|
92
|
+
_getNoLoadedModelVersions(constructorName) {
|
|
93
|
+
const modelVersions = this._getModelVersions(constructorName);
|
|
94
|
+
return modelVersions.filter(
|
|
95
|
+
(modelVersion) =>
|
|
96
|
+
!this._loadedSessions[this._getLoadedModelKey({ modelVersion })]
|
|
97
|
+
);
|
|
98
|
+
},
|
|
86
99
|
|
|
87
100
|
// worker 專心處理 cpu 密集 (model 載入) 的工作,
|
|
88
101
|
// 至於純 IO 下載的任務就交給 main thread 處理就好。
|
|
89
|
-
|
|
102
|
+
loadSession({ modelVersion: { name, version }, modelArrayBuffer }) {
|
|
90
103
|
let fileMounted = false;
|
|
91
104
|
try {
|
|
92
105
|
const FS = self.EngineLib.FS;
|
|
93
|
-
FS.mkdir(`/${
|
|
106
|
+
FS.mkdir(`/${name}-${version}/`);
|
|
94
107
|
FS.mount(
|
|
95
108
|
FS.filesystems.WORKERFS,
|
|
96
109
|
{
|
|
97
110
|
blobs: [
|
|
98
111
|
{
|
|
99
|
-
name:
|
|
112
|
+
name: `${name}-${version}`,
|
|
100
113
|
data: new Blob([modelArrayBuffer], {
|
|
101
114
|
type: 'application/octet-stream',
|
|
102
115
|
}),
|
|
103
116
|
},
|
|
104
117
|
],
|
|
105
118
|
},
|
|
106
|
-
`/${
|
|
119
|
+
`/${name}-${version}/`
|
|
107
120
|
);
|
|
108
121
|
fileMounted = true;
|
|
109
122
|
} catch (error) {
|
|
@@ -116,11 +129,17 @@
|
|
|
116
129
|
}
|
|
117
130
|
|
|
118
131
|
if (fileMounted) {
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
)
|
|
123
|
-
|
|
132
|
+
const sessionKey = this._getLoadedModelKey({
|
|
133
|
+
modelVersion: { name, version },
|
|
134
|
+
});
|
|
135
|
+
if (this._loadedSessions[sessionKey]) {
|
|
136
|
+
throw new Error('should be undefined here.');
|
|
137
|
+
}
|
|
138
|
+
this._loadedSessions[sessionKey] =
|
|
139
|
+
self.EngineLib.createInferenceSession(
|
|
140
|
+
name,
|
|
141
|
+
`/${name}-${version}/${name}-${version}`
|
|
142
|
+
);
|
|
124
143
|
}
|
|
125
144
|
},
|
|
126
145
|
async _init(constructorName) {
|
|
@@ -131,7 +150,10 @@
|
|
|
131
150
|
const instance = new self.EngineLib[constructorName]();
|
|
132
151
|
instance.initial(
|
|
133
152
|
...this._getModelVersions(constructorName).map(
|
|
134
|
-
(
|
|
153
|
+
(modelVersion) =>
|
|
154
|
+
this._loadedSessions[
|
|
155
|
+
this._getLoadedModelKey({ modelVersion })
|
|
156
|
+
]
|
|
135
157
|
)
|
|
136
158
|
);
|
|
137
159
|
const engine = instance;
|
|
@@ -224,10 +246,10 @@
|
|
|
224
246
|
this.instance.delete();
|
|
225
247
|
this.instance = null;
|
|
226
248
|
}
|
|
227
|
-
for (const session of Object.values(this.
|
|
249
|
+
for (const session of Object.values(this._loadedSessions)) {
|
|
228
250
|
self.EngineLib.deleteSession(session);
|
|
229
251
|
}
|
|
230
|
-
this.
|
|
252
|
+
this._loadedSessions = {};
|
|
231
253
|
},
|
|
232
254
|
getJsonReport() {
|
|
233
255
|
return this.instance?.getJsonReport();
|
|
@@ -236,10 +258,12 @@
|
|
|
236
258
|
|
|
237
259
|
// PassportService
|
|
238
260
|
self.PassportService = {
|
|
261
|
+
instance: null,
|
|
262
|
+
_loadedSessions: {},
|
|
239
263
|
...baseFunctions,
|
|
240
264
|
|
|
241
|
-
|
|
242
|
-
return this.
|
|
265
|
+
getNoLoadedModelVersions() {
|
|
266
|
+
return this._getNoLoadedModelVersions('PassportService');
|
|
243
267
|
},
|
|
244
268
|
init() {
|
|
245
269
|
return this._init('PassportService');
|
|
@@ -272,10 +296,12 @@
|
|
|
272
296
|
|
|
273
297
|
// Card OCR
|
|
274
298
|
self.CardOCR = {
|
|
299
|
+
instance: null,
|
|
300
|
+
_loadedSessions: {},
|
|
275
301
|
...baseFunctions,
|
|
276
302
|
|
|
277
|
-
|
|
278
|
-
return this.
|
|
303
|
+
getNoLoadedModelVersions() {
|
|
304
|
+
return this._getNoLoadedModelVersions('CardOCR');
|
|
279
305
|
},
|
|
280
306
|
init() {
|
|
281
307
|
return this._init('CardOCR');
|
|
@@ -296,12 +322,14 @@
|
|
|
296
322
|
}
|
|
297
323
|
return result;
|
|
298
324
|
},
|
|
299
|
-
setType(
|
|
325
|
+
setType({ type }) {
|
|
300
326
|
const engine = this.instance;
|
|
301
327
|
if (engine) {
|
|
302
328
|
const engineParams = engine.getParams();
|
|
303
329
|
engineParams.eTargetCardType =
|
|
304
|
-
self.EngineLib.EAuthMeCardClass
|
|
330
|
+
self.EngineLib.EAuthMeCardClass[
|
|
331
|
+
type.replace(/^EAuthMeCardClass_/, '')
|
|
332
|
+
];
|
|
305
333
|
engineParams.fImageBlurTh = 750;
|
|
306
334
|
engine.setParams(engineParams);
|
|
307
335
|
return true;
|
|
@@ -325,10 +353,12 @@
|
|
|
325
353
|
|
|
326
354
|
// Id Card Anti Fraud
|
|
327
355
|
self.IdCardAntiFraud = {
|
|
356
|
+
instance: null,
|
|
357
|
+
_loadedSessions: {},
|
|
328
358
|
...baseFunctions,
|
|
329
359
|
|
|
330
|
-
|
|
331
|
-
return this.
|
|
360
|
+
getNoLoadedModelVersions() {
|
|
361
|
+
return this._getNoLoadedModelVersions('IdCardAntiFraudService');
|
|
332
362
|
},
|
|
333
363
|
async init() {
|
|
334
364
|
await this._init('IdCardAntiFraudService');
|
|
@@ -382,10 +412,12 @@
|
|
|
382
412
|
};
|
|
383
413
|
|
|
384
414
|
self.Fas = {
|
|
415
|
+
instance: null,
|
|
416
|
+
_loadedSessions: {},
|
|
385
417
|
...baseFunctions,
|
|
386
418
|
|
|
387
|
-
|
|
388
|
-
return this.
|
|
419
|
+
getNoLoadedModelVersions() {
|
|
420
|
+
return this._getNoLoadedModelVersions('CFASService');
|
|
389
421
|
},
|
|
390
422
|
init() {
|
|
391
423
|
return this._init('CFASService');
|
|
@@ -448,6 +480,27 @@
|
|
|
448
480
|
}
|
|
449
481
|
return false;
|
|
450
482
|
},
|
|
483
|
+
checkEnumConsistency(enums) {
|
|
484
|
+
const problem = [];
|
|
485
|
+
for (const [enumName, enumDef] of Object.entries(enums)) {
|
|
486
|
+
const actualEnumDef = self.EngineLib[enumName];
|
|
487
|
+
const actualEnumValues = actualEnumDef?.values ?? {};
|
|
488
|
+
const actualEnumMap = Object.fromEntries(
|
|
489
|
+
Object.values(actualEnumValues).map((enumValue) => [
|
|
490
|
+
enumValue.constructor.name,
|
|
491
|
+
enumValue.value,
|
|
492
|
+
])
|
|
493
|
+
);
|
|
494
|
+
|
|
495
|
+
for (const [key, engineKey] of Object.entries(enumDef)) {
|
|
496
|
+
const actualValue = actualEnumMap[engineKey];
|
|
497
|
+
if (typeof actualValue === 'undefined') {
|
|
498
|
+
problem.push({ enumName, key, engineKey, actualEnumMap });
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
return problem;
|
|
503
|
+
},
|
|
451
504
|
};
|
|
452
505
|
|
|
453
506
|
addEventListener(
|