@bytexbyte/berifyme-react-sdk 1.0.17 → 1.0.19

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 (57) hide show
  1. package/dist/BerifymeModal/index.js +4 -4
  2. package/dist/api/api.js +39 -4
  3. package/dist/components/AllSet/index.js +3 -3
  4. package/dist/components/OnBoarding/incode/SelectType.js +7 -3
  5. package/dist/components/OnBoarding/incode/index.js +13 -14
  6. package/dist/components/SendSns/index.js +18 -15
  7. package/dist/components/SnapMatch/ExceptionView.js +22 -0
  8. package/dist/components/SnapMatch/LangSelector.js +26 -0
  9. package/dist/components/SnapMatch/SnapMatchStep.js +122 -0
  10. package/dist/components/SnapMatch/SuccessView.js +22 -0
  11. package/dist/components/SnapMatch/TryAgainView.js +19 -0
  12. package/dist/components/SnapMatch/index.js +271 -0
  13. package/dist/components/SnapMatch/translations.js +32 -0
  14. package/dist/components/VerifyWithPhoneNumber/User/index.js +12 -9
  15. package/dist/index.js +6 -1
  16. package/dist/types/api/api.d.ts +7 -1
  17. package/dist/types/components/OnBoarding/incode/SelectType.d.ts +2 -1
  18. package/dist/types/components/OnBoarding/incode/index.d.ts +1 -0
  19. package/dist/types/components/SnapMatch/ExceptionView.d.ts +11 -0
  20. package/dist/types/components/SnapMatch/LangSelector.d.ts +11 -0
  21. package/dist/types/components/SnapMatch/SnapMatchStep.d.ts +23 -0
  22. package/dist/types/components/SnapMatch/SuccessView.d.ts +11 -0
  23. package/dist/types/components/SnapMatch/TryAgainView.d.ts +11 -0
  24. package/dist/types/components/SnapMatch/index.d.ts +17 -0
  25. package/dist/types/components/SnapMatch/translations.d.ts +54 -0
  26. package/dist/types/index.d.ts +6 -1
  27. package/dist/types/vender/incode/incode.d.ts +6 -2
  28. package/dist/types/vender/incode/translations/en.d.ts +2638 -0
  29. package/dist/types/vender/incode/translations/zh-TW.d.ts +2634 -0
  30. package/dist/vender/incode/incode.js +81 -5
  31. package/dist/vender/incode/translations/en.js +2638 -0
  32. package/dist/vender/incode/translations/zh-TW.js +2634 -0
  33. package/package.json +5 -2
  34. package/dist/components/Login/sumsub/index.js +0 -212
  35. package/dist/components/Login/veriff/Login.js +0 -168
  36. package/dist/components/Login/veriff/index.js +0 -14
  37. package/dist/components/Login/yoti/Login.js +0 -245
  38. package/dist/components/Login/yoti/index.js +0 -14
  39. package/dist/components/OnBoarding/sumsub/index.js +0 -183
  40. package/dist/components/OnBoarding/veriff/index.js +0 -152
  41. package/dist/components/OnBoarding/yoti/OnBoarding.js +0 -238
  42. package/dist/components/OnBoarding/yoti/index.js +0 -14
  43. package/dist/components/TryAgain.js +0 -16
  44. package/dist/components/TryAgainInModal.js +0 -15
  45. package/dist/event.js +0 -18
  46. package/dist/types/components/Login/sumsub/index.d.ts +0 -10
  47. package/dist/types/components/Login/veriff/Login.d.ts +0 -12
  48. package/dist/types/components/Login/veriff/index.d.ts +0 -11
  49. package/dist/types/components/Login/yoti/Login.d.ts +0 -11
  50. package/dist/types/components/Login/yoti/index.d.ts +0 -10
  51. package/dist/types/components/OnBoarding/sumsub/index.d.ts +0 -10
  52. package/dist/types/components/OnBoarding/veriff/index.d.ts +0 -11
  53. package/dist/types/components/OnBoarding/yoti/OnBoarding.d.ts +0 -12
  54. package/dist/types/components/OnBoarding/yoti/index.d.ts +0 -11
  55. package/dist/types/components/TryAgain.d.ts +0 -6
  56. package/dist/types/components/TryAgainInModal.d.ts +0 -6
  57. package/dist/types/event.d.ts +0 -9
