Skip to content

Commit 5ca0e76

Browse files
author
regula-bot
committed
Merge remote-tracking branch 'origin/develop' into stable
2 parents 5359e2b + 6d725e9 commit 5ca0e76

File tree

130 files changed

+1392
-1245
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+1392
-1245
lines changed

.github/workflows/trivy-scan.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ jobs:
2323
exit-code: '1'
2424
ignore-unfixed: true
2525
severity: 'CRITICAL,HIGH,MEDIUM,LOW'
26+
env:
27+
TRIVY_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-db:2

examples/auth/client/IR.jpg

-575 KB
Binary file not shown.

examples/auth/client/UV.jpg

-1.68 MB
Binary file not shown.

examples/auth/client/index.js

Lines changed: 55 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
import * as fs from 'fs';
22
import {
33
DocumentReaderApi,
4-
Result,
54
Scenario,
65
Source,
7-
TextFieldType,
86
GraphicFieldType,
97
Light,
10-
SecurityFeatureType,
118
} from '@regulaforensics/document-reader-webclient';
129
import axios from 'axios';
1310
import qs from 'qs';
1411

1512
const GATEWAY_BASE_URL = 'http://localhost:8080';
1613

17-
const { PORTRAIT, DOCUMENT_FRONT } = GraphicFieldType;
18-
const { DOCUMENT_NUMBER } = TextFieldType;
19-
2014
async function get_authorization_token() {
2115
let data = qs.stringify({
2216
grant_type: 'password',
@@ -45,116 +39,71 @@ async function get_authorization_token() {
4539
});
4640
}
4741

48-
(async () => {
49-
const apiBasePath = process.env.API_BASE_PATH || 'http://localhost:4333';
50-
let license = process.env.TEST_LICENSE; // optional, used here only for smoke test purposes
51-
52-
if (fs.existsSync('regula.license')) {
53-
license = fs.readFileSync('regula.license');
54-
}
55-
const token = await get_authorization_token();
42+
const apiBasePath = process.env.API_BASE_PATH || 'http://localhost:4333';
43+
let license = process.env.TEST_LICENSE;
5644

57-
const api = new DocumentReaderApi({
58-
basePath: apiBasePath,
59-
baseOptions: { headers: { Authorization: `Bearer ${token}` } },
60-
});
61-
62-
api.setLicense(license);
63-
64-
const serverInfo = await api.ping();
65-
66-
const white_page_0 = fs.readFileSync('WHITE.jpg').buffer;
67-
const ir_page_0 = fs.readFileSync('IR.jpg').buffer;
68-
const uv_page_0 = fs.readFileSync('UV.jpg').buffer;
69-
70-
const request = {
71-
images: [
72-
{
73-
ImageData: white_page_0,
74-
light: Light.WHITE,
75-
page_idx: 0,
76-
},
77-
{
78-
ImageData: ir_page_0,
79-
light: Light.IR,
80-
page_idx: 0,
81-
},
82-
{
83-
ImageData: uv_page_0,
84-
light: Light.UV,
85-
page_idx: 0,
86-
},
87-
],
88-
processParam: {
89-
scenario: Scenario.FULL_AUTH,
90-
resultTypeOutput: [
91-
// actual results
92-
Result.STATUS,
93-
Result.AUTHENTICITY,
94-
Result.TEXT,
95-
Result.IMAGES,
96-
Result.DOCUMENT_TYPE,
97-
Result.DOCUMENT_TYPE_CANDIDATES,
98-
Result.IMAGE_QUALITY,
99-
// legacy results
100-
Result.MRZ_TEXT,
101-
Result.VISUAL_TEXT,
102-
Result.BARCODE_TEXT,
103-
Result.RFID_TEXT,
104-
Result.VISUAL_GRAPHICS,
105-
Result.BARCODE_GRAPHICS,
106-
Result.RFID_GRAPHICS,
107-
Result.LEXICAL_ANALYSIS,
108-
],
109-
},
110-
};
45+
if (fs.existsSync('regula.license')) {
46+
license = fs.readFileSync('regula.license');
47+
}
48+
const token = await get_authorization_token();
11149

112-
const response = await api.process(request);
50+
const api = new DocumentReaderApi({
51+
basePath: apiBasePath,
52+
baseOptions: { headers: { Authorization: `Bearer ${token}` } },
53+
});
11354

114-
const requestJson = JSON.stringify(request);
115-
const responseJson = response.json();
55+
// Uncomment the line below if you want to transfer the license with each request
56+
// api.setLicense(license);
11657

117-
const docOverallStatus = response.status.overallStatus;
118-
const docOpticalTextStatus = response.status.detailsOptical.text;
58+
const serverInfo = await api.ping();
11959

120-
// text fields example
121-
const docNumberField = response.text.getField(DOCUMENT_NUMBER);
122-
const docNumberFieldByName = response.text.getFieldByName('Document Number');
60+
const white_page_0 = fs.readFileSync('WHITE.jpg').buffer;
12361

124-
const docNumberVisual = docNumberField.getValue(Source.VISUAL);
125-
const docNumberMrz = docNumberField.getValue(Source.MRZ);
126-
const docNumberVisualValidity = docNumberField.sourceValidity(Source.VISUAL);
127-
const docNumberMrzValidity = docNumberField.sourceValidity(Source.MRZ);
128-
const docNumberMrzVisualMatching = docNumberField.crossSourceComparison(Source.MRZ, Source.VISUAL);
62+
const request = {
63+
images: [
64+
{
65+
ImageData: white_page_0,
66+
light: Light.WHITE,
67+
page_idx: 0,
68+
},
69+
],
70+
processParam: {
71+
scenario: Scenario.FULL_PROCESS,
72+
alreadyCropped: true,
73+
},
74+
};
12975

130-
const docAuthenticity = response.authenticity();
76+
const response = await api.process(request);
13177

132-
const docIrB900 = docAuthenticity.irB900Checks();
133-
const docIrB900BlankChecks = docIrB900.checksByElement(SecurityFeatureType.BLANK);
78+
// images example
79+
const documentImage = response.images.getField(GraphicFieldType.DOCUMENT_FRONT).getValue();
80+
const portraitField = response.images.getField(GraphicFieldType.PORTRAIT);
13481

135-
const docImagePattern = docAuthenticity.imagePatternChecks();
136-
const docImagePatternBlankChecks = docImagePattern.checksByElement(SecurityFeatureType.BLANK);
82+
if (documentImage) {
83+
fs.appendFileSync('document-image.jpg', Buffer.from(documentImage));
84+
}
13785

138-
// images example
139-
const documentImage = response.images.getField(DOCUMENT_FRONT).getValue();
140-
const portraitField = response.images.getField(PORTRAIT);
86+
if (portraitField) {
14187
const portraitFromVisual = portraitField.getValue(Source.VISUAL);
14288
fs.appendFileSync('portrait.jpg', Buffer.from(portraitFromVisual));
143-
fs.appendFileSync('document-image.jpg', Buffer.from(documentImage));
89+
}
90+
91+
console.log('---------------------------------------------------------------');
92+
console.log(`Document name: ${response.documentType()?.DocumentName || 'UNKNOWN'}`);
93+
console.log('---------------------------------------------------------------');
94+
95+
if (response.text) {
96+
response.text.fieldList.forEach((field) => {
97+
console.log(`\n[${field.fieldName}]`);
98+
field.valueList.forEach(({ source, value }) => {
99+
console.log(` - Source: ${source}`);
100+
console.log(` Value : ${value}`);
101+
});
102+
console.log('---------------------------------------------------------------');
103+
});
104+
} else {
105+
console.log(' NO TEXT DATA');
106+
console.log('---------------------------------------------------------------');
107+
}
144108

145-
const docImageQuality = response.imageQualityChecks();
146-
147-
console.log('-----------------------------------------------------------------');
148-
console.log(` Web API version: ${serverInfo.version}`);
149-
console.log('-----------------------------------------------------------------');
150-
console.log(` Document Overall Status: ${docOverallStatus}`);
151-
console.log(` Document Number Visual: ${docNumberVisual}`);
152-
console.log(` Document Number MRZ: ${docNumberMrz}`);
153-
console.log(`Validity Of Document Number Visual: ${docNumberVisualValidity}`);
154-
console.log(` Validity Of Document Number MRZ: ${docNumberMrzValidity}`);
155-
console.log(` MRZ-Visual values comparison: ${docNumberMrzVisualMatching}`);
156-
console.log('-----------------------------------------------------------------');
157-
158-
// how to get low lvl individual results
159-
const lexResult = response.lowLvlResponse.resultByType(Result.LEXICAL_ANALYSIS);
160-
})();
109+
console.log(` -Web API version: ${serverInfo.version}-`);

examples/auth/client/license.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/auth/client/package-lock.json

Lines changed: 8 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/auth/client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"type": "module",
44
"dependencies": {
55
"@regulaforensics/document-reader-webclient": "file:../../..",
6-
"axios": "^1.7.4",
6+
"axios": "^1.7.7",
77
"qs": "^6.13.0"
88
},
99
"version": "0.0.0"

0 commit comments

Comments
 (0)