@incodetech/core 2.1.0-rc.1 → 2.1.0-rc.2
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/{BrowserStorageProvider-BpJM-gIl.esm.js → BrowserStorageProvider-D5xc7Lqo.esm.js} +18 -1
- package/dist/{Manager-BHn8wH8K.d.ts → Manager-B2OEDYqf.d.ts} +4 -1
- package/dist/{OpenViduRecordingProvider-O4GjBseO.esm.js → OpenViduRecordingProvider-DF7A4ZNJ.esm.js} +1 -1
- package/dist/{StreamCanvasCapture-yyl20qd9.d.ts → StreamCanvasCapture-Ctgyx-oD.d.ts} +1 -1
- package/dist/{StreamCanvasCapture-ImiDQdVA.esm.js → StreamCanvasCapture-Dr5n_iK1.esm.js} +1 -1
- package/dist/{WasmUtilProvider-BKWm8rSA.esm.js → WasmUtilProvider-CIu373BZ.esm.js} +10 -1
- package/dist/{addressSearch-DvmWXKZg.esm.js → addressSearch-BH96a3fq.esm.js} +4 -4
- package/dist/{ae-signature-BFZta3TZ.esm.js → ae-signature-CDEN8y-w.esm.js} +1 -1
- package/dist/ae-signature.d.ts +3 -3
- package/dist/ae-signature.esm.js +9 -7
- package/dist/antifraud.d.ts +3 -3
- package/dist/antifraud.esm.js +6 -6
- package/dist/{antifraudManager-CznnhyvD.d.ts → antifraudManager-B7WQTIdu.d.ts} +2 -2
- package/dist/antifraudManager-DZifA5zX.esm.js +83 -0
- package/dist/{antifraudStateMachine-Ccrb-Jxc.esm.js → antifraudStateMachine-DlKrK2hL.esm.js} +3 -3
- package/dist/authentication.d.ts +12 -13
- package/dist/authentication.esm.js +27 -27
- package/dist/{authenticationManager-BlR6mSaG.esm.js → authenticationManager-BM4LzyV7.esm.js} +17 -8
- package/dist/{authenticationManager-CaiQbp-q.d.ts → authenticationManager-Dve7mGLe.d.ts} +13 -3
- package/dist/{authenticationStateMachine-DkcGUMw5.esm.js → authenticationStateMachine-Chx3ySdT.esm.js} +20 -23
- package/dist/{backCameraStream-D7Wo4Nbx.esm.js → backCameraStream-iftkf3rd.esm.js} +3 -3
- package/dist/browser-DlFgHpoC-7tbRR1aR.esm.js +1425 -0
- package/dist/{browserSimulation-B1dWiXp7.esm.js → browserSimulation-CGjpdNA1.esm.js} +2 -2
- package/dist/camera.d.ts +1 -1
- package/dist/camera.esm.js +4 -4
- package/dist/certificate-issuance.d.ts +311 -0
- package/dist/certificate-issuance.esm.js +73 -0
- package/dist/certificateIssuanceStateMachine-CLNXtXaC.esm.js +127 -0
- package/dist/consent.d.ts +3 -3
- package/dist/consent.esm.js +6 -6
- package/dist/{consentManager-Cg5Sk2tv.d.ts → consentManager-BqUGU_YD.d.ts} +52 -52
- package/dist/{consentManager-BYo9Nu1r.esm.js → consentManager-psDCeJ0E.esm.js} +29 -5
- package/dist/{consentStateMachine-BG3yL8aC.esm.js → consentStateMachine-DRsFFSHE.esm.js} +3 -3
- package/dist/cpf-ocr.d.ts +3 -3
- package/dist/cpf-ocr.esm.js +6 -6
- package/dist/{cpfOcrManager-Dg1s_TY5.d.ts → cpfOcrManager-B2u9hMzd.d.ts} +19 -19
- package/dist/{cpfOcrManager-sSKegxox.esm.js → cpfOcrManager-BxcgxvgO.esm.js} +5 -5
- package/dist/cross-document-data-match.d.ts +1 -1
- package/dist/cross-document-data-match.esm.js +5 -5
- package/dist/curp-validation.d.ts +7 -7
- package/dist/curp-validation.esm.js +6 -6
- package/dist/{curpValidationManager-CFem6zP9.esm.js → curpValidationManager-BgLDw0Ub.esm.js} +51 -5
- package/dist/{curpValidationManager-RttixpIc.d.ts → curpValidationManager-Bt6CVD8b.d.ts} +4 -3
- package/dist/{curpValidationStateMachine-B7V_qp66.esm.js → curpValidationStateMachine-BK_wJ48C.esm.js} +3 -3
- package/dist/custom-fields.d.ts +3 -2
- package/dist/custom-fields.esm.js +48 -6
- package/dist/custom-watchlist.d.ts +1 -1
- package/dist/custom-watchlist.esm.js +26 -6
- package/dist/{customWatchlistStateMachine-HmFybXLX.esm.js → customWatchlistStateMachine-Bi4P59HM.esm.js} +3 -3
- package/dist/{deepsightLoader-8tnddNx-.esm.js → deepsightLoader-BMmvk0X6.esm.js} +13 -13
- package/dist/{deepsightService-Dh5P-hLf.d.ts → deepsightService-ByNKY5Jv.d.ts} +13 -2
- package/dist/{deepsightService-CrHmvx8X.esm.js → deepsightService-CEZrdiW0.esm.js} +7 -7
- package/dist/device.esm.js +4 -4
- package/dist/document-capture.d.ts +177 -177
- package/dist/document-capture.esm.js +77 -14
- package/dist/document-upload.d.ts +47 -47
- package/dist/document-upload.esm.js +9 -9
- package/dist/{documentCaptureStateMachine-CUTUzUw_.esm.js → documentCaptureStateMachine-MpwpJO7t.esm.js} +7 -7
- package/dist/dynamic-forms.d.ts +2 -2
- package/dist/dynamic-forms.esm.js +35 -285
- package/dist/dynamicFormsStateMachine-Do84A4uU.esm.js +284 -0
- package/dist/ekyb.d.ts +7 -6
- package/dist/ekyb.esm.js +59 -17
- package/dist/{ekybStateMachine-klc-AImJ.esm.js → ekybStateMachine-nsuPOw3f.esm.js} +5 -5
- package/dist/ekyc.d.ts +4 -3
- package/dist/ekyc.esm.js +54 -9
- package/dist/{ekycStateMachine-CXbpaJJn.esm.js → ekycStateMachine-DcynX0rj.esm.js} +5 -5
- package/dist/electronic-signature.d.ts +3 -3
- package/dist/electronic-signature.esm.js +8 -6
- package/dist/{electronicSignatureManager-BaECdJ1u.esm.js → electronicSignatureManager-B63aAuI5.esm.js} +103 -23
- package/dist/email.d.ts +4 -4
- package/dist/email.esm.js +8 -8
- package/dist/{emailManager-lAzDoQOs.d.ts → emailManager-C6D2u4mQ.d.ts} +4 -3
- package/dist/{emailManager--D5G3ChB.esm.js → emailManager-DxHjAe5u.esm.js} +46 -6
- package/dist/{emailStateMachine-CxTOMAjC.esm.js → emailStateMachine-758f34gg.esm.js} +5 -5
- package/dist/{endpoints-BeTK0Mlt.esm.js → endpoints-BM2_j_IE.esm.js} +2 -0
- package/dist/{events-Dvvriq9l.esm.js → events-DN-u67gb.esm.js} +110 -43
- package/dist/events.d.ts +21 -16
- package/dist/events.esm.js +2 -2
- package/dist/extensibility.d.ts +25 -26
- package/dist/extensibility.esm.js +58 -56
- package/dist/externalFetch-crimxkN9.esm.js +22 -0
- package/dist/face-match.d.ts +1 -1
- package/dist/face-match.esm.js +5 -5
- package/dist/{faceCaptureManagerFactory-ej2j1LMr.esm.js → faceCaptureManagerFactory-BNXZchWX.esm.js} +94 -13
- package/dist/{faceCaptureManagerFactory-CjdBUS6s.d.ts → faceCaptureManagerFactory-CL-7T_vH.d.ts} +20 -10
- package/dist/{faceCaptureSetup-B9t6bYze.esm.js → faceCaptureSetup-Dqb09D24.esm.js} +7 -7
- package/dist/{faceMatchStateMachine-DeXXzSuz.esm.js → faceMatchStateMachine-FikRaUZH.esm.js} +3 -3
- package/dist/field-comparison.d.ts +3 -3
- package/dist/field-comparison.esm.js +5 -5
- package/dist/{fieldComparisonManager-Bu5TaSr3.d.ts → fieldComparisonManager-BXc6-DJv.d.ts} +2 -2
- package/dist/{fieldComparisonManager-COGI2ARD.esm.js → fieldComparisonManager-Dic0DVgl.esm.js} +4 -4
- package/dist/fiscal-qr.d.ts +3 -3
- package/dist/fiscal-qr.esm.js +12 -12
- package/dist/flow-events.d.ts +6 -6
- package/dist/flow.d.ts +25 -15
- package/dist/flow.esm.js +43 -29
- package/dist/{flowCompletionService-BdR2cGgB.d.ts → flowCompletionService-CdGDKv0z.d.ts} +9 -1
- package/dist/flowCompletionService-D_CsiDZM.esm.js +42 -0
- package/dist/{flowServices-ChgTNggJ.esm.js → flowServices-ar5DXv71.esm.js} +4 -4
- package/dist/geolocation.d.ts +3 -2
- package/dist/geolocation.esm.js +35 -7
- package/dist/{geolocationStateMachine-Dvh7X0wF.esm.js → geolocationStateMachine-BWjrMGS_.esm.js} +4 -4
- package/dist/{getDeviceClass-C8Do2qYu.esm.js → getDeviceClass-rXKlXywy.esm.js} +1 -1
- package/dist/government-validation.d.ts +3 -3
- package/dist/government-validation.esm.js +42 -8
- package/dist/{governmentValidationStateMachine-DcJ-BfsC.esm.js → governmentValidationStateMachine-BoF7U1of.esm.js} +5 -5
- package/dist/home.d.ts +15 -15
- package/dist/home.esm.js +4 -4
- package/dist/http.d.ts +1 -0
- package/dist/http.esm.js +2 -2
- package/dist/id-ocr.d.ts +57 -57
- package/dist/id-ocr.esm.js +6 -6
- package/dist/id-verification.d.ts +27 -27
- package/dist/id-verification.esm.js +5 -5
- package/dist/id.d.ts +19 -13
- package/dist/id.esm.js +41 -33
- package/dist/{idCaptureManager-D3pwWutw.esm.js → idCaptureManager-Bm6Wm6Qv.esm.js} +91 -9
- package/dist/{idCaptureManager-ChCNmgBj.d.ts → idCaptureManager-BvGUSN2e.d.ts} +14 -9
- package/dist/{idCaptureStateMachine-B3AiDIsT.esm.js → idCaptureStateMachine-D1YhOj6n.esm.js} +155 -82
- package/dist/{idOcrStateMachine-CDQ5d_VM.esm.js → idOcrStateMachine-YMCDGplq.esm.js} +5 -5
- package/dist/{idVerificationStateMachine-kRxwImzO.esm.js → idVerificationStateMachine-Bo1IYuZH.esm.js} +3 -3
- package/dist/identity-reuse.d.ts +3 -3
- package/dist/identity-reuse.esm.js +6 -6
- package/dist/{identityReuseManager-C6n_97dw.esm.js → identityReuseManager-D0knIrOy.esm.js} +3 -3
- package/dist/{identityReuseManager-Cww-NDtd.d.ts → identityReuseManager-DcWSvC-A.d.ts} +33 -33
- package/dist/{identityReuseStateMachine-BfE5YiEr.esm.js → identityReuseStateMachine-CSQfZOqD.esm.js} +3 -3
- package/dist/index-52_qi4bd.d.ts +93 -0
- package/dist/{index-B5hPA0Bg.d.ts → index-BgxYUYuD.d.ts} +2 -2
- package/dist/{index-B9NysVDB.d.ts → index-DV134v62.d.ts} +169 -169
- package/dist/index.d.ts +3 -2
- package/dist/index.esm.js +13 -12
- package/dist/{invokeOnCaptureCallback-ygByVdnn.esm.js → invokeOnCaptureCallback-Dzemudhk.esm.js} +1 -1
- package/dist/{lib-BY67lgbq.esm.js → lib-7ZQ9BdKH.esm.js} +1 -1
- package/dist/mandatory-consent.d.ts +7 -7
- package/dist/mandatory-consent.esm.js +6 -6
- package/dist/{mandatoryConsentManager-H6D18cZB.esm.js → mandatoryConsentManager-Lon46nPQ.esm.js} +3 -3
- package/dist/{mandatoryConsentManager-Dq6WiOZh.d.ts → mandatoryConsentManager-Tzl5Qd35.d.ts} +50 -50
- package/dist/{mandatoryConsentStateMachine-DtQNW1ji.esm.js → mandatoryConsentStateMachine-D_dZ7IF6.esm.js} +3 -3
- package/dist/openviduLazy-B_s6jnEk.esm.js +3 -0
- package/dist/{openviduLazy-Dh14JNJc.esm.js → openviduLazy-oAXXI9w_.esm.js} +2 -2
- package/dist/{permissionGuards-D0wGddy7.esm.js → permissionGuards-D-Z-lgNj.esm.js} +1 -1
- package/dist/{permissionServices-Doec4X5L.esm.js → permissionServices-CPDboRoE.esm.js} +3 -3
- package/dist/phone.d.ts +4 -4
- package/dist/phone.esm.js +8 -8
- package/dist/{phoneManager-BmF-0Ez4.esm.js → phoneManager-Blt4Oc2P.esm.js} +47 -6
- package/dist/{phoneManager-fPmIBYQK.d.ts → phoneManager-TSq1Ief6.d.ts} +4 -3
- package/dist/{phoneStateMachine-BiV0yoEx.esm.js → phoneStateMachine-W3c6Z8sj.esm.js} +5 -5
- package/dist/{qe-signature-CUYPcHVo.esm.js → qe-signature-CQLK6LKE.esm.js} +1 -1
- package/dist/qe-signature.d.ts +3 -3
- package/dist/qe-signature.esm.js +9 -7
- package/dist/{recordingService-yRw7hfzU.esm.js → recordingService-CxMJP4tQ.esm.js} +15 -15
- package/dist/redirect-to-mobile.d.ts +3 -3
- package/dist/redirect-to-mobile.esm.js +8 -7
- package/dist/{redirectToMobileManager-Dy3t7o0C.esm.js → redirectToMobileManager-DCvpKdkD.esm.js} +4 -4
- package/dist/{redirectToMobileManager-BNe3IzC_.d.ts → redirectToMobileManager-yOHAmwg-.d.ts} +2 -2
- package/dist/{redirectToMobileStateMachine-DyAdRxfP.esm.js → redirectToMobileStateMachine-DC9z4Vfu.esm.js} +11 -21
- package/dist/{runChildModule-CuoHZ1cx.esm.js → runChildModule-C9G0wfVC.esm.js} +14 -24
- package/dist/selfie.d.ts +20 -14
- package/dist/selfie.esm.js +37 -30
- package/dist/{selfieManager-BNuTIGAz.esm.js → selfieManager-BRL6c_Oc.esm.js} +17 -8
- package/dist/{selfieManager-C2y_t6DG.d.ts → selfieManager-imY2dAcH.d.ts} +13 -3
- package/dist/{selfieStateMachine-Bv99bZJE.esm.js → selfieStateMachine-D2Q0uwDK.esm.js} +4 -4
- package/dist/{session-DoVb-OcB.esm.js → session-Be_IA1e0.esm.js} +3 -3
- package/dist/session.d.ts +9 -8
- package/dist/session.esm.js +14 -12
- package/dist/{sessionInitializer-DRB-hgbV.esm.js → sessionInitializer-CaiGA8GP.esm.js} +13 -10
- package/dist/{setup-BwCluiw3.d.ts → setup-BJZAkajt.d.ts} +47 -1
- package/dist/{setup-CUO4mErT.esm.js → setup-C7tintPc.esm.js} +34 -7
- package/dist/signature.d.ts +3 -2
- package/dist/signature.esm.js +48 -6
- package/dist/{signatureStateMachine-C5qqYLRz.esm.js → signatureStateMachine-DAxXmMrk.esm.js} +21 -39
- package/dist/{stats-BMNUG1AU.esm.js → stats-DntyIiGr.esm.js} +2 -2
- package/dist/stats.esm.js +3 -3
- package/dist/tri-CtxWthxz.esm.js +389 -0
- package/dist/tri.d.ts +2 -0
- package/dist/tri.esm-CrWAulDi.esm.js +2589 -0
- package/dist/tri.esm.js +4 -0
- package/dist/trust-graph.d.ts +3 -3
- package/dist/trust-graph.esm.js +3 -3
- package/dist/{types-DsnEVMhr.esm.js → types-BdVOWGGW.esm.js} +2 -1
- package/dist/{types-NuT8ftBV.d.ts → types-DpTWgfKY.d.ts} +2 -1
- package/dist/{types-DOUhndhT.d.ts → types-Dv-9WPJX.d.ts} +2 -2
- package/dist/{types-Bj9hdFjU.d.ts → types-Z9wv19v2.d.ts} +1 -1
- package/dist/urlUtils-8RNHyW3x.esm.js +16 -0
- package/dist/wasm.d.ts +3 -2
- package/dist/wasm.esm.js +13 -12
- package/dist/watchlist-for-business.d.ts +1 -1
- package/dist/watchlist-for-business.esm.js +29 -7
- package/dist/watchlist.d.ts +1 -1
- package/dist/watchlist.esm.js +27 -6
- package/dist/{watchlistForBusinessStateMachine-DMl8j2Ov.esm.js → watchlistForBusinessStateMachine-DtefJb-D.esm.js} +3 -3
- package/dist/{watchlistStateMachine-DmQlqI6L.esm.js → watchlistStateMachine-B0aIS2_n.esm.js} +3 -3
- package/dist/workflow.d.ts +161 -100
- package/dist/workflow.esm.js +85 -66
- package/dist/{xstate.esm-C9wncMQa.esm.js → xstate.esm-Dkm1jy5u.esm.js} +13 -4
- package/package.json +11 -1
- package/dist/StateMachine-BC_nGvrc.d.ts +0 -2
- package/dist/antifraudManager-CkV4u-LE.esm.js +0 -55
- package/dist/flowCompletionService-DdGojV9K.esm.js +0 -20
- package/dist/openviduLazy-B8L--0oe.esm.js +0 -3
- /package/dist/{Actor-Y0_Fj-KL.d.ts → Actor-fIPLXfoi.d.ts} +0 -0
- /package/dist/{BrowserTimerProvider-DhNc_x02.esm.js → BrowserTimerProvider-BVgutW_b.esm.js} +0 -0
- /package/dist/{ITimerCapability-CB0I1Uf2.esm.js → ITimerCapability-BvH0pDwp.esm.js} +0 -0
- /package/dist/{IpifyProvider-D4LWD15E.esm.js → IpifyProvider-oZf7Ke1O.esm.js} +0 -0
- /package/dist/{MotionSensorProvider-Bx7Mpzt0.esm.js → MotionSensorProvider-C9fPAJdS.esm.js} +0 -0
- /package/dist/{api-CESGtpbH.esm.js → api-DUZwyz0o.esm.js} +0 -0
- /package/dist/{apiError-B-j-gyDx.esm.js → apiError-D-GTvFrH.esm.js} +0 -0
- /package/dist/{camera-SRBpPq2X.d.ts → camera-biGPWlmx.d.ts} +0 -0
- /package/dist/{camera-DJWm3V4g.esm.js → camera-x4LjGTjZ.esm.js} +0 -0
- /package/dist/{canvas-SKcRBxsk.esm.js → canvas-7uX2izHb.esm.js} +0 -0
- /package/dist/{chunk-CMUKZ2uL.esm.js → chunk-BK1xu56N.esm.js} +0 -0
- /package/dist/{cpf-BRzggV8G.esm.js → cpf-xBg-DFNn.esm.js} +0 -0
- /package/dist/{dateUtils-AksLQmgV.esm.js → dateUtils-8dCcuArE.esm.js} +0 -0
- /package/dist/{getBrowser-C8DP7oTB.esm.js → getBrowser-Dv8LZyHE.esm.js} +0 -0
- /package/dist/{getDeviceClass-C0olyNFS.esm.js → getDeviceClass-C0zrM97a.esm.js} +0 -0
- /package/dist/{http-Cai3IoLS.esm.js → http-CfVTgMfU.esm.js} +0 -0
- /package/dist/{otp-DF5A0sFx.d.ts → otp-BHJnjEEc.d.ts} +0 -0
- /package/dist/{otp-CGMdUzBC.esm.js → otp-D87RTwrx.esm.js} +0 -0
- /package/dist/{platform-SKvEfCBh.esm.js → platform-BfoqeM61.esm.js} +0 -0
- /package/dist/{types-DvGZI7BF.d.ts → types-DYZja-k9.d.ts} +0 -0
- /package/dist/{types-ya0LN_MX.d.ts → types-F0IXbaCB.d.ts} +0 -0
- /package/dist/{warmup-Dg8Lh-50.d.ts → warmup--6HA3yUR.d.ts} +0 -0
|
@@ -1,287 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { n as eventModuleNames, o as createManagerInstrumentation } from "./events-
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
1
|
+
import "./api-DUZwyz0o.esm.js";
|
|
2
|
+
import { n as eventModuleNames, o as topLevelStateName, s as createManagerInstrumentation } from "./events-DN-u67gb.esm.js";
|
|
3
|
+
import "./endpoints-BM2_j_IE.esm.js";
|
|
4
|
+
import { c as createManager, s as createActor } from "./xstate.esm-Dkm1jy5u.esm.js";
|
|
5
|
+
import "./dateUtils-8dCcuArE.esm.js";
|
|
6
|
+
import { t as dynamicFormsMachine } from "./dynamicFormsStateMachine-Do84A4uU.esm.js";
|
|
6
7
|
|
|
7
|
-
//#region src/modules/dynamic-forms/dynamicFormsFields.ts
|
|
8
|
-
function getEffectiveType(question) {
|
|
9
|
-
return question.inputType ?? question.overrides ?? "TEXT";
|
|
10
|
-
}
|
|
11
|
-
const FORMAT_ERROR_KEY_BY_TYPE = {
|
|
12
|
-
PHONE: "phone.invalidPhone",
|
|
13
|
-
EMAIL: "verification.errors.emailInvalid",
|
|
14
|
-
CPF: "dynamicForms.invalidCpf"
|
|
15
|
-
};
|
|
16
|
-
function buildQuestionValidation(question) {
|
|
17
|
-
const effectiveType = getEffectiveType(question);
|
|
18
|
-
const rules = [];
|
|
19
|
-
if (!question.isOptional) rules.push({ type: "required" });
|
|
20
|
-
const formatErrorKey = FORMAT_ERROR_KEY_BY_TYPE[effectiveType];
|
|
21
|
-
if (formatErrorKey) rules.push({
|
|
22
|
-
type: "formatViaAnswerValidity",
|
|
23
|
-
errorKey: formatErrorKey
|
|
24
|
-
});
|
|
25
|
-
return rules;
|
|
26
|
-
}
|
|
27
|
-
function buildScreenFields(formScreen) {
|
|
28
|
-
return formScreen.questions.map((q) => ({
|
|
29
|
-
questionId: q.questionId,
|
|
30
|
-
inputType: getEffectiveType(q),
|
|
31
|
-
isOptional: q.isOptional ?? false,
|
|
32
|
-
validation: buildQuestionValidation(q)
|
|
33
|
-
}));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
//#endregion
|
|
37
|
-
//#region src/modules/dynamic-forms/dynamicFormsValidators.ts
|
|
38
|
-
const VALIDATORS = {
|
|
39
|
-
required: ({ value }) => value.trim().length === 0 ? "dynamicForms.fieldRequired" : void 0,
|
|
40
|
-
formatViaAnswerValidity: ({ questionId, answerValidity }, rule) => answerValidity[questionId] === false ? rule.errorKey : void 0
|
|
41
|
-
};
|
|
42
|
-
const normalizeValue = (value) => typeof value === "string" ? value : String(value ?? "");
|
|
43
|
-
function evaluateRules(input, rules) {
|
|
44
|
-
for (const rule of rules) {
|
|
45
|
-
const error = rule.type === "required" ? VALIDATORS.required(input) : VALIDATORS.formatViaAnswerValidity(input, rule);
|
|
46
|
-
if (error) return error;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
/** Runs full-screen validation. Returns first failing key per field; empty = pass. */
|
|
50
|
-
function validateScreenForm(answers, fields, answerValidity) {
|
|
51
|
-
return fields.reduce((errors, field) => {
|
|
52
|
-
const error = evaluateRules({
|
|
53
|
-
value: normalizeValue(answers[field.questionId]),
|
|
54
|
-
questionId: field.questionId,
|
|
55
|
-
answerValidity
|
|
56
|
-
}, field.validation);
|
|
57
|
-
if (error) errors[field.questionId] = error;
|
|
58
|
-
return errors;
|
|
59
|
-
}, {});
|
|
60
|
-
}
|
|
61
|
-
/** Runs single-field validation (blur). Unknown `questionId` → `undefined`. */
|
|
62
|
-
function validateScreenField(answers, questionId, fields, answerValidity) {
|
|
63
|
-
const field = fields.find((f) => f.questionId === questionId);
|
|
64
|
-
if (!field) return void 0;
|
|
65
|
-
return evaluateRules({
|
|
66
|
-
value: normalizeValue(answers[questionId]),
|
|
67
|
-
questionId,
|
|
68
|
-
answerValidity
|
|
69
|
-
}, field.validation);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
//#endregion
|
|
73
|
-
//#region src/modules/dynamic-forms/dynamicFormsServices.ts
|
|
74
|
-
async function fetchForms(flowId, signal) {
|
|
75
|
-
const url = `${endpoints.moduleConfig}?id=${encodeURIComponent(flowId)}&moduleKey=DYNAMIC_FORMS`;
|
|
76
|
-
const res = await api.get(url, { signal });
|
|
77
|
-
if (!res.ok) throw new Error(`GET ${endpoints.moduleConfig} failed: ${res.status} ${res.statusText}`);
|
|
78
|
-
return res.data;
|
|
79
|
-
}
|
|
80
|
-
async function submitFormAnswer(params, signal) {
|
|
81
|
-
const res = await api.post(endpoints.dynamicFormsSubmitAnswer, {
|
|
82
|
-
questionId: params.questionId,
|
|
83
|
-
answerDetails: { singleAnswer: params.singleAnswer }
|
|
84
|
-
}, { signal });
|
|
85
|
-
if (!res.ok) throw new Error(`POST ${endpoints.dynamicFormsSubmitAnswer} failed: ${res.status} ${res.statusText}`);
|
|
86
|
-
return res.data;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
//#endregion
|
|
90
|
-
//#region src/modules/dynamic-forms/dynamicFormsStateMachine.ts
|
|
91
|
-
function transformAnswerValue(inputType, value) {
|
|
92
|
-
switch (inputType) {
|
|
93
|
-
case "CPF": return value.replace(/[-.]/g, "");
|
|
94
|
-
case "DATE": return isoDateToMs(value).toString();
|
|
95
|
-
default: return value;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
const removeKey = (errors, key) => {
|
|
99
|
-
if (!errors?.[key]) return errors;
|
|
100
|
-
const next = { ...errors };
|
|
101
|
-
delete next[key];
|
|
102
|
-
return Object.keys(next).length > 0 ? next : void 0;
|
|
103
|
-
};
|
|
104
|
-
const upsertKey = (errors, key, message) => {
|
|
105
|
-
const next = { ...errors ?? {} };
|
|
106
|
-
if (message) next[key] = message;
|
|
107
|
-
else delete next[key];
|
|
108
|
-
return Object.keys(next).length > 0 ? next : void 0;
|
|
109
|
-
};
|
|
110
|
-
const dynamicFormsMachine = setup({
|
|
111
|
-
types: {
|
|
112
|
-
context: {},
|
|
113
|
-
events: {},
|
|
114
|
-
input: {}
|
|
115
|
-
},
|
|
116
|
-
actors: {
|
|
117
|
-
fetchScreens: fromPromise(async ({ input, signal }) => {
|
|
118
|
-
return fetchForms(input.flowId, signal);
|
|
119
|
-
}),
|
|
120
|
-
submitScreenAnswers: fromPromise(async ({ input, signal }) => {
|
|
121
|
-
const { screen: formScreen, answers } = input;
|
|
122
|
-
for (const question of formScreen.questions) {
|
|
123
|
-
const singleAnswer = transformAnswerValue(question.inputType ?? question.overrides ?? "TEXT", answers[question.questionId] ?? "");
|
|
124
|
-
try {
|
|
125
|
-
await submitFormAnswer({
|
|
126
|
-
questionId: question.questionId,
|
|
127
|
-
singleAnswer
|
|
128
|
-
}, signal);
|
|
129
|
-
} catch {}
|
|
130
|
-
}
|
|
131
|
-
return { success: true };
|
|
132
|
-
})
|
|
133
|
-
},
|
|
134
|
-
actions: {
|
|
135
|
-
setScreens: assign(({ event }) => {
|
|
136
|
-
const screens = event.output.screens;
|
|
137
|
-
const firstScreen = screens[0];
|
|
138
|
-
return {
|
|
139
|
-
screens,
|
|
140
|
-
answers: {},
|
|
141
|
-
currentScreenFields: firstScreen ? buildScreenFields(firstScreen) : []
|
|
142
|
-
};
|
|
143
|
-
}),
|
|
144
|
-
setAnswer: assign(({ context, event }) => {
|
|
145
|
-
const e = event;
|
|
146
|
-
return {
|
|
147
|
-
answers: {
|
|
148
|
-
...context.answers,
|
|
149
|
-
[e.questionId]: e.value
|
|
150
|
-
},
|
|
151
|
-
validationErrors: removeKey(context.validationErrors, e.questionId)
|
|
152
|
-
};
|
|
153
|
-
}),
|
|
154
|
-
setAnswerValidity: assign(({ context, event }) => {
|
|
155
|
-
const e = event;
|
|
156
|
-
return {
|
|
157
|
-
answerValidity: {
|
|
158
|
-
...context.answerValidity,
|
|
159
|
-
[e.questionId]: e.isValid
|
|
160
|
-
},
|
|
161
|
-
validationErrors: removeKey(context.validationErrors, e.questionId)
|
|
162
|
-
};
|
|
163
|
-
}),
|
|
164
|
-
validateFormField: assign(({ context, event }) => {
|
|
165
|
-
if (event.type !== "VALIDATE_FIELD") return {};
|
|
166
|
-
const message = validateScreenField(context.answers, event.questionId, context.currentScreenFields, context.answerValidity);
|
|
167
|
-
return { validationErrors: upsertKey(context.validationErrors, event.questionId, message) };
|
|
168
|
-
}),
|
|
169
|
-
computeValidationResult: assign(({ context }) => {
|
|
170
|
-
const errors = validateScreenForm(context.answers, context.currentScreenFields, context.answerValidity);
|
|
171
|
-
return { validationErrors: Object.keys(errors).length > 0 ? errors : void 0 };
|
|
172
|
-
}),
|
|
173
|
-
advanceScreen: assign(({ context }) => {
|
|
174
|
-
const nextIndex = context.currentScreenIndex + 1;
|
|
175
|
-
const nextScreen = context.screens[nextIndex];
|
|
176
|
-
return {
|
|
177
|
-
currentScreenIndex: nextIndex,
|
|
178
|
-
answers: {},
|
|
179
|
-
answerValidity: {},
|
|
180
|
-
currentScreenFields: nextScreen ? buildScreenFields(nextScreen) : [],
|
|
181
|
-
validationErrors: void 0
|
|
182
|
-
};
|
|
183
|
-
}),
|
|
184
|
-
markCompleted: assign({ result: "completed" }),
|
|
185
|
-
markSkipped: assign({ result: "skipped" })
|
|
186
|
-
},
|
|
187
|
-
guards: {
|
|
188
|
-
hasPreloadedScreens: ({ context }) => (context.config.screens?.length ?? 0) > 0,
|
|
189
|
-
hasFlowId: ({ context }) => !!context.config.flowId,
|
|
190
|
-
isLastScreen: ({ context }) => context.currentScreenIndex >= context.screens.length - 1,
|
|
191
|
-
isScreenValid: ({ context }) => Object.keys(context.validationErrors ?? {}).length === 0
|
|
192
|
-
}
|
|
193
|
-
}).createMachine({
|
|
194
|
-
id: "dynamicForms",
|
|
195
|
-
initial: "idle",
|
|
196
|
-
context: ({ input }) => {
|
|
197
|
-
const screens = input.config.screens ?? [];
|
|
198
|
-
const firstScreen = screens[0];
|
|
199
|
-
return {
|
|
200
|
-
config: input.config,
|
|
201
|
-
screens,
|
|
202
|
-
currentScreenIndex: 0,
|
|
203
|
-
answers: {},
|
|
204
|
-
answerValidity: {},
|
|
205
|
-
currentScreenFields: firstScreen ? buildScreenFields(firstScreen) : [],
|
|
206
|
-
result: null
|
|
207
|
-
};
|
|
208
|
-
},
|
|
209
|
-
states: {
|
|
210
|
-
idle: { on: { LOAD: [
|
|
211
|
-
{
|
|
212
|
-
target: "inputting",
|
|
213
|
-
guard: "hasPreloadedScreens"
|
|
214
|
-
},
|
|
215
|
-
{
|
|
216
|
-
target: "loadingScreens",
|
|
217
|
-
guard: "hasFlowId"
|
|
218
|
-
},
|
|
219
|
-
{ target: "misconfigured" }
|
|
220
|
-
] } },
|
|
221
|
-
loadingScreens: { invoke: {
|
|
222
|
-
id: "fetchScreens",
|
|
223
|
-
src: "fetchScreens",
|
|
224
|
-
input: ({ context }) => ({ flowId: context.config.flowId ?? "" }),
|
|
225
|
-
onDone: {
|
|
226
|
-
target: "inputting",
|
|
227
|
-
actions: "setScreens"
|
|
228
|
-
},
|
|
229
|
-
onError: {
|
|
230
|
-
target: "finished",
|
|
231
|
-
actions: "markSkipped"
|
|
232
|
-
}
|
|
233
|
-
} },
|
|
234
|
-
inputting: {
|
|
235
|
-
initial: "editing",
|
|
236
|
-
states: {
|
|
237
|
-
editing: { on: {
|
|
238
|
-
ANSWER_CHANGED: { actions: "setAnswer" },
|
|
239
|
-
ANSWER_VALIDITY_CHANGED: { actions: "setAnswerValidity" },
|
|
240
|
-
VALIDATE_FIELD: { actions: "validateFormField" },
|
|
241
|
-
SUBMIT: { target: "validatingSubmit" }
|
|
242
|
-
} },
|
|
243
|
-
validatingSubmit: {
|
|
244
|
-
entry: "computeValidationResult",
|
|
245
|
-
always: [{
|
|
246
|
-
guard: "isScreenValid",
|
|
247
|
-
target: "#dynamicForms.submitting"
|
|
248
|
-
}, { target: "editing" }]
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
},
|
|
252
|
-
submitting: { invoke: {
|
|
253
|
-
id: "submitScreenAnswers",
|
|
254
|
-
src: "submitScreenAnswers",
|
|
255
|
-
input: ({ context }) => ({
|
|
256
|
-
screen: context.screens[context.currentScreenIndex],
|
|
257
|
-
answers: context.answers
|
|
258
|
-
}),
|
|
259
|
-
onDone: [{
|
|
260
|
-
target: "success",
|
|
261
|
-
guard: "isLastScreen"
|
|
262
|
-
}, {
|
|
263
|
-
target: "inputting",
|
|
264
|
-
actions: "advanceScreen"
|
|
265
|
-
}],
|
|
266
|
-
onError: [{
|
|
267
|
-
target: "success",
|
|
268
|
-
guard: "isLastScreen"
|
|
269
|
-
}, {
|
|
270
|
-
target: "inputting",
|
|
271
|
-
actions: "advanceScreen"
|
|
272
|
-
}]
|
|
273
|
-
} },
|
|
274
|
-
success: { after: { 3e3: {
|
|
275
|
-
target: "finished",
|
|
276
|
-
actions: "markCompleted"
|
|
277
|
-
} } },
|
|
278
|
-
finished: { type: "final" },
|
|
279
|
-
misconfigured: { on: { CLOSE: { target: "closed" } } },
|
|
280
|
-
closed: { type: "final" }
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
//#endregion
|
|
285
8
|
//#region src/modules/dynamic-forms/dynamicFormsActor.ts
|
|
286
9
|
function createDynamicFormsActor(options) {
|
|
287
10
|
return createActor(dynamicFormsMachine, { input: { config: options.config } }).start();
|
|
@@ -322,6 +45,31 @@ function createDynamicFormsActor(options) {
|
|
|
322
45
|
function hasNoErrors(errors) {
|
|
323
46
|
return Object.keys(errors ?? {}).length === 0;
|
|
324
47
|
}
|
|
48
|
+
function hasAnyAnswer(answers) {
|
|
49
|
+
for (const value of Object.values(answers)) if (typeof value === "string" && value.length > 0) return true;
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Maps a Dynamic Forms state-machine snapshot to the exact Figma
|
|
54
|
+
* "Tracked Events" screen name. Source: Forms and Data entry Figma file
|
|
55
|
+
* (`https://www.figma.com/design/N6otHMuY2Hha5eBqRz0uC3/Forms-and-Data-entry---Latest-Designs?node-id=53-60567`).
|
|
56
|
+
* Family is `forms.*` with a single longform sub-family.
|
|
57
|
+
*
|
|
58
|
+
* `idle`, `loadingScreens`, `submitting`, `misconfigured`, and `closed` are
|
|
59
|
+
* intentionally unmapped — the Figma canvas does not define discrete
|
|
60
|
+
* tracked-event surfaces for them. They fall back to the generic
|
|
61
|
+
* `<module>.<state>` default.
|
|
62
|
+
*/
|
|
63
|
+
function getDynamicFormsScreenName(snapshot) {
|
|
64
|
+
const stateName = topLevelStateName(snapshot.value);
|
|
65
|
+
if (stateName === void 0) return void 0;
|
|
66
|
+
switch (stateName) {
|
|
67
|
+
case "inputting": return hasAnyAnswer(snapshot.context.answers) ? "forms.longform.filled" : "forms.longform.default";
|
|
68
|
+
case "success":
|
|
69
|
+
case "finished": return "forms.success";
|
|
70
|
+
default: return;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
325
73
|
function mapState(snapshot) {
|
|
326
74
|
const typedSnapshot = snapshot;
|
|
327
75
|
const { context } = typedSnapshot;
|
|
@@ -358,7 +106,7 @@ function mapState(snapshot) {
|
|
|
358
106
|
if (typedSnapshot.matches("closed")) return { status: "closed" };
|
|
359
107
|
return { status: "idle" };
|
|
360
108
|
}
|
|
361
|
-
function createApi({ actor }) {
|
|
109
|
+
function createApi({ actor, trackElementClicked }) {
|
|
362
110
|
return {
|
|
363
111
|
load() {
|
|
364
112
|
actor.send({ type: "LOAD" });
|
|
@@ -384,9 +132,11 @@ function createApi({ actor }) {
|
|
|
384
132
|
});
|
|
385
133
|
},
|
|
386
134
|
submit() {
|
|
135
|
+
trackElementClicked?.("submit");
|
|
387
136
|
actor.send({ type: "SUBMIT" });
|
|
388
137
|
},
|
|
389
138
|
close() {
|
|
139
|
+
trackElementClicked?.("close");
|
|
390
140
|
actor.send({ type: "CLOSE" });
|
|
391
141
|
}
|
|
392
142
|
};
|
|
@@ -404,7 +154,7 @@ function createDynamicFormsManager(options) {
|
|
|
404
154
|
actor: createDynamicFormsActor(options),
|
|
405
155
|
mapState,
|
|
406
156
|
createApi,
|
|
407
|
-
instrumentation: createManagerInstrumentation(eventModuleNames.forms)
|
|
157
|
+
instrumentation: createManagerInstrumentation(eventModuleNames.forms, { getEventScreenName: getDynamicFormsScreenName })
|
|
408
158
|
});
|
|
409
159
|
}
|
|
410
160
|
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import { t as api } from "./api-DUZwyz0o.esm.js";
|
|
2
|
+
import { t as endpoints } from "./endpoints-BM2_j_IE.esm.js";
|
|
3
|
+
import { a as fromPromise, r as assign, t as setup } from "./xstate.esm-Dkm1jy5u.esm.js";
|
|
4
|
+
import { t as isoDateToMs } from "./dateUtils-8dCcuArE.esm.js";
|
|
5
|
+
|
|
6
|
+
//#region src/modules/dynamic-forms/dynamicFormsFields.ts
|
|
7
|
+
function getEffectiveType(question) {
|
|
8
|
+
return question.inputType ?? question.overrides ?? "TEXT";
|
|
9
|
+
}
|
|
10
|
+
const FORMAT_ERROR_KEY_BY_TYPE = {
|
|
11
|
+
PHONE: "phone.invalidPhone",
|
|
12
|
+
EMAIL: "verification.errors.emailInvalid",
|
|
13
|
+
CPF: "dynamicForms.invalidCpf"
|
|
14
|
+
};
|
|
15
|
+
function buildQuestionValidation(question) {
|
|
16
|
+
const effectiveType = getEffectiveType(question);
|
|
17
|
+
const rules = [];
|
|
18
|
+
if (!question.isOptional) rules.push({ type: "required" });
|
|
19
|
+
const formatErrorKey = FORMAT_ERROR_KEY_BY_TYPE[effectiveType];
|
|
20
|
+
if (formatErrorKey) rules.push({
|
|
21
|
+
type: "formatViaAnswerValidity",
|
|
22
|
+
errorKey: formatErrorKey
|
|
23
|
+
});
|
|
24
|
+
return rules;
|
|
25
|
+
}
|
|
26
|
+
function buildScreenFields(formScreen) {
|
|
27
|
+
return formScreen.questions.map((q) => ({
|
|
28
|
+
questionId: q.questionId,
|
|
29
|
+
inputType: getEffectiveType(q),
|
|
30
|
+
isOptional: q.isOptional ?? false,
|
|
31
|
+
validation: buildQuestionValidation(q)
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/modules/dynamic-forms/dynamicFormsValidators.ts
|
|
37
|
+
const VALIDATORS = {
|
|
38
|
+
required: ({ value }) => value.trim().length === 0 ? "dynamicForms.fieldRequired" : void 0,
|
|
39
|
+
formatViaAnswerValidity: ({ questionId, answerValidity }, rule) => answerValidity[questionId] === false ? rule.errorKey : void 0
|
|
40
|
+
};
|
|
41
|
+
const normalizeValue = (value) => typeof value === "string" ? value : String(value ?? "");
|
|
42
|
+
function evaluateRules(input, rules) {
|
|
43
|
+
for (const rule of rules) {
|
|
44
|
+
const error = rule.type === "required" ? VALIDATORS.required(input) : VALIDATORS.formatViaAnswerValidity(input, rule);
|
|
45
|
+
if (error) return error;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** Runs full-screen validation. Returns first failing key per field; empty = pass. */
|
|
49
|
+
function validateScreenForm(answers, fields, answerValidity) {
|
|
50
|
+
return fields.reduce((errors, field) => {
|
|
51
|
+
const error = evaluateRules({
|
|
52
|
+
value: normalizeValue(answers[field.questionId]),
|
|
53
|
+
questionId: field.questionId,
|
|
54
|
+
answerValidity
|
|
55
|
+
}, field.validation);
|
|
56
|
+
if (error) errors[field.questionId] = error;
|
|
57
|
+
return errors;
|
|
58
|
+
}, {});
|
|
59
|
+
}
|
|
60
|
+
/** Runs single-field validation (blur). Unknown `questionId` → `undefined`. */
|
|
61
|
+
function validateScreenField(answers, questionId, fields, answerValidity) {
|
|
62
|
+
const field = fields.find((f) => f.questionId === questionId);
|
|
63
|
+
if (!field) return void 0;
|
|
64
|
+
return evaluateRules({
|
|
65
|
+
value: normalizeValue(answers[questionId]),
|
|
66
|
+
questionId,
|
|
67
|
+
answerValidity
|
|
68
|
+
}, field.validation);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/modules/dynamic-forms/dynamicFormsServices.ts
|
|
73
|
+
async function fetchForms(flowId, signal) {
|
|
74
|
+
const url = `${endpoints.moduleConfig}?id=${encodeURIComponent(flowId)}&moduleKey=DYNAMIC_FORMS`;
|
|
75
|
+
const res = await api.get(url, { signal });
|
|
76
|
+
if (!res.ok) throw new Error(`GET ${endpoints.moduleConfig} failed: ${res.status} ${res.statusText}`);
|
|
77
|
+
return res.data;
|
|
78
|
+
}
|
|
79
|
+
async function submitFormAnswer(params, signal) {
|
|
80
|
+
const res = await api.post(endpoints.dynamicFormsSubmitAnswer, {
|
|
81
|
+
questionId: params.questionId,
|
|
82
|
+
answerDetails: { singleAnswer: params.singleAnswer }
|
|
83
|
+
}, { signal });
|
|
84
|
+
if (!res.ok) throw new Error(`POST ${endpoints.dynamicFormsSubmitAnswer} failed: ${res.status} ${res.statusText}`);
|
|
85
|
+
return res.data;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/modules/dynamic-forms/dynamicFormsStateMachine.ts
|
|
90
|
+
function transformAnswerValue(inputType, value) {
|
|
91
|
+
switch (inputType) {
|
|
92
|
+
case "CPF": return value.replace(/[-.]/g, "");
|
|
93
|
+
case "DATE": return isoDateToMs(value).toString();
|
|
94
|
+
default: return value;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const removeKey = (errors, key) => {
|
|
98
|
+
if (!errors?.[key]) return errors;
|
|
99
|
+
const next = { ...errors };
|
|
100
|
+
delete next[key];
|
|
101
|
+
return Object.keys(next).length > 0 ? next : void 0;
|
|
102
|
+
};
|
|
103
|
+
const upsertKey = (errors, key, message) => {
|
|
104
|
+
const next = { ...errors ?? {} };
|
|
105
|
+
if (message) next[key] = message;
|
|
106
|
+
else delete next[key];
|
|
107
|
+
return Object.keys(next).length > 0 ? next : void 0;
|
|
108
|
+
};
|
|
109
|
+
const dynamicFormsMachine = setup({
|
|
110
|
+
types: {
|
|
111
|
+
context: {},
|
|
112
|
+
events: {},
|
|
113
|
+
input: {}
|
|
114
|
+
},
|
|
115
|
+
actors: {
|
|
116
|
+
fetchScreens: fromPromise(async ({ input, signal }) => {
|
|
117
|
+
return fetchForms(input.flowId, signal);
|
|
118
|
+
}),
|
|
119
|
+
submitScreenAnswers: fromPromise(async ({ input, signal }) => {
|
|
120
|
+
const { screen: formScreen, answers } = input;
|
|
121
|
+
for (const question of formScreen.questions) {
|
|
122
|
+
const singleAnswer = transformAnswerValue(question.inputType ?? question.overrides ?? "TEXT", answers[question.questionId] ?? "");
|
|
123
|
+
try {
|
|
124
|
+
await submitFormAnswer({
|
|
125
|
+
questionId: question.questionId,
|
|
126
|
+
singleAnswer
|
|
127
|
+
}, signal);
|
|
128
|
+
} catch {}
|
|
129
|
+
}
|
|
130
|
+
return { success: true };
|
|
131
|
+
})
|
|
132
|
+
},
|
|
133
|
+
actions: {
|
|
134
|
+
setScreens: assign(({ event }) => {
|
|
135
|
+
const screens = event.output.screens;
|
|
136
|
+
const firstScreen = screens[0];
|
|
137
|
+
return {
|
|
138
|
+
screens,
|
|
139
|
+
answers: {},
|
|
140
|
+
currentScreenFields: firstScreen ? buildScreenFields(firstScreen) : []
|
|
141
|
+
};
|
|
142
|
+
}),
|
|
143
|
+
setAnswer: assign(({ context, event }) => {
|
|
144
|
+
const e = event;
|
|
145
|
+
return {
|
|
146
|
+
answers: {
|
|
147
|
+
...context.answers,
|
|
148
|
+
[e.questionId]: e.value
|
|
149
|
+
},
|
|
150
|
+
validationErrors: removeKey(context.validationErrors, e.questionId)
|
|
151
|
+
};
|
|
152
|
+
}),
|
|
153
|
+
setAnswerValidity: assign(({ context, event }) => {
|
|
154
|
+
const e = event;
|
|
155
|
+
return {
|
|
156
|
+
answerValidity: {
|
|
157
|
+
...context.answerValidity,
|
|
158
|
+
[e.questionId]: e.isValid
|
|
159
|
+
},
|
|
160
|
+
validationErrors: removeKey(context.validationErrors, e.questionId)
|
|
161
|
+
};
|
|
162
|
+
}),
|
|
163
|
+
validateFormField: assign(({ context, event }) => {
|
|
164
|
+
if (event.type !== "VALIDATE_FIELD") return {};
|
|
165
|
+
const message = validateScreenField(context.answers, event.questionId, context.currentScreenFields, context.answerValidity);
|
|
166
|
+
return { validationErrors: upsertKey(context.validationErrors, event.questionId, message) };
|
|
167
|
+
}),
|
|
168
|
+
computeValidationResult: assign(({ context }) => {
|
|
169
|
+
const errors = validateScreenForm(context.answers, context.currentScreenFields, context.answerValidity);
|
|
170
|
+
return { validationErrors: Object.keys(errors).length > 0 ? errors : void 0 };
|
|
171
|
+
}),
|
|
172
|
+
advanceScreen: assign(({ context }) => {
|
|
173
|
+
const nextIndex = context.currentScreenIndex + 1;
|
|
174
|
+
const nextScreen = context.screens[nextIndex];
|
|
175
|
+
return {
|
|
176
|
+
currentScreenIndex: nextIndex,
|
|
177
|
+
answers: {},
|
|
178
|
+
answerValidity: {},
|
|
179
|
+
currentScreenFields: nextScreen ? buildScreenFields(nextScreen) : [],
|
|
180
|
+
validationErrors: void 0
|
|
181
|
+
};
|
|
182
|
+
}),
|
|
183
|
+
markCompleted: assign({ result: "completed" }),
|
|
184
|
+
markSkipped: assign({ result: "skipped" })
|
|
185
|
+
},
|
|
186
|
+
guards: {
|
|
187
|
+
hasPreloadedScreens: ({ context }) => (context.config.screens?.length ?? 0) > 0,
|
|
188
|
+
hasFlowId: ({ context }) => !!context.config.flowId,
|
|
189
|
+
isLastScreen: ({ context }) => context.currentScreenIndex >= context.screens.length - 1,
|
|
190
|
+
isScreenValid: ({ context }) => Object.keys(context.validationErrors ?? {}).length === 0
|
|
191
|
+
}
|
|
192
|
+
}).createMachine({
|
|
193
|
+
id: "dynamicForms",
|
|
194
|
+
initial: "idle",
|
|
195
|
+
context: ({ input }) => {
|
|
196
|
+
const screens = input.config.screens ?? [];
|
|
197
|
+
const firstScreen = screens[0];
|
|
198
|
+
return {
|
|
199
|
+
config: input.config,
|
|
200
|
+
screens,
|
|
201
|
+
currentScreenIndex: 0,
|
|
202
|
+
answers: {},
|
|
203
|
+
answerValidity: {},
|
|
204
|
+
currentScreenFields: firstScreen ? buildScreenFields(firstScreen) : [],
|
|
205
|
+
result: null
|
|
206
|
+
};
|
|
207
|
+
},
|
|
208
|
+
states: {
|
|
209
|
+
idle: { on: { LOAD: [
|
|
210
|
+
{
|
|
211
|
+
target: "inputting",
|
|
212
|
+
guard: "hasPreloadedScreens"
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
target: "loadingScreens",
|
|
216
|
+
guard: "hasFlowId"
|
|
217
|
+
},
|
|
218
|
+
{ target: "misconfigured" }
|
|
219
|
+
] } },
|
|
220
|
+
loadingScreens: { invoke: {
|
|
221
|
+
id: "fetchScreens",
|
|
222
|
+
src: "fetchScreens",
|
|
223
|
+
input: ({ context }) => ({ flowId: context.config.flowId ?? "" }),
|
|
224
|
+
onDone: {
|
|
225
|
+
target: "inputting",
|
|
226
|
+
actions: "setScreens"
|
|
227
|
+
},
|
|
228
|
+
onError: {
|
|
229
|
+
target: "finished",
|
|
230
|
+
actions: "markSkipped"
|
|
231
|
+
}
|
|
232
|
+
} },
|
|
233
|
+
inputting: {
|
|
234
|
+
initial: "editing",
|
|
235
|
+
states: {
|
|
236
|
+
editing: { on: {
|
|
237
|
+
ANSWER_CHANGED: { actions: "setAnswer" },
|
|
238
|
+
ANSWER_VALIDITY_CHANGED: { actions: "setAnswerValidity" },
|
|
239
|
+
VALIDATE_FIELD: { actions: "validateFormField" },
|
|
240
|
+
SUBMIT: { target: "validatingSubmit" }
|
|
241
|
+
} },
|
|
242
|
+
validatingSubmit: {
|
|
243
|
+
entry: "computeValidationResult",
|
|
244
|
+
always: [{
|
|
245
|
+
guard: "isScreenValid",
|
|
246
|
+
target: "#dynamicForms.submitting"
|
|
247
|
+
}, { target: "editing" }]
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
submitting: { invoke: {
|
|
252
|
+
id: "submitScreenAnswers",
|
|
253
|
+
src: "submitScreenAnswers",
|
|
254
|
+
input: ({ context }) => ({
|
|
255
|
+
screen: context.screens[context.currentScreenIndex],
|
|
256
|
+
answers: context.answers
|
|
257
|
+
}),
|
|
258
|
+
onDone: [{
|
|
259
|
+
target: "success",
|
|
260
|
+
guard: "isLastScreen"
|
|
261
|
+
}, {
|
|
262
|
+
target: "inputting",
|
|
263
|
+
actions: "advanceScreen"
|
|
264
|
+
}],
|
|
265
|
+
onError: [{
|
|
266
|
+
target: "success",
|
|
267
|
+
guard: "isLastScreen"
|
|
268
|
+
}, {
|
|
269
|
+
target: "inputting",
|
|
270
|
+
actions: "advanceScreen"
|
|
271
|
+
}]
|
|
272
|
+
} },
|
|
273
|
+
success: { after: { 3e3: {
|
|
274
|
+
target: "finished",
|
|
275
|
+
actions: "markCompleted"
|
|
276
|
+
} } },
|
|
277
|
+
finished: { type: "final" },
|
|
278
|
+
misconfigured: { on: { CLOSE: { target: "closed" } } },
|
|
279
|
+
closed: { type: "final" }
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
//#endregion
|
|
284
|
+
export { dynamicFormsMachine as t };
|
package/dist/ekyb.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { t as Manager } from "./Manager-
|
|
2
|
-
import "./Actor-
|
|
3
|
-
import "./camera-
|
|
4
|
-
import "./types-
|
|
5
|
-
import { c as AddressSuggestion, l as FieldDef } from "./types-
|
|
6
|
-
import { i as FlowModuleConfig } from "./types-
|
|
1
|
+
import { t as Manager } from "./Manager-B2OEDYqf.js";
|
|
2
|
+
import "./Actor-fIPLXfoi.js";
|
|
3
|
+
import "./camera-biGPWlmx.js";
|
|
4
|
+
import "./types-Z9wv19v2.js";
|
|
5
|
+
import { c as AddressSuggestion, l as FieldDef } from "./types-DYZja-k9.js";
|
|
6
|
+
import { i as FlowModuleConfig } from "./types-Dv-9WPJX.js";
|
|
7
7
|
|
|
8
8
|
//#region src/modules/ekyb/types.d.ts
|
|
9
9
|
type UboEntry = {
|
|
@@ -60,6 +60,7 @@ type CreateEkybActorOptions = {
|
|
|
60
60
|
};
|
|
61
61
|
//#endregion
|
|
62
62
|
//#region src/modules/ekyb/ekybManager.d.ts
|
|
63
|
+
|
|
63
64
|
type EkybLoadingState = {
|
|
64
65
|
status: 'loading';
|
|
65
66
|
};
|