@authme/core 2.3.1-rc.3 → 2.4.6
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 +370 -8
- package/index.js +365 -7
- package/package.json +4 -2
- package/src/index.d.ts +1 -1
- package/src/lib/data-access/http-client.d.ts +4 -0
- package/src/lib/enum/language.enum.d.ts +2 -1
- package/src/lib/features/event-listener/event-listener.service.d.ts +18 -0
- package/src/lib/features/event-listener/event-logging.api.d.ts +4 -0
- package/src/lib/features/event-listener/index.d.ts +5 -0
- package/src/lib/features/event-listener/mock-api.service.d.ts +7 -0
- package/src/lib/features/event-listener/status.enum.d.ts +81 -0
- package/src/lib/features/event-listener/status.interface.d.ts +40 -0
- package/src/lib/features/event-listener/status.service.d.ts +4 -0
- package/src/lib/features/event-listener/tracking-event.d.ts +22 -0
- package/src/lib/features/index.d.ts +1 -0
- package/src/lib/translate/translate.d.ts +1 -0
- package/src/lib/authme-log.d.ts +0 -1
package/index.cjs
CHANGED
|
@@ -14,6 +14,10 @@ require('core-js/modules/es.symbol.description.js');
|
|
|
14
14
|
require('core-js/modules/es.regexp.exec.js');
|
|
15
15
|
require('core-js/modules/es.string.replace.js');
|
|
16
16
|
require('core-js/modules/es.regexp.constructor.js');
|
|
17
|
+
var rxjs = require('rxjs');
|
|
18
|
+
var operators = require('rxjs/operators');
|
|
19
|
+
var uuid = require('uuid');
|
|
20
|
+
require('core-js/modules/es.string.ends-with.js');
|
|
17
21
|
|
|
18
22
|
function core() {
|
|
19
23
|
return 'core';
|
|
@@ -45,7 +49,7 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
45
49
|
}
|
|
46
50
|
|
|
47
51
|
var name = "@authme/core";
|
|
48
|
-
var version$1 = "2.
|
|
52
|
+
var version$1 = "2.4.6";
|
|
49
53
|
var peerDependencies = {
|
|
50
54
|
"core-js": "^3.6.0"
|
|
51
55
|
};
|
|
@@ -61,6 +65,19 @@ const version = packageInfo.version;
|
|
|
61
65
|
(_a = (_b = window)[_c = Symbol.for('authme-sdk')]) !== null && _a !== void 0 ? _a : _b[_c] = {};
|
|
62
66
|
window[Symbol.for('authme-sdk')][packageInfo.name] = version;
|
|
63
67
|
|
|
68
|
+
function requestLoggingWapper() {
|
|
69
|
+
let loggingFuncInstance = undefined;
|
|
70
|
+
return {
|
|
71
|
+
setRequestLoggingFunc: func => {
|
|
72
|
+
loggingFuncInstance = func;
|
|
73
|
+
},
|
|
74
|
+
getRequestLoggingFunc: () => loggingFuncInstance
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
const {
|
|
78
|
+
setRequestLoggingFunc,
|
|
79
|
+
getRequestLoggingFunc
|
|
80
|
+
} = requestLoggingWapper();
|
|
64
81
|
function tryLoadAndParseJsonAsync(response) {
|
|
65
82
|
return __awaiter(this, void 0, void 0, function* () {
|
|
66
83
|
try {
|
|
@@ -98,6 +115,7 @@ function sendRequest(url, method = 'GET', {
|
|
|
98
115
|
sdkInfo = [`sdk-version: ${version}`, util.getUserAgent()].join(';')
|
|
99
116
|
} = {}) {
|
|
100
117
|
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
+
const requestLoggingFunction = getRequestLoggingFunc();
|
|
101
119
|
const options = Object.assign(Object.assign({
|
|
102
120
|
method
|
|
103
121
|
}, typeof body !== undefined ? {
|
|
@@ -114,7 +132,13 @@ function sendRequest(url, method = 'GET', {
|
|
|
114
132
|
let resp;
|
|
115
133
|
try {
|
|
116
134
|
const normalizedUrl = baseUrl ? new URL(url, baseUrl).toString() : url;
|
|
117
|
-
resp = yield fetch(normalizedUrl.toString(), options)
|
|
135
|
+
resp = requestLoggingFunction ? yield requestLoggingFunction(() => fetch(normalizedUrl.toString(), options), {
|
|
136
|
+
runFunction: util.RUN_FUNCTION_NAME.API_REQUEST,
|
|
137
|
+
message: {
|
|
138
|
+
url: normalizedUrl.toString(),
|
|
139
|
+
options
|
|
140
|
+
}
|
|
141
|
+
}) : yield fetch(normalizedUrl.toString(), options);
|
|
118
142
|
} catch (error) {
|
|
119
143
|
throw new util.AuthmeError(util.ErrorCode.NETWORK_ERROR, error);
|
|
120
144
|
}
|
|
@@ -147,6 +171,20 @@ function sendRequest(url, method = 'GET', {
|
|
|
147
171
|
}
|
|
148
172
|
}
|
|
149
173
|
if (errorMessages.length !== 0) {
|
|
174
|
+
// 5XX
|
|
175
|
+
if (resp.status >= 500 && resp.status < 600 && resp.status !== 503 && resp.status !== 504) {
|
|
176
|
+
throw new util.AuthmeError(util.ErrorCode.SERVER_ERROR, {
|
|
177
|
+
errorMessages,
|
|
178
|
+
meta: {
|
|
179
|
+
status: resp.status,
|
|
180
|
+
ok: resp.ok,
|
|
181
|
+
url,
|
|
182
|
+
responseContentType,
|
|
183
|
+
responseContent,
|
|
184
|
+
parsedError
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
}
|
|
150
188
|
throw new util.AuthmeError(util.ErrorCode.HTTP_ERROR_RESPONSE, {
|
|
151
189
|
errorMessages,
|
|
152
190
|
meta: {
|
|
@@ -167,13 +205,14 @@ exports.AuthmeLanguage = void 0;
|
|
|
167
205
|
(function (AuthmeLanguage) {
|
|
168
206
|
AuthmeLanguage["zh-TW"] = "zh_Hant_TW";
|
|
169
207
|
AuthmeLanguage["en-US"] = "en_US";
|
|
208
|
+
AuthmeLanguage["ja-JP"] = "ja_JP";
|
|
170
209
|
})(exports.AuthmeLanguage || (exports.AuthmeLanguage = {}));
|
|
171
210
|
|
|
172
211
|
class TranslateService {
|
|
173
212
|
constructor() {
|
|
174
213
|
this.originalDict = {};
|
|
175
214
|
this.customDict = {};
|
|
176
|
-
this.languageOptions = [exports.AuthmeLanguage['zh-TW'], exports.AuthmeLanguage['en-US']];
|
|
215
|
+
this.languageOptions = [exports.AuthmeLanguage['zh-TW'], exports.AuthmeLanguage['en-US'], exports.AuthmeLanguage['ja-JP']];
|
|
177
216
|
this.currentLang = exports.AuthmeLanguage['zh-TW'];
|
|
178
217
|
}
|
|
179
218
|
fetchSource(path) {
|
|
@@ -204,12 +243,18 @@ class TranslateService {
|
|
|
204
243
|
translate(key, args = {}) {
|
|
205
244
|
var _a, _b, _c, _d;
|
|
206
245
|
let str = (_d = (_b = (_a = this.customDict[this.currentLang]) === null || _a === void 0 ? void 0 : _a[key]) !== null && _b !== void 0 ? _b : (_c = this.originalDict[this.currentLang]) === null || _c === void 0 ? void 0 : _c[key]) !== null && _d !== void 0 ? _d : key;
|
|
246
|
+
if (!str) {
|
|
247
|
+
return '';
|
|
248
|
+
}
|
|
207
249
|
if (Object.keys(args).length > 0) {
|
|
208
250
|
Object.keys(args).forEach(key => {
|
|
209
251
|
str = str.replace(new RegExp(`{{${key}}}`, 'g'), args[key].toString());
|
|
210
252
|
});
|
|
211
253
|
}
|
|
212
|
-
return str;
|
|
254
|
+
return str.replace(/\\n/g, ' \n');
|
|
255
|
+
}
|
|
256
|
+
getCurrentLang() {
|
|
257
|
+
return this.currentLang;
|
|
213
258
|
}
|
|
214
259
|
}
|
|
215
260
|
TranslateService.instance = null;
|
|
@@ -220,6 +265,319 @@ function getTranslateInstance() {
|
|
|
220
265
|
return TranslateService.instance;
|
|
221
266
|
}
|
|
222
267
|
|
|
268
|
+
class MockApiService {
|
|
269
|
+
constructor() {
|
|
270
|
+
this.data = [];
|
|
271
|
+
}
|
|
272
|
+
postStatus(status) {
|
|
273
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
274
|
+
this.data.push(status);
|
|
275
|
+
return Promise.resolve(status);
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
postMutiStatus(status) {
|
|
279
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
280
|
+
this.data.push(...status);
|
|
281
|
+
return Promise.resolve(status);
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
getStatus() {
|
|
285
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
286
|
+
return Promise.resolve(this.data);
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function sendEventLogging(events, pingMethod) {
|
|
292
|
+
var _a;
|
|
293
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
294
|
+
if (util.Storage.getItem(util.STORAGE_KEY.ENABLE_EVENT_TRACKING) === false) {
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
const logs = events.filter(event => event.customerId !== '').map(event => {
|
|
298
|
+
return {
|
|
299
|
+
message: event,
|
|
300
|
+
createTime: event.userTime
|
|
301
|
+
};
|
|
302
|
+
});
|
|
303
|
+
const pingEvent = yield pingMethod();
|
|
304
|
+
const newLog = [{
|
|
305
|
+
message: pingEvent,
|
|
306
|
+
createTime: pingEvent.userTime
|
|
307
|
+
}, ...logs];
|
|
308
|
+
return sendRequest('/api/event-logging/v1/log/ekyc-sdk', 'POST', {
|
|
309
|
+
body: JSON.stringify({
|
|
310
|
+
logs: newLog
|
|
311
|
+
}),
|
|
312
|
+
baseUrl: (_a = util.Storage.getItem(util.STORAGE_KEY.EVENT_TRACK_URL)) !== null && _a !== void 0 ? _a : util.Storage.getItem(util.STORAGE_KEY.API_BASE_URL)
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
const initialStatus = {
|
|
318
|
+
eventId: '',
|
|
319
|
+
sessionId: '',
|
|
320
|
+
eventType: '',
|
|
321
|
+
userTime: new Date().toISOString(),
|
|
322
|
+
tenantId: '',
|
|
323
|
+
customerId: '',
|
|
324
|
+
duration: 0,
|
|
325
|
+
deviceInfo: '',
|
|
326
|
+
systemInfo: '',
|
|
327
|
+
version: '1.0.0',
|
|
328
|
+
language: '',
|
|
329
|
+
description: 'description',
|
|
330
|
+
platform: 'Web',
|
|
331
|
+
extraInfo: 'extra info'
|
|
332
|
+
};
|
|
333
|
+
const BUFFER_TINTERVAL = 3000;
|
|
334
|
+
class EventListenerService {
|
|
335
|
+
constructor(getStatusProcess, options) {
|
|
336
|
+
var _a;
|
|
337
|
+
this.getStatusProcess = getStatusProcess;
|
|
338
|
+
this.apiService = new MockApiService();
|
|
339
|
+
this.pingInterval = (_a = options === null || options === void 0 ? void 0 : options.pingInterval) !== null && _a !== void 0 ? _a : BUFFER_TINTERVAL;
|
|
340
|
+
this.statusSubject = new rxjs.BehaviorSubject(initialStatus);
|
|
341
|
+
}
|
|
342
|
+
start() {
|
|
343
|
+
this.statusSubject = new rxjs.BehaviorSubject(initialStatus);
|
|
344
|
+
this.statusSubject.pipe(operators.bufferTime(this.pingInterval), operators.filter(() => util.Storage.getItem(util.STORAGE_KEY.ENABLE_EVENT_TRACKING) === true), operators.mergeMap(events => {
|
|
345
|
+
sendEventLogging(events, this.getStatusProcess);
|
|
346
|
+
return events;
|
|
347
|
+
})).subscribe();
|
|
348
|
+
}
|
|
349
|
+
stop() {
|
|
350
|
+
if (this.pingSubscription) {
|
|
351
|
+
this.pingSubscription.unsubscribe();
|
|
352
|
+
this.pingSubscription = undefined;
|
|
353
|
+
}
|
|
354
|
+
this.statusSubject.complete();
|
|
355
|
+
}
|
|
356
|
+
sendUserActionStatus(status) {
|
|
357
|
+
this.statusSubject.next(status);
|
|
358
|
+
return this.sendStatus(status);
|
|
359
|
+
}
|
|
360
|
+
sendStatus(status) {
|
|
361
|
+
return this.apiService.postStatus(status);
|
|
362
|
+
}
|
|
363
|
+
getStatusObservable() {
|
|
364
|
+
return this.statusSubject;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
exports.Feature = void 0;
|
|
369
|
+
(function (Feature) {
|
|
370
|
+
Feature["OCRFraud"] = "OCRFraud";
|
|
371
|
+
Feature["OCR"] = "OCR";
|
|
372
|
+
Feature["SelectCardTypeAndCountry"] = "SelectCardTypeAndCountry";
|
|
373
|
+
Feature["LivenessActive"] = "LivenessActive";
|
|
374
|
+
Feature["LivenessPassive"] = "LivenessPassive";
|
|
375
|
+
})(exports.Feature || (exports.Feature = {}));
|
|
376
|
+
exports.StatusEvent = void 0;
|
|
377
|
+
(function (StatusEvent) {
|
|
378
|
+
StatusEvent["TWID"] = "TWID";
|
|
379
|
+
StatusEvent["TWIDFraud"] = "TWIDFraud";
|
|
380
|
+
StatusEvent["TWIDFront"] = "TWIDFront";
|
|
381
|
+
StatusEvent["TWDriverLicenseFront"] = "TWDriverLicenseFront";
|
|
382
|
+
StatusEvent["Passport"] = "Passport";
|
|
383
|
+
StatusEvent["ResidencePermitFront"] = "ResidencePermitFront";
|
|
384
|
+
StatusEvent["ResidencePermitBack"] = "ResidencePermitBack";
|
|
385
|
+
StatusEvent["TWIDBack"] = "TWIDBack";
|
|
386
|
+
StatusEvent["TWDriverLicenseBack"] = "TWDriverLicenseBack";
|
|
387
|
+
StatusEvent["TWHealthCardFront"] = "TWHealthCardFront";
|
|
388
|
+
StatusEvent["TWDriverLicense"] = "TWDriverLicense";
|
|
389
|
+
StatusEvent["TWHealthCard"] = "TWHealthCard";
|
|
390
|
+
StatusEvent["ResidencePermit"] = "ResidencePermit";
|
|
391
|
+
StatusEvent["PassportFront"] = "PassportFront";
|
|
392
|
+
StatusEvent["OpenMouth"] = "OpenMouth";
|
|
393
|
+
StatusEvent["CloseMouth"] = "CloseMouth";
|
|
394
|
+
StatusEvent["Smile"] = "Smile";
|
|
395
|
+
StatusEvent["Scale"] = "Scale";
|
|
396
|
+
StatusEvent["Done"] = "Done";
|
|
397
|
+
StatusEvent["Passive"] = "Passive";
|
|
398
|
+
StatusEvent["SelectCardTypeAndCountry"] = "SelectCardTypeAndCountry";
|
|
399
|
+
})(exports.StatusEvent || (exports.StatusEvent = {}));
|
|
400
|
+
exports.StatusView = void 0;
|
|
401
|
+
(function (StatusView) {
|
|
402
|
+
StatusView["Info"] = "Info";
|
|
403
|
+
StatusView["Init"] = "Init";
|
|
404
|
+
StatusView["Aligning"] = "Aligning";
|
|
405
|
+
StatusView["Start"] = "Start";
|
|
406
|
+
StatusView["Up"] = "Up";
|
|
407
|
+
StatusView["Down"] = "Down";
|
|
408
|
+
StatusView["Left"] = "Left";
|
|
409
|
+
StatusView["Right"] = "Right";
|
|
410
|
+
StatusView["Running"] = "Running";
|
|
411
|
+
StatusView["Confirm"] = "Confirm";
|
|
412
|
+
StatusView["Uploading"] = "Uploading";
|
|
413
|
+
StatusView["Select"] = "Select";
|
|
414
|
+
})(exports.StatusView || (exports.StatusView = {}));
|
|
415
|
+
exports.StatusAction = void 0;
|
|
416
|
+
(function (StatusAction) {
|
|
417
|
+
StatusAction["Uploading"] = "Uploading";
|
|
418
|
+
StatusAction["Show"] = "Show";
|
|
419
|
+
StatusAction["BtnClose"] = "BtnClose";
|
|
420
|
+
StatusAction["BtnStart"] = "BtnStart";
|
|
421
|
+
StatusAction["InitError"] = "InitError";
|
|
422
|
+
StatusAction["Start"] = "Start";
|
|
423
|
+
StatusAction["Confirm"] = "Confirm";
|
|
424
|
+
StatusAction["Retry"] = "Retry";
|
|
425
|
+
})(exports.StatusAction || (exports.StatusAction = {}));
|
|
426
|
+
exports.StatusDescription = void 0;
|
|
427
|
+
(function (StatusDescription) {
|
|
428
|
+
StatusDescription["NoCard"] = "NoCard";
|
|
429
|
+
StatusDescription["WrongCardType"] = "WrongCardType";
|
|
430
|
+
StatusDescription["PositionNotMatch"] = "PositionNotMatch";
|
|
431
|
+
StatusDescription["Reflective"] = "Reflective";
|
|
432
|
+
StatusDescription["Blur"] = "Blur";
|
|
433
|
+
StatusDescription["Pass"] = "Pass";
|
|
434
|
+
StatusDescription["Error"] = "Error";
|
|
435
|
+
StatusDescription["Failed"] = "Failed";
|
|
436
|
+
StatusDescription["Timeout"] = "Timeout";
|
|
437
|
+
StatusDescription["Gray"] = "Gray";
|
|
438
|
+
StatusDescription["NeedMoreFrame"] = "NeedMoreFrame";
|
|
439
|
+
StatusDescription["NotAligned"] = "NotAligned";
|
|
440
|
+
StatusDescription["NoFace"] = "NoFace";
|
|
441
|
+
StatusDescription["FaceNotAtCenter"] = "FaceNotAtCenter";
|
|
442
|
+
StatusDescription["FaceTooSmall"] = "FaceTooSmall";
|
|
443
|
+
StatusDescription["FaceTooLarge"] = "FaceTooLarge";
|
|
444
|
+
StatusDescription["NeedFaceToCamera"] = "NeedFaceToCamera";
|
|
445
|
+
StatusDescription["FaceMasked"] = "FaceMasked";
|
|
446
|
+
StatusDescription["NeedOpenMouth"] = "NeedOpenMouth";
|
|
447
|
+
StatusDescription["NeedCloseMouth"] = "NeedCloseMouth";
|
|
448
|
+
StatusDescription["NeedSmile"] = "NeedSmile";
|
|
449
|
+
StatusDescription["NeedOpenEyes"] = "NeedOpenEyes";
|
|
450
|
+
StatusDescription["UploadingStart"] = "UploadingStart";
|
|
451
|
+
StatusDescription["UploadingEnd"] = "UploadingEnd";
|
|
452
|
+
StatusDescription["Complete"] = "Complete";
|
|
453
|
+
})(exports.StatusDescription || (exports.StatusDescription = {}));
|
|
454
|
+
|
|
455
|
+
class TrackingEvent {
|
|
456
|
+
constructor(params) {
|
|
457
|
+
this._feature = params.feature;
|
|
458
|
+
this._event = params.event;
|
|
459
|
+
this._view = params.view;
|
|
460
|
+
this._action = params.action;
|
|
461
|
+
this._description = params.description;
|
|
462
|
+
}
|
|
463
|
+
nonNull(data) {
|
|
464
|
+
return data !== null && data !== undefined;
|
|
465
|
+
}
|
|
466
|
+
get feature() {
|
|
467
|
+
return this._feature;
|
|
468
|
+
}
|
|
469
|
+
set feature(value) {
|
|
470
|
+
if (value && !(value in exports.Feature)) {
|
|
471
|
+
throw new Error('Invalid feature');
|
|
472
|
+
}
|
|
473
|
+
this._feature = value;
|
|
474
|
+
}
|
|
475
|
+
get event() {
|
|
476
|
+
return this._event;
|
|
477
|
+
}
|
|
478
|
+
set event(value) {
|
|
479
|
+
if (value && !(value in exports.StatusEvent)) {
|
|
480
|
+
throw new Error('Invalid event');
|
|
481
|
+
}
|
|
482
|
+
this._event = value;
|
|
483
|
+
}
|
|
484
|
+
get view() {
|
|
485
|
+
return this._view;
|
|
486
|
+
}
|
|
487
|
+
set view(value) {
|
|
488
|
+
if (value && !(value in exports.StatusView)) {
|
|
489
|
+
throw new Error('Invalid view');
|
|
490
|
+
}
|
|
491
|
+
this._view = value;
|
|
492
|
+
}
|
|
493
|
+
get action() {
|
|
494
|
+
return this._action;
|
|
495
|
+
}
|
|
496
|
+
set action(value) {
|
|
497
|
+
if (value && !(value in exports.StatusAction)) {
|
|
498
|
+
throw new Error('Invalid action');
|
|
499
|
+
}
|
|
500
|
+
this._action = value;
|
|
501
|
+
}
|
|
502
|
+
get description() {
|
|
503
|
+
return this._description;
|
|
504
|
+
}
|
|
505
|
+
set description(value) {
|
|
506
|
+
if (value && !(value in exports.StatusDescription)) {
|
|
507
|
+
throw new Error('Invalid description');
|
|
508
|
+
}
|
|
509
|
+
this._description = value;
|
|
510
|
+
}
|
|
511
|
+
toString() {
|
|
512
|
+
let result = '';
|
|
513
|
+
if (this.nonNull(this._feature)) {
|
|
514
|
+
result += `${this._feature}:`;
|
|
515
|
+
}
|
|
516
|
+
if (this.nonNull(this._event)) {
|
|
517
|
+
result += `${this._event}:`;
|
|
518
|
+
}
|
|
519
|
+
if (this.nonNull(this._view)) {
|
|
520
|
+
result += `${this._view}:`;
|
|
521
|
+
}
|
|
522
|
+
if (this.nonNull(this._action)) {
|
|
523
|
+
result += `${this._action}:`;
|
|
524
|
+
}
|
|
525
|
+
if (this.nonNull(this._description)) {
|
|
526
|
+
result += `${this._description}`;
|
|
527
|
+
}
|
|
528
|
+
if (result.endsWith(':')) {
|
|
529
|
+
result = result.slice(0, -1); // 刪除最後一個字符
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
return result;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
const tokenSubject = new rxjs.BehaviorSubject('');
|
|
537
|
+
tokenSubject.pipe(rxjs.tap(token => {
|
|
538
|
+
if (!token) return;
|
|
539
|
+
const _jwt = util.decodeToken(token);
|
|
540
|
+
setAuthmeJWT(_jwt.payload);
|
|
541
|
+
})).subscribe();
|
|
542
|
+
const defaultEventName = new TrackingEvent({});
|
|
543
|
+
const [getAuthmeJWT, setAuthmeJWT] = util.useState();
|
|
544
|
+
const [getAccessToken, setAccessToken] = util.useState('', tokenSubject);
|
|
545
|
+
const [getSessionId, setSessionId] = util.useState('');
|
|
546
|
+
function generateStatus(params = {}) {
|
|
547
|
+
const _authmeJWT = getAuthmeJWT();
|
|
548
|
+
const {
|
|
549
|
+
eventType = defaultEventName,
|
|
550
|
+
sessionId = getSessionId(),
|
|
551
|
+
userTime = new Date().toISOString(),
|
|
552
|
+
tenantId = _authmeJWT.client_tenant,
|
|
553
|
+
customerId = _authmeJWT.client_id,
|
|
554
|
+
duration = 0,
|
|
555
|
+
deviceInfo = util.getDeviceInfo(),
|
|
556
|
+
systemInfo = util.getSystemInfo(),
|
|
557
|
+
version: version$1 = version,
|
|
558
|
+
language = '',
|
|
559
|
+
description = '',
|
|
560
|
+
platform = 'web',
|
|
561
|
+
extraInfo = ''
|
|
562
|
+
} = params;
|
|
563
|
+
return {
|
|
564
|
+
eventId: uuid.v4(),
|
|
565
|
+
eventType: eventType.toString(),
|
|
566
|
+
sessionId,
|
|
567
|
+
userTime,
|
|
568
|
+
tenantId,
|
|
569
|
+
customerId,
|
|
570
|
+
duration,
|
|
571
|
+
deviceInfo,
|
|
572
|
+
systemInfo,
|
|
573
|
+
version: version$1,
|
|
574
|
+
language,
|
|
575
|
+
description,
|
|
576
|
+
platform,
|
|
577
|
+
extraInfo
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
|
|
223
581
|
Object.defineProperty(exports, 'AuthmeError', {
|
|
224
582
|
enumerable: true,
|
|
225
583
|
get: function () { return util.AuthmeError; }
|
|
@@ -228,11 +586,15 @@ Object.defineProperty(exports, 'ErrorCode', {
|
|
|
228
586
|
enumerable: true,
|
|
229
587
|
get: function () { return util.ErrorCode; }
|
|
230
588
|
});
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
get: function () { return util.debugLog; }
|
|
234
|
-
});
|
|
589
|
+
exports.EventListenerService = EventListenerService;
|
|
590
|
+
exports.TrackingEvent = TrackingEvent;
|
|
235
591
|
exports.core = core;
|
|
592
|
+
exports.generateStatus = generateStatus;
|
|
593
|
+
exports.getAccessToken = getAccessToken;
|
|
594
|
+
exports.getSessionId = getSessionId;
|
|
236
595
|
exports.getTranslateInstance = getTranslateInstance;
|
|
237
596
|
exports.sendRequest = sendRequest;
|
|
597
|
+
exports.setAccessToken = setAccessToken;
|
|
598
|
+
exports.setRequestLoggingFunc = setRequestLoggingFunc;
|
|
599
|
+
exports.setSessionId = setSessionId;
|
|
238
600
|
exports.version = version;
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Storage, getUserAgent, AuthmeError, ErrorCode } from '@authme/util';
|
|
2
|
-
export { AuthmeError, ErrorCode
|
|
1
|
+
import { Storage, getUserAgent, RUN_FUNCTION_NAME, AuthmeError, ErrorCode, STORAGE_KEY, decodeToken, useState, getDeviceInfo, getSystemInfo } from '@authme/util';
|
|
2
|
+
export { AuthmeError, ErrorCode } from '@authme/util';
|
|
3
3
|
import 'core-js/modules/es.object.assign.js';
|
|
4
4
|
import 'core-js/modules/es.regexp.to-string.js';
|
|
5
5
|
import 'core-js/modules/es.array.iterator.js';
|
|
@@ -11,6 +11,10 @@ import 'core-js/modules/es.symbol.description.js';
|
|
|
11
11
|
import 'core-js/modules/es.regexp.exec.js';
|
|
12
12
|
import 'core-js/modules/es.string.replace.js';
|
|
13
13
|
import 'core-js/modules/es.regexp.constructor.js';
|
|
14
|
+
import { BehaviorSubject, tap } from 'rxjs';
|
|
15
|
+
import { bufferTime, filter, mergeMap } from 'rxjs/operators';
|
|
16
|
+
import { v4 } from 'uuid';
|
|
17
|
+
import 'core-js/modules/es.string.ends-with.js';
|
|
14
18
|
|
|
15
19
|
function core() {
|
|
16
20
|
return 'core';
|
|
@@ -42,7 +46,7 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
42
46
|
}
|
|
43
47
|
|
|
44
48
|
var name = "@authme/core";
|
|
45
|
-
var version$1 = "2.
|
|
49
|
+
var version$1 = "2.4.6";
|
|
46
50
|
var peerDependencies = {
|
|
47
51
|
"core-js": "^3.6.0"
|
|
48
52
|
};
|
|
@@ -58,6 +62,19 @@ const version = packageInfo.version;
|
|
|
58
62
|
(_a = (_b = window)[_c = Symbol.for('authme-sdk')]) !== null && _a !== void 0 ? _a : _b[_c] = {};
|
|
59
63
|
window[Symbol.for('authme-sdk')][packageInfo.name] = version;
|
|
60
64
|
|
|
65
|
+
function requestLoggingWapper() {
|
|
66
|
+
let loggingFuncInstance = undefined;
|
|
67
|
+
return {
|
|
68
|
+
setRequestLoggingFunc: func => {
|
|
69
|
+
loggingFuncInstance = func;
|
|
70
|
+
},
|
|
71
|
+
getRequestLoggingFunc: () => loggingFuncInstance
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
const {
|
|
75
|
+
setRequestLoggingFunc,
|
|
76
|
+
getRequestLoggingFunc
|
|
77
|
+
} = requestLoggingWapper();
|
|
61
78
|
function tryLoadAndParseJsonAsync(response) {
|
|
62
79
|
return __awaiter(this, void 0, void 0, function* () {
|
|
63
80
|
try {
|
|
@@ -95,6 +112,7 @@ function sendRequest(url, method = 'GET', {
|
|
|
95
112
|
sdkInfo = [`sdk-version: ${version}`, getUserAgent()].join(';')
|
|
96
113
|
} = {}) {
|
|
97
114
|
return __awaiter(this, void 0, void 0, function* () {
|
|
115
|
+
const requestLoggingFunction = getRequestLoggingFunc();
|
|
98
116
|
const options = Object.assign(Object.assign({
|
|
99
117
|
method
|
|
100
118
|
}, typeof body !== undefined ? {
|
|
@@ -111,7 +129,13 @@ function sendRequest(url, method = 'GET', {
|
|
|
111
129
|
let resp;
|
|
112
130
|
try {
|
|
113
131
|
const normalizedUrl = baseUrl ? new URL(url, baseUrl).toString() : url;
|
|
114
|
-
resp = yield fetch(normalizedUrl.toString(), options)
|
|
132
|
+
resp = requestLoggingFunction ? yield requestLoggingFunction(() => fetch(normalizedUrl.toString(), options), {
|
|
133
|
+
runFunction: RUN_FUNCTION_NAME.API_REQUEST,
|
|
134
|
+
message: {
|
|
135
|
+
url: normalizedUrl.toString(),
|
|
136
|
+
options
|
|
137
|
+
}
|
|
138
|
+
}) : yield fetch(normalizedUrl.toString(), options);
|
|
115
139
|
} catch (error) {
|
|
116
140
|
throw new AuthmeError(ErrorCode.NETWORK_ERROR, error);
|
|
117
141
|
}
|
|
@@ -144,6 +168,20 @@ function sendRequest(url, method = 'GET', {
|
|
|
144
168
|
}
|
|
145
169
|
}
|
|
146
170
|
if (errorMessages.length !== 0) {
|
|
171
|
+
// 5XX
|
|
172
|
+
if (resp.status >= 500 && resp.status < 600 && resp.status !== 503 && resp.status !== 504) {
|
|
173
|
+
throw new AuthmeError(ErrorCode.SERVER_ERROR, {
|
|
174
|
+
errorMessages,
|
|
175
|
+
meta: {
|
|
176
|
+
status: resp.status,
|
|
177
|
+
ok: resp.ok,
|
|
178
|
+
url,
|
|
179
|
+
responseContentType,
|
|
180
|
+
responseContent,
|
|
181
|
+
parsedError
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
}
|
|
147
185
|
throw new AuthmeError(ErrorCode.HTTP_ERROR_RESPONSE, {
|
|
148
186
|
errorMessages,
|
|
149
187
|
meta: {
|
|
@@ -164,13 +202,14 @@ var AuthmeLanguage;
|
|
|
164
202
|
(function (AuthmeLanguage) {
|
|
165
203
|
AuthmeLanguage["zh-TW"] = "zh_Hant_TW";
|
|
166
204
|
AuthmeLanguage["en-US"] = "en_US";
|
|
205
|
+
AuthmeLanguage["ja-JP"] = "ja_JP";
|
|
167
206
|
})(AuthmeLanguage || (AuthmeLanguage = {}));
|
|
168
207
|
|
|
169
208
|
class TranslateService {
|
|
170
209
|
constructor() {
|
|
171
210
|
this.originalDict = {};
|
|
172
211
|
this.customDict = {};
|
|
173
|
-
this.languageOptions = [AuthmeLanguage['zh-TW'], AuthmeLanguage['en-US']];
|
|
212
|
+
this.languageOptions = [AuthmeLanguage['zh-TW'], AuthmeLanguage['en-US'], AuthmeLanguage['ja-JP']];
|
|
174
213
|
this.currentLang = AuthmeLanguage['zh-TW'];
|
|
175
214
|
}
|
|
176
215
|
fetchSource(path) {
|
|
@@ -201,12 +240,18 @@ class TranslateService {
|
|
|
201
240
|
translate(key, args = {}) {
|
|
202
241
|
var _a, _b, _c, _d;
|
|
203
242
|
let str = (_d = (_b = (_a = this.customDict[this.currentLang]) === null || _a === void 0 ? void 0 : _a[key]) !== null && _b !== void 0 ? _b : (_c = this.originalDict[this.currentLang]) === null || _c === void 0 ? void 0 : _c[key]) !== null && _d !== void 0 ? _d : key;
|
|
243
|
+
if (!str) {
|
|
244
|
+
return '';
|
|
245
|
+
}
|
|
204
246
|
if (Object.keys(args).length > 0) {
|
|
205
247
|
Object.keys(args).forEach(key => {
|
|
206
248
|
str = str.replace(new RegExp(`{{${key}}}`, 'g'), args[key].toString());
|
|
207
249
|
});
|
|
208
250
|
}
|
|
209
|
-
return str;
|
|
251
|
+
return str.replace(/\\n/g, ' \n');
|
|
252
|
+
}
|
|
253
|
+
getCurrentLang() {
|
|
254
|
+
return this.currentLang;
|
|
210
255
|
}
|
|
211
256
|
}
|
|
212
257
|
TranslateService.instance = null;
|
|
@@ -217,4 +262,317 @@ function getTranslateInstance() {
|
|
|
217
262
|
return TranslateService.instance;
|
|
218
263
|
}
|
|
219
264
|
|
|
220
|
-
|
|
265
|
+
class MockApiService {
|
|
266
|
+
constructor() {
|
|
267
|
+
this.data = [];
|
|
268
|
+
}
|
|
269
|
+
postStatus(status) {
|
|
270
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
271
|
+
this.data.push(status);
|
|
272
|
+
return Promise.resolve(status);
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
postMutiStatus(status) {
|
|
276
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
277
|
+
this.data.push(...status);
|
|
278
|
+
return Promise.resolve(status);
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
getStatus() {
|
|
282
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
283
|
+
return Promise.resolve(this.data);
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function sendEventLogging(events, pingMethod) {
|
|
289
|
+
var _a;
|
|
290
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
291
|
+
if (Storage.getItem(STORAGE_KEY.ENABLE_EVENT_TRACKING) === false) {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
const logs = events.filter(event => event.customerId !== '').map(event => {
|
|
295
|
+
return {
|
|
296
|
+
message: event,
|
|
297
|
+
createTime: event.userTime
|
|
298
|
+
};
|
|
299
|
+
});
|
|
300
|
+
const pingEvent = yield pingMethod();
|
|
301
|
+
const newLog = [{
|
|
302
|
+
message: pingEvent,
|
|
303
|
+
createTime: pingEvent.userTime
|
|
304
|
+
}, ...logs];
|
|
305
|
+
return sendRequest('/api/event-logging/v1/log/ekyc-sdk', 'POST', {
|
|
306
|
+
body: JSON.stringify({
|
|
307
|
+
logs: newLog
|
|
308
|
+
}),
|
|
309
|
+
baseUrl: (_a = Storage.getItem(STORAGE_KEY.EVENT_TRACK_URL)) !== null && _a !== void 0 ? _a : Storage.getItem(STORAGE_KEY.API_BASE_URL)
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
const initialStatus = {
|
|
315
|
+
eventId: '',
|
|
316
|
+
sessionId: '',
|
|
317
|
+
eventType: '',
|
|
318
|
+
userTime: new Date().toISOString(),
|
|
319
|
+
tenantId: '',
|
|
320
|
+
customerId: '',
|
|
321
|
+
duration: 0,
|
|
322
|
+
deviceInfo: '',
|
|
323
|
+
systemInfo: '',
|
|
324
|
+
version: '1.0.0',
|
|
325
|
+
language: '',
|
|
326
|
+
description: 'description',
|
|
327
|
+
platform: 'Web',
|
|
328
|
+
extraInfo: 'extra info'
|
|
329
|
+
};
|
|
330
|
+
const BUFFER_TINTERVAL = 3000;
|
|
331
|
+
class EventListenerService {
|
|
332
|
+
constructor(getStatusProcess, options) {
|
|
333
|
+
var _a;
|
|
334
|
+
this.getStatusProcess = getStatusProcess;
|
|
335
|
+
this.apiService = new MockApiService();
|
|
336
|
+
this.pingInterval = (_a = options === null || options === void 0 ? void 0 : options.pingInterval) !== null && _a !== void 0 ? _a : BUFFER_TINTERVAL;
|
|
337
|
+
this.statusSubject = new BehaviorSubject(initialStatus);
|
|
338
|
+
}
|
|
339
|
+
start() {
|
|
340
|
+
this.statusSubject = new BehaviorSubject(initialStatus);
|
|
341
|
+
this.statusSubject.pipe(bufferTime(this.pingInterval), filter(() => Storage.getItem(STORAGE_KEY.ENABLE_EVENT_TRACKING) === true), mergeMap(events => {
|
|
342
|
+
sendEventLogging(events, this.getStatusProcess);
|
|
343
|
+
return events;
|
|
344
|
+
})).subscribe();
|
|
345
|
+
}
|
|
346
|
+
stop() {
|
|
347
|
+
if (this.pingSubscription) {
|
|
348
|
+
this.pingSubscription.unsubscribe();
|
|
349
|
+
this.pingSubscription = undefined;
|
|
350
|
+
}
|
|
351
|
+
this.statusSubject.complete();
|
|
352
|
+
}
|
|
353
|
+
sendUserActionStatus(status) {
|
|
354
|
+
this.statusSubject.next(status);
|
|
355
|
+
return this.sendStatus(status);
|
|
356
|
+
}
|
|
357
|
+
sendStatus(status) {
|
|
358
|
+
return this.apiService.postStatus(status);
|
|
359
|
+
}
|
|
360
|
+
getStatusObservable() {
|
|
361
|
+
return this.statusSubject;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
var Feature;
|
|
366
|
+
(function (Feature) {
|
|
367
|
+
Feature["OCRFraud"] = "OCRFraud";
|
|
368
|
+
Feature["OCR"] = "OCR";
|
|
369
|
+
Feature["SelectCardTypeAndCountry"] = "SelectCardTypeAndCountry";
|
|
370
|
+
Feature["LivenessActive"] = "LivenessActive";
|
|
371
|
+
Feature["LivenessPassive"] = "LivenessPassive";
|
|
372
|
+
})(Feature || (Feature = {}));
|
|
373
|
+
var StatusEvent;
|
|
374
|
+
(function (StatusEvent) {
|
|
375
|
+
StatusEvent["TWID"] = "TWID";
|
|
376
|
+
StatusEvent["TWIDFraud"] = "TWIDFraud";
|
|
377
|
+
StatusEvent["TWIDFront"] = "TWIDFront";
|
|
378
|
+
StatusEvent["TWDriverLicenseFront"] = "TWDriverLicenseFront";
|
|
379
|
+
StatusEvent["Passport"] = "Passport";
|
|
380
|
+
StatusEvent["ResidencePermitFront"] = "ResidencePermitFront";
|
|
381
|
+
StatusEvent["ResidencePermitBack"] = "ResidencePermitBack";
|
|
382
|
+
StatusEvent["TWIDBack"] = "TWIDBack";
|
|
383
|
+
StatusEvent["TWDriverLicenseBack"] = "TWDriverLicenseBack";
|
|
384
|
+
StatusEvent["TWHealthCardFront"] = "TWHealthCardFront";
|
|
385
|
+
StatusEvent["TWDriverLicense"] = "TWDriverLicense";
|
|
386
|
+
StatusEvent["TWHealthCard"] = "TWHealthCard";
|
|
387
|
+
StatusEvent["ResidencePermit"] = "ResidencePermit";
|
|
388
|
+
StatusEvent["PassportFront"] = "PassportFront";
|
|
389
|
+
StatusEvent["OpenMouth"] = "OpenMouth";
|
|
390
|
+
StatusEvent["CloseMouth"] = "CloseMouth";
|
|
391
|
+
StatusEvent["Smile"] = "Smile";
|
|
392
|
+
StatusEvent["Scale"] = "Scale";
|
|
393
|
+
StatusEvent["Done"] = "Done";
|
|
394
|
+
StatusEvent["Passive"] = "Passive";
|
|
395
|
+
StatusEvent["SelectCardTypeAndCountry"] = "SelectCardTypeAndCountry";
|
|
396
|
+
})(StatusEvent || (StatusEvent = {}));
|
|
397
|
+
var StatusView;
|
|
398
|
+
(function (StatusView) {
|
|
399
|
+
StatusView["Info"] = "Info";
|
|
400
|
+
StatusView["Init"] = "Init";
|
|
401
|
+
StatusView["Aligning"] = "Aligning";
|
|
402
|
+
StatusView["Start"] = "Start";
|
|
403
|
+
StatusView["Up"] = "Up";
|
|
404
|
+
StatusView["Down"] = "Down";
|
|
405
|
+
StatusView["Left"] = "Left";
|
|
406
|
+
StatusView["Right"] = "Right";
|
|
407
|
+
StatusView["Running"] = "Running";
|
|
408
|
+
StatusView["Confirm"] = "Confirm";
|
|
409
|
+
StatusView["Uploading"] = "Uploading";
|
|
410
|
+
StatusView["Select"] = "Select";
|
|
411
|
+
})(StatusView || (StatusView = {}));
|
|
412
|
+
var StatusAction;
|
|
413
|
+
(function (StatusAction) {
|
|
414
|
+
StatusAction["Uploading"] = "Uploading";
|
|
415
|
+
StatusAction["Show"] = "Show";
|
|
416
|
+
StatusAction["BtnClose"] = "BtnClose";
|
|
417
|
+
StatusAction["BtnStart"] = "BtnStart";
|
|
418
|
+
StatusAction["InitError"] = "InitError";
|
|
419
|
+
StatusAction["Start"] = "Start";
|
|
420
|
+
StatusAction["Confirm"] = "Confirm";
|
|
421
|
+
StatusAction["Retry"] = "Retry";
|
|
422
|
+
})(StatusAction || (StatusAction = {}));
|
|
423
|
+
var StatusDescription;
|
|
424
|
+
(function (StatusDescription) {
|
|
425
|
+
StatusDescription["NoCard"] = "NoCard";
|
|
426
|
+
StatusDescription["WrongCardType"] = "WrongCardType";
|
|
427
|
+
StatusDescription["PositionNotMatch"] = "PositionNotMatch";
|
|
428
|
+
StatusDescription["Reflective"] = "Reflective";
|
|
429
|
+
StatusDescription["Blur"] = "Blur";
|
|
430
|
+
StatusDescription["Pass"] = "Pass";
|
|
431
|
+
StatusDescription["Error"] = "Error";
|
|
432
|
+
StatusDescription["Failed"] = "Failed";
|
|
433
|
+
StatusDescription["Timeout"] = "Timeout";
|
|
434
|
+
StatusDescription["Gray"] = "Gray";
|
|
435
|
+
StatusDescription["NeedMoreFrame"] = "NeedMoreFrame";
|
|
436
|
+
StatusDescription["NotAligned"] = "NotAligned";
|
|
437
|
+
StatusDescription["NoFace"] = "NoFace";
|
|
438
|
+
StatusDescription["FaceNotAtCenter"] = "FaceNotAtCenter";
|
|
439
|
+
StatusDescription["FaceTooSmall"] = "FaceTooSmall";
|
|
440
|
+
StatusDescription["FaceTooLarge"] = "FaceTooLarge";
|
|
441
|
+
StatusDescription["NeedFaceToCamera"] = "NeedFaceToCamera";
|
|
442
|
+
StatusDescription["FaceMasked"] = "FaceMasked";
|
|
443
|
+
StatusDescription["NeedOpenMouth"] = "NeedOpenMouth";
|
|
444
|
+
StatusDescription["NeedCloseMouth"] = "NeedCloseMouth";
|
|
445
|
+
StatusDescription["NeedSmile"] = "NeedSmile";
|
|
446
|
+
StatusDescription["NeedOpenEyes"] = "NeedOpenEyes";
|
|
447
|
+
StatusDescription["UploadingStart"] = "UploadingStart";
|
|
448
|
+
StatusDescription["UploadingEnd"] = "UploadingEnd";
|
|
449
|
+
StatusDescription["Complete"] = "Complete";
|
|
450
|
+
})(StatusDescription || (StatusDescription = {}));
|
|
451
|
+
|
|
452
|
+
class TrackingEvent {
|
|
453
|
+
constructor(params) {
|
|
454
|
+
this._feature = params.feature;
|
|
455
|
+
this._event = params.event;
|
|
456
|
+
this._view = params.view;
|
|
457
|
+
this._action = params.action;
|
|
458
|
+
this._description = params.description;
|
|
459
|
+
}
|
|
460
|
+
nonNull(data) {
|
|
461
|
+
return data !== null && data !== undefined;
|
|
462
|
+
}
|
|
463
|
+
get feature() {
|
|
464
|
+
return this._feature;
|
|
465
|
+
}
|
|
466
|
+
set feature(value) {
|
|
467
|
+
if (value && !(value in Feature)) {
|
|
468
|
+
throw new Error('Invalid feature');
|
|
469
|
+
}
|
|
470
|
+
this._feature = value;
|
|
471
|
+
}
|
|
472
|
+
get event() {
|
|
473
|
+
return this._event;
|
|
474
|
+
}
|
|
475
|
+
set event(value) {
|
|
476
|
+
if (value && !(value in StatusEvent)) {
|
|
477
|
+
throw new Error('Invalid event');
|
|
478
|
+
}
|
|
479
|
+
this._event = value;
|
|
480
|
+
}
|
|
481
|
+
get view() {
|
|
482
|
+
return this._view;
|
|
483
|
+
}
|
|
484
|
+
set view(value) {
|
|
485
|
+
if (value && !(value in StatusView)) {
|
|
486
|
+
throw new Error('Invalid view');
|
|
487
|
+
}
|
|
488
|
+
this._view = value;
|
|
489
|
+
}
|
|
490
|
+
get action() {
|
|
491
|
+
return this._action;
|
|
492
|
+
}
|
|
493
|
+
set action(value) {
|
|
494
|
+
if (value && !(value in StatusAction)) {
|
|
495
|
+
throw new Error('Invalid action');
|
|
496
|
+
}
|
|
497
|
+
this._action = value;
|
|
498
|
+
}
|
|
499
|
+
get description() {
|
|
500
|
+
return this._description;
|
|
501
|
+
}
|
|
502
|
+
set description(value) {
|
|
503
|
+
if (value && !(value in StatusDescription)) {
|
|
504
|
+
throw new Error('Invalid description');
|
|
505
|
+
}
|
|
506
|
+
this._description = value;
|
|
507
|
+
}
|
|
508
|
+
toString() {
|
|
509
|
+
let result = '';
|
|
510
|
+
if (this.nonNull(this._feature)) {
|
|
511
|
+
result += `${this._feature}:`;
|
|
512
|
+
}
|
|
513
|
+
if (this.nonNull(this._event)) {
|
|
514
|
+
result += `${this._event}:`;
|
|
515
|
+
}
|
|
516
|
+
if (this.nonNull(this._view)) {
|
|
517
|
+
result += `${this._view}:`;
|
|
518
|
+
}
|
|
519
|
+
if (this.nonNull(this._action)) {
|
|
520
|
+
result += `${this._action}:`;
|
|
521
|
+
}
|
|
522
|
+
if (this.nonNull(this._description)) {
|
|
523
|
+
result += `${this._description}`;
|
|
524
|
+
}
|
|
525
|
+
if (result.endsWith(':')) {
|
|
526
|
+
result = result.slice(0, -1); // 刪除最後一個字符
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
return result;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
const tokenSubject = new BehaviorSubject('');
|
|
534
|
+
tokenSubject.pipe(tap(token => {
|
|
535
|
+
if (!token) return;
|
|
536
|
+
const _jwt = decodeToken(token);
|
|
537
|
+
setAuthmeJWT(_jwt.payload);
|
|
538
|
+
})).subscribe();
|
|
539
|
+
const defaultEventName = new TrackingEvent({});
|
|
540
|
+
const [getAuthmeJWT, setAuthmeJWT] = useState();
|
|
541
|
+
const [getAccessToken, setAccessToken] = useState('', tokenSubject);
|
|
542
|
+
const [getSessionId, setSessionId] = useState('');
|
|
543
|
+
function generateStatus(params = {}) {
|
|
544
|
+
const _authmeJWT = getAuthmeJWT();
|
|
545
|
+
const {
|
|
546
|
+
eventType = defaultEventName,
|
|
547
|
+
sessionId = getSessionId(),
|
|
548
|
+
userTime = new Date().toISOString(),
|
|
549
|
+
tenantId = _authmeJWT.client_tenant,
|
|
550
|
+
customerId = _authmeJWT.client_id,
|
|
551
|
+
duration = 0,
|
|
552
|
+
deviceInfo = getDeviceInfo(),
|
|
553
|
+
systemInfo = getSystemInfo(),
|
|
554
|
+
version: version$1 = version,
|
|
555
|
+
language = '',
|
|
556
|
+
description = '',
|
|
557
|
+
platform = 'web',
|
|
558
|
+
extraInfo = ''
|
|
559
|
+
} = params;
|
|
560
|
+
return {
|
|
561
|
+
eventId: v4(),
|
|
562
|
+
eventType: eventType.toString(),
|
|
563
|
+
sessionId,
|
|
564
|
+
userTime,
|
|
565
|
+
tenantId,
|
|
566
|
+
customerId,
|
|
567
|
+
duration,
|
|
568
|
+
deviceInfo,
|
|
569
|
+
systemInfo,
|
|
570
|
+
version: version$1,
|
|
571
|
+
language,
|
|
572
|
+
description,
|
|
573
|
+
platform,
|
|
574
|
+
extraInfo
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
export { AuthmeLanguage, EventListenerService, Feature, StatusAction, StatusDescription, StatusEvent, StatusView, TrackingEvent, core, generateStatus, getAccessToken, getSessionId, getTranslateInstance, sendRequest, setAccessToken, setRequestLoggingFunc, setSessionId, version };
|
package/package.json
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@authme/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.6",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"core-js": "^3.6.0",
|
|
6
|
-
"@authme/util": "2.
|
|
6
|
+
"@authme/util": "2.4.6",
|
|
7
|
+
"rxjs": "7.5.7",
|
|
8
|
+
"uuid": "8.3.2"
|
|
7
9
|
},
|
|
8
10
|
"module": "./index.js",
|
|
9
11
|
"main": "./index.cjs",
|
package/src/index.d.ts
CHANGED
|
@@ -2,6 +2,6 @@ export * from './lib/core';
|
|
|
2
2
|
export * from './lib/model';
|
|
3
3
|
export * from './lib/data-access';
|
|
4
4
|
export * from './lib/translate';
|
|
5
|
-
export * from './lib/authme-log';
|
|
6
5
|
export * from './lib/enum/language.enum';
|
|
6
|
+
export * from './lib/features';
|
|
7
7
|
export { version } from './lib/version';
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { DebugLog } from '@authme/util';
|
|
2
|
+
declare type LoggingFunc = (fun: () => Promise<any>, logParams?: Partial<DebugLog<any>>) => Promise<any>;
|
|
3
|
+
declare const setRequestLoggingFunc: (func: LoggingFunc) => void;
|
|
4
|
+
export { setRequestLoggingFunc };
|
|
1
5
|
export interface RequestOptions {
|
|
2
6
|
header: {
|
|
3
7
|
[header: string]: string;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BehaviorSubject } from 'rxjs';
|
|
2
|
+
import { EventTrackingStatus } from './status.interface';
|
|
3
|
+
declare class EventListenerService {
|
|
4
|
+
private readonly getStatusProcess;
|
|
5
|
+
private pingInterval;
|
|
6
|
+
private statusSubject;
|
|
7
|
+
private pingSubscription;
|
|
8
|
+
private apiService;
|
|
9
|
+
constructor(getStatusProcess: () => Promise<EventTrackingStatus>, options?: {
|
|
10
|
+
pingInterval?: number;
|
|
11
|
+
});
|
|
12
|
+
start(): void;
|
|
13
|
+
stop(): void;
|
|
14
|
+
sendUserActionStatus(status: EventTrackingStatus): Promise<any>;
|
|
15
|
+
private sendStatus;
|
|
16
|
+
getStatusObservable(): BehaviorSubject<EventTrackingStatus>;
|
|
17
|
+
}
|
|
18
|
+
export { EventListenerService };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { EventTrackingStatus } from './status.interface';
|
|
2
|
+
export declare class MockApiService {
|
|
3
|
+
private data;
|
|
4
|
+
postStatus(status: EventTrackingStatus): Promise<EventTrackingStatus>;
|
|
5
|
+
postMutiStatus(status: EventTrackingStatus[]): Promise<EventTrackingStatus[]>;
|
|
6
|
+
getStatus(): Promise<EventTrackingStatus[]>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export declare enum Feature {
|
|
2
|
+
OCRFraud = "OCRFraud",
|
|
3
|
+
OCR = "OCR",
|
|
4
|
+
SelectCardTypeAndCountry = "SelectCardTypeAndCountry",
|
|
5
|
+
LivenessActive = "LivenessActive",
|
|
6
|
+
LivenessPassive = "LivenessPassive"
|
|
7
|
+
}
|
|
8
|
+
export declare enum StatusEvent {
|
|
9
|
+
TWID = "TWID",
|
|
10
|
+
TWIDFraud = "TWIDFraud",
|
|
11
|
+
TWIDFront = "TWIDFront",
|
|
12
|
+
TWDriverLicenseFront = "TWDriverLicenseFront",
|
|
13
|
+
Passport = "Passport",
|
|
14
|
+
ResidencePermitFront = "ResidencePermitFront",
|
|
15
|
+
ResidencePermitBack = "ResidencePermitBack",
|
|
16
|
+
TWIDBack = "TWIDBack",
|
|
17
|
+
TWDriverLicenseBack = "TWDriverLicenseBack",
|
|
18
|
+
TWHealthCardFront = "TWHealthCardFront",
|
|
19
|
+
TWDriverLicense = "TWDriverLicense",
|
|
20
|
+
TWHealthCard = "TWHealthCard",
|
|
21
|
+
ResidencePermit = "ResidencePermit",
|
|
22
|
+
PassportFront = "PassportFront",
|
|
23
|
+
OpenMouth = "OpenMouth",
|
|
24
|
+
CloseMouth = "CloseMouth",
|
|
25
|
+
Smile = "Smile",
|
|
26
|
+
Scale = "Scale",
|
|
27
|
+
Done = "Done",
|
|
28
|
+
Passive = "Passive",
|
|
29
|
+
SelectCardTypeAndCountry = "SelectCardTypeAndCountry"
|
|
30
|
+
}
|
|
31
|
+
export declare enum StatusView {
|
|
32
|
+
Info = "Info",
|
|
33
|
+
Init = "Init",
|
|
34
|
+
Aligning = "Aligning",
|
|
35
|
+
Start = "Start",
|
|
36
|
+
Up = "Up",
|
|
37
|
+
Down = "Down",
|
|
38
|
+
Left = "Left",
|
|
39
|
+
Right = "Right",
|
|
40
|
+
Running = "Running",
|
|
41
|
+
Confirm = "Confirm",
|
|
42
|
+
Uploading = "Uploading",
|
|
43
|
+
Select = "Select"
|
|
44
|
+
}
|
|
45
|
+
export declare enum StatusAction {
|
|
46
|
+
Uploading = "Uploading",
|
|
47
|
+
Show = "Show",
|
|
48
|
+
BtnClose = "BtnClose",
|
|
49
|
+
BtnStart = "BtnStart",
|
|
50
|
+
InitError = "InitError",
|
|
51
|
+
Start = "Start",
|
|
52
|
+
Confirm = "Confirm",
|
|
53
|
+
Retry = "Retry"
|
|
54
|
+
}
|
|
55
|
+
export declare enum StatusDescription {
|
|
56
|
+
NoCard = "NoCard",
|
|
57
|
+
WrongCardType = "WrongCardType",
|
|
58
|
+
PositionNotMatch = "PositionNotMatch",
|
|
59
|
+
Reflective = "Reflective",
|
|
60
|
+
Blur = "Blur",
|
|
61
|
+
Pass = "Pass",
|
|
62
|
+
Error = "Error",
|
|
63
|
+
Failed = "Failed",
|
|
64
|
+
Timeout = "Timeout",
|
|
65
|
+
Gray = "Gray",
|
|
66
|
+
NeedMoreFrame = "NeedMoreFrame",
|
|
67
|
+
NotAligned = "NotAligned",
|
|
68
|
+
NoFace = "NoFace",
|
|
69
|
+
FaceNotAtCenter = "FaceNotAtCenter",
|
|
70
|
+
FaceTooSmall = "FaceTooSmall",
|
|
71
|
+
FaceTooLarge = "FaceTooLarge",
|
|
72
|
+
NeedFaceToCamera = "NeedFaceToCamera",
|
|
73
|
+
FaceMasked = "FaceMasked",
|
|
74
|
+
NeedOpenMouth = "NeedOpenMouth",
|
|
75
|
+
NeedCloseMouth = "NeedCloseMouth",
|
|
76
|
+
NeedSmile = "NeedSmile",
|
|
77
|
+
NeedOpenEyes = "NeedOpenEyes",
|
|
78
|
+
UploadingStart = "UploadingStart",
|
|
79
|
+
UploadingEnd = "UploadingEnd",
|
|
80
|
+
Complete = "Complete"
|
|
81
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Feature, StatusAction, StatusDescription, StatusEvent, StatusView } from './status.enum';
|
|
2
|
+
import { TrackingEvent } from './tracking-event';
|
|
3
|
+
export interface EventTrackingStatus {
|
|
4
|
+
eventId: string;
|
|
5
|
+
sessionId: string;
|
|
6
|
+
eventType: string;
|
|
7
|
+
userTime: string;
|
|
8
|
+
tenantId: string;
|
|
9
|
+
customerId: string;
|
|
10
|
+
duration: number;
|
|
11
|
+
deviceInfo: string;
|
|
12
|
+
systemInfo: string;
|
|
13
|
+
version: string;
|
|
14
|
+
language: string;
|
|
15
|
+
description: string;
|
|
16
|
+
platform: string;
|
|
17
|
+
extraInfo: string;
|
|
18
|
+
}
|
|
19
|
+
export interface GenerateStatusParams {
|
|
20
|
+
eventType?: TrackingEvent;
|
|
21
|
+
sessionId?: string;
|
|
22
|
+
userTime?: string;
|
|
23
|
+
tenantId?: string;
|
|
24
|
+
customerId?: string;
|
|
25
|
+
duration?: number;
|
|
26
|
+
deviceInfo?: string;
|
|
27
|
+
systemInfo?: string;
|
|
28
|
+
version?: string;
|
|
29
|
+
language?: string;
|
|
30
|
+
description?: string;
|
|
31
|
+
platform?: string;
|
|
32
|
+
extraInfo?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface NewEventNameDTO {
|
|
35
|
+
feature?: Feature;
|
|
36
|
+
event?: StatusEvent;
|
|
37
|
+
view?: StatusView;
|
|
38
|
+
action?: StatusAction;
|
|
39
|
+
description?: StatusDescription;
|
|
40
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { EventTrackingStatus, GenerateStatusParams } from './status.interface';
|
|
2
|
+
export declare const getAccessToken: () => string, setAccessToken: (value: string) => void;
|
|
3
|
+
export declare const getSessionId: () => string, setSessionId: (value: string) => void;
|
|
4
|
+
export declare function generateStatus(params?: GenerateStatusParams): EventTrackingStatus;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Feature, StatusAction, StatusDescription, StatusEvent, StatusView } from './status.enum';
|
|
2
|
+
import { NewEventNameDTO } from './status.interface';
|
|
3
|
+
export declare class TrackingEvent {
|
|
4
|
+
private _feature?;
|
|
5
|
+
private _event?;
|
|
6
|
+
private _view?;
|
|
7
|
+
private _action?;
|
|
8
|
+
private _description?;
|
|
9
|
+
constructor(params: NewEventNameDTO);
|
|
10
|
+
nonNull(data: any): boolean;
|
|
11
|
+
get feature(): Feature | undefined;
|
|
12
|
+
set feature(value: Feature | undefined);
|
|
13
|
+
get event(): StatusEvent | undefined;
|
|
14
|
+
set event(value: StatusEvent | undefined);
|
|
15
|
+
get view(): StatusView | undefined;
|
|
16
|
+
set view(value: StatusView | undefined);
|
|
17
|
+
get action(): StatusAction | undefined;
|
|
18
|
+
set action(value: StatusAction | undefined);
|
|
19
|
+
get description(): StatusDescription | undefined;
|
|
20
|
+
set description(value: StatusDescription | undefined);
|
|
21
|
+
toString(): string;
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './event-listener';
|
|
@@ -10,6 +10,7 @@ declare class TranslateService {
|
|
|
10
10
|
translate(key: string, args?: {
|
|
11
11
|
[key: string]: string | number;
|
|
12
12
|
}): string;
|
|
13
|
+
getCurrentLang(): AuthmeLanguage;
|
|
13
14
|
static instance: TranslateService | null;
|
|
14
15
|
}
|
|
15
16
|
declare function getTranslateInstance(): TranslateService;
|
package/src/lib/authme-log.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { debugLog } from '@authme/util';
|