@incodetech/core 2.0.0-alpha.8 → 2.0.0-rc.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.
- package/dist/Actor-CI32dTbG.d.ts +2 -0
- package/dist/BaseWasmProvider-C_DLEI40.esm.js +1118 -0
- package/dist/BrowserStorageProvider-CuOW1Er2.esm.js +55 -0
- package/dist/BrowserTimerProvider-DhNc_x02.esm.js +22 -0
- package/dist/ITimerCapability-C67ZRskg.esm.js +7 -0
- package/dist/IpifyProvider-D7jx52AL.esm.js +139 -0
- package/dist/MotionSensorProvider-4v7xkqAp.esm.js +254 -0
- package/dist/OpenViduRecordingProvider-CMu6XVdc.esm.js +87 -0
- package/dist/StateMachine-BCQrZJhf.d.ts +2 -0
- package/dist/WasmUtilProvider-j98OJf-S.esm.js +114 -0
- package/dist/addressSearch-BpTbTWCa.esm.js +430 -0
- package/dist/ae-signature-DDDZmWXj.esm.js +12 -0
- package/dist/ae-signature.d.ts +25 -0
- package/dist/ae-signature.esm.js +8 -0
- package/dist/antifraud.d.ts +57 -0
- package/dist/antifraud.esm.js +45 -0
- package/dist/antifraudStateMachine-O0TMf6yc.esm.js +39 -0
- package/dist/api-CESGtpbH.esm.js +53 -0
- package/dist/authentication.d.ts +12 -0
- package/dist/authentication.esm.js +25 -0
- package/dist/authenticationManager-5M-fKzXx.esm.js +67 -0
- package/dist/authenticationManager-C83GNIhl.d.ts +66 -0
- package/dist/authenticationStateMachine-BMZqatiF.esm.js +139 -0
- package/dist/backCameraStream-DMdMeGk2.esm.js +346 -0
- package/dist/browserSimulation-gxD8cSpM.esm.js +20 -0
- package/dist/camera-DBSxa6ML.d.ts +4 -0
- package/dist/camera-PA2Ljri3.esm.js +22 -0
- package/dist/camera.d.ts +15 -0
- package/dist/camera.esm.js +5 -0
- package/dist/consent.d.ts +398 -0
- package/dist/consent.esm.js +79 -0
- package/dist/consentStateMachine-CCT-B60O.esm.js +151 -0
- package/dist/cpf-PPz2Njto.esm.js +38 -0
- package/dist/cpf-ocr.d.ts +204 -0
- package/dist/cpf-ocr.esm.js +177 -0
- package/dist/cross-document-data-match.d.ts +34 -0
- package/dist/cross-document-data-match.esm.js +71 -0
- package/dist/curp-validation.d.ts +188 -0
- package/dist/curp-validation.esm.js +110 -0
- package/dist/curpValidationStateMachine-CitWLr2c.esm.js +595 -0
- package/dist/custom-fields.d.ts +115 -0
- package/dist/custom-fields.esm.js +177 -0
- package/dist/custom-watchlist.d.ts +66 -0
- package/dist/custom-watchlist.esm.js +86 -0
- package/dist/dateUtils-UoN5xswP.esm.js +23 -0
- package/dist/deepsightLoader-Cm4JIT_z.esm.js +52 -0
- package/dist/deepsightService-CEVxzehb.d.ts +412 -0
- package/dist/deepsightService-O74l4Y__.esm.js +489 -0
- package/dist/device.d.ts +46 -0
- package/dist/device.esm.js +106 -0
- package/dist/displayErrors-DqJ_IbsG.d.ts +39 -0
- package/dist/document-capture.d.ts +906 -0
- package/dist/document-capture.esm.js +156 -0
- package/dist/document-upload.d.ts +331 -0
- package/dist/document-upload.esm.js +203 -0
- package/dist/documentCaptureStateMachine-BqzTDy9k.esm.js +394 -0
- package/dist/dynamic-forms.d.ts +178 -0
- package/dist/dynamic-forms.esm.js +323 -0
- package/dist/ekyb.d.ts +148 -0
- package/dist/ekyb.esm.js +127 -0
- package/dist/ekybStateMachine-B59rQjgj.esm.js +674 -0
- package/dist/ekyc.d.ts +164 -0
- package/dist/ekyc.esm.js +104 -0
- package/dist/ekycStateMachine-oeO0Iekd.esm.js +10626 -0
- package/dist/electronic-signature.d.ts +4 -0
- package/dist/electronic-signature.esm.js +7 -0
- package/dist/electronicSignatureManager-D9OHzTpG.esm.js +428 -0
- package/dist/email.d.ts +3 -263
- package/dist/email.esm.js +7 -477
- package/dist/emailManager-DIfnS5g1.d.ts +352 -0
- package/dist/emailManager-wAV0LE-H.esm.js +238 -0
- package/dist/emailStateMachine-DOf4j58N.esm.js +292 -0
- package/dist/endpoints-CnN3SyDa.esm.js +87 -0
- package/dist/events-D6-e4vok.esm.js +596 -0
- package/dist/events.d.ts +265 -0
- package/dist/events.esm.js +4 -0
- package/dist/extensibility.d.ts +122 -0
- package/dist/extensibility.esm.js +43 -0
- package/dist/face-match.d.ts +228 -0
- package/dist/face-match.esm.js +173 -0
- package/dist/faceCaptureManagerFactory-Dh2PdGlF.esm.js +290 -0
- package/dist/faceCaptureManagerFactory-yqtpxjnN.d.ts +690 -0
- package/dist/faceCaptureSetup-B3faSpYA.esm.js +873 -0
- package/dist/faceMatchStateMachine-DNFrxTFS.esm.js +127 -0
- package/dist/flow-events.d.ts +6 -0
- package/dist/flow-events.esm.js +0 -0
- package/dist/flow.d.ts +101 -321
- package/dist/flow.esm.js +370 -173
- package/dist/flowCompletionService-DhkT4SRY.d.ts +10 -0
- package/dist/flowCompletionService-P54yzGvA.esm.js +13 -0
- package/dist/flowServices-DTsm-Vf1.esm.js +188 -0
- package/dist/geolocation.d.ts +127 -0
- package/dist/geolocation.esm.js +89 -0
- package/dist/geolocationStateMachine-asasuHY2.esm.js +105 -0
- package/dist/getBrowser-BSXUTWXw.esm.js +41 -0
- package/dist/getDeviceClass-BSntT9_j.esm.js +14 -0
- package/dist/government-validation.d.ts +67 -0
- package/dist/government-validation.esm.js +81 -0
- package/dist/governmentValidationStateMachine-BDDYrJTo.esm.js +271 -0
- package/dist/home.d.ts +99 -0
- package/dist/home.esm.js +61 -0
- package/dist/http.d.ts +68 -0
- package/dist/http.esm.js +3 -0
- package/dist/id-ocr.d.ts +635 -0
- package/dist/id-ocr.esm.js +86 -0
- package/dist/id-verification.d.ts +190 -0
- package/dist/id-verification.esm.js +43 -0
- package/dist/id.d.ts +24 -0
- package/dist/id.esm.js +164 -0
- package/dist/idCaptureManager-B9TGA5dq.d.ts +956 -0
- package/dist/idCaptureManager-DMK0GIt3.esm.js +581 -0
- package/dist/idCaptureStateMachine-Bq0fVZXl.esm.js +2954 -0
- package/dist/idOcrStateMachine-YbjjC_Gg.esm.js +388 -0
- package/dist/idVerificationStateMachine-xbw9HP1Z.esm.js +71 -0
- package/dist/identity-reuse.d.ts +530 -0
- package/dist/identity-reuse.esm.js +274 -0
- package/dist/index-BLKtMA0g.d.ts +1177 -0
- package/dist/index-BcRG8rtJ.d.ts +97 -0
- package/dist/index.d.ts +3 -226
- package/dist/index.esm.js +11 -154
- package/dist/invokeOnCaptureCallback-rc6kBHo5.esm.js +30 -0
- package/dist/{lib-Bu9XGMBW.esm.js → lib-BB0B_qQX.esm.js} +801 -2
- package/dist/mandatory-consent.d.ts +412 -0
- package/dist/mandatory-consent.esm.js +78 -0
- package/dist/mandatoryConsentStateMachine-Cnco1jvn.esm.js +126 -0
- package/dist/openviduLazy-Cm0XFh_v.esm.js +3 -0
- package/dist/openviduLazy-Cok70ZSg.esm.js +12 -0
- package/dist/permissionServices-D_i6nzEw.esm.js +50 -0
- package/dist/phone.d.ts +3 -291
- package/dist/phone.esm.js +7 -548
- package/dist/phoneManager-B6M30hKE.d.ts +397 -0
- package/dist/phoneManager-DAJbGhlY.esm.js +256 -0
- package/dist/phoneStateMachine-CuPARRaT.esm.js +351 -0
- package/dist/platform-CfrjKhmi.esm.js +83 -0
- package/dist/qe-signature-DFo_Cc-I.esm.js +12 -0
- package/dist/qe-signature.d.ts +25 -0
- package/dist/qe-signature.esm.js +8 -0
- package/dist/recordingService-Ig2UgbLv.esm.js +1003 -0
- package/dist/redirect-to-mobile.d.ts +107 -0
- package/dist/redirect-to-mobile.esm.js +102 -0
- package/dist/redirectToMobileStateMachine-BOEqe46A.esm.js +249 -0
- package/dist/runChildModule-CqqwqAkW.esm.js +219 -0
- package/dist/selfie.d.ts +21 -754
- package/dist/selfie.esm.js +113 -962
- package/dist/selfieManager-D0lSgd-J.d.ts +68 -0
- package/dist/selfieManager-Duisl7qN.esm.js +60 -0
- package/dist/selfieStateMachine-D76whWEf.esm.js +68 -0
- package/dist/session-BS-d_vuE.esm.js +3206 -0
- package/dist/session.d.ts +217 -0
- package/dist/session.esm.js +9 -0
- package/dist/setup-Buy-hyj4.esm.js +887 -0
- package/dist/setup-C5AITV8m.d.ts +254 -0
- package/dist/signature.d.ts +94 -0
- package/dist/signature.esm.js +66 -0
- package/dist/signatureStateMachine-B5-QVUve.esm.js +132 -0
- package/dist/stats-CIfiPzb1.esm.js +16 -0
- package/dist/stats.d.ts +16 -0
- package/dist/stats.esm.js +4 -0
- package/dist/trust-graph.d.ts +54 -0
- package/dist/trust-graph.esm.js +56 -0
- package/dist/types-B06Ypu2F.d.ts +49 -0
- package/dist/types-BP1m8VRw.d.ts +340 -0
- package/dist/types-CFV9G_7j.d.ts +24 -0
- package/dist/{warmup-CEJTfxQr.d.ts → warmup-CEcppFiS.d.ts} +11 -3
- package/dist/wasm.d.ts +15 -0
- package/dist/wasm.esm.js +12 -0
- package/dist/watchlist-for-business.d.ts +79 -0
- package/dist/watchlist-for-business.esm.js +148 -0
- package/dist/watchlist.d.ts +62 -0
- package/dist/watchlist.esm.js +86 -0
- package/dist/watchlistServices-DMbUhkBX.esm.js +12 -0
- package/dist/workflow.d.ts +907 -0
- package/dist/workflow.esm.js +702 -0
- package/dist/{xstate.esm-B_rda9yU.esm.js → xstate.esm-B70JrNqo.esm.js} +144 -1
- package/package.json +203 -6
- package/dist/OpenViduLogger-BdPfiZO6.esm.js +0 -3
- package/dist/OpenViduLogger-CQyDxBvM.esm.js +0 -803
- package/dist/StateMachine-DRE1oH2B.d.ts +0 -2
- package/dist/addEvent-W0ORK0jT.esm.js +0 -16
- package/dist/endpoints-BSTFaHYo.esm.js +0 -1706
- package/dist/permissionServices-I6vX6DBy.esm.js +0 -72
- /package/dist/{Manager-BGfxEmyv.d.ts → Manager-C8PrhBOx.d.ts} +0 -0
- /package/dist/{chunk-C_Yo44FK.esm.js → chunk-CRF6K_H_.esm.js} +0 -0
- /package/dist/{types-iZi2rawo.d.ts → types-CAD4va6a.d.ts} +0 -0
package/dist/phone.esm.js
CHANGED
|
@@ -1,550 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import "./BrowserTimerProvider-DhNc_x02.esm.js";
|
|
2
|
+
import "./api-CESGtpbH.esm.js";
|
|
3
|
+
import "./events-D6-e4vok.esm.js";
|
|
4
|
+
import "./endpoints-CnN3SyDa.esm.js";
|
|
5
|
+
import "./xstate.esm-B70JrNqo.esm.js";
|
|
6
|
+
import { t as phoneMachine } from "./phoneStateMachine-CuPARRaT.esm.js";
|
|
7
|
+
import { t as createPhoneManager } from "./phoneManager-DAJbGhlY.esm.js";
|
|
4
8
|
|
|
5
|
-
//#region src/modules/phone/phoneServices.ts
|
|
6
|
-
async function fetchPhone(signal) {
|
|
7
|
-
const res = await api.get(endpoints.getPhone, { signal });
|
|
8
|
-
if (!res.ok) throw new Error(`GET ${endpoints.getPhone} failed: ${res.status} ${res.statusText}`);
|
|
9
|
-
return res.data;
|
|
10
|
-
}
|
|
11
|
-
async function fetchStartInfo(signal) {
|
|
12
|
-
const res = await api.get(endpoints.startInfo, { signal });
|
|
13
|
-
if (!res.ok) throw new Error(`GET ${endpoints.startInfo} failed: ${res.status} ${res.statusText}`);
|
|
14
|
-
return res.data;
|
|
15
|
-
}
|
|
16
|
-
async function addPhone(params, signal) {
|
|
17
|
-
const res = await api.post(endpoints.phone, {
|
|
18
|
-
phone: params.phone,
|
|
19
|
-
optInGranted: params.optInGranted
|
|
20
|
-
}, { signal });
|
|
21
|
-
if (!res.ok) throw new Error(`POST ${endpoints.phone} failed: ${res.status} ${res.statusText}`);
|
|
22
|
-
return res.data;
|
|
23
|
-
}
|
|
24
|
-
async function addPhoneInstantVerify(params, signal) {
|
|
25
|
-
const res = await api.post(endpoints.phoneInstant, {
|
|
26
|
-
phone: params.phone,
|
|
27
|
-
optInGranted: params.optInGranted
|
|
28
|
-
}, { signal });
|
|
29
|
-
if (!res.ok) throw new Error(`POST ${endpoints.phoneInstant} failed: ${res.status} ${res.statusText}`);
|
|
30
|
-
return res.data;
|
|
31
|
-
}
|
|
32
|
-
async function sendOtp(signal) {
|
|
33
|
-
const res = await api.get(`${endpoints.sendSmsOtp}?communicationchannel=SMS`, { signal });
|
|
34
|
-
if (!res.ok) throw new Error(`GET ${endpoints.sendSmsOtp} failed: ${res.status} ${res.statusText}`);
|
|
35
|
-
}
|
|
36
|
-
async function verifyOtp(code, signal) {
|
|
37
|
-
const res = await api.get(`${endpoints.compareOtp}?code=${code}&channel=SMS`, { signal });
|
|
38
|
-
if (!res.ok) throw new Error(`GET ${endpoints.compareOtp} failed: ${res.status} ${res.statusText}`);
|
|
39
|
-
return res.data;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
//#endregion
|
|
43
|
-
//#region src/modules/phone/phoneStateMachine.ts
|
|
44
|
-
const RESEND_TIMER_SECONDS = 30;
|
|
45
|
-
const phoneMachine = setup({
|
|
46
|
-
types: {
|
|
47
|
-
context: {},
|
|
48
|
-
events: {},
|
|
49
|
-
input: {}
|
|
50
|
-
},
|
|
51
|
-
actors: {
|
|
52
|
-
fetchPhone: fromPromise(async ({ signal }) => {
|
|
53
|
-
return fetchPhone(signal);
|
|
54
|
-
}),
|
|
55
|
-
fetchStartInfo: fromPromise(async ({ signal }) => {
|
|
56
|
-
return fetchStartInfo(signal);
|
|
57
|
-
}),
|
|
58
|
-
submitPhone: fromPromise(async ({ input, signal }) => {
|
|
59
|
-
if (input.isInstantVerify) return addPhoneInstantVerify({
|
|
60
|
-
phone: input.phone,
|
|
61
|
-
optInGranted: input.optInGranted
|
|
62
|
-
}, signal);
|
|
63
|
-
return addPhone({
|
|
64
|
-
phone: input.phone,
|
|
65
|
-
optInGranted: input.optInGranted
|
|
66
|
-
}, signal);
|
|
67
|
-
}),
|
|
68
|
-
sendOtp: fromPromise(async ({ signal }) => {
|
|
69
|
-
return sendOtp(signal);
|
|
70
|
-
}),
|
|
71
|
-
verifyOtp: fromPromise(async ({ input, signal }) => {
|
|
72
|
-
return verifyOtp(input.code, signal);
|
|
73
|
-
}),
|
|
74
|
-
resendTimer: fromCallback(({ sendBack }) => {
|
|
75
|
-
let seconds = RESEND_TIMER_SECONDS;
|
|
76
|
-
const interval = setInterval(() => {
|
|
77
|
-
seconds -= 1;
|
|
78
|
-
sendBack({ type: "TICK" });
|
|
79
|
-
if (seconds <= 0) clearInterval(interval);
|
|
80
|
-
}, 1e3);
|
|
81
|
-
return () => clearInterval(interval);
|
|
82
|
-
})
|
|
83
|
-
},
|
|
84
|
-
actions: {
|
|
85
|
-
setStartInfo: assign(({ event }) => {
|
|
86
|
-
const info = event.output;
|
|
87
|
-
return {
|
|
88
|
-
startInfo: info,
|
|
89
|
-
countryCode: info.ipIsoCode,
|
|
90
|
-
phonePrefix: info.phonePrefix
|
|
91
|
-
};
|
|
92
|
-
}),
|
|
93
|
-
setPrefilledPhone: assign(({ event }) => {
|
|
94
|
-
const phone = event.output.phone;
|
|
95
|
-
return {
|
|
96
|
-
prefilledPhone: phone,
|
|
97
|
-
phone
|
|
98
|
-
};
|
|
99
|
-
}),
|
|
100
|
-
setPhone: assign(({ event }) => {
|
|
101
|
-
const e = event;
|
|
102
|
-
return {
|
|
103
|
-
phone: e.phone,
|
|
104
|
-
isValid: e.isValid,
|
|
105
|
-
phoneError: e.isValid ? void 0 : "Invalid phone number"
|
|
106
|
-
};
|
|
107
|
-
}),
|
|
108
|
-
setPhoneError: assign(({ event }) => ({ phoneError: String(event.error) })),
|
|
109
|
-
setOptInGranted: assign(({ event }) => ({ optInGranted: event.granted })),
|
|
110
|
-
setError: assign(({ event }) => ({ error: String(event.error) })),
|
|
111
|
-
clearError: assign({ error: () => void 0 }),
|
|
112
|
-
clearPhoneError: assign({ phoneError: () => void 0 }),
|
|
113
|
-
setOtpCode: assign(({ event }) => ({
|
|
114
|
-
otpCode: event.code,
|
|
115
|
-
otpError: void 0
|
|
116
|
-
})),
|
|
117
|
-
setOtpError: assign(({ context, event }) => ({
|
|
118
|
-
otpError: String(event.error),
|
|
119
|
-
attemptsRemaining: context.attemptsRemaining - 1
|
|
120
|
-
})),
|
|
121
|
-
clearOtpError: assign({
|
|
122
|
-
otpError: () => void 0,
|
|
123
|
-
otpCode: () => ""
|
|
124
|
-
}),
|
|
125
|
-
startResendTimer: assign({
|
|
126
|
-
resendTimer: () => RESEND_TIMER_SECONDS,
|
|
127
|
-
resendTimerActive: () => true
|
|
128
|
-
}),
|
|
129
|
-
tickResendTimer: assign(({ context }) => {
|
|
130
|
-
const newTimer = Math.max(0, context.resendTimer - 1);
|
|
131
|
-
return {
|
|
132
|
-
resendTimer: newTimer,
|
|
133
|
-
resendTimerActive: newTimer > 0
|
|
134
|
-
};
|
|
135
|
-
}),
|
|
136
|
-
stopResendTimer: assign({ resendTimerActive: () => false }),
|
|
137
|
-
resetContext: assign(({ context }) => ({
|
|
138
|
-
config: context.config,
|
|
139
|
-
phone: "",
|
|
140
|
-
isValid: false,
|
|
141
|
-
phoneError: void 0,
|
|
142
|
-
countryCode: "",
|
|
143
|
-
phonePrefix: "",
|
|
144
|
-
prefilledPhone: void 0,
|
|
145
|
-
optInGranted: false,
|
|
146
|
-
startInfo: void 0,
|
|
147
|
-
error: void 0,
|
|
148
|
-
otpCode: "",
|
|
149
|
-
otpError: void 0,
|
|
150
|
-
attemptsRemaining: context.config.maxOtpAttempts ?? 3,
|
|
151
|
-
resendTimer: 0,
|
|
152
|
-
resendTimerActive: false
|
|
153
|
-
})),
|
|
154
|
-
sendPhoneSubmitEvent: () => {
|
|
155
|
-
addEvent({
|
|
156
|
-
code: "continue",
|
|
157
|
-
module: "phone",
|
|
158
|
-
screen: "phoneInput"
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
},
|
|
162
|
-
guards: {
|
|
163
|
-
hasPrefill: ({ context }) => context.config.prefill,
|
|
164
|
-
hasOtpVerification: ({ context }) => context.config.otpVerification,
|
|
165
|
-
isValidPhone: ({ context }) => context.isValid,
|
|
166
|
-
hasAttemptsRemaining: ({ context }) => context.attemptsRemaining > 0,
|
|
167
|
-
canResend: ({ context }) => !context.resendTimerActive
|
|
168
|
-
}
|
|
169
|
-
}).createMachine({
|
|
170
|
-
id: "phone",
|
|
171
|
-
initial: "idle",
|
|
172
|
-
context: ({ input }) => ({
|
|
173
|
-
config: input.config,
|
|
174
|
-
phone: "",
|
|
175
|
-
isValid: false,
|
|
176
|
-
phoneError: void 0,
|
|
177
|
-
countryCode: "",
|
|
178
|
-
phonePrefix: "",
|
|
179
|
-
prefilledPhone: void 0,
|
|
180
|
-
optInGranted: false,
|
|
181
|
-
startInfo: void 0,
|
|
182
|
-
error: void 0,
|
|
183
|
-
otpCode: "",
|
|
184
|
-
otpError: void 0,
|
|
185
|
-
attemptsRemaining: input.config.maxOtpAttempts ?? 3,
|
|
186
|
-
resendTimer: 0,
|
|
187
|
-
resendTimerActive: false
|
|
188
|
-
}),
|
|
189
|
-
states: {
|
|
190
|
-
idle: { on: { LOAD: [{
|
|
191
|
-
target: "loadingPrefill",
|
|
192
|
-
guard: "hasPrefill"
|
|
193
|
-
}, { target: "loadingStartInfo" }] } },
|
|
194
|
-
loadingPrefill: { invoke: {
|
|
195
|
-
id: "fetchPhone",
|
|
196
|
-
src: "fetchPhone",
|
|
197
|
-
onDone: {
|
|
198
|
-
target: "loadingStartInfo",
|
|
199
|
-
actions: "setPrefilledPhone"
|
|
200
|
-
},
|
|
201
|
-
onError: { target: "loadingStartInfo" }
|
|
202
|
-
} },
|
|
203
|
-
loadingStartInfo: { invoke: {
|
|
204
|
-
id: "fetchStartInfo",
|
|
205
|
-
src: "fetchStartInfo",
|
|
206
|
-
onDone: {
|
|
207
|
-
target: "inputting",
|
|
208
|
-
actions: "setStartInfo"
|
|
209
|
-
},
|
|
210
|
-
onError: { target: "inputting" }
|
|
211
|
-
} },
|
|
212
|
-
inputting: {
|
|
213
|
-
entry: "clearPhoneError",
|
|
214
|
-
on: {
|
|
215
|
-
PHONE_CHANGED: { actions: "setPhone" },
|
|
216
|
-
OPT_IN_CHANGED: { actions: "setOptInGranted" },
|
|
217
|
-
SUBMIT: {
|
|
218
|
-
target: "submitting",
|
|
219
|
-
guard: "isValidPhone"
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
},
|
|
223
|
-
submitting: { invoke: {
|
|
224
|
-
id: "submitPhone",
|
|
225
|
-
src: "submitPhone",
|
|
226
|
-
input: ({ context }) => ({
|
|
227
|
-
phone: context.phone,
|
|
228
|
-
optInGranted: context.config.optinEnabled ? context.optInGranted : void 0,
|
|
229
|
-
isInstantVerify: context.config.isInstantVerify ?? false
|
|
230
|
-
}),
|
|
231
|
-
onDone: [{
|
|
232
|
-
target: "sendingOtp",
|
|
233
|
-
guard: "hasOtpVerification",
|
|
234
|
-
actions: "sendPhoneSubmitEvent"
|
|
235
|
-
}, {
|
|
236
|
-
target: "success",
|
|
237
|
-
actions: "sendPhoneSubmitEvent"
|
|
238
|
-
}],
|
|
239
|
-
onError: {
|
|
240
|
-
target: "inputting",
|
|
241
|
-
actions: "setPhoneError"
|
|
242
|
-
}
|
|
243
|
-
} },
|
|
244
|
-
sendingOtp: { invoke: {
|
|
245
|
-
id: "sendOtp",
|
|
246
|
-
src: "sendOtp",
|
|
247
|
-
onDone: { target: "awaitingOtp" },
|
|
248
|
-
onError: {
|
|
249
|
-
target: "awaitingOtp",
|
|
250
|
-
actions: "setError"
|
|
251
|
-
}
|
|
252
|
-
} },
|
|
253
|
-
awaitingOtp: {
|
|
254
|
-
entry: "startResendTimer",
|
|
255
|
-
invoke: {
|
|
256
|
-
id: "resendTimer",
|
|
257
|
-
src: "resendTimer"
|
|
258
|
-
},
|
|
259
|
-
on: {
|
|
260
|
-
TICK: { actions: "tickResendTimer" },
|
|
261
|
-
OTP_CHANGED: { actions: "setOtpCode" },
|
|
262
|
-
VERIFY_OTP: { target: "verifyingOtp" },
|
|
263
|
-
RESEND_OTP: {
|
|
264
|
-
target: "sendingOtp",
|
|
265
|
-
guard: "canResend"
|
|
266
|
-
},
|
|
267
|
-
BACK: { target: "inputting" }
|
|
268
|
-
}
|
|
269
|
-
},
|
|
270
|
-
verifyingOtp: { invoke: {
|
|
271
|
-
id: "verifyOtp",
|
|
272
|
-
src: "verifyOtp",
|
|
273
|
-
input: ({ context }) => ({ code: context.otpCode }),
|
|
274
|
-
onDone: [
|
|
275
|
-
{
|
|
276
|
-
target: "success",
|
|
277
|
-
guard: ({ event }) => event.output.success === true
|
|
278
|
-
},
|
|
279
|
-
{
|
|
280
|
-
target: "otpError",
|
|
281
|
-
guard: "hasAttemptsRemaining",
|
|
282
|
-
actions: assign(({ context }) => ({
|
|
283
|
-
otpError: "Invalid OTP code",
|
|
284
|
-
attemptsRemaining: context.attemptsRemaining - 1
|
|
285
|
-
}))
|
|
286
|
-
},
|
|
287
|
-
{
|
|
288
|
-
target: "error",
|
|
289
|
-
actions: assign({ error: () => "Maximum OTP attempts exceeded" })
|
|
290
|
-
}
|
|
291
|
-
],
|
|
292
|
-
onError: [{
|
|
293
|
-
target: "otpError",
|
|
294
|
-
guard: "hasAttemptsRemaining",
|
|
295
|
-
actions: "setOtpError"
|
|
296
|
-
}, {
|
|
297
|
-
target: "error",
|
|
298
|
-
actions: "setError"
|
|
299
|
-
}]
|
|
300
|
-
} },
|
|
301
|
-
otpError: { on: {
|
|
302
|
-
OTP_CHANGED: {
|
|
303
|
-
target: "awaitingOtp",
|
|
304
|
-
actions: "setOtpCode"
|
|
305
|
-
},
|
|
306
|
-
RESEND_OTP: {
|
|
307
|
-
target: "sendingOtp",
|
|
308
|
-
guard: "canResend"
|
|
309
|
-
},
|
|
310
|
-
BACK: { target: "inputting" }
|
|
311
|
-
} },
|
|
312
|
-
success: { type: "final" },
|
|
313
|
-
error: { on: { RESET: {
|
|
314
|
-
target: "idle",
|
|
315
|
-
actions: "resetContext"
|
|
316
|
-
} } }
|
|
317
|
-
}
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
//#endregion
|
|
321
|
-
//#region src/modules/phone/phoneActor.ts
|
|
322
|
-
function createPhoneActor(options) {
|
|
323
|
-
return createActor(phoneMachine, { input: { config: options.config } }).start();
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
//#endregion
|
|
327
|
-
//#region src/modules/phone/phoneManager.ts
|
|
328
|
-
/**
|
|
329
|
-
* @module @incodetech/core/phone
|
|
330
|
-
*
|
|
331
|
-
* Phone verification module for the Incode Web SDK.
|
|
332
|
-
* Supports both headless (programmatic) and UI-driven usage patterns.
|
|
333
|
-
*
|
|
334
|
-
* ## Headless Usage
|
|
335
|
-
*
|
|
336
|
-
* The phone manager can be used entirely without UI for backend integrations,
|
|
337
|
-
* custom UI implementations, or automated workflows.
|
|
338
|
-
*
|
|
339
|
-
* @example Basic headless phone verification with OTP
|
|
340
|
-
* ```typescript
|
|
341
|
-
* import { createPhoneManager } from '@incodetech/core/phone';
|
|
342
|
-
* import { setup } from '@incodetech/core';
|
|
343
|
-
*
|
|
344
|
-
* // 1. Configure the SDK (required before using any module)
|
|
345
|
-
* setup({ apiURL: 'https://api.example.com', token: 'your-token' });
|
|
346
|
-
*
|
|
347
|
-
* // 2. Create the phone manager
|
|
348
|
-
* const phoneManager = createPhoneManager({
|
|
349
|
-
* config: {
|
|
350
|
-
* otpVerification: true,
|
|
351
|
-
* otpExpirationInMinutes: 5,
|
|
352
|
-
* prefill: false,
|
|
353
|
-
* maxOtpAttempts: 3,
|
|
354
|
-
* },
|
|
355
|
-
* });
|
|
356
|
-
*
|
|
357
|
-
* // 3. Subscribe to state changes (optional but recommended)
|
|
358
|
-
* phoneManager.subscribe((state) => {
|
|
359
|
-
* console.log('Phone state:', state.status);
|
|
360
|
-
* if (state.status === 'success') {
|
|
361
|
-
* console.log('Phone verified successfully!');
|
|
362
|
-
* }
|
|
363
|
-
* if (state.status === 'error') {
|
|
364
|
-
* console.error('Error:', state.error);
|
|
365
|
-
* }
|
|
366
|
-
* });
|
|
367
|
-
*
|
|
368
|
-
* // 4. Start the flow
|
|
369
|
-
* phoneManager.load();
|
|
370
|
-
*
|
|
371
|
-
* // 5. When state is 'inputting', set the phone number
|
|
372
|
-
* phoneManager.setPhoneNumber('+14155551234', true);
|
|
373
|
-
*
|
|
374
|
-
* // 6. Submit the phone number
|
|
375
|
-
* phoneManager.submit();
|
|
376
|
-
*
|
|
377
|
-
* // 7. When state is 'awaitingOtp', submit the OTP code
|
|
378
|
-
* phoneManager.submitOtp('ABC123');
|
|
379
|
-
*
|
|
380
|
-
* // 8. Clean up when done
|
|
381
|
-
* phoneManager.stop();
|
|
382
|
-
* ```
|
|
383
|
-
*
|
|
384
|
-
* @example Polling-based headless usage
|
|
385
|
-
* ```typescript
|
|
386
|
-
* const phoneManager = createPhoneManager({ config });
|
|
387
|
-
*
|
|
388
|
-
* phoneManager.load();
|
|
389
|
-
*
|
|
390
|
-
* // Poll for state changes
|
|
391
|
-
* const interval = setInterval(() => {
|
|
392
|
-
* const state = phoneManager.getState();
|
|
393
|
-
*
|
|
394
|
-
* switch (state.status) {
|
|
395
|
-
* case 'inputting':
|
|
396
|
-
* phoneManager.setPhoneNumber('+14155551234', true);
|
|
397
|
-
* phoneManager.submit();
|
|
398
|
-
* break;
|
|
399
|
-
* case 'awaitingOtp':
|
|
400
|
-
* // Get OTP from user or external source
|
|
401
|
-
* phoneManager.submitOtp(otpCode);
|
|
402
|
-
* break;
|
|
403
|
-
* case 'success':
|
|
404
|
-
* clearInterval(interval);
|
|
405
|
-
* phoneManager.stop();
|
|
406
|
-
* break;
|
|
407
|
-
* case 'error':
|
|
408
|
-
* clearInterval(interval);
|
|
409
|
-
* console.error(state.error);
|
|
410
|
-
* phoneManager.stop();
|
|
411
|
-
* break;
|
|
412
|
-
* }
|
|
413
|
-
* }, 100);
|
|
414
|
-
* ```
|
|
415
|
-
*/
|
|
416
|
-
function mapState(snapshot) {
|
|
417
|
-
const typedSnapshot = snapshot;
|
|
418
|
-
const { context } = typedSnapshot;
|
|
419
|
-
if (typedSnapshot.matches("idle")) return { status: "idle" };
|
|
420
|
-
if (typedSnapshot.matches("loadingPrefill")) return { status: "loadingPrefill" };
|
|
421
|
-
if (typedSnapshot.matches("loadingStartInfo")) return {
|
|
422
|
-
status: "inputting",
|
|
423
|
-
countryCode: context.countryCode,
|
|
424
|
-
phonePrefix: context.phonePrefix,
|
|
425
|
-
prefilledPhone: context.prefilledPhone
|
|
426
|
-
};
|
|
427
|
-
if (typedSnapshot.matches("inputting")) return {
|
|
428
|
-
status: "inputting",
|
|
429
|
-
countryCode: context.countryCode,
|
|
430
|
-
phonePrefix: context.phonePrefix,
|
|
431
|
-
prefilledPhone: context.prefilledPhone,
|
|
432
|
-
phoneError: context.phoneError
|
|
433
|
-
};
|
|
434
|
-
if (typedSnapshot.matches("submitting")) return { status: "submitting" };
|
|
435
|
-
if (typedSnapshot.matches("sendingOtp")) return { status: "sendingOtp" };
|
|
436
|
-
if (typedSnapshot.matches("awaitingOtp")) return {
|
|
437
|
-
status: "awaitingOtp",
|
|
438
|
-
resendTimer: context.resendTimer,
|
|
439
|
-
canResend: !context.resendTimerActive,
|
|
440
|
-
attemptsRemaining: context.attemptsRemaining
|
|
441
|
-
};
|
|
442
|
-
if (typedSnapshot.matches("verifyingOtp")) return { status: "verifyingOtp" };
|
|
443
|
-
if (typedSnapshot.matches("otpError")) return {
|
|
444
|
-
status: "otpError",
|
|
445
|
-
error: context.otpError ?? "Invalid OTP code",
|
|
446
|
-
attemptsRemaining: context.attemptsRemaining
|
|
447
|
-
};
|
|
448
|
-
if (typedSnapshot.matches("success")) return { status: "success" };
|
|
449
|
-
if (typedSnapshot.matches("error")) return {
|
|
450
|
-
status: "error",
|
|
451
|
-
error: context.error ?? "An error occurred"
|
|
452
|
-
};
|
|
453
|
-
return { status: "idle" };
|
|
454
|
-
}
|
|
455
|
-
function createApi({ actor }) {
|
|
456
|
-
return {
|
|
457
|
-
load() {
|
|
458
|
-
actor.send({ type: "LOAD" });
|
|
459
|
-
},
|
|
460
|
-
setPhoneNumber(phone, isValid) {
|
|
461
|
-
actor.send({
|
|
462
|
-
type: "PHONE_CHANGED",
|
|
463
|
-
phone,
|
|
464
|
-
isValid
|
|
465
|
-
});
|
|
466
|
-
},
|
|
467
|
-
setOptInGranted(granted) {
|
|
468
|
-
actor.send({
|
|
469
|
-
type: "OPT_IN_CHANGED",
|
|
470
|
-
granted
|
|
471
|
-
});
|
|
472
|
-
},
|
|
473
|
-
submit() {
|
|
474
|
-
actor.send({ type: "SUBMIT" });
|
|
475
|
-
},
|
|
476
|
-
setOtpCode(code) {
|
|
477
|
-
actor.send({
|
|
478
|
-
type: "OTP_CHANGED",
|
|
479
|
-
code
|
|
480
|
-
});
|
|
481
|
-
},
|
|
482
|
-
submitOtp(code) {
|
|
483
|
-
actor.send({
|
|
484
|
-
type: "OTP_CHANGED",
|
|
485
|
-
code
|
|
486
|
-
});
|
|
487
|
-
actor.send({ type: "VERIFY_OTP" });
|
|
488
|
-
},
|
|
489
|
-
resendOtp() {
|
|
490
|
-
actor.send({ type: "RESEND_OTP" });
|
|
491
|
-
},
|
|
492
|
-
back() {
|
|
493
|
-
actor.send({ type: "BACK" });
|
|
494
|
-
},
|
|
495
|
-
reset() {
|
|
496
|
-
actor.send({ type: "RESET" });
|
|
497
|
-
}
|
|
498
|
-
};
|
|
499
|
-
}
|
|
500
|
-
/**
|
|
501
|
-
* Creates a phone verification manager for headless or UI-driven usage.
|
|
502
|
-
*
|
|
503
|
-
* The manager provides a state machine-based API for phone number verification
|
|
504
|
-
* with optional OTP (one-time password) verification.
|
|
505
|
-
*
|
|
506
|
-
* @param options - Configuration options
|
|
507
|
-
* @param options.config - Phone verification configuration
|
|
508
|
-
* @param options.config.otpVerification - Whether to require OTP verification
|
|
509
|
-
* @param options.config.otpExpirationInMinutes - How long the OTP is valid
|
|
510
|
-
* @param options.config.prefill - Whether to fetch a pre-filled phone number
|
|
511
|
-
* @param options.config.isInstantVerify - Use instant verification API
|
|
512
|
-
* @param options.config.optinEnabled - Show marketing opt-in checkbox
|
|
513
|
-
* @param options.config.maxOtpAttempts - Maximum OTP verification attempts (default: 3)
|
|
514
|
-
*
|
|
515
|
-
* @returns Phone manager with state, API methods, and subscription
|
|
516
|
-
*
|
|
517
|
-
* @example Headless usage
|
|
518
|
-
* ```typescript
|
|
519
|
-
* const manager = createPhoneManager({
|
|
520
|
-
* config: { otpVerification: true, otpExpirationInMinutes: 5, prefill: false },
|
|
521
|
-
* });
|
|
522
|
-
*
|
|
523
|
-
* manager.subscribe((state) => console.log(state.status));
|
|
524
|
-
* manager.load();
|
|
525
|
-
* manager.setPhoneNumber('+14155551234', true);
|
|
526
|
-
* manager.submit();
|
|
527
|
-
* // ... wait for 'awaitingOtp' state ...
|
|
528
|
-
* manager.submitOtp('ABC123');
|
|
529
|
-
* manager.stop();
|
|
530
|
-
* ```
|
|
531
|
-
*
|
|
532
|
-
* @example With React/Preact UI hook
|
|
533
|
-
* ```tsx
|
|
534
|
-
* const [state, manager] = useManager(() => createPhoneManager({ config }));
|
|
535
|
-
*
|
|
536
|
-
* if (state.status === 'inputting') {
|
|
537
|
-
* return <input onChange={(e) => manager.setPhoneNumber(e.target.value, true)} />;
|
|
538
|
-
* }
|
|
539
|
-
* ```
|
|
540
|
-
*/
|
|
541
|
-
function createPhoneManager(options) {
|
|
542
|
-
return createManager({
|
|
543
|
-
actor: createPhoneActor(options),
|
|
544
|
-
mapState,
|
|
545
|
-
createApi
|
|
546
|
-
});
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
//#endregion
|
|
550
9
|
export { createPhoneManager, phoneMachine };
|