react-native-scanbot-sdk
Version:
Scanbot Document and Barcode Scanner SDK React Native Plugin for Android and iOS
186 lines (163 loc) • 5.42 kB
text/typescript
/// Auto-generated with ScanbotSDKCodegenV3. Modifications will be overwritten.
/// Generated from core/schemas/MRZTypes.yaml
import { GenericDocument } from '../documents/GenericDocument';
import { AccumulatedResultsVerifierConfiguration } from '../frame_accumulation/FrameAccumulationTypes';
import { ToJsonConfiguration } from '../utils/json/JsonSerializationTypes';
import { DeepPartial, PartiallyConstructible } from '../utils/utils';
/**
Type of document containing the MRZ.
- `UNKNOWN`:
Undefined.
- `CREW_MEMBER_CERTIFICATE`:
Crew member certificate.
- `ID_CARD`:
ID card.
- `PASSPORT`:
Passport.
- `VISA`:
Visa card.
- `CH_DRIVING_LICENSE`:
Swiss driver license.
*/
export type MrzDocumentType =
| 'UNKNOWN'
| 'CREW_MEMBER_CERTIFICATE'
| 'ID_CARD'
| 'PASSPORT'
| 'VISA'
| 'CH_DRIVING_LICENSE';
export const MrzDocumentTypeValues: MrzDocumentType[] = [
'UNKNOWN',
'CREW_MEMBER_CERTIFICATE',
'ID_CARD',
'PASSPORT',
'VISA',
'CH_DRIVING_LICENSE',
];
/**
Container for result of MRZ scanning attempt.
*/
export class MrzScannerResult extends PartiallyConstructible {
/**
Scanning successful.
Default is false
*/
public readonly success: boolean = false;
/**
Raw string value of MRZ.
*/
public readonly rawMRZ: string;
/**
Generic document containing MRZ data.
*/
public readonly document: GenericDocument | null;
/** @param source {@displayType `DeepPartial<MrzScannerResult>`} */
public constructor(source: DeepPartial<MrzScannerResult> = {}) {
super();
if (source.success !== undefined) {
this.success = source.success;
}
if (source.rawMRZ !== undefined) {
this.rawMRZ = source.rawMRZ;
} else {
throw new Error('rawMRZ must be present in constructor argument');
}
if (source.document !== undefined) {
this.document = source.document != null ? new GenericDocument(source.document) : null;
} else {
throw new Error('document must be present in constructor argument');
}
}
public async serialize(
config: ToJsonConfiguration = new ToJsonConfiguration()
): Promise<DeepPartial<MrzScannerResult>> {
return {
success: this.success,
rawMRZ: this.rawMRZ,
document: this.document != null ? await this.document.serialize(config) : null,
};
}
private _released: Boolean = false;
public release() {
if (this._released) {
return;
}
{
if (this.document != null) {
this.document.release();
}
}
this._released = true;
}
public async encodeImages(): Promise<void> {
if (this.document != null) {
await this.document.encodeImages();
}
}
}
/**
Defines how to handle incomplete MRZ results (e.g. caused by failed validation).
- `ACCEPT`:
Accept incomplete results. Fields failing validation will have a validation status of INVALID. Typically used for single-shot scanning.
- `REJECT`:
Reject incomplete results. If any fields are missing or fail validation, the result document will be empty. Typically used for live scanning.
*/
export type MrzIncompleteResultHandling = 'ACCEPT' | 'REJECT';
export const MrzIncompleteResultHandlingValues: MrzIncompleteResultHandling[] = [
'ACCEPT',
'REJECT',
];
/**
The scanning mode.
- `LIVE`:
The scanner will merge all information from multiple frames to provide the best possible result.
Use this mode when the input is a video or camera stream.
- `SINGLE_SHOT`:
The scanner will only use the current frame and will spend additional time to ensure the
best possible result. Use this mode when scanning single images, e.g. imported from the gallery.
*/
export type MrzScanningMode = 'LIVE' | 'SINGLE_SHOT';
export const MrzScanningModeValues: MrzScanningMode[] = ['LIVE', 'SINGLE_SHOT'];
/**
Configuration for MRZ scanner.
*/
export class MrzScannerConfiguration extends PartiallyConstructible {
/**
Configure the frame accumulation process.
*/
public frameAccumulationConfiguration: AccumulatedResultsVerifierConfiguration =
new AccumulatedResultsVerifierConfiguration({});
/**
Enable MRZ detection. If disabled, the scanner skips the detection step and assumes that the input image is a crop of the MRZ area.
Default is true
*/
public enableDetection: boolean = true;
/**
Defines how to handle incomplete MRZ results (e.g. caused by failed validation).
Default is REJECT
*/
public incompleteResultHandling: MrzIncompleteResultHandling = 'REJECT';
/**
If true, crops of the detected MRZ and its fields will be returned in the result.
Default is false
*/
public returnCrops: boolean = false;
/** @param source {@displayType `DeepPartial<MrzScannerConfiguration>`} */
public constructor(source: DeepPartial<MrzScannerConfiguration> = {}) {
super();
if (source.frameAccumulationConfiguration !== undefined) {
this.frameAccumulationConfiguration = new AccumulatedResultsVerifierConfiguration(
source.frameAccumulationConfiguration
);
}
if (source.enableDetection !== undefined) {
this.enableDetection = source.enableDetection;
}
if (source.incompleteResultHandling !== undefined) {
this.incompleteResultHandling = source.incompleteResultHandling;
}
if (source.returnCrops !== undefined) {
this.returnCrops = source.returnCrops;
}
}
}