@bytexbyte/berifyme-react-sdk 1.0.0

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 (129) hide show
  1. package/README.md +20 -0
  2. package/dist/BerifymeModal/MainModal.js +29 -0
  3. package/dist/BerifymeModal/index.js +331 -0
  4. package/dist/api/api.js +1337 -0
  5. package/dist/api/client.js +21 -0
  6. package/dist/api/index.js +96 -0
  7. package/dist/common.js +216 -0
  8. package/dist/components/AllSet/index.js +169 -0
  9. package/dist/components/AuthenticationLogs.js +148 -0
  10. package/dist/components/Clear.js +107 -0
  11. package/dist/components/Footer/index.js +11 -0
  12. package/dist/components/Layout.js +9 -0
  13. package/dist/components/Login/authid/authid.js +196 -0
  14. package/dist/components/Login/authid/index.js +13 -0
  15. package/dist/components/Login/clear.js +35 -0
  16. package/dist/components/Login/clearAllSet.js +96 -0
  17. package/dist/components/Login/incode/Login.js +129 -0
  18. package/dist/components/Login/incode/index.js +16 -0
  19. package/dist/components/OnBoarding/authId/authIdSelectType.js +82 -0
  20. package/dist/components/OnBoarding/authId/idOrPassport.js +30 -0
  21. package/dist/components/OnBoarding/authId/index.js +323 -0
  22. package/dist/components/OnBoarding/clear/clearAllSet.js +118 -0
  23. package/dist/components/OnBoarding/clear/index.js +36 -0
  24. package/dist/components/OnBoarding/incode/BackId.js +25 -0
  25. package/dist/components/OnBoarding/incode/FinishOnboarding.js +26 -0
  26. package/dist/components/OnBoarding/incode/FrontId.js +27 -0
  27. package/dist/components/OnBoarding/incode/Passport.js +27 -0
  28. package/dist/components/OnBoarding/incode/ProcessFace.js +22 -0
  29. package/dist/components/OnBoarding/incode/ProcessId.js +22 -0
  30. package/dist/components/OnBoarding/incode/SelectType.js +68 -0
  31. package/dist/components/OnBoarding/incode/Selfie.js +25 -0
  32. package/dist/components/OnBoarding/incode/Steps.js +7 -0
  33. package/dist/components/OnBoarding/incode/UserConsent.js +30 -0
  34. package/dist/components/OnBoarding/incode/index.js +234 -0
  35. package/dist/components/OnBoarding/vender/grid/authIdGrid.js +94 -0
  36. package/dist/components/OnBoarding/vender/grid/clearGrid.js +14 -0
  37. package/dist/components/OnBoarding/vender/grid/incodeGrid.js +14 -0
  38. package/dist/components/OnBoarding/vender/grid/index.js +118 -0
  39. package/dist/components/OnBoarding/vender/grid/sumsubGrid.js +14 -0
  40. package/dist/components/OnBoarding/vender/grid/veriffGrid.js +14 -0
  41. package/dist/components/OnBoarding/vender/grid/yotiGrid.js +14 -0
  42. package/dist/components/OnBoarding/vender/index.js +123 -0
  43. package/dist/components/RedirectToMobile/index.js +139 -0
  44. package/dist/components/ScreenRotation.js +11 -0
  45. package/dist/components/SendSns/index.js +341 -0
  46. package/dist/components/SendSns/style.css +1 -0
  47. package/dist/components/TryAgain.js +16 -0
  48. package/dist/components/TryAgainInModal.js +15 -0
  49. package/dist/components/VerifyWithPhoneNumber/NewUser/index.js +189 -0
  50. package/dist/components/VerifyWithPhoneNumber/User/index.js +322 -0
  51. package/dist/components/createDeveloperLog.js +60 -0
  52. package/dist/components/phoneNumberProcesser.js +32 -0
  53. package/dist/components/speedTest/SpeedProvider.js +57 -0
  54. package/dist/components/theme.js +120 -0
  55. package/dist/enum/index.js +24 -0
  56. package/dist/index.js +7 -0
  57. package/dist/lib/environmentDomains.js +12 -0
  58. package/dist/lib/webauthb.js +158 -0
  59. package/dist/state.js +23 -0
  60. package/dist/theme.js +120 -0
  61. package/dist/types/BerifymeModal/MainModal.d.ts +7 -0
  62. package/dist/types/BerifymeModal/index.d.ts +12 -0
  63. package/dist/types/api/api.d.ts +606 -0
  64. package/dist/types/api/client.d.ts +2 -0
  65. package/dist/types/api/index.d.ts +16 -0
  66. package/dist/types/common.d.ts +3 -0
  67. package/dist/types/components/AllSet/index.d.ts +8 -0
  68. package/dist/types/components/AuthenticationLogs.d.ts +19 -0
  69. package/dist/types/components/Clear.d.ts +9 -0
  70. package/dist/types/components/Footer/index.d.ts +3 -0
  71. package/dist/types/components/Layout.d.ts +5 -0
  72. package/dist/types/components/Login/authid/authid.d.ts +11 -0
  73. package/dist/types/components/Login/authid/index.d.ts +9 -0
  74. package/dist/types/components/Login/clear.d.ts +7 -0
  75. package/dist/types/components/Login/clearAllSet.d.ts +6 -0
  76. package/dist/types/components/Login/incode/Login.d.ts +13 -0
  77. package/dist/types/components/Login/incode/index.d.ts +9 -0
  78. package/dist/types/components/OnBoarding/authId/authIdSelectType.d.ts +6 -0
  79. package/dist/types/components/OnBoarding/authId/idOrPassport.d.ts +7 -0
  80. package/dist/types/components/OnBoarding/authId/index.d.ts +11 -0
  81. package/dist/types/components/OnBoarding/clear/clearAllSet.d.ts +6 -0
  82. package/dist/types/components/OnBoarding/clear/index.d.ts +8 -0
  83. package/dist/types/components/OnBoarding/incode/BackId.d.ts +11 -0
  84. package/dist/types/components/OnBoarding/incode/FinishOnboarding.d.ts +11 -0
  85. package/dist/types/components/OnBoarding/incode/FrontId.d.ts +10 -0
  86. package/dist/types/components/OnBoarding/incode/Passport.d.ts +10 -0
  87. package/dist/types/components/OnBoarding/incode/ProcessFace.d.ts +11 -0
  88. package/dist/types/components/OnBoarding/incode/ProcessId.d.ts +11 -0
  89. package/dist/types/components/OnBoarding/incode/SelectType.d.ts +6 -0
  90. package/dist/types/components/OnBoarding/incode/Selfie.d.ts +11 -0
  91. package/dist/types/components/OnBoarding/incode/Steps.d.ts +7 -0
  92. package/dist/types/components/OnBoarding/incode/UserConsent.d.ts +8 -0
  93. package/dist/types/components/OnBoarding/incode/index.d.ts +9 -0
  94. package/dist/types/components/OnBoarding/vender/grid/authIdGrid.d.ts +8 -0
  95. package/dist/types/components/OnBoarding/vender/grid/clearGrid.d.ts +5 -0
  96. package/dist/types/components/OnBoarding/vender/grid/incodeGrid.d.ts +5 -0
  97. package/dist/types/components/OnBoarding/vender/grid/index.d.ts +10 -0
  98. package/dist/types/components/OnBoarding/vender/grid/sumsubGrid.d.ts +5 -0
  99. package/dist/types/components/OnBoarding/vender/grid/veriffGrid.d.ts +5 -0
  100. package/dist/types/components/OnBoarding/vender/grid/yotiGrid.d.ts +5 -0
  101. package/dist/types/components/OnBoarding/vender/index.d.ts +9 -0
  102. package/dist/types/components/RedirectToMobile/index.d.ts +7 -0
  103. package/dist/types/components/ScreenRotation.d.ts +3 -0
  104. package/dist/types/components/SendSns/index.d.ts +16 -0
  105. package/dist/types/components/TryAgain.d.ts +6 -0
  106. package/dist/types/components/TryAgainInModal.d.ts +6 -0
  107. package/dist/types/components/VerifyWithPhoneNumber/NewUser/index.d.ts +11 -0
  108. package/dist/types/components/VerifyWithPhoneNumber/User/index.d.ts +13 -0
  109. package/dist/types/components/createDeveloperLog.d.ts +11 -0
  110. package/dist/types/components/phoneNumberProcesser.d.ts +6 -0
  111. package/dist/types/components/speedTest/SpeedProvider.d.ts +9 -0
  112. package/dist/types/components/theme.d.ts +9 -0
  113. package/dist/types/enum/index.d.ts +22 -0
  114. package/dist/types/index.d.ts +12 -0
  115. package/dist/types/lib/environmentDomains.d.ts +7 -0
  116. package/dist/types/lib/webauthb.d.ts +18 -0
  117. package/dist/types/state.d.ts +11 -0
  118. package/dist/types/theme.d.ts +9 -0
  119. package/dist/types/vender/incode/incode.d.ts +8 -0
  120. package/dist/vender/incode/incode.js +13 -0
  121. package/index.css +52 -0
  122. package/package.json +49 -0
  123. package/public/US-UK_Add_to_Apple_Wallet_RGB_101421.svg +259 -0
  124. package/public/berify-title.webp +0 -0
  125. package/public/clearme.svg +39 -0
  126. package/public/idme.svg +13 -0
  127. package/public/incode.svg +9 -0
  128. package/public/scan.svg +8 -0
  129. package/public/trackablehealth-one-logo-1024x229.jpg +0 -0
