DocumentDetector

Importing SDK

To use DocumentDetector, you can either remotely import the .js file or download it locally.

Remotely

Include the .js file directly from the CDN:

<script
  src="https://repo.combateafraude.com/javascript/release/document-detector/<VERSION>.umd.js"
  type="text/javascript"
></script>

You can retrieve the class from the SDK using the following code:

const { DocumentDetectorSdk } = window["@combateafraude/document-detector"];

Locally

Download the .js file and import it as an ES6 module:

import { DocumentDetectorSdk } from "../assets/js/document-detector-<VERSION>.js";

Construction

In the builder, the SDK receives a single parameter with the settings:

const sdk = new DocumentDetectorSdk(options);

Supported parameters

* Advanced capture consists of using more complex and not-so-stable APIs in browsers that support them (e.g. ImageCapture)

Example

const sdk = new DocumentDetectorSdk({
    token: `my-sdk-token`,

    language: `pt_BR`,

    analyticsSettings: {
        disableAnalytics: false,
        trackingId: '',
        trackingInfo: '',
    },

    environmentSettings: {
        disableDesktopExecution: false,
    },

    appearenceSettings: {
        hideCaptureTitle: false,
        hideCaptureMask: false,
        hideCameraSwitchButton: false,
        useGenericMask: false,
    },

    capturerSettings: {
        disableAdvancedCapturing: false,
    },

    textSettings: {
        messages: {
            processMessage: '',
            wrongDocumentMessage: '',
            bothWrongSideMessage: '',
            wrongSideMessage: '',
            lowQualityMessage: '',
            captureFailedMessage: '',
        }
});

CaptureStage

CaptureStage allows the client to configure the stages. To do this, we offer the CaptureStage object, where you can set the following parameters:

Example CaptureStage

const stages = [
  { mode: "automatic", attempts: 3, duration: 60 },
  { mode: "manual", attempts: 3, duration: 60 },
  { mode: "upload", attempts: 0, duration: 0 },
];

Initialization

initialize(): Promise<void>

The SDK has a separate method of initialization, to allow greater control over when it occurs.

During this initialization, the SDK will initialize its internal variables and download the resources it needs to run.

[!] You must call this method before using other SDK methods.

[!] The initialization of the SDK can take a few seconds. We recommend that you call this function as early as possible in your flow so that opening the SDK is smooth for the user.

Example

await sdk.initialize();

Utilization

Opening and capturing documents

capture(container: HTMLElement, stages, {type: SupportedDocumentType, side: DocumentSide, totalAttempts?: Number}): Promise<Result>

The method used to load the SDK onto the screen and perform document capture.

It will initialize the video stream (requesting permissions if needed) and load it into the container.

Parameters

¹ The type any does not have the validations for quality and document type, thus accepting any side or document - recommended for unsupported documents such as the OAB card.

² The type other corresponds to other documents (not including those already specified), such as vaccination cards, etc.

³ If not specified, a default value of 30 seconds is used

⁴ The side both correspond to the document showing both sides in the same photo (e.g. open CNH)

⁵ The side parameter depends on the type of document entered in type. See the table below.

Example

// div or another element on DOM
const sdkContainer = document.getElementById("sdk-displayer");
await sdk.capture(sdkContainer, stages, {
  documentType,
  documentSide,
  totalAttempts,
});

Accepted sides for each document type

Return

The return consists of an object with the following fields:

Example

const result = sdk.capture(sdkContainer, stages, {
  documentType,
  documentSide,
  totalAttempts,
});
// { imageUrl: '[link of image]', blob: Blob, documentType: 'rg', documentSide: 'front' }

Close SDK

close(): Promise<void>

The method used to remove the SDK on the screen, removing the visual elements of the SDK from the DOM.

Will remove the visual elements of the SDK from the DOM.

De-initialize the SDK

dispose(): Promise<void>

The method used to remove the SDK on the screen.

Will de-initialize the video stream and clear the SDK's internal variables

Complete Example

Soon.

Last updated

Logo

2023 © Caf. - All rights reserved