@@ -50,19 +50,19 @@ import { ClearOnboarding } from '../components/OnBoarding/clear';
50
50
  import { ClearOnboardingAllSet } from '../components/OnBoarding/clear/clearAllSet';
51
51
  import { IncodeOnBoarding } from '../components/OnBoarding/incode';
52
52
  import Vender from '../components/OnBoarding/vender';
53
+ import QrcodeExpired from '../components/QrcodeExpired';
53
54
  import RedirectToMobile from '../components/RedirectToMobile';
54
55
  import ScreenRotation from '../components/ScreenRotation';
55
56
  import SendSns from '../components/SendSns';
56
- import theme from '../components/theme';
57
+ import SessionInterrupted from '../components/SessionInterrupted';
57
58
  import SomethingWrong from '../components/SomethingWrong';
59
+ import theme from '../components/theme';
58
60
  import VerifyNewUser from '../components/VerifyWithPhoneNumber/NewUser';
59
61
  import VerifyUser from '../components/VerifyWithPhoneNumber/User';
60
62
  import { getPageStatusString, PageStatus } from '../enum';
61
63
  import { environmentDomains } from '../lib/environmentDomains';
62
64
  import { incode } from '../vender/incode/incode';
63
65
  import Modal from './MainModal';
64
- import QrcodeExpired from '../components/QrcodeExpired';
65
- import SessionInterrupted from '../components/SessionInterrupted';
66
66
  var HomeModal = function (_a) {
67
67
  var apiKeyId = _a.apiKeyId, secretKey = _a.secretKey, redirectUrl = _a.redirectUrl, _b = _a.initialPhoneNumber, initialPhoneNumber = _b === void 0 ? '' : _b, environment = _a.environment, forceQrcode = _a.forceQrcode, onUpdate = _a.onUpdate;
68
68
  var _c = useState(window.innerWidth > window.innerHeight), isLandscape = _c[0], setIsLandscape = _c[1];
@@ -353,7 +353,7 @@ var HomeModal = function (_a) {
353
353
  pageStatus === PageStatus.ClearOnboarding && user &&
354
354
  React.createElement(ClearOnboarding, { token: token, user: user, desktopRedirectUrlId: desktopRedirectUrlId }),
355
355
  pageStatus === PageStatus.IncodeOnBoarding && user &&
356
- React.createElement(IncodeOnBoarding, { user: user, setUser: setUser, token: token, goToAllSet: function () { return setPageStatus(PageStatus.AllSet); }, setError: setError }),
356
+ React.createElement(IncodeOnBoarding, { user: user, setUser: setUser, token: token, goToAllSet: function () { return setPageStatus(PageStatus.AllSet); }, setError: setError, onGoBack: function () { return setPageStatus(PageStatus.Vender); } }),
357
357
  pageStatus === PageStatus.AuthidLogin && processedPhoneNumber &&
358
358
  React.createElement(AuthidLogin, { token: token, goToAllSet: function () { return setPageStatus(PageStatus.AllSet); }, phoneNumber: processedPhoneNumber, setUser: setUser, setError: setError }),
359
359
  pageStatus === PageStatus.ClearLogin &&
package/dist/api/api.js CHANGED
@@ -794,6 +794,40 @@ function createSessionToken(_a) {
794
794
  });
795
795
  });
796
796
  }
