From 422dc8c45c403b71caba3e1c160260603aa22df5 Mon Sep 17 00:00:00 2001 From: Ray Smets Date: Mon, 10 Oct 2022 17:19:43 -0700 Subject: [PATCH] [HV SDK] v5 (#33) * [V5] working. * package * [package] release version of types. --- package-lock.json | 4 +- package.json | 2 +- public/index.html | 2 +- src/components/Register.tsx | 186 ++++++++++++++++++++---------------- 4 files changed, 106 insertions(+), 88 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5c1d10b..305b267 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2751,8 +2751,8 @@ } }, "@unumid/id-verification-types": { - "version": "git+ssh://git@github.com/UnumID/id-verification-types.git#a67c48244dbe044d435cb3f99df0c566cae6124b", - "from": "git+ssh://git@github.com/UnumID/id-verification-types.git#v0.1.0", + "version": "git+ssh://git@github.com/UnumID/id-verification-types.git#372f3ad606476690828035c8cd88434ab2498be6", + "from": "git+ssh://git@github.com/UnumID/id-verification-types.git#v1.0.0", "dev": true }, "@unumid/types": { diff --git a/package.json b/package.json index c65b915..5be5355 100644 --- a/package.json +++ b/package.json @@ -80,7 +80,7 @@ "@types/validator": "^13.1.3", "@typescript-eslint/eslint-plugin": "^4.15.2", "@typescript-eslint/parser": "^4.15.2", - "@unumid/id-verification-types": "git+ssh://git@github.com:UnumID/id-verification-types.git#v0.1.0", + "@unumid/id-verification-types": "git+ssh://git@github.com/UnumID/id-verification-types#v1.0.0", "eslint": "^7.20.0", "eslint-config-semistandard": "^16.0.0", "eslint-config-standard": "^16.0.3", diff --git a/public/index.html b/public/index.html index 68a002c..84c9c3e 100644 --- a/public/index.html +++ b/public/index.html @@ -26,7 +26,7 @@ --> Unum ID Verification - + diff --git a/src/components/Register.tsx b/src/components/Register.tsx index 95fb5ff..e202226 100644 --- a/src/components/Register.tsx +++ b/src/components/Register.tsx @@ -20,13 +20,33 @@ import { config } from '../config'; import { useSearchParams } from 'react-router-dom'; import { HvDocScanData } from '../types'; -import { KYCData as _KYCData } from '@unumid/id-verification-types'; - -interface KYCData extends Omit<_KYCData, 'docImage' | 'fullFaceImage'> { - docImage?: string; - fullFaceImage?: string; - -} +import { KYCData as _KYCData, HvClientResponse } from '@unumid/id-verification-types'; + +// export interface HVDetails { +// dateOfBirth: string; +// firstName: string; +// fullName: string; +// // eslint-disable-next-line camelcase +// id_back_imagePath: string; +// idNumber: string; +// lastName: string; +// middleName: string; +// } + +// export interface HvResult { +// status: string; +// transactionId: string; +// details: HVDetails; +// } + +// interface KYCData extends Omit<_KYCData, 'docImage' | 'fullFaceImage'> { +// docImage?: string; +// fullFaceImage?: string; +// } + +// interface HvDocScanResult { +// status: string; +// } // types for global variables added by the hyperverge sdk declare global { @@ -38,81 +58,76 @@ declare global { } } -const makeHvHandler = (callback: (data: KYCData) => void) => (HyperKycResult: any) => { - if (HyperKycResult.Cancelled) { - // user cancelled - console.log('hyperverge cancelled', HyperKycResult); - } else if (HyperKycResult.Failure) { - // fail - console.log('hyperverge failed', HyperKycResult); - } else if (HyperKycResult.Success) { - // success - console.log('hyperverge success', HyperKycResult); - - const hvDocScanData: HvDocScanData = HyperKycResult.Success.data; - const docCountryId = hvDocScanData.selectedCountryId; - - const faceMatchData = hvDocScanData.faceMatchData.responseResult.result.details.match; - const faceMatch = faceMatchData.value; - const faceMatchConfidence = faceMatchData.confidence; - - const faceData = hvDocScanData.faceData; - // const fullFaceImage = faceData.fullFaceImagePath; - const liveFace = faceData.responseResult.result.details.liveFace.value; - const liveFaceConfidence = faceData.responseResult.result.details.liveFace.confidence; - - const docData = hvDocScanData.docListData[0]; - // const docImage = docData.docImagePath; - const docType = docData.documentId; - const { address, dateOfBirth, fullName, gender } = docData.responseResult.result.details[0].fieldsExtracted; - debugger; - /** - * Reformat the DOB from the HV document scan. - * dateOfBirthday was taking the format MM-DD-YYYY from HV, but as of 6/23 was updated to dD-mM-YYYY. - * and Prove needs it in the format YYYY-MM-DD, so just turning it in that here - */ - const proveDob = dateOfBirth.value.split('-'); - - // loop through the split data array and ensure all values have at least 2 digits - for (let i = 0; i < proveDob.length; i++) { - if (proveDob[i].length < 2) { - proveDob[i] = '0' + proveDob[i]; - } - } - - // shift values to fit desired format; this was working when HV was returning in format MM-DD-YYYY - // const hold = proveDob[2]; - // proveDob[2] = proveDob[1]; - // proveDob[1] = proveDob[0]; - // proveDob[0] = hold; - - // shift values to fit desired format; having to deal with new format of DD-MM-YYYY - const hold = proveDob[2]; - proveDob[2] = proveDob[0]; - proveDob[0] = hold; +const makeHvHandler = (callback: (data: HvClientResponse) => void) => (HyperKycResult: any) => { + switch (HyperKycResult.status) { + case 'user_cancelled': + // user cancelled + console.log('hyperverge cancelled', HyperKycResult); + break; + case 'error': + // failure + console.log('hyperverge error', HyperKycResult); + break; + case 'auto_approved': + case 'auto_declined': + case 'needs_review': + // workflow success + break; + } - // now should be in YYYY-MM-DD format - const dob = proveDob.join('-'); + // const hvDocScanData: HvDocScanData = HyperKycResult.Success.data; + // const docCountryId = hvDocScanData.selectedCountryId; + + // const faceMatchData = hvDocScanData.faceMatchData.responseResult.result.details.match; + // const faceMatch = faceMatchData.value; + // const faceMatchConfidence = faceMatchData.confidence; + + // const faceData = hvDocScanData.faceData; + // // const fullFaceImage = faceData.fullFaceImagePath; + // const liveFace = faceData.responseResult.result.details.liveFace.value; + // const liveFaceConfidence = faceData.responseResult.result.details.liveFace.confidence; + + // const docData = hvDocScanData.docListData[0]; + // // const docImage = docData.docImagePath; + // const docType = docData.documentId; + // const { address, dateOfBirth, fullName, gender } = docData.responseResult.result.details[0].fieldsExtracted; + // debugger; + // /** + // * Reformat the DOB from the HV document scan. + // * dateOfBirthday was taking the format MM-DD-YYYY from HV, but as of 6/23 was updated to dD-mM-YYYY. + // * and Prove needs it in the format YYYY-MM-DD, so just turning it in that here + // */ + // const proveDob = dateOfBirth.value.split('-'); + + // // loop through the split data array and ensure all values have at least 2 digits + // for (let i = 0; i < proveDob.length; i++) { + // if (proveDob[i].length < 2) { + // proveDob[i] = '0' + proveDob[i]; + // } + // } + + // // shift values to fit desired format; this was working when HV was returning in format MM-DD-YYYY + // // const hold = proveDob[2]; + // // proveDob[2] = proveDob[1]; + // // proveDob[1] = proveDob[0]; + // // proveDob[0] = hold; + + // // shift values to fit desired format; having to deal with new format of DD-MM-YYYY + // const hold = proveDob[2]; + // proveDob[2] = proveDob[0]; + // proveDob[0] = hold; + + // // now should be in YYYY-MM-DD format + // const dob = proveDob.join('-'); - debugger; - // eslint-disable-next-line node/no-callback-literal - callback({ - address: address.value, - dob, - fullName: fullName.value, - gender: gender.value, - // docImage, - docType, - docCountryId, - // fullFaceImage, - liveFace, - liveFaceConfidence, - faceMatch, - faceMatchConfidence - }); + debugger; + // eslint-disable-next-line node/no-callback-literal + callback( + HyperKycResult + ); - console.log('success'); - } + console.log('success'); + // } }; /** @@ -208,7 +223,7 @@ const Register: FC = () => { * calls the hvService to persist the data on a user entity for credential issuance later. * the service creates a user and returns the userCode for linking to the prove prefill data */ - const sendHvDocScanData = async (data: KYCData): Promise => { + const sendHvDocScanData = async (data: HvClientResponse): Promise => { // TODO add auth with backend const hvService = backendClient.service('hyperVerge'); @@ -258,16 +273,19 @@ const Register: FC = () => { const transactionId = `${v1()}`; const documentHv = new window.Document(true, defaultCountryId, defaultDocumentId); const face = new window.Face(); - const workflow = [documentHv, face]; - const hyperKycConfig = new window.HyperKycConfig(accessToken, workflow, transactionId, defaultCountryId); + // const workflow = [documentHv, face]; + // const workflowId = 'global_workflow'; + const workflowId = 'USA_DL_Workflow'; + const hyperKycConfig = new window.HyperKycConfig(accessToken, workflowId, transactionId); + // const hyperKycConfig = new window.HyperKycConfig(accessToken, workflow, transactionId, defaultCountryId); - const callback = async (data: KYCData) => { + const callback = async (data: HvClientResponse) => { const userCode = await sendHvDocScanData(data); debugger; if (config.proveEnabled) { // kick off Prove InstantLink sms - sendProveSms(userCode, data.dob); + // sendProveSms(userCode, data.dob); } else { // redirect to the deeplink router with the userCode and issuer did redirectToDeeplinkRouter(userCode, config.hvIssuerDid);