3.1.2 • Published 2 days ago

trully-sdk-react-2 v3.1.2

Weekly downloads
-
License
-
Repository
-
Last release
2 days ago

TrullyWebSDK

Install

npm i trully-sdk-react-2

How to use

The component receives the configuration prop, which should contain an object for configuring and personalizing the experience. This object has three keys: DocumentReader, AppConfiguration, and usage. Of these keys, only usage is required for the component to function properly.

The DocumentReader key will pass data related to document scanning. The AppConfiguration key will pass colors, images, fonts, and URLs that can be used to create your own KYC experience. Finally, the usage key will receive the necessary API Key to obtain the Decision Maker data, the user ID to match Decision Maker response with user, two functions to manage the response: handleData will allow you to access the response, while handleError will let you control what to do in case of a communication error.

KeyDescription
usageObject containing process configuration settings
AppConfigurationObject containing process configuration settings
DocumentReaderObject containing document processing setting

usage key

For the component to work you only need to pass apiKey, user_id, handleData, and handleError using the usage key. These are the keys you can pass.

KeyDescription
apiKeyString (required). These will allow you to enter your client API KEY. The component won't work with out it
handleDataCallback (required). These function should declare a parameter that will hold the process resulting data
handleErrorCallback (required). These function should declare a parameter that will hold the process error
user_idString (required). Will match the response you get with the user completing the process.
handleTrackCallback. Catch the step changing of the operation.
handleTrackDetailCallback. Catch the user's interaction during the operation.
forceLocation*Boolean. If true, the process won't finished unless the candidate share their location. Default true
userIDIsCURP**Boolean. If you're using the CURP as user_id and want to send it to the Decision Maker mark this as true. Default false

*If the candidate chooses to use a mobile device, the access to the location will depend on the Browser App permissions. iOS devices block location access by default so the user will need to manually set the permission. ⚠️ If you choose not to force the location, we won't be able to guarantee location related information **curp input won't be showing in form page

Example

import { TrullyWebSDK } from "trully-sdk-react-2";

<TrullyWebSDK
  configuration={{
    usage: {
      apiKey: "YOUR_API_KEY",
      user_id: "YOU_USER_ID",
      handleData: (processResponse) => {
        //What should be done with the obtained processResponse?
      },
      handleError: (error) => {
        //What should be done if there is an error?
      },
    },
  }}
/>;

Callbacks data structure

Here you'll found the structures of the data received in each callback function

handleTrack

This function will be called every time the user starts a new step on the process. There are five different steps. When a new step is started, you'll receive the data from the previous completed step.

KeyDescription
stepName of the previous completed step.
user_idThe user_id you passed in usage key.
started_onUTC timezone. Step starting time.
completed_onUTC timezone. Step completion time.

Example

import { TrullyWebSDK } from "trully-sdk-react-2";

<TrullyWebSDK
  configuration={{
    usage: {
      //...other usage data
      handleTrack: (step) => {
        console.log(step);
      },
    },
  }}
/>;
Steps Table
NameDescription
form_startUser is currently scanning the document.
form_documentProcess is currently trying to obtained location.
form_locationUser is currently completing liveness process.
form_selfieUser reach the final step of the operation.
form_decision_makerOperation has the Decision Maker respond.

handleTrackDetail

This function will be called when the user take some actions during the operation. The actions that will trigger it are the ones related to the data needed for the Decision Maker.

KeyDescription
user_idThe user_id you passed in usage key.
actionName of the action that trigger the function.
timestampUTC timezone. When the function was trigger.

Example

import { TrullyWebSDK } from "trully-sdk-react-2";

<TrullyWebSDK
  configuration={{
    usage: {
      //...other usage data
      handleTrackDetail: (trackDetail) => {
        console.log(trackDetail);
      },
    },
  }}
