Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1833,17 +1833,18 @@ The scanner will attempt to request camera permissions automatically. Only
available in Mein Blau and Mein O2.

```ts
openOcrScanner: ({regex: string}) => Promise<{scannedText: string | null}>;
openOcrScanner: ({regex: string, timeoutMs?: number}) => Promise<{scannedText: string}>;
```

#### Parameters

- `regex`: Regular expression pattern to match the scanned text
- `timeoutMs`: Timeout in milliseconds before closing the scanner
automatically if no text is scanned. Optional, default is 15000 milliseconds

#### Response

- `scannedText`: The scanned text matching the regex pattern, or `null` if the
user closed the scanner before any text was found
- `scannedText`: The scanned text matching the regex pattern.
Comment on lines -1845 to +1847

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could have just added a new error code for the timeout case and keep this field nullable, however I preferred to avoid nulls as much as possible and give more semantic to each scenario. WDYT

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok


#### Example

Expand All @@ -1864,9 +1865,11 @@ openOcrScanner({regex: '\\b(?:\\d{4}-\\d{4}-\\d{4}-\\d{4}|\\d{16})\\b'})

#### Error cases

- `204`: User manually closed OCR scanner
- `401`: Missing permissions (user rejected camera permissions)
- `405`: Feature not supported in current brand (only available in Mein Blau
and Mein O2)
- `408`: Timeout reached without scanning any text
- `500`: Internal error (e.g., unexpected error thrown by native scanner)

## Error handling
Expand Down
4 changes: 3 additions & 1 deletion src/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,12 @@ export const setBiometricsAuthenticationStatus = (params: {
*/
export const openOcrScanner = (params: {
regex: string;
}): Promise<{scannedText: string | null}> =>
timeoutMs?: number;
}): Promise<{scannedText: string}> =>
postMessageToNativeApp({
type: 'OPEN_OCR_SCANNER',
payload: {
regex: params.regex,
timeoutMs: params.timeoutMs,
},
});
2 changes: 1 addition & 1 deletion src/post-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ export type ResponsesFromNativeApp = {
OPEN_OCR_SCANNER: {
type: 'OPEN_OCR_SCANNER';
id: string;
payload: {scannedText: string | null};
payload: {scannedText: string};
};
};

Expand Down