ID OCR Module

The ID OCR module extracts structured data (name, address, document number, dates, etc.) from a captured ID image. Typically runs after ID Capture.

📘

This guide is specific to Web SDK 2.0. If you are still using 1.x, you can find documentation here. Contact your Incode Representative for upgrade information and check if you are a candidate for this upgrade.

Full rollout to all clients still TBD.


The ID OCR module extracts structured data (name, address, document number, dates, etc.) from a captured ID image. Typically runs after ID Capture.

Follows the form-based pattern, with an additional readonly state when editableOcr is false (display extracted data without letting the user edit). See the patterns page for the shared lifecycle.

Availability

This module is headless-only — there is no public <incode-id-ocr> web component. Drive it with createIdOcrManager from @incodetech/core/id-ocr and render your own UI (form fields, validation messages, etc.).

Configuration

type IdOcrConfig = {
  editableOcr?: boolean; // Allow user to edit OCR data (default: false)
  cpfOnly?: boolean; // Show and validate only the CPF document number field
  secondId?: boolean; // After first ID OCR step, load second captured ID's OCR (orchestrated flow only)
  flowId?: string; // Session flow ID; when listed in CPFFlowIds, only the CPF field is shown
};
OptionTypeRequiredDescription
editableOcrbooleanWhen true, the user can edit extracted fields before submitting. Default false.
cpfOnlybooleanWhen true, only the CPF document number field is shown and CPF validation is applied.
secondIdbooleanUsed in orchestrated flows when a second ID was captured. Loads OCR for that document next.
flowIdstringSet by the orchestrator. CPF flows render only the CPF field; otherwise full OCR fields.

When <incode-flow> receives useCPF: true, it keeps the dashboard's ID_OCR step and configuration, then adds cpfOnly: true. The module continues to use the standard ID OCR lifecycle: editableOcr is respected, edited values are sent to the editable OCR endpoint, and values are not automatically formatted or submitted.

State machine

IdOcrState is a discriminated union over status:

StatusDescription
idleInitial state.
loadingFetching OCR data from the backend.
readonlyDisplay extracted data; no edits allowed (editableOcr === false). User can confirm to advance.
inputtingEditable form rendered. User can edit fields and validate.
submittingSending the (possibly edited) data back to the backend.
successServer accepted the submission.
finishedTerminal — the module is done.
errorFatal error.

Field descriptors

The manager exposes the fields it wants rendered as OcrFieldConfig[], so a headless host can build the form without hard-coding a field list:

type OcrFieldConfig = {
  key: keyof UpdateOcrDataParams;
  labelKey: string;
  type: 'text' | 'date' | 'radio';
  options?: { label: string; value: string }[];
  validation?: ValidationRule[];
  required: boolean;
};
PropertyTypeDescription
keykeyof UpdateOcrDataParamsThe OCR field this descriptor drives. Pass it to setField() and validateField().
labelKeystringTranslation key for the field's label. Resolve it through your i18n setup rather than displaying it directly.
type'text' | 'date' | 'radio'Which control to render.
options{ label: string; value: string }[]?Choices for a radio field.
validationValidationRule[]?Rules validateField() applies to this field.
requiredbooleanWhether the field must have a value before submitting.

OcrFieldConfig, UpdateOcrDataParams, and ValidationRule are exported from @incodetech/core/id-ocr.

API methods

MethodPurpose
load()Fetch the OCR data and transition to readonly or inputting.
setField(field, value)Update a field while in inputting. field is a key of UpdateOcrDataParams.
validateField(field)Run validation (required, minimum age, CPF format) on a single field.
continue()Confirm and submit. Transitions to submitting.
retry()After error, restart the OCR fetch.

Plus the universal lifecycle: subscribe, getState, reset, stop.

Headless example

import { createIdOcrManager } from '@incodetech/core/id-ocr';

const manager = createIdOcrManager({
  config: { editableOcr: true },
});

manager.subscribe((state) => {
  switch (state.status) {
    case 'readonly':
      // Render state.formData read-only with a "Confirm" button → manager.continue()
      break;
    case 'inputting':
      // Render editable form. On change: manager.setField('firstName', value)
      // On submit: manager.continue()
      // state.validationErrors lists per-field error keys
      break;
    case 'finished':
      manager.stop();
      break;
  }
});

manager.load();

See also


Did this page help you?