/>;
Actions Table
NameDescription
LEGAL_DOCUMENTATION_ACCEPTEDUser accept Privacy Policy and Terms and Conditions.
LEGAL_DOCUMENTATION_DECLINEDUser declined Privacy Policy and Terms and Conditions.
LOAD_NEXT_PAGEOperation start new page.
NO_CAMERA_AVAILABLEThe operation couldn't start camera.
FRONT_IMAGE_OBTAINEDOperation has document front.
BACK_IMAGE_OBTAINEDOperation has document back.
DOCUMENT_ANALYSIS_RETRYOperation needs to re start document analysis.
DOCUMENT_ANALYSIS_COMPLETEOperation has analyzed front and back image.
LOCATION_OBTAINEDOperation has user's location.
LOCATION_SKIPPEDOperation has continued without user's location.
LIVENESS_RECOGNITION_PROCESS_STARTEDOperation has start liveness analysis.
LIVENESS_RECOGNITION_PROCESS_COMPLETEDOperation has analyzed liveness status.
DATA_SEND_TO_DECISION_MAKEROperation has sended data collected to Decision Maker. Awaiting result
END_KYC_PROCESSOperation has Decision Maker result.

handleData

This function will be called when the operation gets the Decision Maker result. Go to Data handling section to get more information

onError

This function will be called in case of an error during the operation. You'll receive the error object as is generated

We recommend you save this error into a log file.

KeyDescription
processWhich part of the process trigger the function.
messageError message
userIDThe userID you passed during initialization.
timestampUTC timezone. When the function was trigger.
errorObject. Extra information about the error

Example

import { TrullyWebSDK } from "trully-sdk-react-2";

<TrullyWebSDK
  configuration={{
    usage: {
      //...other usage data
      handleError: (error) => {
        console.log(error);
      },
    },
  }}
/>;
Process Table
NameDescription
SAVING_TRACK_STEPHTTP error when saving track data.
OBTAINING_IPHTTP error when getting ip data.
INITIALIZING_DOCUMENT_READERProcess error during document reader initialization.
READING_DOCUMENTProcess error analyzing document.
GETTING_LIVENESSProcess error analyzing liveness.
OBTAINING_DM_RESPONSEHTTP error when getting Decision Maker response.

Personalize

To customize the component, add the AppConfiguration key to the object passed in the configuration prop. These are the keys you can pass. Neither of them are required.

KeyDescription
termsAndConditions*String. URL to your terms and conditions page
privacyPolicy*String. URL to your privacy policy page
pagesToIncludeStrings array. Will allow to add/remove pages from the process
inputsObject. Will allow to add/remove inputs from form page
textsObject. The keys from this object will modify some of the texts of the component
stylesObject. Will allow you to modify images, videos, font and colors

*By default the component uses our terms and conditions and privacy policy pages

Example

import { TrullyWebSDK } from "trully-sdk-react-2";

<TrullyWebSDK
  configuration={{
    usage: {
      //required configuration
    },
    AppConfiguration: {
      termsAndConditions: "URL_TO_TERMS_AND_CONDITIONS",
      privacyPolicy: "URL_TO_PRIVACY_POLICY",
    },
  }}
/>;

pagesToInclude key

With these key you'll be able to adapt the process to take some extra data from your user by adding pages to the process. To add the pages you should pass an array containing the following strings. Each string represents one page to include.

StringDescription
formThis will add a form to your process. The data collect with it can be select using the inputs key
personal_infoThis will add a form asking for personal info such as complete name, date of birth, place of birth and gender

inputs key

If you include form page, inputs will let you choose which data will be asked for. There are no inputs shown by default.

KeyDescription
emailInput asking for valid email address
phone_numberInput asking for valid mexican phone number
curpInput asking for valid curp. If are using curp as user_id and and passed true in userIDIsCURP key. This input won't be showing
addressInput asking for valid address

Example

import { TrullyWebSDK } from "trully-sdk-react-2";

<TrullyWebSDK
  configuration={{
    usage: {
      //...required usage configuration
    },
    AppConfiguration: {
      pagesToInclude: ["form"],
      inputs: {
        phone_number: true,
      },
    },
  }}
