document-ocr 0.0.0-stage → 3.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +260 -2
- package/dist/index.cjs +659 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +293 -0
- package/dist/index.d.ts +293 -0
- package/dist/index.js +616 -0
- package/dist/index.js.map +1 -0
- package/hosting/.dockerignore +17 -0
- package/hosting/.gcloudignore +14 -0
- package/hosting/FEATURES.md +172 -0
- package/hosting/HOSTING.md +268 -0
- package/hosting/LICENSE +21 -0
- package/hosting/README.md +369 -0
- package/hosting/core/__init__.py +0 -0
- package/hosting/core/aadhaar_extractor.py +298 -0
- package/hosting/core/back_page_extractor.py +492 -0
- package/hosting/core/barcodes.py +125 -0
- package/hosting/core/card_recovery.py +244 -0
- package/hosting/core/document_bundle.py +82 -0
- package/hosting/core/document_classifier.py +233 -0
- package/hosting/core/document_input.py +135 -0
- package/hosting/core/document_registry.py +143 -0
- package/hosting/core/driving_licence_extractor.py +510 -0
- package/hosting/core/ead_recovery.py +54 -0
- package/hosting/core/evidence.py +54 -0
- package/hosting/core/form_recovery.py +61 -0
- package/hosting/core/jobs.py +232 -0
- package/hosting/core/kyc_ocr.py +132 -0
- package/hosting/core/kyc_validation.py +411 -0
- package/hosting/core/model_setup.py +13 -0
- package/hosting/core/mrz_parser.py +336 -0
- package/hosting/core/mrz_recovery.py +193 -0
- package/hosting/core/npr_extractor.py +410 -0
- package/hosting/core/nrega_extractor.py +827 -0
- package/hosting/core/ocr_engine.py +207 -0
- package/hosting/core/page_classifier.py +137 -0
- package/hosting/core/pan_extractor.py +183 -0
- package/hosting/core/pipeline.py +712 -0
- package/hosting/core/preprocessor.py +297 -0
- package/hosting/core/recovery_budget.py +67 -0
- package/hosting/core/redaction.py +48 -0
- package/hosting/core/review.html +244 -0
- package/hosting/core/structured_documents.py +422 -0
- package/hosting/core/travel_mrz.py +164 -0
- package/hosting/core/travel_recovery.py +187 -0
- package/hosting/core/validator.py +396 -0
- package/hosting/core/validators.py +179 -0
- package/hosting/core/voter_id_extractor.py +363 -0
- package/hosting/deploy/cloudflare/deploy.sh +44 -0
- package/hosting/deploy/cloudflare/package-lock.json +3088 -0
- package/hosting/deploy/cloudflare/package.json +29 -0
- package/hosting/deploy/cloudflare/src/gateway.ts +42 -0
- package/hosting/deploy/cloudflare/src/index.ts +21 -0
- package/hosting/deploy/cloudflare/test/gateway.test.ts +59 -0
- package/hosting/deploy/cloudflare/tsconfig.json +12 -0
- package/hosting/deploy/cloudflare/worker-configuration.d.ts +16253 -0
- package/hosting/deploy/cloudflare/wrangler.jsonc +26 -0
- package/hosting/deploy/cloudrun/cloudbuild.yaml +18 -0
- package/hosting/deploy/cloudrun/deploy.sh +71 -0
- package/hosting/deploy/cloudrun/render_service.py +47 -0
- package/hosting/deploy/common.sh +14 -0
- package/hosting/deploy/docker/Dockerfile +16 -0
- package/hosting/deploy/docker/server.py +313 -0
- package/hosting/deploy/lambda/Dockerfile.lambda +11 -0
- package/hosting/deploy/lambda/deploy.sh +22 -0
- package/hosting/deploy/lambda/handler.py +132 -0
- package/hosting/deploy/lambda/template.yaml +59 -0
- package/hosting/deploy/local/dev.sh +18 -0
- package/hosting/deploy/server/Caddyfile +5 -0
- package/hosting/deploy/server/compose.jobs.yaml +36 -0
- package/hosting/deploy/server/compose.yaml +38 -0
- package/hosting/deploy/server/deploy.sh +23 -0
- package/hosting/infra/cloudrun/main.tf +104 -0
- package/hosting/infra/cloudrun/terraform.tfvars.example +7 -0
- package/hosting/infra/cloudrun/variables.tf +55 -0
- package/hosting/infra/lambda/main.tf +63 -0
- package/hosting/infra/lambda/terraform.tfvars.example +6 -0
- package/hosting/infra/lambda/variables.tf +37 -0
- package/hosting/pyproject.toml +65 -0
- package/hosting/requirements.lock +134 -0
- package/package.json +76 -4
- package/python/core/__init__.py +0 -0
- package/python/core/aadhaar_extractor.py +298 -0
- package/python/core/back_page_extractor.py +492 -0
- package/python/core/barcodes.py +125 -0
- package/python/core/card_recovery.py +244 -0
- package/python/core/document_bundle.py +82 -0
- package/python/core/document_classifier.py +233 -0
- package/python/core/document_input.py +135 -0
- package/python/core/document_registry.py +143 -0
- package/python/core/driving_licence_extractor.py +510 -0
- package/python/core/ead_recovery.py +54 -0
- package/python/core/evidence.py +54 -0
- package/python/core/form_recovery.py +61 -0
- package/python/core/jobs.py +232 -0
- package/python/core/kyc_ocr.py +132 -0
- package/python/core/kyc_validation.py +411 -0
- package/python/core/model_setup.py +13 -0
- package/python/core/mrz_parser.py +336 -0
- package/python/core/mrz_recovery.py +193 -0
- package/python/core/npr_extractor.py +410 -0
- package/python/core/nrega_extractor.py +827 -0
- package/python/core/ocr_engine.py +207 -0
- package/python/core/page_classifier.py +137 -0
- package/python/core/pan_extractor.py +183 -0
- package/python/core/pipeline.py +712 -0
- package/python/core/preprocessor.py +297 -0
- package/python/core/recovery_budget.py +67 -0
- package/python/core/redaction.py +48 -0
- package/python/core/review.html +244 -0
- package/python/core/structured_documents.py +422 -0
- package/python/core/travel_mrz.py +164 -0
- package/python/core/travel_recovery.py +187 -0
- package/python/core/validator.py +396 -0
- package/python/core/validators.py +179 -0
- package/python/core/voter_id_extractor.py +363 -0
- package/python/pyproject.toml +34 -0
- package/python/requirements.lock +134 -0
- package/python/server.py +313 -0
- package/scripts/dococr.mjs +163 -0
- package/scripts/postinstall.mjs +173 -0
- package/scripts/sync-hosting.mjs +35 -0
- package/scripts/sync-python.sh +20 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
interface PassportFields {
|
|
2
|
+
surname: string | null;
|
|
3
|
+
givenNames: string | null;
|
|
4
|
+
fullName: string | null;
|
|
5
|
+
passportNumber: string | null;
|
|
6
|
+
nationality: string | null;
|
|
7
|
+
dateOfBirth: string | null;
|
|
8
|
+
sex: 'M' | 'F' | 'X' | null;
|
|
9
|
+
expiryDate: string | null;
|
|
10
|
+
issueDate: string | null;
|
|
11
|
+
placeOfBirth: string | null;
|
|
12
|
+
countryCode: string | null;
|
|
13
|
+
}
|
|
14
|
+
interface BackPageFields {
|
|
15
|
+
fatherName: string | null;
|
|
16
|
+
motherName: string | null;
|
|
17
|
+
spouseName: string | null;
|
|
18
|
+
address: string | null;
|
|
19
|
+
pincode: string | null;
|
|
20
|
+
city: string | null;
|
|
21
|
+
state: string | null;
|
|
22
|
+
fileNumber: string | null;
|
|
23
|
+
oldPassportNumber: string | null;
|
|
24
|
+
oldPassportDateOfIssue: string | null;
|
|
25
|
+
oldPassportPlaceOfIssue: string | null;
|
|
26
|
+
}
|
|
27
|
+
interface PanFields {
|
|
28
|
+
panNumber: string | null;
|
|
29
|
+
name: string | null;
|
|
30
|
+
fatherName: string | null;
|
|
31
|
+
dateOfBirth: string | null;
|
|
32
|
+
}
|
|
33
|
+
interface AadhaarFields {
|
|
34
|
+
aadhaarNumber: string | null;
|
|
35
|
+
name: string | null;
|
|
36
|
+
dateOfBirth: string | null;
|
|
37
|
+
yearOfBirth: string | null;
|
|
38
|
+
gender: string | null;
|
|
39
|
+
address: string | null;
|
|
40
|
+
pincode: string | null;
|
|
41
|
+
checksumValid: boolean;
|
|
42
|
+
aadhaarMasked: boolean;
|
|
43
|
+
aadhaarLast4: string | null;
|
|
44
|
+
vid: string | null;
|
|
45
|
+
}
|
|
46
|
+
interface DrivingLicenceFields {
|
|
47
|
+
dlNumber: string | null;
|
|
48
|
+
name: string | null;
|
|
49
|
+
dateOfBirth: string | null;
|
|
50
|
+
issueDate: string | null;
|
|
51
|
+
validityDate: string | null;
|
|
52
|
+
address: string | null;
|
|
53
|
+
relationName: string | null;
|
|
54
|
+
bloodGroup: string | null;
|
|
55
|
+
classOfVehicle: string | null;
|
|
56
|
+
validityDateTransport: string | null;
|
|
57
|
+
}
|
|
58
|
+
interface VoterIdFields {
|
|
59
|
+
epicNumber: string | null;
|
|
60
|
+
name: string | null;
|
|
61
|
+
relationName: string | null;
|
|
62
|
+
relationType: string | null;
|
|
63
|
+
gender: string | null;
|
|
64
|
+
dateOfBirth: string | null;
|
|
65
|
+
age: string | null;
|
|
66
|
+
}
|
|
67
|
+
interface NregaMember {
|
|
68
|
+
serialNumber: string | null;
|
|
69
|
+
name: string | null;
|
|
70
|
+
fatherOrHusbandName: string | null;
|
|
71
|
+
gender: 'MALE' | 'FEMALE' | 'TRANSGENDER' | null;
|
|
72
|
+
age: number | null;
|
|
73
|
+
}
|
|
74
|
+
interface NregaJobCardFields {
|
|
75
|
+
jobCardNumber: string | null;
|
|
76
|
+
headOfHousehold: string | null;
|
|
77
|
+
category: string | null;
|
|
78
|
+
registrationDate: string | null;
|
|
79
|
+
validityFrom: string | null;
|
|
80
|
+
validityTo: string | null;
|
|
81
|
+
address: string | null;
|
|
82
|
+
village: string | null;
|
|
83
|
+
gramPanchayat: string | null;
|
|
84
|
+
block: string | null;
|
|
85
|
+
district: string | null;
|
|
86
|
+
state: string | null;
|
|
87
|
+
bplStatus: boolean | null;
|
|
88
|
+
familyId: string | null;
|
|
89
|
+
members: NregaMember[];
|
|
90
|
+
}
|
|
91
|
+
interface NprLetterFields {
|
|
92
|
+
referenceNumber: string | null;
|
|
93
|
+
name: string | null;
|
|
94
|
+
address: string | null;
|
|
95
|
+
pincode: string | null;
|
|
96
|
+
issueDate: string | null;
|
|
97
|
+
}
|
|
98
|
+
type DocumentStatus = 'success' | 'unsupported_page' | 'failure';
|
|
99
|
+
type DocumentType = 'passport' | 'pan' | 'aadhaar' | 'driving_licence' | 'voter_id' | 'nrega_job_card' | 'npr_letter' | 'us_driver_license' | 'us_state_id' | 'passport_card' | 'us_green_card' | 'us_ead' | 'visa' | 'us_i94' | 'us_w9' | 'unknown';
|
|
100
|
+
type PageType = DocumentType | 'passport_biodata' | 'passport_non_biodata';
|
|
101
|
+
type UnsupportedReason = 'UNSUPPORTED_DOCUMENT';
|
|
102
|
+
type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
103
|
+
[key: string]: JsonValue;
|
|
104
|
+
};
|
|
105
|
+
interface FieldEvidence {
|
|
106
|
+
text: string;
|
|
107
|
+
bbox: number[][];
|
|
108
|
+
source: 'ocr' | 'pdf_text' | 'mrz' | 'pdf417' | 'qr';
|
|
109
|
+
confidence: number;
|
|
110
|
+
page?: number;
|
|
111
|
+
}
|
|
112
|
+
interface BaseDocumentScanResult {
|
|
113
|
+
schemaVersion?: number;
|
|
114
|
+
documentFields?: Record<string, JsonValue> | null;
|
|
115
|
+
issuingCountry?: string | null;
|
|
116
|
+
issuingRegion?: string | null;
|
|
117
|
+
fieldEvidence?: Record<string, FieldEvidence[]>;
|
|
118
|
+
imageSize?: [number, number] | null;
|
|
119
|
+
checks?: Record<string, boolean | string | null>;
|
|
120
|
+
status: DocumentStatus;
|
|
121
|
+
documentType: DocumentType;
|
|
122
|
+
pageType: PageType;
|
|
123
|
+
confidence: number;
|
|
124
|
+
lowConfidence: boolean;
|
|
125
|
+
mrzRaw: [string, string] | null;
|
|
126
|
+
mrzValid: boolean;
|
|
127
|
+
unsupportedReason: UnsupportedReason | null;
|
|
128
|
+
identifierValid: boolean | null;
|
|
129
|
+
missingRequiredFields: string[];
|
|
130
|
+
backPageFields: BackPageFields | null;
|
|
131
|
+
panFields: PanFields | null;
|
|
132
|
+
aadhaarFields: AadhaarFields | null;
|
|
133
|
+
drivingLicenceFields: DrivingLicenceFields | null;
|
|
134
|
+
voterIdFields: VoterIdFields | null;
|
|
135
|
+
nregaJobCardFields: NregaJobCardFields | null;
|
|
136
|
+
nprLetterFields: NprLetterFields | null;
|
|
137
|
+
probeText: string[];
|
|
138
|
+
errors: string[];
|
|
139
|
+
warnings: string[];
|
|
140
|
+
processingMs: number;
|
|
141
|
+
}
|
|
142
|
+
interface SuccessfulDocumentScanResult extends BaseDocumentScanResult {
|
|
143
|
+
status: 'success';
|
|
144
|
+
fields: PassportFields | null;
|
|
145
|
+
}
|
|
146
|
+
interface UnsupportedPageDocumentScanResult extends BaseDocumentScanResult {
|
|
147
|
+
status: 'unsupported_page';
|
|
148
|
+
fields: null;
|
|
149
|
+
unsupportedReason: UnsupportedReason;
|
|
150
|
+
}
|
|
151
|
+
interface FailedDocumentScanResult extends BaseDocumentScanResult {
|
|
152
|
+
status: 'failure';
|
|
153
|
+
fields: PassportFields | null;
|
|
154
|
+
}
|
|
155
|
+
type DocumentScanResult = SuccessfulDocumentScanResult | UnsupportedPageDocumentScanResult | FailedDocumentScanResult;
|
|
156
|
+
type PassportScanResult = DocumentScanResult;
|
|
157
|
+
type ImageInput = File | Blob | Buffer | ArrayBuffer | string;
|
|
158
|
+
type ClientMode = 'local' | 'http' | 'lambda';
|
|
159
|
+
interface DocumentOCROptions {
|
|
160
|
+
mode?: ClientMode;
|
|
161
|
+
endpoint?: string;
|
|
162
|
+
functionName?: string;
|
|
163
|
+
timeoutMs?: number;
|
|
164
|
+
retries?: number;
|
|
165
|
+
apiKey?: string;
|
|
166
|
+
authHeaders?: (url: string, signal?: AbortSignal) => HeadersInit | Promise<HeadersInit>;
|
|
167
|
+
}
|
|
168
|
+
type PassportOCROptions = DocumentOCROptions;
|
|
169
|
+
interface ScanOptions {
|
|
170
|
+
documentType?: string;
|
|
171
|
+
country?: string;
|
|
172
|
+
includeEvidence?: boolean;
|
|
173
|
+
}
|
|
174
|
+
interface BatchScanResult {
|
|
175
|
+
results: DocumentScanResult[];
|
|
176
|
+
status: 'success' | 'partial' | 'failure';
|
|
177
|
+
errors: string[];
|
|
178
|
+
}
|
|
179
|
+
interface DocumentScanGroupResult extends BatchScanResult {
|
|
180
|
+
documentFields: Record<string, JsonValue>;
|
|
181
|
+
conflicts: Array<{
|
|
182
|
+
field: string;
|
|
183
|
+
values: Array<{
|
|
184
|
+
page: number;
|
|
185
|
+
value: JsonValue;
|
|
186
|
+
}>;
|
|
187
|
+
}>;
|
|
188
|
+
}
|
|
189
|
+
interface JobOptions extends ScanOptions {
|
|
190
|
+
grouped?: boolean;
|
|
191
|
+
notify?: boolean;
|
|
192
|
+
}
|
|
193
|
+
interface OCRJob {
|
|
194
|
+
id: string;
|
|
195
|
+
status: 'queued' | 'running' | 'succeeded' | 'failed';
|
|
196
|
+
createdAt: number;
|
|
197
|
+
expiresAt: number;
|
|
198
|
+
attempts: number;
|
|
199
|
+
error: string | null;
|
|
200
|
+
result?: BatchScanResult | DocumentScanGroupResult;
|
|
201
|
+
}
|
|
202
|
+
interface S3ImageInput {
|
|
203
|
+
bucket: string;
|
|
204
|
+
key: string;
|
|
205
|
+
versionId?: string;
|
|
206
|
+
}
|
|
207
|
+
interface DocumentDefinition {
|
|
208
|
+
documentType: DocumentType;
|
|
209
|
+
label: string;
|
|
210
|
+
countries: string[];
|
|
211
|
+
fields: string[];
|
|
212
|
+
requiredFields: string[];
|
|
213
|
+
requiredFieldsByVariant?: Record<string, string[]>;
|
|
214
|
+
requirementAlternatives?: Record<string, string[][]>;
|
|
215
|
+
sources: string[];
|
|
216
|
+
experimental: boolean;
|
|
217
|
+
}
|
|
218
|
+
interface DocumentCatalog {
|
|
219
|
+
schemaVersion: number;
|
|
220
|
+
documents: DocumentDefinition[];
|
|
221
|
+
capabilities: {
|
|
222
|
+
barcode: boolean;
|
|
223
|
+
jobs: boolean;
|
|
224
|
+
review: boolean;
|
|
225
|
+
multipage: boolean;
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
declare class DocumentOCR {
|
|
230
|
+
private mode;
|
|
231
|
+
private endpoint?;
|
|
232
|
+
private functionName?;
|
|
233
|
+
private timeoutMs;
|
|
234
|
+
private retries;
|
|
235
|
+
private apiKey?;
|
|
236
|
+
private authHeaders?;
|
|
237
|
+
constructor(options?: DocumentOCROptions);
|
|
238
|
+
scan(image: ImageInput, options?: ScanOptions): Promise<DocumentScanResult>;
|
|
239
|
+
scanBatch(images: ImageInput[], options?: ScanOptions): Promise<BatchScanResult>;
|
|
240
|
+
scanDocument(images: ImageInput[], options?: ScanOptions): Promise<DocumentScanGroupResult>;
|
|
241
|
+
private uploadMany;
|
|
242
|
+
documents(): Promise<DocumentCatalog>;
|
|
243
|
+
enqueueJob(images: ImageInput[], options?: JobOptions): Promise<OCRJob>;
|
|
244
|
+
job(id: string): Promise<OCRJob>;
|
|
245
|
+
deleteJob(id: string): Promise<{
|
|
246
|
+
deleted: true;
|
|
247
|
+
}>;
|
|
248
|
+
scanS3(image: S3ImageInput, options?: ScanOptions): Promise<DocumentScanResult>;
|
|
249
|
+
stop(): Promise<void>;
|
|
250
|
+
private requireHttp;
|
|
251
|
+
private retry;
|
|
252
|
+
private request;
|
|
253
|
+
private invokeLambda;
|
|
254
|
+
}
|
|
255
|
+
declare const PassportOCR: typeof DocumentOCR;
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Manages a local Python FastAPI server for passport OCR.
|
|
259
|
+
*
|
|
260
|
+
* Uses a module-level singleton so multiple PassportOCR instances
|
|
261
|
+
* share a single server process.
|
|
262
|
+
*/
|
|
263
|
+
declare class LocalServer {
|
|
264
|
+
private process;
|
|
265
|
+
private ready;
|
|
266
|
+
private startupAbort;
|
|
267
|
+
private cleanupHandler;
|
|
268
|
+
/**
|
|
269
|
+
* Ensure the local Python server is running and return its endpoint URL.
|
|
270
|
+
*/
|
|
271
|
+
ensureRunning(): Promise<string>;
|
|
272
|
+
private _start;
|
|
273
|
+
private _waitForReady;
|
|
274
|
+
/**
|
|
275
|
+
* Stop the local Python server if running.
|
|
276
|
+
*/
|
|
277
|
+
stop(): Promise<void>;
|
|
278
|
+
}
|
|
279
|
+
declare function getLocalServer(): LocalServer;
|
|
280
|
+
|
|
281
|
+
/** Preserve transport status separately from the server's human-readable message. */
|
|
282
|
+
declare class HttpError extends Error {
|
|
283
|
+
readonly status: number;
|
|
284
|
+
constructor(status: number, message: string);
|
|
285
|
+
get retryable(): boolean;
|
|
286
|
+
}
|
|
287
|
+
/** Invalid client input cannot succeed by retrying the same request. */
|
|
288
|
+
declare class InputValidationError extends Error {
|
|
289
|
+
constructor(message: string);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export { DocumentOCR, HttpError, InputValidationError, LocalServer, PassportOCR, getLocalServer };
|
|
293
|
+
export type { AadhaarFields, BackPageFields, BatchScanResult, ClientMode, DocumentCatalog, DocumentDefinition, DocumentOCROptions, DocumentScanGroupResult, DocumentScanResult, DocumentStatus, DocumentType, DrivingLicenceFields, FieldEvidence, ImageInput, JobOptions, JsonValue, NprLetterFields, NregaJobCardFields, NregaMember, OCRJob, PageType, PanFields, PassportFields, PassportOCROptions, PassportScanResult, S3ImageInput, ScanOptions, UnsupportedReason, VoterIdFields };
|