@@ -0,0 +1,189 @@
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 from "react";
38
+ import { Box, CircularProgress, IconButton, Input, Stack, Typography } from "@mui/material";
39
+ import theme from "../../theme";
40
+ import { useEffect, useState } from "react";
41
+ import berifymeApi from "../../../api/api";
42
+ import ArrowBackRoundedIcon from '@mui/icons-material/ArrowBackRounded';
43
+ import InfoOutlinedIcon from '@mui/icons-material/InfoOutlined';
44
+ import Footer from "../../Footer";
45
+ import webauthn from "../../../lib/webauthb";
46
+ import { environmentDomains } from "../../../lib/environmentDomains";
47
+ import { createDeveloperLog } from "../../createDeveloperLog";
48
+ import { processPhoneNumber } from "../../phoneNumberProcesser";
49
+ var VerifyNewUser = function (_a) {
50
+ var token = _a.token, inputValue = _a.inputValue, setPageStatus = _a.setPageStatus, setUser = _a.setUser, environment = _a.environment;
51
+ var _b = useState(60), countdown = _b[0], setCountdown = _b[1]; // 倒數計時器,秒數為0表示可重新發送
52
+ var _c = useState(false), loading = _c[0], setLoading = _c[1]; // 控制API撥打時顯示loading
53
+ var _d = useState(""), code = _d[0], setCode = _d[1]; // 儲存輸入的驗證碼
54
+ var _e = useState(''), errorMessage = _e[0], setErrorMessage = _e[1];
55
+ useEffect(function () {
56
+ if (countdown > 0) {
57
+ var timer_1 = setInterval(function () {
58
+ setCountdown(function (prevCount) { return prevCount - 1; });
59
+ }, 1000);
60
+ return function () { return clearInterval(timer_1); };
61
+ }
62
+ }, [countdown]);
63
+ var handleResend = function () { return __awaiter(void 0, void 0, void 0, function () {
64
+ var processedInputValue, res;
65
+ return __generator(this, function (_a) {
66
+ switch (_a.label) {
67
+ case 0:
68
+ setLoading(true);
69
+ processedInputValue = inputValue;
70
+ processedInputValue = processPhoneNumber(processedInputValue);
71
+ return [4 /*yield*/, berifymeApi.auth.sendPhoneNumberCode({ phoneNumber: processedInputValue, token: token })];
72
+ case 1:
73
+ res = _a.sent();
74
+ setLoading(false);
75
+ if (res.error)
76
+ setErrorMessage(res.error);
77
+ setCountdown(60);
78
+ createDeveloperLog({
79
+ source: 'FRONTEND',
80
+ action: 'resend otp',
81
+ sessionToken: token,
82
+ firstDetail: processedInputValue,
83
+ secondDetail: "success: ".concat(res.success, ", error: ").concat(res.error),
84
+ });
85
+ return [2 /*return*/];
86
+ }
87
+ });
88
+ }); };
89
+ var handleChange = function (e) { return __awaiter(void 0, void 0, void 0, function () {
90
+ var value, processedInputValue, res, urlString, url;
91
+ var _a, _b;
92
+ return __generator(this, function (_c) {
93
+ switch (_c.label) {
94
+ case 0:
95
+ value = e.target.value;
96
+ setCode(value);
97
+ processedInputValue = inputValue;
98
+ processedInputValue = processPhoneNumber(processedInputValue);
99
+ if (!(value.length === 6)) return [3 /*break*/, 3];
100
+ e.target.blur();
101
+ setLoading(true);
102
+ return [4 /*yield*/, berifymeApi.user.getUserByPhoneNumberAndVerifyCode({ phoneNumber: processedInputValue, code: value })];
103
+ case 1:
104
+ res = _c.sent();
105
+ createDeveloperLog({
106
+ userId: (_a = res.user) === null || _a === void 0 ? void 0 : _a.id,
107
+ userDataJson: res.user,
108
+ source: 'FRONTEND',
109
+ action: 'check otp code and get user',
110
+ sessionToken: token,
111
+ firstDetail: processedInputValue,
112
+ secondDetail: "user: ".concat(res.user, ", error: ").concat(res.error),
113
+ });
114
+ if (res.error) {
115
+ setLoading(false);
116
+ setErrorMessage(res.error);
117
+ return [2 /*return*/];
118
+ }
119
+ if (!res.user) {
120
+ setLoading(false);
121
+ setErrorMessage('Oops! Something went wrong...');
122
+ return [2 /*return*/];
123
+ }
124
+ setErrorMessage('');
125
+ setUser(res.user);
126
+ setLoading(false);
127
+ urlString = window.location.href;
128
+ url = new URL(urlString);
129
+ return [4 /*yield*/, webauthn.register({
130
+ phoneNumber: processedInputValue,
131
+ backendDomain: environmentDomains[environment],
132
+ frontendDomain: "".concat(url.protocol, "//").concat(url.host),
133
+ frontendDomainName: url.host,
134
+ })];
135
+ case 2:
136
+ _c.sent();
137
+ createDeveloperLog({
138
+ userId: (_b = res.user) === null || _b === void 0 ? void 0 : _b.id,
139
+ userDataJson: res.user,
140
+ source: 'FRONTEND',
141
+ action: 'webauthn register success',
142
+ sessionToken: token,
143
+ });
144
+ setPageStatus(1.1);
145
+ _c.label = 3;
146
+ case 3: return [2 /*return*/];
147
+ }
148
+ });
149
+ }); };
150
+ return (React.createElement(Stack, { height: 1, width: 1, justifyContent: 'space-between', overflow: 'auto' },
151
+ React.createElement("form", { onSubmit: handleResend, style: { width: '100%' } },
152
+ React.createElement(Stack, { height: 1, spacing: 2, pt: 1 },
153
+ React.createElement(Stack, { direction: 'row' },
154
+ React.createElement(IconButton, { color: 'primary', onClick: function () {
155
+ setPageStatus(0);
156
+ } },
157
+ React.createElement(ArrowBackRoundedIcon, null))),
158
+ React.createElement(Stack, { spacing: 2 },
159
+ React.createElement(Typography, { variant: 'h2', fontWeight: 700 }, "Sign up"),
160
+ React.createElement(Stack, { spacing: 1 },
161
+ React.createElement(Typography, { variant: 'h5' },
162
+ "Enter the 6-digit code sent to ",
163
+ inputValue,
164
+ "."),
165
+ React.createElement(Box, { sx: { position: 'relative', width: '100%' } },
166
+ React.createElement(Input, { fullWidth: true, disableUnderline: true, inputProps: { maxLength: 6, type: 'tel' }, sx: {
167
+ borderRadius: '12px',
168
+ padding: '10px 15px',
169
+ backgroundColor: '#f0f0f0',
170
+ fontSize: '18px',
171
+ }, endAdornment: loading && React.createElement(CircularProgress, { size: 24, sx: { color: theme.palette.info.light } }), value: code, onChange: handleChange }))),
172
+ React.createElement(Stack, null,
173
+ React.createElement(Typography, { variant: 'body2', color: theme.palette.error.main, alignSelf: 'end' }, errorMessage),
174
+ React.createElement(Stack, null,
175
+ React.createElement(Typography, { variant: "body2", color: theme.palette.info.light, onClick: countdown === 0 ? handleResend : undefined },
176
+ countdown > 0 && "Resend available in 00:".concat(countdown.toString().padStart(2, '0')),
177
+ countdown === 0 && "Resend code")))),
178
+ React.createElement(Stack, { spacing: 2, px: 2, py: 1, bgcolor: theme.palette.secondary.light, borderRadius: 2 },
179
+ React.createElement(Stack, { direction: 'row', spacing: 2, color: theme.palette.secondary.dark },
180
+ React.createElement(InfoOutlinedIcon, null),
181
+ React.createElement(Typography, { variant: 'h5', fontWeight: 700 }, "2 Easy Steps")),
182
+ React.createElement(Stack, { component: 'ol', color: theme.palette.secondary.dark, pl: 8 },
183
+ React.createElement(Typography, { variant: 'body1', component: 'li' }, "Choose verification provider"),
184
+ React.createElement(Typography, { variant: 'body1', component: 'li' }, "Upload your ID or Passport and Take a Selfie")),
185
+ React.createElement(Stack, { pl: 5, color: theme.palette.secondary.dark },
186
+ React.createElement(Typography, { variant: 'h5', fontWeight: 700 }, "Congrats, you\u2019re Berified!"))))),
187
+ React.createElement(Footer, null)));
188
+ };
189
+ export default VerifyNewUser;
@@ -0,0 +1,322 @@
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 from "react";
38
+ import { environmentDomains } from "../../../lib/environmentDomains";
39
+ import ArrowBackRoundedIcon from '@mui/icons-material/ArrowBackRounded';
40
+ import { Box, Button, CircularProgress, IconButton, Input, Stack, Typography } from "@mui/material";
41
+ import { useEffect, useState } from "react";
42
+ import berifymeApi, { ActionType } from "../../../api/api";
43
+ import theme from "../../theme";
44
+ import { createAuthenticationLog } from "../../AuthenticationLogs";
45
+ import { createDeveloperLog } from "../../createDeveloperLog";
46
+ import Footer from "../../Footer";
47
+ import webauthn from "../../../lib/webauthb";
48
+ import { processPhoneNumber } from "../../phoneNumberProcesser";
49
+ var VerifyUser = function (_a) {
50
+ var token = _a.token, inputValue = _a.inputValue, setError = _a.setError, setPageStatus = _a.setPageStatus, setUser = _a.setUser, setModalHeight = _a.setModalHeight, environment = _a.environment;
51
+ var _b = useState(60), countdown = _b[0], setCountdown = _b[1]; // 倒數計時器,秒數為0表示可重新發送
52
+ var _c = useState(false), loading = _c[0], setLoading = _c[1]; // 控制API撥打時顯示loading
53
+ var _d = useState(""), code = _d[0], setCode = _d[1]; // 儲存輸入的驗證碼
54
+ var _e = useState(''), errorMessage = _e[0], setErrorMessage = _e[1];
55
+ var _f = useState(), login = _f[0], setLogin = _f[1];
56
+ var _g = useState(), fullName = _g[0], setFullName = _g[1];
57
+ useEffect(function () {
58
+ if (countdown > 0) {
59
+ var timer_1 = setInterval(function () {
60
+ setCountdown(function (prevCount) { return prevCount - 1; });
61
+ }, 1000);
62
+ return function () { return clearInterval(timer_1); };
63
+ }
64
+ }, [countdown]);
65
+ var handleResend = function () { return __awaiter(void 0, void 0, void 0, function () {
66
+ var processedInputValue, res;
67
+ return __generator(this, function (_a) {
68
+ switch (_a.label) {
69
+ case 0:
70
+ setLoading(true);
71
+ processedInputValue = inputValue;
72
+ processedInputValue = processPhoneNumber(processedInputValue);
73
+ return [4 /*yield*/, berifymeApi.auth.sendPhoneNumberCode({ phoneNumber: processedInputValue, token: token })];
74
+ case 1:
75
+ res = _a.sent();
76
+ setLoading(false);
77
+ if (res.error)
78
+ setErrorMessage(res.error);
79
+ setCountdown(60);
80
+ return [2 /*return*/];
81
+ }
82
+ });
83
+ }); };
84
+ var handleChange = function (e) { return __awaiter(void 0, void 0, void 0, function () {
85
+ var processedInputValue, value, res, urlString, url, deviceId, deviceUser, getVender;
86
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
87
+ return __generator(this, function (_l) {
88
+ switch (_l.label) {
89
+ case 0:
90
+ processedInputValue = inputValue;
91
+ processedInputValue = processPhoneNumber(processedInputValue);
92
+ value = e.target.value;
93
+ setCode(value);
94
+ if (!(value.length === 6)) return [3 /*break*/, 6];
95
+ e.target.blur();
96
+ setLoading(true);
97
+ createDeveloperLog({
98
+ source: 'FRONTEND',
99
+ action: 'handle phone number code start loading',
100
+ sessionToken: token,
101
+ firstDetail: processedInputValue,
102
+ });
103
+ return [4 /*yield*/, berifymeApi.user.getUserByPhoneNumberAndVerifyCode({ phoneNumber: processedInputValue, code: value })];
104
+ case 1:
105
+ res = _l.sent();
106
+ createDeveloperLog({
107
+ userId: (_a = res.user) === null || _a === void 0 ? void 0 : _a.id,
108
+ userDataJson: res.user,
109
+ source: 'FRONTEND',
110
+ action: 'check otp code and get user',
111
+ sessionToken: token,
112
+ firstDetail: processedInputValue,
113
+ secondDetail: "user: ".concat(res.user, ", error: ").concat(res.error),
114
+ });
115
+ if (res.error) {
116
+ setLoading(false);
117
+ setErrorMessage(res.error);
118
+ createDeveloperLog({
119
+ source: 'FRONTEND',
120
+ action: 'handle phone number submit stop loading',
121
+ sessionToken: token,
122
+ firstDetail: processedInputValue,
123
+ secondDetail: 'get vender error'
124
+ });
125
+ return [2 /*return*/];
126
+ }
127
+ setErrorMessage('');
128
+ setUser(res.user);
129
+ urlString = window.location.href;
130
+ url = new URL(urlString);
131
+ return [4 /*yield*/, webauthn.register({
132
+ phoneNumber: processedInputValue,
133
+ backendDomain: environmentDomains[environment],
134
+ frontendDomain: "".concat(url.protocol, "//").concat(url.host),
135
+ frontendDomainName: url.host,
136
+ })];
137
+ case 2:
138
+ _l.sent();
139
+ createDeveloperLog({
140
+ userId: (_b = res.user) === null || _b === void 0 ? void 0 : _b.id,
141
+ userDataJson: res.user,
142
+ source: 'FRONTEND',
143
+ action: 'webauthn register success',
144
+ sessionToken: token,
145
+ });
146
+ deviceId = localStorage.getItem('deviceId');
147
+ if (!(deviceId && token)) return [3 /*break*/, 4];
148
+ return [4 /*yield*/, berifymeApi.user.checkDeviceId({ phoneNumber: processedInputValue, deviceId: deviceId, token: token })];
149
+ case 3:
150
+ deviceUser = _l.sent();
151
+ if (deviceUser.user) {
152
+ createDeveloperLog({
153
+ userId: (_c = deviceUser.user.id) !== null && _c !== void 0 ? _c : '',
154
+ source: 'FRONTEND',
155
+ action: 'checkDeviceId success',
156
+ sessionToken: token,
157
+ userDataJson: deviceUser.user,
158
+ firstDetail: "deviceId: ".concat(deviceId),
159
+ });
160
+ createAuthenticationLog({
161
+ actionType: ActionType.LOGIN,
162
+ userId: deviceUser.user.id,
163
+ vender: 'auto verify',
164
+ token: token,
165
+ isPass: true,
166
+ });
167
+ setUser(deviceUser.user);
168
+ setModalHeight('60vh');
169
+ setPageStatus(10);
170
+ createDeveloperLog({
171
+ source: 'FRONTEND',
172
+ action: 'handle phone number submit stop loading',
173
+ sessionToken: token,
174
+ firstDetail: processedInputValue,
175
+ secondDetail: 'device id success'
176
+ });
177
+ return [2 /*return*/];
178
+ }
179
+ createDeveloperLog({
180
+ userId: (_d = res.user) === null || _d === void 0 ? void 0 : _d.id,
181
+ source: 'FRONTEND',
182
+ action: 'checkDeviceId failed',
183
+ sessionToken: token,
184
+ firstDetail: deviceUser.error,
185
+ secondDetail: "deviceId: ".concat(deviceId),
186
+ });
187
+ _l.label = 4;
188
+ case 4: return [4 /*yield*/, berifymeApi.user.getUserVenderByPhone({ phoneNumber: processedInputValue })];
189
+ case 5:
190
+ getVender = _l.sent();
191
+ if (getVender.error) {
192
+ setError('Oops! Something went wrong...');
193
+ setLoading(false);
194
+ createDeveloperLog({
195
+ userId: (_e = res.user) === null || _e === void 0 ? void 0 : _e.id,
196
+ source: 'FRONTEND',
197
+ action: 'getUserVenderByPhone error',
198
+ sessionToken: token,
199
+ firstDetail: (_f = getVender.error) !== null && _f !== void 0 ? _f : 'error',
200
+ });
201
+ createDeveloperLog({
202
+ userId: (_g = res.user) === null || _g === void 0 ? void 0 : _g.id,
203
+ source: 'FRONTEND',
204
+ action: 'handle phone number submit stop loading',
205
+ sessionToken: token,
206
+ firstDetail: processedInputValue,
207
+ secondDetail: 'get vender error'
208
+ });
209
+ return [2 /*return*/];
210
+ }
211
+ else {
212
+ createDeveloperLog({
213
+ userId: (_h = res.user) === null || _h === void 0 ? void 0 : _h.id,
214
+ source: 'FRONTEND',
215
+ action: 'getUserVenderByPhone success',
216
+ sessionToken: token,
217
+ firstDetail: (_j = getVender.vender) !== null && _j !== void 0 ? _j : 'null',
218
+ });
219
+ }
220
+ if (getVender.vender === 'authid') {
221
+ setLogin(3);
222
+ setModalHeight('50vh');
223
+ setFullName(getVender.fullName);
224
+ }
225
+ else if (getVender.vender === 'clear') {
226
+ setLogin(4);
227
+ setModalHeight('50vh');
228
+ setFullName(getVender.fullName);
229
+ }
230
+ else if (getVender.vender === 'incode') {
231
+ setLogin(5);
232
+ setModalHeight('50vh');
233
+ setFullName(getVender.fullName);
234
+ }
235
+ else if (getVender.vender === 'sumsub') {
236
+ setLogin(8);
237
+ setModalHeight('50vh');
238
+ setFullName(getVender.fullName);
239
+ }
240
+ else if (getVender.vender === 'veriff') {
241
+ setLogin(9);
242
+ setModalHeight('50vh');
243
+ setFullName(getVender.fullName);
244
+ }
245
+ setLoading(false);
246
+ createDeveloperLog({
247
+ userId: (_k = res.user) === null || _k === void 0 ? void 0 : _k.id,
248
+ source: 'FRONTEND',
249
+ action: 'handle phone number submit stop loading',
250
+ sessionToken: token,
251
+ firstDetail: processedInputValue,
252
+ secondDetail: 'webauthn success'
253
+ });
254
+ _l.label = 6;
255
+ case 6: return [2 /*return*/];
256
+ }
257
+ });
258
+ }); };
259
+ var initAuthId = function () { return __awaiter(void 0, void 0, void 0, function () {
260
+ var authIdTokenRes;
261
+ return __generator(this, function (_a) {
262
+ switch (_a.label) {
263
+ case 0: return [4 /*yield*/, berifymeApi.authID.getAuthIDToken()];
264
+ case 1:
265
+ authIdTokenRes = _a.sent();
266
+ if (!authIdTokenRes.token) {
267
+ setError('Auth id error');
268
+ return [2 /*return*/];
269
+ }
270
+ localStorage.setItem('authID_token', authIdTokenRes.token);
271
+ return [2 /*return*/];
272
+ }
273
+ });
274
+ }); };
275
+ useEffect(function () { initAuthId(); }, []);
276
+ return (React.createElement(React.Fragment, null,
277
+ login &&
278
+ React.createElement(Stack, { height: 1, spacing: 4, justifyContent: 'space-between', pt: 2 },
279
+ React.createElement(Stack, { spacing: 2, textAlign: 'center', alignItems: 'center' },
280
+ React.createElement(Typography, { variant: "h1" }, "\uD83D\uDC4B"),
281
+ React.createElement(Stack, null,
282
+ React.createElement(Typography, { variant: "h2", fontWeight: 700 }, "Welcome back,"),
283
+ React.createElement(Typography, { variant: "h2", fontWeight: 700 }, fullName)),
284
+ React.createElement(Typography, { variant: "body1", color: theme.palette.text.secondary }, "Take a selfie to verify your identity.")),
285
+ React.createElement(Stack, { alignItems: 'center' },
286
+ React.createElement(Button, { variant: "contained", size: 'large', sx: { minWidth: 170, borderRadius: 4 }, type: "submit", onClick: function () { setPageStatus(login); } },
287
+ React.createElement(Typography, { variant: 'body1', color: theme.palette.common.white }, "Take my selfie"))),
288
+ React.createElement(Footer, null)),
289
+ !login && React.createElement(Stack, { height: 1, width: 1, justifyContent: 'space-between', overflow: 'auto' },
290
+ React.createElement("form", { onSubmit: handleResend, style: { width: '100%' } },
291
+ React.createElement(Stack, { height: 1, spacing: 2, pt: 1 },
292
+ React.createElement(Stack, { direction: 'row' },
293
+ React.createElement(IconButton, { color: 'primary', onClick: function () {
294
+ setPageStatus(0);
295
+ } },
296
+ React.createElement(ArrowBackRoundedIcon, null))),
297
+ React.createElement(Stack, { spacing: 2 },
298
+ React.createElement(Typography, { variant: 'h2', fontWeight: 700 }, "Verify your identity"),
299
+ React.createElement(Stack, { spacing: 1 },
300
+ React.createElement(Typography, { variant: 'h5' },
301
+ "Enter the 6-digit code sent to ",
302
+ inputValue,
303
+ "."),
304
+ React.createElement(Box, { sx: { position: 'relative', width: '100%' } },
305
+ React.createElement(Input, { fullWidth: true, disableUnderline: true, inputProps: { maxLength: 6, type: 'tel' }, sx: {
306
+ borderRadius: '12px',
307
+ padding: '10px 15px',
308
+ backgroundColor: '#f0f0f0',
309
+ fontSize: '18px',
310
+ '& input:-webkit-autofill,input:-webkit-autofill:hover,input:-webkit-autofill:focus,input:-webkit-autofill:active': {
311
+ transition: 'background-color 5000s ease-in-out 0s'
312
+ }
313
+ }, endAdornment: loading && React.createElement(CircularProgress, { size: 24, sx: { color: theme.palette.info.light } }), value: code, onChange: handleChange })),
314
+ React.createElement(Stack, null,
315
+ React.createElement(Typography, { variant: 'body2', color: theme.palette.error.main, alignSelf: 'end' }, errorMessage),
316
+ React.createElement(Stack, null,
317
+ React.createElement(Typography, { variant: "body2", color: theme.palette.info.light, onClick: countdown === 0 ? handleResend : undefined },
318
+ countdown > 0 && "Resend available in 00:".concat(countdown.toString().padStart(2, '0')),
319
+ countdown === 0 && "Resend code"))))))),
320
+ React.createElement(Footer, null))));
321
+ };
322
+ export default VerifyUser;
@@ -0,0 +1,60 @@
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 berifymeApi from "../api/api";
38
+ export var createDeveloperLog = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
39
+ var userAgent;
40
+ 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;
41
+ return __generator(this, function (_c) {
42
+ switch (_c.label) {
43
+ case 0:
44
+ userAgent = navigator.userAgent || navigator.vendor || window.opera;
45
+ return [4 /*yield*/, berifymeApi.developerLogs.createDeveloperLog({
46
+ userId: userId,
47
+ sessionToken: sessionToken,
48
+ action: action,
49
+ firstDetail: firstDetail,
50
+ secondDetail: secondDetail,
51
+ userDataJson: userDataJson,
52
+ source: source,
53
+ browser: browser ? browser : userAgent,
54
+ })];
55
+ case 1:
56
+ _c.sent();
57
+ return [2 /*return*/];
58
+ }
59
+ });
60
+ }); };
@@ -0,0 +1,32 @@
1
+ // 各國區碼前綴處理規則
2
+ var countryPhonePatterns = [
3
+ { code: '886', regex: /^8860+/, replacement: '886' }, // 台灣
4
+ { code: '81', regex: /^810+/, replacement: '81' }, // 日本
5
+ { code: '82', regex: /^820+/, replacement: '82' }, // 韓國
6
+ { code: '44', regex: /^440+/, replacement: '44' }, // 英國
7
+ { code: '61', regex: /^610+/, replacement: '61' }, // 澳大利亞
8
+ { code: '49', regex: /^490+/, replacement: '49' }, // 德國
9
+ { code: '27', regex: /^270+/, replacement: '27' }, // 南非
10
+ { code: '39', regex: /^390+/, replacement: '39' }, // 意大利
11
+ // 可根據需求擴展其他國家
12
+ ];
13
+ /**
14
+ * 處理電話號碼,根據不同國家的格式進行標準化
15
+ * @param {string} inputValue - 要處理的電話號碼
16
+ * @returns {string} - 標準化後的電話號碼
17
+ */
18
+ export function processPhoneNumber(inputValue) {
19
+ var processedInputValue = inputValue.trim();
20
+ // 移除前面的 + 號
21
+ if (/^\+/.test(processedInputValue)) {
22
+ processedInputValue = processedInputValue.replace(/^\+/, '');
23
+ }
24
+ // 根據不同國家進行前綴的處理
25
+ countryPhonePatterns.forEach(function (_a) {
26
+ var regex = _a.regex, replacement = _a.replacement;
27
+ if (regex.test(processedInputValue)) {
28
+ processedInputValue = processedInputValue.replace(regex, replacement);
29
+ }
30
+ });
31
+ return processedInputValue;
32
+ }