/>;

texts key

You can change some texts by using the texts key. This key should receive an object. Here are key you could pass

KeyDescription
docTypeNumber. Will let you change the text asking for document type
0.- INE o Pasaporte vigente. 1.- INE vigente. 2.- Pasaporte vigente

Example

import { TrullyWebSDK } from "trully-sdk-react-2";

<TrullyWebSDK
  configuration={{
    usage: {
      //...required usage configuration
    },
    AppConfiguration: {
      texts: {
        docType: 0,
      },
    },
  }}
/>;

styles key

The styles key will let customized the look and feel of the component. Every one of these are optional.

KeyDescription
boxShadowSet it to false to remove the component shadow
showLogoSet it to false to remove the logo image
imagesObject containing the images to replace the default ones
videosObject containing the videos to replace the default ones
fontReceives an object to declare font specific styles
colorsReceives an object to declare colors styles

Example

import { TrullyWebSDK } from "trully-sdk-react-2";

<TrullyWebSDK
  configuration={{
    usage: {
      //required configuration
    },
    AppConfiguration: {
      styles: {
        showLogo: false,
        boxShadow: false,
        images: {
          //...images
        },
        videos: {
          //...videos
        },
        font: {
          //...font
        },
        colors: {
          //...colors
        },
      },
    },
  }}
/>;

images key

Images are loaded using an image HTML tag, so to change it you should pass the corresponding path to the image. Every one of these keys are optional. These are the default values

KeyDescription
logoObject. Receiving source key. This is the default url https://trully-api-documentation.s3.amazonaws.com/trully-sdk/logo-trully.svg
DatosIconhttps://trully-api-documentation.s3.amazonaws.com/trully-sdk/Datos-1.svg
IDIconhttps://trully-api-documentation.s3.amazonaws.com/trully-sdk/ID-1.svg
VideoIconhttps://trully-api-documentation.s3.amazonaws.com/trully-sdk/Video-1.svg
IDImagehttps://trully-api-documentation.s3.amazonaws.com/trully-sdk/ID2-1.svg
locationDeniedImagehttps://trully-api-documentation.s3.amazonaws.com/trully-sdk/pin-1.svg
cameraDeniedImagehttps://trully-api-documentation.s3.amazonaws.com/trully-sdk/cameraDenied-1.svg
permissionshttps://trully-api-documentation.s3.amazonaws.com/trully-sdk/ModalWeb.svg
timeouthttps://trully-api-documentation.s3.amazonaws.com/trully-sdk/timeout.webp
lightIconhttps://trully-api-documentation.s3.amazonaws.com/trully-sdk/luzIcon.svg
crossIconhttps://trully-api-documentation.s3.amazonaws.com/trully-sdk/retirarElementosIcon.svg
iconCheckhttps://trully-api-documentation.s3.amazonaws.com/trully-sdk/icon-check.svg
videoFallbackhttps://trully-api-documentation.s3.amazonaws.com/trully-sdk/livenessFallback.svg

Example

import { TrullyWebSDK } from "trully-sdk-react-2";

<TrullyWebSDK
  configuration={{
    usage: {
      //required configuration
    },
    AppConfiguration: {
      styles: {
        images: {
          logo: {
            source: "logo_image_url",
          },
          IDIcon: "image_url",
          VideoIcon: "image_url",
          IDImage: "image_url",
          locationDeniedImage: "image_url",
          cameraDeniedImage: "image_url",
          permissions: "image_url",
          timeout: "image_url",
          iconCheck: "image_url",
          lightIcon: "image_url",
          crossIcon: "image_url",
          videoFallback: "image_url",
        },
      },
    },
  }}
/>;

videos key

Videos are loaded using a video HTML tag, to change it you should pass the corresponding path to the video. We recommend to change the corresponding image if you're going to change a video. Every one of these keys are optional. These are the default values.

