Functionality
The Sybrin Document Javascript API provides multiple ways of running document capture and other functions to control the Web SDK.
These include:
Capture Using Camera
Capture Using File Upload
Execute Document OCR
Cancel
Additionally, the API provides:
Set Translations
Version Information Retrieval
Client Information Retrieval
Compatibility Check
Get Video Input Devices
Capture Using Camera
To use the camera for capture, you may make use of the captureDocument
function exposed by the JavaScript API.
Signature:
captureDocument(params?: { id?: string; element?: HTMLElement; countryCode: string; documentTypeName: string; documentTypeId: string; deviceId?: string; imageCaptureFormat?: 'jpeg'; }): Promise<DocumentCaptureResult>
An argument, provided as an object literal, is required for this function call. The object literal must have these required properties:
id (string)
: The ID of the element to create the video feed in. Theelement
property takes precedence over theid
property. Not required if theelement
property is provided.countryCode (string)
: The country code of the document. Used during capture, in conjunction with document type parameters, to determine page count. May be obtained by using the Country Select component.documentTypeName (string)
: The document type name of the document. Used during capture, in conjunction with country code parameters, to determine page count. May be obtained by using the Document Select component.documentTypeId (string)
: The document type ID of the document. Used during capture, in conjunction with country code parameters, to determine page count. May be obtained by using the Document Select component.element (HTMLElement)
: The element to create the video feed in. Takes precedence over theid
property. Not required if theid
property is provided.
Optionally you may also specify the following properties:
deviceId (string
): ID of the specific device to use for capture.imageCaptureFormat (string: 'jpeg')
: Sets the format that the images will be captured in. Defaults to JPEG.
The function returns a promise, so you may choose to use either the asynchronous await pattern or to subscribe to the result using .then()
, .catch()
and .finally()
.
Example:
The result parameter is of type Sybrin.Document.DocumentCaptureResult
and includes the following properties:
success (boolean)
: Whether or not the document was captured successfully.facingMode (string)
: The facing direction of the camera used during capture.message (string)
: Additional information when applicable, for instance an error message if one occurred.originalDocumentImages (string[])
: Base64 string array of the original photos of the document.documentImage (string[])
: Base64 string array of the processed photos of the document (if the document crop component was used).correlationId (string)
: The unique identifier used for advanced tracking and backend data synchronization.countryCode (string)
: The Alpha-3 standard country code of the country that was selected during the journey.documentType (string)
: The document type name string of the document type that was selected during the journey.ocrResults (DocumentOcrResult[])
: The array of document OCR result instances representing the data that was read from the images.
Capture Using File Upload
To use a file upload for image capture, you may make use of the uploadDocument
function exposed by the JavaScript API.
Signature:
uploadDocument(params?: { frontFile?: File; frontBase64?: string; backFile?: File; backBase64?: string; documentTypeId?: string; documentTypeName?: string; countryCode?: string; loaderContainer?: HTMLElement; imageUploadFormat?: 'original' | 'jpeg'; }): Promise<DocumentCaptureResult>
An argument may be provided as an object literal to this function call. The object literal must have these required properties:
countryCode (string)
: Not required ifdocumentTypeId
is specified. Used in conjunction withdocumentTypeName
to determine page count.documentTypeId (string)
: Not required if bothcountryCode
anddocumentTypeName
are provided. Used to determine page count.documentTypeName (string)
: Not required ifdocumentTypeId
is specified. Used in conjunction withcountryCode
to determine page count.
Optionally it may specify the following properties:
frontFile (File)
: The front image file. If provided, no file picker will be displayed, and the SDK will instead use the provided image to construct and return aDocumentCaptureResult
instance.frontBase64 (string)
: A base64 string of the front image. If provided, no file picker will be displayed, and the SDK will instead use the provided image to construct and return aDocumentCaptureResult
instance.imageUploadFormat (string: 'original' | 'jpeg')
: Sets the format that images will be converted to for upload. Defaults to original.loaderContainer (HTMLElement)
: The HTML element to display a loader inside while processing.
The frontFile
and frontBase64
properties offer an opportunity to implement your own method of obtaining files for upload. If none of these are provided, the Web SDK will invoke the default file explorer window provided by the browser to allow for file selection.
If you wish to provide the file, only one parameter between frontFile
and frontBase64
is required.
The function returns a promise, so you may choose to use either the asynchronous await pattern or to subscribe to the result using .then()
, .catch()
and .finally()
.
Example:
The result parameter is of type Sybrin.Document.DocumentCaptureResult
and includes the following properties:
success (boolean)
: Whether or not the document was captured successfully.facingMode (string)
: The facing direction of the camera used during capture.message (string)
: Additional information when applicable, for instance an error message if one occurred.originalDocumentImages (string[])
: Base64 string array of the original photos of the document.documentImage (string[])
: Base64 string array of the processed photos of the document (if the document crop component was used).correlationId (string)
: The unique identifier used for advanced tracking and backend data synchronization.countryCode (string)
: The Alpha-3 standard country code of the country that was selected during the journey.documentType (string)
: The document type name string of the document type that was selected during the journey.ocrResults (DocumentOcrResult[])
: The array of document OCR result instances representing the data that was read from the images.
Execute Document OCR
To run OCR on an image, you may make use of the executeDocumentOcr function exposed by the JavaScript API.
Signature:
executeDocumentOcr(params?: { base64s?: string[]; files?: File[]; facingMode?: string; countryCode?: string; documentTypeName?: string; documentTypeId?: string; correlationId?: string }): Promise<DocumentCaptureResult>
An argument, provided as an object literal, is required for this function call. The object literal must have these required properties:
base64s (string[])
: Array of images, in base64 format, to run OCR on. Not required iffiles
parameter is provided.files (File[])
: Array of images, in File format, to run OCR on. Not required ifbase64s
parameter is provided.countryCode
: The country code of the document. Used during capture, in conjunction with document type parameters, to determine OCR implementation. May be obtained by using the Country Select component. Not required if documentTypeId has been specified.documentTypeName
: The document type name of the document. Used during capture, in conjunction with country code parameters, to determine OCR implementation. May be obtained by using the Document Select component. Not required if documentTypeId has been specified.documentTypeId
: The document type ID of the document. Used during capture, in conjunction with country code parameters, to determine OCR implementation. May be obtained by using the Document Select component. Not required if both countryCode and documentTypeName have been specified.element (HTMLElement)
: The element to create the video feed in. Takes precedence over theid
property. Not required if theid
property is provided.
Optionally you may also specify the following properties:
deviceId (string
): ID of the specific device to use for capture.correlationId (string)
: Value that is used to associate the result with a specific case.facingMode (string: user | environment | left | right)
: The direction/orientation of the camera that was used during capture.
The function returns a promise, so you may choose to use either the asynchronous await pattern or to subscribe to the result using .then()
, .catch()
and .finally()
.
Example:
The result parameter is of type Sybrin.Document.DocumentOcrResult
and includes the following properties:
success (boolean)
: Whether or not document OCR ran successfully.message (string)
: Additional information when applicable, for instance an error message if one occurred.ocrData (any)
: A structured data object or unstructured string representing the OCR text that was extracted from the image.images (object)
: Object containing extracted images, if applicable.portraitImage (string)
: Base64 string of a face portrait image if one was detected and extracted from the document image.
Cancel
A function to cancel any action that the document Web SDK is currently executing. This is useful if you wish to add a cancel button to the UI so that the user may stop image capture while it's in progress.
Signature:
cancel(): void
Example:
Set Translations
This function may be used to set translations on a JavaScript API level.
Signature:
setTranslations(translations: { [key: string]: string }): void
Usage example:
Version Information Retrieval
To get all version info regarding the Web SDK and its components, the API exposes a function called getVersionInfo
.
Signature:
getVersionInfo(): Promise<any>
Usage example:
The result has the following properties:
webSdkVersion (string)
: The semantic version number of the JavaScript web SDK that is currently in use.
Client Information Retrieval
To get all version info regarding the client environment in which the application is currently running, the API exposes a function called getClientInfo
.
Signature:
getClientInfo(): Promise<ClientInfo>
Usage example:
The result is of type ClientInfo
and has the following properties:
isMobile (boolean)
: Whether or not the client environment is mobile (tablet or phone).isMobileAndroid (boolean)
: Whether or not the client environment is running Android.isMobileBlackberry (boolean)
: Whether or not the client environment is running Blackberry.isIphone (boolean)
: Whether or not the client environment is running on an iPhone.isIpad (boolean)
: Whether or not the client environment is running on an iPad.isIpadPro (boolean)
: Whether or not the client environment is running on an iPad Pro.isIpod (boolean)
: Whether or not the client environment is running on iPod.isMobileIos (boolean)
: Whether or not the client environment is running iOS.isMobileOpera (boolean)
: Whether or not the client environment is mobile Opera.isMobileWindows (boolean)
: Whether or not the client environment is Windows Mobile.isMac (boolean)
: Whether or not the client environment is running on Mac.
Compatibility Check
This function checks compatibility of the web SDK with the environment in which it is running (device, operating system, browser etc.) and reports back on it.
Signature:
checkCompatibility(handleIncompatibility?: boolean): Promise<CompatibilityInfo>
Optionally, you may pass down true
to signal for the web SDK to handle incompatibility internally. This will result in a modal prompt with an appropriate message automatically being shown if the function finds incompatibility with the environment.
Usage example:
The result is of type CompatibilityInfo
and has the following properties:
compatible (boolean)
: Whether or not the web SDK is compatible with the client environment.mediaStream (boolean)
: Whether or not the client environment supports media stream access.message (string)
: An appropriate message that describes the related incompatibility if detected.
Get Video Input Devices
This function returns a list of all video input devices that can be used.
Signature:
getVideoInputDevices(showLoader?: boolean, loaderContainer?: HTMLElement): Promise<VideoInputDevice[]>
The optional showLoader
parameter sets whether or not the UI must be blocked with a loader. When used in conjunction with the optional loaderContainer
parameter, the specific element will be blocked with a loader.
The function returns a promise, so you may choose to use either the asynchronous await pattern or to subscribe to the result using .then()
, .catch()
and .finally()
.
Usage example:
The result is an array of type VideoInputDevice
and each instance has the following properties:
deviceId (string)
: ID of the device.groupId (string)
: Group that the device belongs to.type (string: Camera | Webcam | Device)
: The type of device.direction (string: Front | Back | Integrated)
: The direction of the device.label (string)
: A short description of the device.counter (number)
: Number indicator for the device. Value is 0 unless there are multiple devices of the same type and direction available.