-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding Autofill endpoint. * MR comments adjustments. * Tests for autofill endpoint. * Fixes after MR. * Bumped version, changed test data slightly.
- Loading branch information
Showing
5 changed files
with
106 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { AxiosInstance } from "axios"; | ||
import { Method, Resource } from "../Resource"; | ||
|
||
export type ExtractionResult = { | ||
documentId: string; | ||
documentClassification: { | ||
issuingCountry: string; | ||
documentType: string; | ||
issuingState?: string; | ||
}; | ||
extractedData: { | ||
documentNumber?: string; | ||
firstName?: string; | ||
lastName?: string; | ||
middleName?: string; | ||
fullName?: string; | ||
gender?: string; | ||
dateOfBirth?: string; | ||
dateOfExpiry?: string; | ||
nationality?: string; | ||
mrzLine1?: string; | ||
mrzLine2?: string; | ||
mrzLine3?: string; | ||
addressLine1?: string; | ||
addressLine2?: string; | ||
addressLine3?: string; | ||
addressLine4?: string; | ||
addressLine5?: string; | ||
}; | ||
}; | ||
|
||
type AutofillResource = { | ||
documentId: string; | ||
}; | ||
|
||
export class Autofill extends Resource<AutofillResource> { | ||
constructor(axiosInstance: AxiosInstance) { | ||
super("extractions", axiosInstance); | ||
} | ||
|
||
public async perform(documentId: string): Promise<ExtractionResult> { | ||
return this.request({ | ||
method: Method.POST, | ||
body: { documentId } | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import nock from "nock"; | ||
import { Onfido } from "onfido-node"; | ||
|
||
const onfido = new Onfido({ apiToken: "api_token" }); | ||
|
||
// Fake data, taken from documentation. | ||
const exampleAutofillJson = { | ||
document_id: "21345-xxx", | ||
document_classification: { | ||
issuing_country: "FRA", | ||
document_type: "national_identity_card" | ||
}, | ||
extracted_data: { | ||
date_of_birth: "1990-07-21", | ||
date_of_expiry: "2025-07-07", | ||
document_number: "200407512345", | ||
first_name: "AMANDINE CHANTAL", | ||
gender: "Female", | ||
last_name: "MAVARINE", | ||
mrz_line1: "IDFRAMAVARINE<<<<<<<<<<<<<<<<<075123", | ||
mrz_line2: "2000000000000AMANDINE<CHANT9007219F5", | ||
nationality: "FRA" | ||
} | ||
}; | ||
|
||
const exampleAutofillResult = { | ||
documentId: "21345-xxx", | ||
documentClassification: { | ||
issuingCountry: "FRA", | ||
documentType: "national_identity_card" | ||
}, | ||
extractedData: { | ||
dateOfBirth: "1990-07-21", | ||
dateOfExpiry: "2025-07-07", | ||
documentNumber: "200407512345", | ||
firstName: "AMANDINE CHANTAL", | ||
gender: "Female", | ||
lastName: "MAVARINE", | ||
mrzLine1: "IDFRAMAVARINE<<<<<<<<<<<<<<<<<075123", | ||
mrzLine2: "2000000000000AMANDINE<CHANT9007219F5", | ||
nationality: "FRA" | ||
} | ||
}; | ||
|
||
it("performs autofill", async () => { | ||
nock("https://api.onfido.com/v3") | ||
.post("/extractions/", { | ||
document_id: "21345-xxx" | ||
}) | ||
.reply(201, exampleAutofillJson); | ||
|
||
const result = await onfido.autofill.perform("21345-xxx"); | ||
expect(result).toEqual(exampleAutofillResult); | ||
}); |