KeyDescription
timeoutVideohttps://trully-api-documentation.s3.amazonaws.com/trully-sdk/timeout.webm
livenessVideohttps://trully-api-documentation.s3.amazonaws.com/trully-sdk/LivenessVideo.webm

Example

import { TrullyWebSDK } from "trully-sdk-react-2";

<TrullyWebSDK
  configuration={{
    usage: {
      //required configuration
    },
    AppConfiguration: {
      styles: {
        videos: {
          timeoutVideo: "video_url",
          livenessVideo: "video_url",
        },
      },
    },
  }}
/>;

font key

You can change the entire font using fonFamily or changes an specific font using the individualFamily object. Every one of these keys are optional. These are the default values.

KeyDescription
fontFamily"DM Sans", sans-serif
individualFamilyObject to declare font for specific elements
primaryTextColor#181c21
secondaryTextColor#5f6877

Example

import { TrullyWebSDK } from "trully-sdk-react-2";

<TrullyWebSDK
  configuration={{
    usage: {
      //required configuration
    },
    AppConfiguration: {
      styles: {
        font: {
          family: "font_family",
          colors: {
            primaryTextColor: "hexadecimal_color_value",
            secondaryTextColor: "hexadecimal_color_value",
          },
        },
      },
    },
  }}
/>;
individualFamily

Every one of these keys are optional. If not specified will default to "DM Sans", sans-serif

KeyDescription
text1BoldFamilyTitles. Each bold text
text1FamilySubtitles. Texts providing some explanation to titles
textFamilyTexts

Example

import { TrullyWebSDK } from "trully-sdk-react-2";

<TrullyWebSDK
  configuration={{
    usage: {
      //required configuration
    },
    AppConfiguration: {
      styles: {
        font: {
          individualFamily: {
            heading1: "font_family",
            heading2: "font_family",
            text: "font_family",
          },
          colors: {
            primaryTextColor: "hexadecimal_color_value",
            secondaryTextColor: "hexadecimal_color_value",
          },
        },
      },
    },
  }}
/>;

colors key

Colors will allow you change the different colors to match your brand design. Every one of these keys are optional. These are the default values.

KeyDescription
primary#475fff
secondary#121e40
disabled#D6A0FF
white#FFFFFF
background#FFFFFF

Example

import { TrullyWebSDK } from "trully-sdk-react-2";

<TrullyWebSDK
  configuration={{
    usage: {
      //required configuration
    },
    AppConfiguration: {
      colors: {
        primary: "hexadecimal_color_value",
        secondary: "hexadecimal_color_value",
        disabled: "hexadecimal_color_value",
        white: "hexadecimal_color_value",
        backgroundColor: "hexadecimal_color_value",
      },
    },
  }}
/>;

Document Reader

To ensure that the component works correctly during development, it is necessary to pass a boolean value of true to inform the component that it is in development mode. This can be achieved by adding the DocumentReader key to the configuration prop.

KeyDescription
processParamObject. Will let you configure the document reader process
devOptionsObject. Will let you configure development options

processParam key

KeyDescription
timeoutNumber. How long should be wait for a valid document. Time represent in milliseconds. Default one minute

Example

import { TrullyWebSDK } from "trully-sdk-react-2";

<TrullyWebSDK
  configuration={{
    usage: {
      //required configuration
    },
    DocumentReader: {
      processParam: {
        timeout: 60000,
      },
    },
  }}
/>;

devOptions key

KeyDescription
environmentBoolean. Make sure is true for development. By default the component will run on prod mode
logErrorsBoolean. Will show error on browser console. Make sure to set it on false for prod

Example

import { TrullyWebSDK } from "trully-sdk-react-2";

<TrullyWebSDK
  configuration={{
    usage: {
      //required configuration
    },
    DocumentReader: {
      devOptions: {
        environment: true,
        logErrors: true,
      },
    },
  }}
/>;

Add it to Next.js

TrulyWebComponent is a client-side component, which means it needs to run on the client. By default, every component created in Next.js is executed on the server. You need to make sure our component runs only on the client.

