UNPKG

@privateid/ultra-web-sdk-alpha

Version:
326 lines 23.7 kB
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) : ''); printLogs(`[JS RESPONSE]: operation': `, operation || 'null'); printLogs(`[JS RESPONSE]: id: `, id || 'null'); 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 === 'validate_face') { 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; printLogs(`[JS RESPONSE]: response_str': `, isResponse ? JSON.parse(response_str) : ''); printLogs(`[JS RESPONSE]: operation': `, operation || 'null'); printLogs(`[JS RESPONSE]: id: `, id || 'null'); if (isResponse) { const returnValue = JSON.parse(response_str); if (operation === 'user_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; printLogs(`[JS RESPONSE]: response_str': `, isResponse ? JSON.parse(response_str) : ''); printLogs(`[JS RESPONSE]: operation': `, operation || 'null'); printLogs(`[JS RESPONSE]: id: `, id || 'null'); 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 === 'user_predict') { if (returnType && returnType === 'all') { callback(returnValue); } else { callback(returnData); } } } }; const createCallbackFrontDlScan = ({ callback, returnType, inputImage }) => (operation, id, response_str) => { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q; const isResponse = response_str.length > 0; printLogs(`[JS RESPONSE]: response_str': `, isResponse ? JSON.parse(response_str) : ''); printLogs(`[JS RESPONSE]: operation': `, operation || 'null'); printLogs(`[JS RESPONSE]: id: `, id || 'null'); if (isResponse) { if (operation === 'doc_scan_front') { 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, input_image: ((_l = (_k = returnValue === null || returnValue === void 0 ? void 0 : returnValue.uber_operation_result) === null || _k === void 0 ? void 0 : _k.document) === null || _l === void 0 ? void 0 : _l.document_validation_status) === 0 ? inputImage : undefined, embedding: (_m = returnValue === null || returnValue === void 0 ? void 0 : returnValue.uber_operation_result) === null || _m === void 0 ? void 0 : _m.embedding, api_request: (_o = returnValue === null || returnValue === void 0 ? void 0 : returnValue.uber_operation_result) === null || _o === void 0 ? void 0 : _o.request, barcode_detection_status: ((_q = (_p = returnValue === null || returnValue === void 0 ? void 0 : returnValue.uber_operation_result) === null || _p === void 0 ? void 0 : _p.barcode) === null || _q === void 0 ? void 0 : _q.bar_code_detection_status) === 0, }; if (returnType === 'all') { callback(returnValue); } else { callback(returnData); } } } }; const createCallbackPassportScan = ({ callback, returnType }) => (operation, id, response_str) => { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m; const isResponse = response_str.length > 0; printLogs(`[JS RESPONSE]: Passport response_str': `, isResponse ? JSON.parse(response_str) : ''); printLogs(`[JS RESPONSE]: operation': `, operation || 'null'); printLogs(`[JS RESPONSE]: id: `, id || 'null'); if (isResponse) { if (operation === 'doc_scan_front') { 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, mrz_text_detected: ((_m = (_l = returnValue === null || returnValue === void 0 ? void 0 : returnValue.uber_operation_result) === null || _l === void 0 ? void 0 : _l.document) === null || _m === void 0 ? void 0 : _m.mrz_text.length) > 0, }; if (returnType === 'all') { callback(returnValue); } else { callback(returnData); } } } }; const createCallbackDelete = ({ callback }) => (operation, id, response_str) => { const isResponse = response_str.length > 0; printLogs(`[JS RESPONSE]: response_str': `, isResponse ? JSON.parse(response_str) : ''); printLogs(`[JS RESPONSE]: operation': `, operation || 'null'); printLogs(`[JS RESPONSE]: id: `, id || 'null'); 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; printLogs(`[JS RESPONSE]: response_str': `, isResponse ? JSON.parse(response_str) : ''); printLogs(`[JS RESPONSE]: operation': `, operation || 'null'); printLogs(`[JS RESPONSE]: id: `, id || 'null'); 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) : ''); printLogs(`[JS RESPONSE]: operation': `, operation || 'null'); printLogs(`[JS RESPONSE]: id: `, id || 'null'); 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 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; printLogs(`[JS RESPONSE]: response_str': `, isResponse ? JSON.parse(response_str) : ''); printLogs(`[JS RESPONSE]: operation': `, operation || 'null'); printLogs(`[JS RESPONSE]: id: `, id || 'null'); 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 === 'doc_scan_back') { if (returnType && returnType === 'all') { callback(returnValue); } else { callback(returnData); } } } }; const createCallbackCompareEmbeddings = ({ callback, returnType }) => (operation, id, response_str) => { var _a, _b, _c, _d, _e; const isResponse = response_str.length > 0; printLogs(`[JS RESPONSE]: response_str': `, isResponse ? JSON.parse(response_str) : ''); printLogs(`[JS RESPONSE]: operation': `, operation || 'null'); printLogs(`[JS RESPONSE]: id: `, id || 'null'); if (isResponse) { if (operation === 'compare_embeddings') { 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, is_same_face: (_d = returnValue === null || returnValue === void 0 ? void 0 : returnValue.uber_operation_result) === null || _d === void 0 ? void 0 : _d.is_same_face, api_request: (_e = returnValue === null || returnValue === void 0 ? void 0 : returnValue.uber_operation_result) === null || _e === void 0 ? void 0 : _e.request, }; if (returnType === 'all') { callback(returnValue); } else { callback(returnData); } } } }; const createCallbackDocumentOcr = ({ callback }) => (operation, id, response_str) => { var _a, _b, _c; const isResponse = response_str.length > 0; printLogs(`[JS RESPONSE]: response_str': `, isResponse ? JSON.parse(response_str) : ''); printLogs(`[JS RESPONSE]: operation': `, operation || 'null'); printLogs(`[JS RESPONSE]: id: `, id || 'null'); if (isResponse) { if (operation === 'doc_ocr_front') { const returnValue = JSON.parse(response_str); const returnData = { api_request: (_a = returnValue === null || returnValue === void 0 ? void 0 : returnValue.uber_operation_result) === null || _a === void 0 ? void 0 : _a.request, 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, }; 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, inputImage: imageData }); 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 }); case callbackTypeEnum.passportScan: return createCallbackPassportScan({ callback: callbackFunction }); case callbackTypeEnum.documentOcr: return createCallbackDocumentOcr({ callback: callbackFunction }); default: return null; } }; //# sourceMappingURL=createCallback.js.map