797
+ /** SnapMatch(1:N)用:建立 session token(無 redirectUrl),回傳 sessionToken(session_ 前綴) */
798
+ function createSessionTokenWithoutRedirectUrl(_a) {
799
+ return __awaiter(this, arguments, void 0, function (_b) {
800
+ var url, res, error_2;
801
+ var _c;
802
+ var apiKeyId = _b.apiKeyId, secretKey = _b.secretKey;
803
+ return __generator(this, function (_d) {
804
+ switch (_d.label) {
805
+ case 0:
806
+ url = "".concat(config.backendDomain, "/api/thirdParty/createTokenWithoutRedirectUrl");
807
+ _d.label = 1;
808
+ case 1:
809
+ _d.trys.push([1, 3, , 4]);
810
+ return [4 /*yield*/, axios.post(url, {
811
+ apiKeyId: apiKeyId,
812
+ secretKey: secretKey,
813
+ })];
814
+ case 2:
815
+ res = _d.sent();
816
+ return [2 /*return*/, res.data];
817
+ case 3:
818
+ error_2 = _d.sent();
819
+ if (error_2.response) {
820
+ return [2 /*return*/, { error: ((_c = error_2.response.data) === null || _c === void 0 ? void 0 : _c.error) || 'An error occurred. Please try again.' }];
821
+ }
822
+ else if (error_2.request) {
823
+ return [2 /*return*/, { error: 'No response from server. Please check your network and try again.' }];
824
+ }
825
+ return [2 /*return*/, { error: 'Unexpected error. Please try again later.' }];
826
+ case 4: return [2 /*return*/];
827
+ }
828
+ });
829
+ });
830
+ }
797
831
  function createAuthenticationLogs(_a) {
798
832
  return __awaiter(this, arguments, void 0, function (_b) {
799
833
  var url, res;
@@ -848,7 +882,7 @@ function updateAuthenticationLogs(_a) {
848
882
  }
849
883
  function createDeveloperLog(_a) {
850
884
  return __awaiter(this, arguments, void 0, function (_b) {
851
- var url, res, error_2;
885
+ var url, res, error_3;
852
886
  var userId = _b.userId, sessionToken = _b.sessionToken, action = _b.action, firstDetail = _b.firstDetail, secondDetail = _b.secondDetail, userDataJson = _b.userDataJson, source = _b.source, browser = _b.browser;
853
887
  return __generator(this, function (_c) {
854
888
  switch (_c.label) {
@@ -876,9 +910,9 @@ function createDeveloperLog(_a) {
876
910
  res = _c.sent();
877
911
  return [2 /*return*/, res.data];
878
912
  case 3:
879
- error_2 = _c.sent();
880
- console.error('Error creating developer log:', error_2);
881
- throw error_2;
913
+ error_3 = _c.sent();
914
+ console.error('Error creating developer log:', error_3);
915
+ throw error_3;
882
916
  case 4: return [2 /*return*/];
883
917
  }
884
918
  });
@@ -1181,6 +1215,7 @@ var berifymeApi = {
1181
1215
  getRedirectUrl: getRedirectUrl,
1182
1216
  checkThirdPartyVerificationToken: checkThirdPartyVerificationToken,
1183
1217
  checkDesktopRedirectUrlIdExpired: checkDesktopRedirectUrlIdExpired,
1218
+ createSessionTokenWithoutRedirectUrl: createSessionTokenWithoutRedirectUrl,
1184
1219
  },
1185
1220
  scheduld: {
1186
1221
  initUpdateAdminTokenSchedule: initUpdateAdminTokenSchedule,
@@ -101,9 +101,9 @@ var AllSet = function (_a) {
101
101
  checkOldDeviceId();
102
102
  }, [user === null || user === void 0 ? void 0 : user.phoneNumber]);
103
103
  var checkAndIssueToken = function () {
104
- // if (user) {
105
- // berifymeApi.blockchain.checkAndIssueToken({ userId: user.id });
106
- // }
104
+ if (user) {
105
+ berifymeApi.blockchain.checkAndIssueToken({ userId: user.id });
106
+ }
107
107
  };
108
108
  var startSpeedTest = useSpeedTest().startSpeedTest;
109
109
  useEffect(function () {
@@ -34,15 +34,19 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
34
34
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
35
  }
36
36
  };
37
- import { Button, Stack, Typography } from "@mui/material";
38
- import Layout from "../../Layout";
37
+ import CloseIcon from "@mui/icons-material/Close";
38
+ import { Button, IconButton, Stack, Typography } from "@mui/material";
39
39
  import React from "react";
40
+ import Layout from "../../Layout";
40
41
  var SelectType = function (_a) {
41
- var goToID = _a.goToID, goToPassport = _a.goToPassport;
42
+ var goToID = _a.goToID, goToPassport = _a.goToPassport, onCloseButtonClick = _a.onCloseButtonClick;
42
43
  return (React.createElement(React.Fragment, null,
43
44
  React.createElement(Layout, null,
44
45
  React.createElement(Stack, { minHeight: 1, width: 1, spacing: 4, maxHeight: 900, py: 20, justifyContent: 'space-between' },
45
46
  React.createElement(Stack, { spacing: 2 },
47
+ React.createElement(Stack, { direction: 'row', justifyContent: 'flex-end' },
48
+ React.createElement(IconButton, { onClick: onCloseButtonClick },
49
+ React.createElement(CloseIcon, null))),
46
50
  React.createElement(Stack, { spacing: 1, textAlign: 'center' },
47
51
  React.createElement(Typography, { variant: "h3", fontWeight: 700 }, "Select what document you want to scan"))),
48
52
  React.createElement(Stack, { spacing: 2, alignItems: 'center' },
@@ -34,23 +34,22 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
34
34
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
35
  }
36
36
  };
37
- import React from "react";
38
- import { useEffect, useRef, useState } from "react";
39
- import Steps from "./Steps";
40
- import { UserConsent } from "./UserConsent";
41
- import { FrontId } from "./FrontId";
42
- import { BackId } from "./BackId";
43
- import { ProcessId } from "./ProcessId";
44
- import { Selfie } from "./Selfie";
45
- import { ProcessFace } from "./ProcessFace";
46
- import { FinishOnboarding } from "./FinishOnboarding";
47
- import SelectType from "./SelectType";
48
- import { Passport } from "./Passport";
49
37
  import { Box, CircularProgress } from "@mui/material";
38
+ import React, { useEffect, useRef, useState } from "react";
50
39
  import berifymeApi, { ActionType } from "../../../api/api";
51
40
  import { createAuthenticationLog, updateAuthenticationLog } from "../../AuthenticationLogs";
52
41
  import { createDeveloperLog } from "../../createDeveloperLog";
42
+ import { BackId } from "./BackId";
43
+ import { FinishOnboarding } from "./FinishOnboarding";
44
+ import { FrontId } from "./FrontId";
45
+ import { Passport } from "./Passport";
46
+ import { ProcessFace } from "./ProcessFace";
53
47
  import { ProcessGlobalWatchlist } from "./processGlobalWatchlist";
48
+ import { ProcessId } from "./ProcessId";
49
+ import SelectType from "./SelectType";
50
+ import { Selfie } from "./Selfie";
51
+ import Steps from "./Steps";
52
+ import { UserConsent } from "./UserConsent";
54
53
  function startOnboardingSession(_a) {
55
54
  return __awaiter(this, arguments, void 0, function (_b) {
56
55
  var res;
@@ -66,7 +65,7 @@ function startOnboardingSession(_a) {
66
65
  });
67
66
  }
68
67
  var IncodeOnBoarding = function (_a) {
69
- var user = _a.user, setUser = _a.setUser, goToAllSet = _a.goToAllSet, token = _a.token, setError = _a.setError;
68
+ var user = _a.user, setUser = _a.setUser, goToAllSet = _a.goToAllSet, token = _a.token, setError = _a.setError, onGoBack = _a.onGoBack;
70
69
  var _b = useState(0), step = _b[0], setStep = _b[1]; // Store the current step
71
70
  var _c = useState(null), session = _c[0], setSession = _c[1]; // Stores the Session
72
71
  var isLoaded = useRef(false);
@@ -218,7 +217,7 @@ var IncodeOnBoarding = function (_a) {
218
217
  React.createElement(CircularProgress, null)));
219
218
  return (React.createElement(React.Fragment, null, user.id && React.createElement(Steps, { currentStep: step },
220
219
  React.createElement(UserConsent, { session: session, onSuccess: goNext }),
221
- React.createElement(SelectType, { goToID: goNext, goToPassport: function () { goTo(4); } }),
220
+ React.createElement(SelectType, { goToID: goNext, goToPassport: function () { goTo(4); }, onCloseButtonClick: onGoBack }),
222
221
  React.createElement(FrontId, { session: session, onError: handleError, onSuccess: goNext }),
223
222
  React.createElement(BackId, { session: session, onError: handleError, onSuccess: function () { goTo(5); } }),
224
223
  React.createElement(Passport, { session: session, onError: handleError, onSuccess: goNext }),
@@ -130,7 +130,7 @@ var SendSns = function (_a) {
130
130
  })];
131
131
  case 2:
132
132
  webauthnLogin = _f.sent();
133
- if (!webauthnLogin.success) return [3 /*break*/, 5];
133
+ if (!webauthnLogin.success) return [3 /*break*/, 6];
134
134
  createDeveloperLog({
135
135
  userId: (_d = webauthnLogin.user.id) !== null && _d !== void 0 ? _d : '',
136
136
  source: 'FRONTEND',
@@ -139,10 +139,13 @@ var SendSns = function (_a) {
139
139
  userDataJson: webauthnLogin.user,
140
140
  });
141
141
  setUser(webauthnLogin.user);
142
+ return [4 /*yield*/, berifymeApi.wallet.getWallet({ phoneNumber: processedInputValue })];
143
+ case 3:
144
+ _f.sent();
142
145
  deviceId = localStorage.getItem('deviceId');
143
- if (!(deviceId && token)) return [3 /*break*/, 4];
146
+ if (!(deviceId && token)) return [3 /*break*/, 5];
144
147
  return [4 /*yield*/, berifymeApi.user.checkDeviceId({ phoneNumber: processedInputValue, deviceId: deviceId, token: token })];
145
- case 3:
148
+ case 4:
146
149
  deviceUser = _f.sent();
147
150
  if (deviceUser.user) {
148
151
  createDeveloperLog({
@@ -182,8 +185,8 @@ var SendSns = function (_a) {
182
185
  firstDetail: deviceUser.error,
183
186
  secondDetail: "deviceId: ".concat(deviceId),
184
187
  });
185
- _f.label = 4;
186
- case 4:
188
+ _f.label = 5;
189
+ case 5:
187
190
  // const blockchainToken = await berifymeApi.blockchain.getNFTToken({ phoneNumber: processedInputValue });
188
191
  // if (blockchainToken && blockchainToken.nfts.length > 0 && token) {
189
192
  // const blockchainTokenId = blockchainToken.nfts[0].tokenId;
@@ -246,17 +249,17 @@ var SendSns = function (_a) {
246
249
  secondDetail: 'webauthn success'
247
250
  });
248
251
  return [2 /*return*/];
249
- case 5:
252
+ case 6:
250
253
  createDeveloperLog({
251
254
  source: 'FRONTEND',
252
255
  action: 'webauthnLogin failed',
253
256
  sessionToken: token,
254
257
  });
255
- _f.label = 6;
256
- case 6:
257
- if (!(getVender.vender === null)) return [3 /*break*/, 8];
258
- return [4 /*yield*/, berifymeApi.auth.sendPhoneNumberCode({ phoneNumber: processedInputValue, token: token })];
258
+ _f.label = 7;
259
259
  case 7:
260
+ if (!(getVender.vender === null)) return [3 /*break*/, 9];
261
+ return [4 /*yield*/, berifymeApi.auth.sendPhoneNumberCode({ phoneNumber: processedInputValue, token: token })];
262
+ case 8:
260
263
  res = _f.sent();
261
264
  if (res.success) {
262
265
  setPageStatus(1);
@@ -275,9 +278,9 @@ var SendSns = function (_a) {
275
278
  firstDetail: res.error,
276
279
  });
277
280
  }
278
- return [3 /*break*/, 10];
279
- case 8: return [4 /*yield*/, berifymeApi.auth.sendPhoneNumberCode({ phoneNumber: processedInputValue, token: token })];
280
- case 9:
281
+ return [3 /*break*/, 11];
282
+ case 9: return [4 /*yield*/, berifymeApi.auth.sendPhoneNumberCode({ phoneNumber: processedInputValue, token: token })];
283
+ case 10:
281
284
  res = _f.sent();
282
285
  if (res.success) {
283
286
  setModalHeight('50vh');
@@ -297,8 +300,8 @@ var SendSns = function (_a) {
297
300
  firstDetail: res.error,
298
301
  });
299
302
  }
300
- _f.label = 10;
301
- case 10:
303
+ _f.label = 11;
304
+ case 11:
302
305
  setIsLoading(false);
303
306
  createDeveloperLog({
304
307
  source: 'FRONTEND',
@@ -0,0 +1,22 @@
1
+ import React from "react";
2
+ import { Button, Container, Stack, Typography } from "@mui/material";
3
+ import WarningAmberRoundedIcon from "@mui/icons-material/WarningAmberRounded";
4
+ import { getSnapMatchResultTranslations } from "./translations";
5
+ var ExceptionView = function (_a) {
6
+ var lang = _a.lang, message = _a.message, onBack = _a.onBack, _b = _a.returnLoading, returnLoading = _b === void 0 ? false : _b, _c = _a.autoRedirectSeconds, autoRedirectSeconds = _c === void 0 ? 0 : _c, _d = _a.countdown, countdown = _d === void 0 ? 0 : _d;
7
+ var t = getSnapMatchResultTranslations(lang);
8
+ var handleBack = function () {
9
+ if (onBack)
10
+ onBack();
11
+ else
12
+ window.location.reload();
13
+ };
14
+ return (React.createElement(Container, { maxWidth: "sm", sx: { px: 3 } },
15
+ React.createElement(Stack, { height: "100vh", width: 1, maxHeight: 900, justifyContent: "center", alignItems: "center", spacing: 4 },
16
+ React.createElement(WarningAmberRoundedIcon, { sx: { fontSize: 64, color: "warning.main" }, "aria-hidden": true }),
17
+ React.createElement(Typography, { variant: "h3", fontWeight: 700, textAlign: "center", sx: { whiteSpace: "pre-line" } }, t.exceptionTitle),
18
+ React.createElement(Typography, { variant: "body1", color: "text.secondary", textAlign: "center", sx: { whiteSpace: "pre-line" } }, message !== null && message !== void 0 ? message : t.exceptionDescription),
19
+ autoRedirectSeconds > 0 && (React.createElement(Typography, { variant: "body2", color: "text.secondary", sx: { whiteSpace: "pre-line" } }, countdown > 0 ? t.countdownReturn(countdown) : t.redirecting)),
20
+ React.createElement(Button, { variant: "contained", color: "warning", onClick: handleBack, disabled: returnLoading, fullWidth: true, sx: { whiteSpace: "pre-line" } }, returnLoading ? t.redirecting : t.backToVerification))));
21
+ };
22
+ export default ExceptionView;
@@ -0,0 +1,26 @@
1
+ import React from "react";
2
+ import { Box, Button, Typography } from "@mui/material";
3
+ import TranslateIcon from "@mui/icons-material/Translate";
4
+ export var LANG_OPTIONS = [
5
+ { value: "en", label: "English" },
6
+ { value: "zh-TW", label: "繁體中文" },
7
+ ];
8
+ function LangSelector(_a) {
9
+ var _b, _c;
10
+ var lang = _a.lang, onLangChange = _a.onLangChange;
11
+ var nextLang = lang === "en" ? "zh-TW" : "en";
12
+ var currentLabel = (_c = (_b = LANG_OPTIONS.find(function (o) { return o.value === lang; })) === null || _b === void 0 ? void 0 : _b.label) !== null && _c !== void 0 ? _c : lang;
13
+ return (React.createElement(Box, { sx: {
14
+ position: "fixed",
15
+ top: 16,
16
+ right: 16,
17
+ zIndex: 2147483647,
18
+ pointerEvents: "auto",
19
+ } },
20
+ React.createElement(Button, { variant: "outlined", size: "small", onClick: function () { return onLangChange(nextLang); }, startIcon: React.createElement(TranslateIcon, null), sx: {
21
+ bgcolor: "background.paper",
22
+ "&:hover": { bgcolor: "action.hover" },
23
+ } },
24
+ React.createElement(Typography, { variant: "body2" }, currentLabel))));
25
+ }
26
+ export default LangSelector;
@@ -0,0 +1,122 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import React, { useEffect, useRef } from "react";
38
+ import { Box, CircularProgress } from "@mui/material";
39
+ import { createIncodeLogin } from "../../vender/incode/incode";
40
+ /** 清空容器前先停止所有 video 的 MediaStream,正確釋放相機,避免 reload 後新頁面無法取得相機或卡在權限 */
41
+ function stopAllMediaStreamsInContainer(container) {
42
+ try {
43
+ container.querySelectorAll("video").forEach(function (el) {
44
+ var src = el.srcObject;
45
+ if (src && typeof src.getTracks === "function") {
46
+ src.getTracks().forEach(function (track) { return track.stop(); });
47
+ }
48
+ });
49
+ }
50
+ catch (_a) {
51
+ // ignore
52
+ }
53
+ }
54
+ /**
55
+ * 直接開啟 Incode SnapMatch(1:N)驗證步驟。
56
+ * 與 Frontend SnapMatchStep 對齊:僅依 lang 建立實例並轉發結果,父層負責 getUserByIncodeId 與 step。
57
+ * 以 key={`${lang}-${loginKey}`} 渲染可強制語系切換/返回時完整重掛載,避免 Incode 翻譯 cache。
58
+ */
59
+ var SnapMatchStep = function (_a) {
60
+ var lang = _a.lang, loginKey = _a.loginKey, onSuccess = _a.onSuccess, onError = _a.onError;
61
+ var containerRef = useRef(null);
62
+ var loginKeyRef = useRef(loginKey);
63
+ loginKeyRef.current = loginKey;
64
+ useEffect(function () {
65
+ var container = containerRef.current;
66
+ if (!container)
67
+ return;
68
+ var cancelled = false;
69
+ var currentKey = loginKeyRef.current;
70
+ // 延遲再掛載,讓上一輪 cleanup(清空容器、釋放相機)完成,避免 Incode 全域 i18n/狀態殘留導致翻譯錯亂
71
+ var delayMs = 120;
72
+ var t = setTimeout(function () {
73
+ if (cancelled)
74
+ return;
75
+ void createIncodeLogin(lang).then(function (instance) {
76
+ var _a;
77
+ if (cancelled || !containerRef.current)
78
+ return;
79
+ instance.renderLogin(container, {
80
+ onSuccess: function (response) { return __awaiter(void 0, void 0, void 0, function () {
81
+ return __generator(this, function (_a) {
82
+ if (cancelled)
83
+ return [2 /*return*/];
84
+ onSuccess({
85
+ customerId: response.customerId,
86
+ interviewId: response.interviewId,
87
+ token: response.token,
88
+ transactionId: response.transactionId,
89
+ }, { loginKey: currentKey });
90
+ return [2 /*return*/];
91
+ });
92
+ }); },
93
+ onError: function () {
94
+ if (cancelled)
95
+ return;
96
+ onError();
97
+ },
98
+ stopAtError: true,
99
+ timeout: 1000 * 60 * 60 * 24,
100
+ });
101
+ if ((_a = instance.i18n) === null || _a === void 0 ? void 0 : _a.changeLanguage) {
102
+ setTimeout(function () {
103
+ var _a, _b;
104
+ if (cancelled)
105
+ return;
106
+ void ((_b = (_a = instance.i18n) === null || _a === void 0 ? void 0 : _a.changeLanguage) === null || _b === void 0 ? void 0 : _b.call(_a, "en"));
107
+ }, 200);
108
+ }
109
+ });
110
+ }, delayMs);
111
+ return function () {
112
+ cancelled = true;
113
+ clearTimeout(t);
114
+ stopAllMediaStreamsInContainer(container);
115
+ container.innerHTML = "";
116
+ };
117
+ }, [lang, loginKey, onSuccess, onError]);
118
+ return (React.createElement("div", { ref: containerRef, style: { width: "100%", height: "100%", minHeight: "100vh" } },
119
+ React.createElement(Box, { sx: { display: "flex", justifyContent: "center", alignItems: "center", height: "100vh", background: "#FFFFFF" } },
120
+ React.createElement(CircularProgress, null))));
121
+ };
122
+ export default SnapMatchStep;
@@ -0,0 +1,22 @@
1
+ import React from "react";
2
+ import { Button, Stack, Typography } from "@mui/material";
3
+ import VerifiedRoundedIcon from "@mui/icons-material/VerifiedRounded";
4
+ import Layout from "../Layout";
5
+ import { getSnapMatchResultTranslations } from "./translations";
6
+ import theme from "../theme";
7
+ var SuccessView = function (_a) {
8
+ var lang = _a.lang, fullName = _a.fullName, onContinue = _a.onContinue, _b = _a.returnLoading, returnLoading = _b === void 0 ? false : _b, _c = _a.autoRedirectSeconds, autoRedirectSeconds = _c === void 0 ? 3 : _c, _d = _a.countdown, countdown = _d === void 0 ? 0 : _d;
9
+ var t = getSnapMatchResultTranslations(lang);
10
+ return (React.createElement(Layout, null,
11
+ React.createElement(Stack, { height: 1, width: 1, maxHeight: 900, justifyContent: "center", alignItems: "center", spacing: 4, py: 4 },
12
+ React.createElement(VerifiedRoundedIcon, { color: "success", sx: { fontSize: 64 } }),
13
+ React.createElement(Typography, { variant: "h1", textAlign: "center", sx: { whiteSpace: "pre-line" } },
14
+ fullName ? "\uD83C\uDF89 ".concat(fullName) : "🎉",
15
+ React.createElement("br", null),
16
+ React.createElement("br", null),
17
+ t.successTitle),
18
+ React.createElement(Typography, { variant: "body1", color: theme.palette.info.light, textAlign: "center", sx: { whiteSpace: "pre-line" } }, t.successDescription),
19
+ autoRedirectSeconds > 0 && (React.createElement(Typography, { variant: "body2", color: theme.palette.info.light, sx: { whiteSpace: "pre-line" } }, countdown > 0 ? t.countdownReturn(countdown) : t.redirecting)),
20
+ React.createElement(Button, { variant: "contained", color: "primary", onClick: function () { return (onContinue ? onContinue() : window.close()); }, disabled: returnLoading, fullWidth: true, sx: { whiteSpace: "pre-line" } }, returnLoading ? t.redirecting : t.nextPerson))));
21
+ };
22
+ export default SuccessView;
@@ -0,0 +1,19 @@
1
+ import React from "react";
2
+ import { Button, Container, Stack, Typography } from "@mui/material";
3
+ import { getSnapMatchResultTranslations } from "./translations";
4
+ var TryAgainView = function (_a) {
5
+ var lang = _a.lang, message = _a.message, onRetry = _a.onRetry, _b = _a.retryLoading, retryLoading = _b === void 0 ? false : _b, _c = _a.autoRedirectSeconds, autoRedirectSeconds = _c === void 0 ? 0 : _c, _d = _a.countdown, countdown = _d === void 0 ? 0 : _d;
6
+ var t = getSnapMatchResultTranslations(lang);
7
+ var handleContinue = function () {
8
+ if (onRetry)
9
+ onRetry();
10
+ else
11
+ window.location.reload();
12
+ };
13
+ return (React.createElement(Container, { maxWidth: "sm", sx: { px: 3 } },
14
+ React.createElement(Stack, { height: "100vh", width: 1, maxHeight: 900, justifyContent: "center", alignItems: "center", spacing: 4 },
15
+ React.createElement(Typography, { variant: "h3", fontWeight: 700, textAlign: "center", sx: { whiteSpace: "pre-line" } }, message !== null && message !== void 0 ? message : t.failureDefault),
16
+ autoRedirectSeconds > 0 && (React.createElement(Typography, { variant: "body2", color: "text.secondary", sx: { whiteSpace: "pre-line" } }, countdown > 0 ? t.countdownReturn(countdown) : t.redirecting)),
17
+ React.createElement(Button, { variant: "contained", color: "primary", onClick: handleContinue, disabled: retryLoading, sx: { whiteSpace: "pre-line" } }, retryLoading ? t.redirecting : t.retry))));
18
+ };
19
+ export default TryAgainView;