Creating a client-side component

To ensure a component runs on the client, it should be marked as a client-side component using the "use client" tag. In the Next.js project, create a new component and mark it as a client-side component.

"use client";
import { TrullyWebSDK } from "trully-sdk-react-2";

const Trully = () => {
  return (
    <TrullyWebSDK
      configuration={{
        usage: {
          apiKey: "YOUR_API_KEY",
          user_id: "YOU_USER_ID",
          handleData: (processResponse) => {
            //What should be done with the obtained processResponse?
          },
          handleError: (error) => {
            //What should be done if there is an error?
          },
        },
      }}
    />
  );
};
export default Trully;

Import the client-side component

Once created, import it into any page

import Trully from "./components/Trully";

export default function Home() {
  return <Trully />;
}

Data handling

TrullyWebSDK sends the obtained data to the API Decision Maker to assist in your decision-making process. Using this component, you can access the response data from the Decision Maker and all the data collected during the KYC process. The required "usage" key should have a "handleData" function and an "handleError" function, both of which should receive a parameter. The "handleData" function stores an object with the data processed by the Decision Maker and the data obtained during the KYC process in its parameter. On the other hand, the "handleError" function stores the error generated during the query. This way, we can specify the actions to be taken when the server request is successful (handleData) or if there is an error in the process (handleError).

Process completed successfully

KeyDescription
raw_dataObject containing the un process data from the Decision Maker. You can learn more about here
labelString. The label generate by the Decision Maker for the user who has completed the process
No Threat - low risk user. Review - medium risk user. Potential Threat - high risk user
reasonArray. Contains the reasons behind the decision
request_idString. ID created by the Decision Maker
user_idString. The user_id you passed in usage
imageBase64 string. Selfie
document_imageBase64 string. Document front cropped image
document_image_completeBase64 string. Document front uncropped image
document_image_backBase64 string. Document back cropped image
document_image_back_completeBase64 string. Document back uncropped image

Example

const Trully = () => {
  return (
    <TrullyWebSDK
      configuration={{
        usage: {
          apiKey: "YOUR_API_KEY",
          user_id: "YOU_USER_ID",
          //data - Decision Maker response
          handleData: (processResponse) => {
            const { label, reason } = processResponse;
            console.log(label, reason);
          },
          handleError: (error) => {
            //error - AJAX error
          },
        },
      }}
    />
  );
};
export default Trully;

How to use the images obtained

import { TrullyWebSDK } from "trully-sdk-react-2";
import { useState } from "react";

const Trully = () => {
  const [doc, setDoc] = useState("");
  const [selfie, setSelfie] = useState("");

  return (
    <>
      <TrullyWebSDK
        configuration={{
          usage: {
            apiKey: "YOUR_API_KEY",
            user_id: "YOU_USER_ID",
            handleData: (processResponse) => {
              console.log(processResponse);
              const { document_image, image } = processResponse;
              setDoc(() => document_image);
              setSelfie(() => image);
            },
            handleError: (err) => {
              console.log(err);
            },
          },
        }}
      />
      <h2>Document</h2>
      <img src={`data:image/png;base64,${doc}`} alt="" />
      <h2>Selfie</h2>
      <img src={`data:image/png;base64,${selfie}`} alt="" />
    </>
  );
};
export default Trully;

Full Example

import { TrullyWebSDK } from "trully-sdk-react-2";

