UNPKG

@privateid/ultra-web-sdk-alpha

Version:
311 lines 22.1 kB
import { LOGTYPE } from './types'; import { printLogs } from './utils'; export var callbackTypeEnum; (function (callbackTypeEnum) { callbackTypeEnum["isValid"] = "isValid"; callbackTypeEnum["predict"] = "predict"; callbackTypeEnum["enroll"] = "enroll"; callbackTypeEnum["frontScan"] = "frontScan"; callbackTypeEnum["passportScan"] = "passportScan"; callbackTypeEnum["documentScanNoFace"] = "documentScanNoFace"; callbackTypeEnum["backScan"] = "backScan"; callbackTypeEnum["faceLogin"] = "faceLogin"; callbackTypeEnum["faceISO"] = "faceISO"; callbackTypeEnum["delete"] = "delete"; callbackTypeEnum["documentOcr"] = "documentOcr"; callbackTypeEnum["continuousPredict"] = "continuousPredict"; callbackTypeEnum["ageEstimation"] = "ageEstimation"; callbackTypeEnum["faceCompare"] = "faceCompare"; callbackTypeEnum["faceCompareDocumentAndFace"] = "faceCompareDocumentAndFace"; callbackTypeEnum["compareEmbeddings"] = "compareEmbeddings"; })(callbackTypeEnum || (callbackTypeEnum = {})); export const createCallback = ({ type, callbackFunction, returnType, imageData, portrait, isMobile, }) => { const createCallbackIsValid = ({ callback, returnType }) => (operation, id, response_str) => { const isResponse = response_str.length > 0; printLogs('================[JS RESPONSE]: response_str', isResponse ? JSON.parse(response_str) : '', LOGTYPE.LOG); printLogs('[JS RESPONSE]: operation', operation || 'null', LOGTYPE.LOG); printLogs('[JS RESPONSE]: id', id || 'null', LOGTYPE.LOG); if (isResponse) { const returnValue = JSON.parse(response_str); const returnData = { call_status: returnValue.call_status.return_status, face_validation_status: returnValue.faces.faces[0].face_validation_status, antispoof_status: returnValue.faces.faces[0].antispoofing_status, }; if (operation === 'is_valid') { if (returnType && returnType === 'all') { callback(returnValue); } else { callback(returnData); } } } }; const createCallbackEnroll = ({ callback, returnType }) => (operation, id, response_str) => { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o; const isResponse = response_str.length > 0; console.log('================[JS RESPONSE]: response_str', isResponse ? JSON.parse(response_str) : ''); //, LOGTYPE.LOG); // , LOGTYPE.LOG); console.log('[JS RESPONSE]: operation', operation || 'null'); //, LOGTYPE.LOG); //, LOGTYPE.LOG); console.log('[JS RESPONSE]: id', id || 'null'); //, LOGTYPE.LOG); //, LOGTYPE.LOG); if (isResponse) { const returnValue = JSON.parse(response_str); if (operation === 'enroll') { const returnData = { mf_token: (_a = returnValue === null || returnValue === void 0 ? void 0 : returnValue.call_status) === null || _a === void 0 ? void 0 : _a.mf_token, callback_status: (_b = returnValue === null || returnValue === void 0 ? void 0 : returnValue.call_status) === null || _b === void 0 ? void 0 : _b.return_status, face_validation_status: (_d = (_c = returnValue === null || returnValue === void 0 ? void 0 : returnValue.uber_operation_result) === null || _c === void 0 ? void 0 : _c.face) === null || _d === void 0 ? void 0 : _d.face_validation_status, antispoof_status: (_f = (_e = returnValue === null || returnValue === void 0 ? void 0 : returnValue.uber_operation_result) === null || _e === void 0 ? void 0 : _e.face) === null || _f === void 0 ? void 0 : _f.antispoofing_status, encrypted_embeddings: (_g = returnValue === null || returnValue === void 0 ? void 0 : returnValue.uber_operation_result) === null || _g === void 0 ? void 0 : _g.embedding, iso_image: (_k = (_j = (_h = returnValue === null || returnValue === void 0 ? void 0 : returnValue.uber_operation_result) === null || _h === void 0 ? void 0 : _h.cropped_images) === null || _j === void 0 ? void 0 : _j.items) === null || _k === void 0 ? void 0 : _k.iso, api_response: (_l = returnValue === null || returnValue === void 0 ? void 0 : returnValue.uber_operation_result) === null || _l === void 0 ? void 0 : _l.response, face_position: (_o = (_m = returnValue === null || returnValue === void 0 ? void 0 : returnValue.uber_operation_result) === null || _m === void 0 ? void 0 : _m.face) === null || _o === void 0 ? void 0 : _o.face_position, }; if (returnType && returnType === 'all') { callback(returnValue); } else { callback(returnData); } } } }; const createCallbackPredict = ({ callback, returnType }) => (operation, id, response_str) => { var _a, _b, _c, _d, _e, _f, _g, _h; const isResponse = response_str.length > 0; console.log('================[JS RESPONSE]: response_str', isResponse ? JSON.parse(response_str) : ''); // , LOGTYPE.LOG); //, LOGTYPE.LOG); console.log('[JS RESPONSE]: operation', operation || 'null'); //, LOGTYPE.LOG); //, LOGTYPE.LOG); console.log('[JS RESPONSE]: id', id || 'null'); //, LOGTYPE.LOG); //, LOGTYPE.LOG); if (isResponse) { const returnValue = JSON.parse(response_str); const returnData = { mf_token: (_a = returnValue === null || returnValue === void 0 ? void 0 : returnValue.call_status) === null || _a === void 0 ? void 0 : _a.mf_token, callback_status: (_b = returnValue === null || returnValue === void 0 ? void 0 : returnValue.call_status) === null || _b === void 0 ? void 0 : _b.return_status, face_validation_status: (_d = (_c = returnValue === null || returnValue === void 0 ? void 0 : returnValue.uber_operation_result) === null || _c === void 0 ? void 0 : _c.face) === null || _d === void 0 ? void 0 : _d.face_validation_status, antispoof_status: (_f = (_e = returnValue === null || returnValue === void 0 ? void 0 : returnValue.uber_operation_result) === null || _e === void 0 ? void 0 : _e.face) === null || _f === void 0 ? void 0 : _f.antispoofing_status, api_response: (_g = returnValue === null || returnValue === void 0 ? void 0 : returnValue.uber_operation_result) === null || _g === void 0 ? void 0 : _g.response, encrypted_embeddings: (_h = returnValue === null || returnValue === void 0 ? void 0 : returnValue.uber_operation_result) === null || _h === void 0 ? void 0 : _h.embedding, }; if (operation === 'predict') { if (returnType && returnType === 'all') { callback(returnValue); } else { callback(returnData); } } } }; const createCallbackFrontDlScan = ({ callback, returnType }) => (operation, id, response_str) => { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o; const isResponse = response_str.length > 0; console.log('================[JS RESPONSE]: response_str', isResponse ? JSON.parse(response_str) : ''); //, LOGTYPE.LOG); console.log('[JS RESPONSE]: operation', operation || 'null'); //, LOGTYPE.LOG); console.log('[JS RESPONSE]: id', id || 'null'); //, LOGTYPE.LOG); if (isResponse) { if (operation === 'document_model') { const returnValue = JSON.parse(response_str); const returnData = { callback_status: (_a = returnValue === null || returnValue === void 0 ? void 0 : returnValue.call_status) === null || _a === void 0 ? void 0 : _a.return_status, doc_validation_status: (_c = (_b = returnValue === null || returnValue === void 0 ? void 0 : returnValue.uber_operation_result) === null || _b === void 0 ? void 0 : _b.document) === null || _c === void 0 ? void 0 : _c.document_validation_status, cropped_document: (_f = (_e = (_d = returnValue === null || returnValue === void 0 ? void 0 : returnValue.uber_operation_result) === null || _d === void 0 ? void 0 : _d.cropped_images) === null || _e === void 0 ? void 0 : _e.items) === null || _f === void 0 ? void 0 : _f.document, cropped_mugshot: (_j = (_h = (_g = returnValue === null || returnValue === void 0 ? void 0 : returnValue.uber_operation_result) === null || _g === void 0 ? void 0 : _g.cropped_images) === null || _h === void 0 ? void 0 : _h.items) === null || _j === void 0 ? void 0 : _j.mugshot, embedding: (_k = returnValue === null || returnValue === void 0 ? void 0 : returnValue.uber_operation_result) === null || _k === void 0 ? void 0 : _k.embedding, api_request: (_l = returnValue === null || returnValue === void 0 ? void 0 : returnValue.uber_operation_result) === null || _l === void 0 ? void 0 : _l.request, barcode_detection_status: ((_o = (_m = returnValue === null || returnValue === void 0 ? void 0 : returnValue.uber_operation_result) === null || _m === void 0 ? void 0 : _m.barcode) === null || _o === void 0 ? void 0 : _o.bar_code_detection_status) === 0, }; if (returnType === 'all') { callback(returnValue); } else { callback(returnData); } } } }; const createCallbackDelete = ({ callback }) => (operation, id, response_str) => { const isResponse = response_str.length > 0; console.log('================[JS RESPONSE]: response_str', isResponse ? JSON.parse(response_str) : ''); //, LOGTYPE.LOG); console.log('[JS RESPONSE]: operation', operation || 'null'); //, LOGTYPE.LOG); console.log('[JS RESPONSE]: id', id || 'null'); //, LOGTYPE.LOG); if (isResponse) { const returnValue = JSON.parse(response_str); const returnData = { call_status: returnValue.call_status.return_status, delete_status: returnValue.user_delete.status, delete_message: returnValue.user_delete.message, }; if (operation === 'delete') { callback(returnData); } } }; const createCallbackPredictAge = ({ callback, portrait, returnType }) => (operation, id, response_str) => { var _a, _b, _c, _d, _e, _f, _g, _h, _j; const isResponse = response_str.length > 0; console.log('================[JS RESPONSE]: response_str', isResponse ? JSON.parse(response_str) : ''); //, LOGTYPE.LOG); console.log('[JS RESPONSE]: operation', operation || 'null'); //, LOGTYPE.LOG); console.log('[JS RESPONSE]: id', id || 'null'); //, LOGTYPE.LOG); if (isResponse) { const returnValue = JSON.parse(response_str); const returnData = { mf_token: (_a = returnValue === null || returnValue === void 0 ? void 0 : returnValue.call_status) === null || _a === void 0 ? void 0 : _a.mf_token, face_validation_status: (_c = (_b = returnValue === null || returnValue === void 0 ? void 0 : returnValue.uber_operation_result) === null || _b === void 0 ? void 0 : _b.face) === null || _c === void 0 ? void 0 : _c.face_validation_status, antispoof_status: (_e = (_d = returnValue === null || returnValue === void 0 ? void 0 : returnValue.uber_operation_result) === null || _d === void 0 ? void 0 : _d.face) === null || _e === void 0 ? void 0 : _e.antispoofing_status, call_status: (_f = returnValue === null || returnValue === void 0 ? void 0 : returnValue.call_status) === null || _f === void 0 ? void 0 : _f.return_status, api_request: (_g = returnValue === null || returnValue === void 0 ? void 0 : returnValue.uber_operation_result) === null || _g === void 0 ? void 0 : _g.request, embedding: (_h = returnValue === null || returnValue === void 0 ? void 0 : returnValue.uber_operation_result) === null || _h === void 0 ? void 0 : _h.embedding, remove_glasses: (_j = returnValue === null || returnValue === void 0 ? void 0 : returnValue.uber_operation_result) === null || _j === void 0 ? void 0 : _j.young_person_with_glasses, }; if (operation === 'estimate_age') { if (returnType && returnType === 'all') { callback(Object.assign(Object.assign({}, returnValue), { portrait })); } else { callback(Object.assign(Object.assign({}, returnData), { portrait })); } } } }; const createCallbackCompareDocumentAndFace = ({ callback, returnType }) => (operation, id, response_str) => { const isResponse = response_str.length > 0; printLogs('================[JS RESPONSE]: response_str', isResponse ? JSON.parse(response_str) : '', LOGTYPE.LOG); printLogs('[JS RESPONSE]: operation', operation || 'null', LOGTYPE.LOG); printLogs('[JS RESPONSE]: id', id || 'null', LOGTYPE.LOG); if (isResponse) { if (operation === 'compare_mugshot_and_face') { const returnValue = JSON.parse(response_str); const returnData = { image_a_face_validation_status: returnValue.face_compare.a_face_validation_status, image_b_face_validation_status: returnValue.face_compare.b_face_validation_status, call_status: returnValue.call_status.return_status, compare_score: returnValue.face_compare.conf_score, compare_status: returnValue.face_compare.result, }; if (returnType === 'all') { callback(returnValue); } else { callback(returnData); } } } }; const createResultFaceISO = ({ callback, portrait, returnType }) => (operation, id, response_str) => { const isResponse = response_str.length > 0; console.log('================[JS RESPONSE]: response_str', isResponse ? JSON.parse(response_str) : ''); //, LOGTYPE.LOG); console.log('[JS RESPONSE]: operation', operation || 'null'); //, LOGTYPE.LOG); console.log('[JS RESPONSE]: id', id || 'null'); //, LOGTYPE.LOG); if (isResponse) { const returnValue = JSON.parse(response_str); if (operation === 'face_iso') { callback(Object.assign(Object.assign({}, returnValue), { portrait })); } } }; // const createCallbackScanDocumentNoFace = // ({ callback, returnType }: createCallbackInternalProps) => // (operation: string, id: string, response_str: any) => { // const isResponse = response_str.length > 0; // printLogs('================[JS RESPONSE]: response_str', isResponse ? JSON.parse(response_str) : '', LOGTYPE.LOG); // printLogs('[JS RESPONSE]: operation', operation || 'null', LOGTYPE.LOG); // printLogs('[JS RESPONSE]: id', id || 'null', LOGTYPE.LOG); // if (isResponse) { // if (operation === 'scan_doc_with_no_face') { // const returnValue: frontDocumentScanReturnValueProps = JSON.parse(response_str); // const returnData = { // callback_status: returnValue?.call_status?.return_status, // doc_validation_status: returnValue?.doc_face?.document_data.document_validation_status, // cropped_document: { // data: returnValue?.doc_face?.document_data?.cropped_document_image?.data, // width: returnValue?.doc_face?.document_data?.cropped_document_image?.info?.width, // height: returnValue?.doc_face?.document_data?.cropped_document_image?.info?.height, // }, // }; // if (returnType === 'all') { // callback(returnValue); // } else { // callback(returnData); // } // } // } // }; const createCallbackBackDlScan = ({ callback, returnType, isMobile = false }) => (operation, id, response_str) => { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o; const isResponse = response_str.length > 0; console.log('================[JS RESPONSE]: response_str', isResponse ? JSON.parse(response_str) : ''); //, LOGTYPE.LOG); console.log('[JS RESPONSE]: operation', operation || 'null'); //, LOGTYPE.LOG); console.log('[JS RESPONSE]: id', id || 'null'); // , LOGTYPE.LOG); if (isResponse) { const returnValue = JSON.parse(response_str); const returnData = { callback_status: (_a = returnValue === null || returnValue === void 0 ? void 0 : returnValue.call_status) === null || _a === void 0 ? void 0 : _a.return_status, doc_validation_status: (_c = (_b = returnValue === null || returnValue === void 0 ? void 0 : returnValue.uber_operation_result) === null || _b === void 0 ? void 0 : _b.document) === null || _c === void 0 ? void 0 : _c.document_validation_status, barcode_detection_status: (_e = (_d = returnValue === null || returnValue === void 0 ? void 0 : returnValue.uber_operation_result) === null || _d === void 0 ? void 0 : _d.barcode) === null || _e === void 0 ? void 0 : _e.bar_code_detection_status, cropped_document_base64: (_h = (_g = (_f = returnValue === null || returnValue === void 0 ? void 0 : returnValue.uber_operation_result) === null || _f === void 0 ? void 0 : _f.cropped_images) === null || _g === void 0 ? void 0 : _g.items) === null || _h === void 0 ? void 0 : _h.document, cropped_barcode_base64: (_l = (_k = (_j = returnValue === null || returnValue === void 0 ? void 0 : returnValue.uber_operation_result) === null || _j === void 0 ? void 0 : _j.cropped_images) === null || _k === void 0 ? void 0 : _k.items) === null || _l === void 0 ? void 0 : _l.barcode, barcode_data: (_o = (_m = returnValue === null || returnValue === void 0 ? void 0 : returnValue.uber_operation_result) === null || _m === void 0 ? void 0 : _m.barcode) === null || _o === void 0 ? void 0 : _o.barcode_data, is_mobile: isMobile, }; if (operation === 'is_valid_barcode') { if (returnType && returnType === 'all') { callback(returnValue); } else { callback(returnData); } } } }; const createCallbackCompareEmbeddings = ({ callback, returnType }) => (operation, id, response_str) => { var _a, _b, _c, _d; const isResponse = response_str.length > 0; console.log('================[JS RESPONSE]: response_str', isResponse ? JSON.parse(response_str) : ''); //, LOGTYPE.LOG); console.log('[JS RESPONSE]: operation', operation || 'null'); //, LOGTYPE.LOG); console.log('[JS RESPONSE]: id', id || 'null'); //, LOGTYPE.LOG); if (isResponse) { if (operation === 'compare_files') { const returnValue = JSON.parse(response_str); const returnData = { confidence_score: (_a = returnValue === null || returnValue === void 0 ? void 0 : returnValue.uber_operation_result) === null || _a === void 0 ? void 0 : _a.confidence_score, call_status: (_b = returnValue === null || returnValue === void 0 ? void 0 : returnValue.call_status) === null || _b === void 0 ? void 0 : _b.return_status, call_status_message: (_c = returnValue === null || returnValue === void 0 ? void 0 : returnValue.call_status) === null || _c === void 0 ? void 0 : _c.return_message, api_request: (_d = returnValue === null || returnValue === void 0 ? void 0 : returnValue.uber_operation_result) === null || _d === void 0 ? void 0 : _d.request, }; if (returnType === 'all') { callback(returnValue); } else { callback(returnData); } } } }; switch (type) { case callbackTypeEnum.isValid: return createCallbackIsValid({ callback: callbackFunction }); case callbackTypeEnum.enroll: return createCallbackEnroll({ callback: callbackFunction }); case callbackTypeEnum.predict: return createCallbackPredict({ callback: callbackFunction }); case callbackTypeEnum.faceLogin: return createCallbackPredict({ callback: callbackFunction }); case callbackTypeEnum.continuousPredict: return createCallbackPredict({ callback: callbackFunction }); case callbackTypeEnum.delete: return createCallbackDelete({ callback: callbackFunction }); case callbackTypeEnum.frontScan: return createCallbackFrontDlScan({ callback: callbackFunction }); case callbackTypeEnum.backScan: return createCallbackBackDlScan({ callback: callbackFunction, returnType, isMobile }); case callbackTypeEnum.faceCompareDocumentAndFace: return createCallbackCompareDocumentAndFace({ callback: callbackFunction }); case callbackTypeEnum.compareEmbeddings: return createCallbackCompareEmbeddings({ callback: callbackFunction, returnType }); case callbackTypeEnum.ageEstimation: return createCallbackPredictAge({ callback: callbackFunction, portrait, returnType }); default: return null; } }; //# sourceMappingURL=createCallback.js.map