@authme/identity-verification 2.8.16 → 2.8.18

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.
Files changed (3) hide show
  1. package/index.cjs +45 -4
  2. package/index.js +46 -5
  3. package/package.json +6 -6
package/index.cjs CHANGED
@@ -34,6 +34,7 @@ require('core-js/modules/es.typed-array.sort.js');
34
34
  require('core-js/modules/es.typed-array.to-locale-string.js');
35
35
  require('core-js/modules/es.string.pad-start.js');
36
36
  require('core-js/modules/es.string.match.js');
37
+ require('core-js/modules/es.string.starts-with.js');
37
38
  require('core-js/modules/es.regexp.constructor.js');
38
39
  require('core-js/modules/es.typed-array.uint8-array.js');
39
40
 
@@ -30804,6 +30805,20 @@ const ocrResultModal = arg => {
30804
30805
  }
30805
30806
  return regex.test(dateStr);
30806
30807
  }
30808
+ function isValidDate(dateStr, format) {
30809
+ if (format === 'yyy/MM/dd') {
30810
+ // 民國年格式轉換回西元年
30811
+ const _year2 = parseInt(dateStr.split('/')[0]) + 1911;
30812
+ dateStr = dateStr.replace(/^\d{3}/, _year2.toString());
30813
+ }
30814
+ // 先用正則檢查格式 yyyy/MM/dd
30815
+ const regex = /^\d{4}\/(0[1-9]|1[0-2])\/(0[1-9]|[12]\d|3[01])$/;
30816
+ if (!regex.test(dateStr)) return false;
30817
+ const [year, month, day] = dateStr.split('/').map(Number);
30818
+ const date = new Date(year, month - 1, day);
30819
+ // 檢查轉換後的日期是否一致(避免像 2023/02/30 自動變成 2023/03/02)
30820
+ return date.getFullYear() === year && date.getMonth() === month - 1 && date.getDate() === day;
30821
+ }
30807
30822
  function isValidDateBeforeToday(dateStr, format) {
30808
30823
  if (format === 'yyy/MM/dd') {
30809
30824
  // 民國年格式轉換回西元年
@@ -30823,6 +30838,25 @@ const ocrResultModal = arg => {
30823
30838
  return true; // 如果日期在今天之前或等於今天,返回 true
30824
30839
  }
30825
30840
 
30841
+ function parseRegex(input, forceUnicode = false) {
30842
+ try {
30843
+ let pattern = input;
30844
+ let flags = '';
30845
+ if (input.startsWith('/') && input.lastIndexOf('/') > 0) {
30846
+ const lastSlash = input.lastIndexOf('/');
30847
+ pattern = input.slice(1, lastSlash);
30848
+ flags = input.slice(lastSlash + 1);
30849
+ }
30850
+ // 如果有需要強制 Unicode 模式
30851
+ if (forceUnicode && !flags.includes('u')) {
30852
+ flags += 'u';
30853
+ }
30854
+ return new RegExp(pattern, flags);
30855
+ } catch (e) {
30856
+ console.warn('⚠️ 無效的 regex:', input, e);
30857
+ return null;
30858
+ }
30859
+ }
30826
30860
  function checkModifiedData() {
30827
30861
  const items = domModal.querySelectorAll('.video-container__ocrResultModal-group-item');
30828
30862
  items.forEach(item => {
@@ -30887,7 +30921,7 @@ const ocrResultModal = arg => {
30887
30921
  }
30888
30922
  }
30889
30923
  } else if (input && item.dateFormat) {
30890
- if (isValidDateFormat(input, item.dateFormat) && isValidDateBeforeToday(input.value, item.dateFormat)) {
30924
+ if (isValidDateFormat(input, item.dateFormat) && isValidDateBeforeToday(input.value, item.dateFormat) && isValidDate(input.value, item.dateFormat)) {
30891
30925
  // if (item.dateFormat.test(input.value)) {
30892
30926
  item.validate = true;
30893
30927
  (_g = domItem.querySelector('.video-container__ocrResultModal-input')) === null || _g === void 0 ? void 0 : _g.classList.remove('error');
@@ -30962,11 +30996,14 @@ const ocrResultModal = arg => {
30962
30996
  return ((_a = a.order) !== null && _a !== void 0 ? _a : Infinity) - ((_b = b.order) !== null && _b !== void 0 ? _b : Infinity);
30963
30997
  });
30964
30998
  arg.items.forEach(item => {
30999
+ var _a;
31000
+ const needsUnicode = ((_a = item.regex) === null || _a === void 0 ? void 0 : _a.includes('\\u')) || item.name === 'name';
31001
+ const parsed = parseRegex(item.regex, needsUnicode);
30965
31002
  // init validateMap
30966
31003
  if (item.regex) {
30967
31004
  validateMap[item.name] = {
30968
31005
  validate: false,
30969
- regex: new RegExp(item.regex.slice(1, -1))
31006
+ regex: parsed
30970
31007
  };
30971
31008
  } else if (item.selections) {
30972
31009
  validateMap[item.name] = {
@@ -32058,6 +32095,10 @@ function startOCR(config) {
32058
32095
  return rxjs.merge(flow$, cancel$, detectScreenResizeError$, timeout$).pipe(rxjs.take(1));
32059
32096
  }
32060
32097
  rxjs.fromEvent(window, 'offline').pipe(rxjs.switchMap(() => util.asyncOnLineShowErrorMessage(translateService.translate('sdk.general.error.alert.offline'), translateService.translate('sdk.general.error.retry'), false)), rxjs.takeUntil(unsubscribe$)).subscribe();
32098
+ rxjs.fromEvent(window, 'online').pipe(rxjs.switchMap(() => {
32099
+ util.hideErrorMessage(); // 執行副作用
32100
+ return rxjs.EMPTY; // 回傳一個空的 Observable
32101
+ }), rxjs.takeUntil(unsubscribe$)).subscribe();
32061
32102
  // resize
32062
32103
  rxjs.fromEvent(window, 'resize').pipe(rxjs.switchMapTo(util.getCanvasSize(uiComponentBasic.video)), rxjs.switchMap(canvasSizeInfo => config.setFrameSize(canvasSizeInfo.canvasWidth, canvasSizeInfo.canvasHeight, getCardBorderPoint())), rxjs.tap(() => {
32063
32104
  uiComponentOCR.scanAnimationContainer.style.width = `${cardSizeInfo.width + scanPadding}px`;
@@ -35871,8 +35912,8 @@ class AuthmeIdentityVerification extends engine.AuthmeFunctionModule {
35871
35912
  }
35872
35913
 
35873
35914
  var name = "authme/sdk";
35874
- var version$1 = "2.8.16";
35875
- var date = "2025-05-19T07:31:15+0000";
35915
+ var version$1 = "2.8.18";
35916
+ var date = "2025-05-26T03:17:12+0000";
35876
35917
  var packageInfo = {
35877
35918
  name: name,
35878
35919
  version: version$1,
package/index.js CHANGED
@@ -7,7 +7,7 @@ import 'core-js/modules/es.promise.js';
7
7
  import { getTranslateInstance, EventListenerService, TrackingEvent, generateStatus, StatusDescription, AuthmeError, ErrorCode, Feature, StatusEvent, StatusView, StatusAction, setRequestLoggingFunc, setAccessToken, getCustomerState } from '@authme/core';
8
8
  import { EAuthMeFASServiceStatus, EAuthMeIDCardAntiFraudStage as EAuthMeIDCardAntiFraudStage$1, EAuthMeCardClass as EAuthMeCardClass$1, AuthmeFunctionModule, MlEngine, EngineModule, EAuthMeEngineReturnCode, AuthmeEngineModuleBase } from '@authme/engine';
9
9
  import { IdRecognitionCardType, CountryCode, EAuthMeCardClass, EAuthMeIDCardAntiFraudStatus, EAuthMeIDCardAntiFraudStage, thicknessDefaultConfig, mapCardtypeToAuthmeClass, getRecognitionColumnOrder, cardTypeTitle, cardTypeConfirmTitle, cardTypeHeader, EAuthMeCardOCRStatus, EAuthMeMRZServiceStatus, saveExtraDoc, initScanDocumentResourceBase64, MRZService, option, themeUI, initScan, initScanDocument, ResourceImageType, uploadFrameBase64, finishScanDocument, CardOCR, IdCardAntiFraudService, twoWayAuthmeCardClassMap, RecognitionFileType, recognizeBase64, getCardSubTypes, getCardTypes, confirmScan } from '@authme/id-recognition';
10
- import { getCssVariable, RGBToLottieColor, colorToRGB, Storage, useState, uiThemeText, uiThemeHint, clearCanvas, getImageData, isMobile, hidePopup, showPopup, waitTime, TIME_UNIT, AuthmeError as AuthmeError$1, ErrorCode as ErrorCode$1, uiThemeButton, uiThemeSmallButton, requestCamera, showElement, asyncOnLineShowErrorMessage, getCanvasSize, startSpinner, stopSpinner, themeConfigDefault, fontWeight, hideElement, dataURItoBlob, showErrorMessage, checkOnlineStatus, dropMenu, UintArrayToBlob, isIphone14proOrProMax, cropByRatio, switchCamera, asyncShowPopup, retryPromiseWithCondition, asyncShowErrorMessage, hideErrorMessage, uploadModal, backgroundRequest, debugTools, showErrorMessageEventName, RUN_FUNCTION_NAME, STORAGE_KEY, splitResult, DEVICE_TYPE, combineResult, startLoadingSDK, stopLoadingSDK } from '@authme/util';
10
+ import { getCssVariable, RGBToLottieColor, colorToRGB, Storage, useState, uiThemeText, uiThemeHint, clearCanvas, getImageData, isMobile, hidePopup, showPopup, waitTime, TIME_UNIT, AuthmeError as AuthmeError$1, ErrorCode as ErrorCode$1, uiThemeButton, uiThemeSmallButton, requestCamera, showElement, asyncOnLineShowErrorMessage, getCanvasSize, startSpinner, stopSpinner, themeConfigDefault, fontWeight, hideElement, dataURItoBlob, showErrorMessage, checkOnlineStatus, dropMenu, hideErrorMessage, UintArrayToBlob, isIphone14proOrProMax, cropByRatio, switchCamera, asyncShowPopup, retryPromiseWithCondition, asyncShowErrorMessage, uploadModal, backgroundRequest, debugTools, showErrorMessageEventName, RUN_FUNCTION_NAME, STORAGE_KEY, splitResult, DEVICE_TYPE, combineResult, startLoadingSDK, stopLoadingSDK } from '@authme/util';
11
11
  import { mergeMap, animationFrames, filter, tap, map, from, catchError, EMPTY, of, merge, fromEvent, concatAll, takeUntil, Subject, defer, throttleTime, switchMap, raceWith, concatMap, throwError, finalize, timer, Observable, take, interval, mapTo, firstValueFrom, shareReplay, switchMapTo, takeWhile as takeWhile$1, race } from 'rxjs';
12
12
  import 'core-js/modules/es.regexp.to-string.js';
13
13
  import { FasRecognitionResult, EAuthMeFASServiceStage, FasService, LivenessAPI, EAuthMeMouthStatus, LivenessResultStatus } from '@authme/liveness';
@@ -30,6 +30,7 @@ import 'core-js/modules/es.typed-array.sort.js';
30
30
  import 'core-js/modules/es.typed-array.to-locale-string.js';
31
31
  import 'core-js/modules/es.string.pad-start.js';
32
32
  import 'core-js/modules/es.string.match.js';
33
+ import 'core-js/modules/es.string.starts-with.js';
33
34
  import 'core-js/modules/es.regexp.constructor.js';
34
35
  import 'core-js/modules/es.typed-array.uint8-array.js';
35
36
 
@@ -30796,6 +30797,20 @@ const ocrResultModal = arg => {
30796
30797
  }
30797
30798
  return regex.test(dateStr);
30798
30799
  }
30800
+ function isValidDate(dateStr, format) {
30801
+ if (format === 'yyy/MM/dd') {
30802
+ // 民國年格式轉換回西元年
30803
+ const _year2 = parseInt(dateStr.split('/')[0]) + 1911;
30804
+ dateStr = dateStr.replace(/^\d{3}/, _year2.toString());
30805
+ }
30806
+ // 先用正則檢查格式 yyyy/MM/dd
30807
+ const regex = /^\d{4}\/(0[1-9]|1[0-2])\/(0[1-9]|[12]\d|3[01])$/;
30808
+ if (!regex.test(dateStr)) return false;
30809
+ const [year, month, day] = dateStr.split('/').map(Number);
30810
+ const date = new Date(year, month - 1, day);
30811
+ // 檢查轉換後的日期是否一致(避免像 2023/02/30 自動變成 2023/03/02)
30812
+ return date.getFullYear() === year && date.getMonth() === month - 1 && date.getDate() === day;
30813
+ }
30799
30814
  function isValidDateBeforeToday(dateStr, format) {
30800
30815
  if (format === 'yyy/MM/dd') {
30801
30816
  // 民國年格式轉換回西元年
@@ -30815,6 +30830,25 @@ const ocrResultModal = arg => {
30815
30830
  return true; // 如果日期在今天之前或等於今天,返回 true
30816
30831
  }
30817
30832
 
30833
+ function parseRegex(input, forceUnicode = false) {
30834
+ try {
30835
+ let pattern = input;
30836
+ let flags = '';
30837
+ if (input.startsWith('/') && input.lastIndexOf('/') > 0) {
30838
+ const lastSlash = input.lastIndexOf('/');
30839
+ pattern = input.slice(1, lastSlash);
30840
+ flags = input.slice(lastSlash + 1);
30841
+ }
30842
+ // 如果有需要強制 Unicode 模式
30843
+ if (forceUnicode && !flags.includes('u')) {
30844
+ flags += 'u';
30845
+ }
30846
+ return new RegExp(pattern, flags);
30847
+ } catch (e) {
30848
+ console.warn('⚠️ 無效的 regex:', input, e);
30849
+ return null;
30850
+ }
30851
+ }
30818
30852
  function checkModifiedData() {
30819
30853
  const items = domModal.querySelectorAll('.video-container__ocrResultModal-group-item');
30820
30854
  items.forEach(item => {
@@ -30879,7 +30913,7 @@ const ocrResultModal = arg => {
30879
30913
  }
30880
30914
  }
30881
30915
  } else if (input && item.dateFormat) {
30882
- if (isValidDateFormat(input, item.dateFormat) && isValidDateBeforeToday(input.value, item.dateFormat)) {
30916
+ if (isValidDateFormat(input, item.dateFormat) && isValidDateBeforeToday(input.value, item.dateFormat) && isValidDate(input.value, item.dateFormat)) {
30883
30917
  // if (item.dateFormat.test(input.value)) {
30884
30918
  item.validate = true;
30885
30919
  (_g = domItem.querySelector('.video-container__ocrResultModal-input')) === null || _g === void 0 ? void 0 : _g.classList.remove('error');
@@ -30954,11 +30988,14 @@ const ocrResultModal = arg => {
30954
30988
  return ((_a = a.order) !== null && _a !== void 0 ? _a : Infinity) - ((_b = b.order) !== null && _b !== void 0 ? _b : Infinity);
30955
30989
  });
30956
30990
  arg.items.forEach(item => {
30991
+ var _a;
30992
+ const needsUnicode = ((_a = item.regex) === null || _a === void 0 ? void 0 : _a.includes('\\u')) || item.name === 'name';
30993
+ const parsed = parseRegex(item.regex, needsUnicode);
30957
30994
  // init validateMap
30958
30995
  if (item.regex) {
30959
30996
  validateMap[item.name] = {
30960
30997
  validate: false,
30961
- regex: new RegExp(item.regex.slice(1, -1))
30998
+ regex: parsed
30962
30999
  };
30963
31000
  } else if (item.selections) {
30964
31001
  validateMap[item.name] = {
@@ -32050,6 +32087,10 @@ function startOCR(config) {
32050
32087
  return merge(flow$, cancel$, detectScreenResizeError$, timeout$).pipe(take(1));
32051
32088
  }
32052
32089
  fromEvent(window, 'offline').pipe(switchMap(() => asyncOnLineShowErrorMessage(translateService.translate('sdk.general.error.alert.offline'), translateService.translate('sdk.general.error.retry'), false)), takeUntil(unsubscribe$)).subscribe();
32090
+ fromEvent(window, 'online').pipe(switchMap(() => {
32091
+ hideErrorMessage(); // 執行副作用
32092
+ return EMPTY; // 回傳一個空的 Observable
32093
+ }), takeUntil(unsubscribe$)).subscribe();
32053
32094
  // resize
32054
32095
  fromEvent(window, 'resize').pipe(switchMapTo(getCanvasSize(uiComponentBasic.video)), switchMap(canvasSizeInfo => config.setFrameSize(canvasSizeInfo.canvasWidth, canvasSizeInfo.canvasHeight, getCardBorderPoint())), tap(() => {
32055
32096
  uiComponentOCR.scanAnimationContainer.style.width = `${cardSizeInfo.width + scanPadding}px`;
@@ -35863,8 +35904,8 @@ class AuthmeIdentityVerification extends AuthmeFunctionModule {
35863
35904
  }
35864
35905
 
35865
35906
  var name = "authme/sdk";
35866
- var version$1 = "2.8.16";
35867
- var date = "2025-05-19T07:31:15+0000";
35907
+ var version$1 = "2.8.18";
35908
+ var date = "2025-05-26T03:17:12+0000";
35868
35909
  var packageInfo = {
35869
35910
  name: name,
35870
35911
  version: version$1,
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@authme/identity-verification",
3
- "version": "2.8.16",
3
+ "version": "2.8.18",
4
4
  "peerDependencies": {
5
5
  "core-js": "^3.6.0",
6
6
  "lottie-web": "^5.9.2",
7
7
  "rxjs": "^7.4.0",
8
- "@authme/core": "2.8.16",
9
- "@authme/engine": "2.8.16",
10
- "@authme/id-recognition": "2.8.16",
11
- "@authme/liveness": "2.8.16",
12
- "@authme/util": "2.8.16"
8
+ "@authme/core": "2.8.18",
9
+ "@authme/engine": "2.8.18",
10
+ "@authme/id-recognition": "2.8.18",
11
+ "@authme/liveness": "2.8.18",
12
+ "@authme/util": "2.8.18"
13
13
  },
14
14
  "module": "./index.js",
15
15
  "main": "./index.cjs",