const Trully = () => {
  return (
    <TrullyWebSDK
      configuration={{
        usage: {
          apiKey: "YOUR_API_KEY",
          user_id: "YOU_USER_ID",
          handleTrackDetail: (trackDetail) => {
            console.log(trackDetail);
          },
          handleTrack: (step) => {
            console.log(step);
          },
          handleData: (processResponse) => {
            console.log(processResponse);
          },
          handleError: (err) => {
            console.log(err);
          },
        },
        DocumentReader: {
          processParam: {
            timeout: 60000,
          },
          devOptions: {
            environment: true,
            logErrors: true,
          },
        },
        AppConfiguration: {
          termsAndConditions: "URL_TO_TERMS_AND_CONDITIONS",
          privacyPolicy: "URL_TO_PRIVACY_POLICY",
          pagesToInclude: ["form"],
          inputs: {
            phone_number: true,
          },
          texts: {
            docType: 0,
          },
          styles: {
            showLogo: false,
            boxShadow: false,
            images: {
              logo: {
                source: "logo_image_url",
              },
              IDIcon: "image_url",
              VideoIcon: "image_url",
              IDImage: "image_url",
              locationDeniedImage: "image_url",
              cameraDeniedImage: "image_url",
              permissions: "image_url",
              timeout: "image_url",
              iconCheck: "image_url",
              lightIcon: "image_url",
              crossIcon: "image_url",
              videoFallback: "image_url",
            },
            videos: {
              timeoutVideo: "video_url",
              livenessVideo: "video_url",
            },
            font: {
              family: "font_family",
              colors: {
                primaryTextColor: "hexadecimal_color_value",
                secondaryTextColor: "hexadecimal_color_value",
              },
            },
            colors: {
              primary: "hexadecimal_color_value",
              secondary: "hexadecimal_color_value",
              disabled: "hexadecimal_color_value",
              white: "hexadecimal_color_value",
              backgroundColor: "hexadecimal_color_value",
            },
          },
        },
      }}
    />
  );
};
export default Trully;

Known issues

This section provides workarounds for some known issues that may occur while using the component.

Camera permission was accepted, but a message asking to accept it appears

This may happen for three reasons:

  1. The component needs to work under the HTTPS protocol because the Browser Camera API will revoke access to the device if the connection is not secure. Make sure that you're working with HTTPS.
  2. Some browsers will revoke access to the device while using auto-signed certificates. If you're working in development, you're probably creating an auto-signed certificate to force the HTTPS protocol. If that's the case, open your app in an incognito tab.
  3. The Browser Camera API will automatically revoke permissions if there is another instance running. Make sure that you're only working in one tab at a time.

Location permission was accepted, but a message asking to accept it appears

This may happen for two reasons:

  1. The component needs to work under the HTTPS protocol because the Browser Geolocation API will revoke access to the device if the connection is not secure. Make sure that you're working with HTTPS.
  2. Some browsers will revoke access to the device while using auto-signed certificates. If you're working in development, you're probably creating an auto-signed certificate to force the HTTPS protocol. If that's the case, open your app in an incognito tab.
3.1.2

2 days ago

3.1.1

2 days ago

3.1.0

2 days ago

3.0.21

3 days ago

3.0.20

8 days ago

3.0.16

12 days ago

3.0.15

12 days ago

3.0.14

27 days ago

3.0.13

1 month ago

3.0.9

1 month ago

3.0.12

1 month ago

3.0.10

1 month ago

3.0.11

1 month ago

3.0.8

1 month ago

3.0.7

1 month ago

3.0.4

2 months ago

3.0.3

2 months ago

3.0.2

2 months ago

3.0.1

2 months ago

3.0.6

2 months ago

3.0.5

2 months ago

3.0.0

2 months ago

2.0.7

2 months ago

2.0.5

3 months ago

2.0.6

3 months ago

2.0.3

3 months ago

2.0.4

3 months ago

2.0.2

3 months ago

1.0.21

3 months ago

2.0.1

3 months ago

2.0.0

3 months ago

1.0.20

3 months ago

1.0.19

3 months ago

1.0.18

3 months ago

1.0.17

3 months ago

1.0.16

3 months ago

1.0.15

4 months ago

1.0.14

5 months ago

1.0.11

5 months ago

1.0.13

5 months ago

1.0.10

5 months ago

1.0.9

6 months ago

1.0.8

6 months ago

1.0.7

6 months ago

1.0.6

6 months ago

1.0.5

6 months ago

1.0.4

6 months ago

1.0.3

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago