@frankieone/one-sdk 1.4.3-beta → 1.4.4-rc
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/dist/commit.txt +2 -2
- package/dist/esm/modules/common/vendors/incode/onBoarding.types.d.ts +6 -1
- package/dist/esm/modules/common/vendors/incode/onBoarding.types.d.ts.map +1 -1
- package/dist/esm/modules/common/vendors/incode/startCamera.d.ts +3 -2
- package/dist/esm/modules/common/vendors/incode/startCamera.d.ts.map +1 -1
- package/dist/esm/modules/common/vendors/incode/startCamera.js +5 -2
- package/dist/esm/modules/common/vendors/incode/startCamera.js.map +1 -1
- package/dist/esm/modules/form/vendors/react/components/base/FrankieButton/BaseButton.d.ts +4 -3
- package/dist/esm/modules/form/vendors/react/components/base/FrankieButton/BaseButton.d.ts.map +1 -1
- package/dist/esm/modules/form/vendors/react/components/base/FrankieButton/BaseButton.js +4 -6
- package/dist/esm/modules/form/vendors/react/components/base/FrankieButton/BaseButton.js.map +1 -1
- package/dist/esm/modules/form/vendors/react/components/base/FrankieButton/FrankieButton.d.ts +3 -1
- package/dist/esm/modules/form/vendors/react/components/base/FrankieButton/FrankieButton.d.ts.map +1 -1
- package/dist/esm/modules/form/vendors/react/components/base/FrankieButton/FrankieButton.js +3 -3
- package/dist/esm/modules/form/vendors/react/components/base/FrankieButton/FrankieButton.js.map +1 -1
- package/dist/esm/modules/form/vendors/react/components/base/index.d.ts +0 -1
- package/dist/esm/modules/form/vendors/react/components/base/index.d.ts.map +1 -1
- package/dist/esm/modules/form/vendors/react/components/base/index.js +0 -1
- package/dist/esm/modules/form/vendors/react/components/base/index.js.map +1 -1
- package/dist/esm/modules/form/vendors/react/index.d.ts +3 -3
- package/dist/esm/modules/form/vendors/react/index.d.ts.map +1 -1
- package/dist/esm/modules/form/vendors/react/index.js +3 -3
- package/dist/esm/modules/form/vendors/react/index.js.map +1 -1
- package/dist/esm/modules/frankie-client/clients/OCRClient.d.ts +5 -5
- package/dist/esm/modules/frankie-client/clients/OCRClient.d.ts.map +1 -1
- package/dist/esm/modules/frankie-client/clients/OCRClient.js +11 -10
- package/dist/esm/modules/frankie-client/clients/OCRClient.js.map +1 -1
- package/dist/esm/modules/meta.json +1 -1
- package/dist/esm/modules/ocr/actions/start.d.ts +2 -0
- package/dist/esm/modules/ocr/actions/start.d.ts.map +1 -1
- package/dist/esm/modules/ocr/actions/start.js +3 -1
- package/dist/esm/modules/ocr/actions/start.js.map +1 -1
- package/dist/esm/modules/ocr/definition.d.ts +8 -4
- package/dist/esm/modules/ocr/definition.d.ts.map +1 -1
- package/dist/esm/modules/ocr/index.d.ts.map +1 -1
- package/dist/esm/modules/ocr/index.js +2 -1
- package/dist/esm/modules/ocr/index.js.map +1 -1
- package/dist/esm/modules/ocr/vendors/Incode/index.d.ts +1 -11
- package/dist/esm/modules/ocr/vendors/Incode/index.d.ts.map +1 -1
- package/dist/esm/modules/ocr/vendors/Incode/index.js +39 -2
- package/dist/esm/modules/ocr/vendors/Incode/index.js.map +1 -1
- package/dist/esm/modules/ocr/vendors/Onfido/index.d.ts +1 -11
- package/dist/esm/modules/ocr/vendors/Onfido/index.d.ts.map +1 -1
- package/dist/esm/modules/ocr/vendors/dummy-ocr/index.d.ts +1 -11
- package/dist/esm/modules/ocr/vendors/dummy-ocr/index.d.ts.map +1 -1
- package/dist/esm/styles/f1-style.css +1 -1
- package/dist/release.txt +2 -2
- package/dist/umd/955.js +3 -0
- package/dist/umd/955.js.map +1 -0
- package/dist/umd/biometrics-incode.js +1 -1
- package/dist/umd/biometrics-incode.js.map +1 -1
- package/dist/umd/form-react.js +1 -1
- package/dist/umd/form-react.js.map +1 -1
- package/dist/umd/ocr-incode.js +1 -1
- package/dist/umd/ocr-incode.js.map +1 -1
- package/dist/umd/oneSdk.umd.js +1 -1
- package/dist/umd/oneSdk.umd.js.map +1 -1
- package/dist/version.txt +2 -2
- package/package.json +2 -2
- package/dist/esm/modules/form/vendors/react/components/base/FrankieInput/BaseInput.d.ts +0 -51
- package/dist/esm/modules/form/vendors/react/components/base/FrankieInput/BaseInput.d.ts.map +0 -1
- package/dist/esm/modules/form/vendors/react/components/base/FrankieInput/BaseInput.js +0 -24
- package/dist/esm/modules/form/vendors/react/components/base/FrankieInput/BaseInput.js.map +0 -1
- package/dist/esm/modules/form/vendors/react/components/base/FrankieInput/FrankieInput.d.ts +0 -5
- package/dist/esm/modules/form/vendors/react/components/base/FrankieInput/FrankieInput.d.ts.map +0 -1
- package/dist/esm/modules/form/vendors/react/components/base/FrankieInput/FrankieInput.js +0 -19
- package/dist/esm/modules/form/vendors/react/components/base/FrankieInput/FrankieInput.js.map +0 -1
- package/dist/esm/modules/form/vendors/react/components/base/FrankieInput/index.d.ts +0 -2
- package/dist/esm/modules/form/vendors/react/components/base/FrankieInput/index.d.ts.map +0 -1
- package/dist/esm/modules/form/vendors/react/components/base/FrankieInput/index.js +0 -2
- package/dist/esm/modules/form/vendors/react/components/base/FrankieInput/index.js.map +0 -1
- package/dist/esm/modules/form/vendors/react/components/fragments/Dob.d.ts +0 -2
- package/dist/esm/modules/form/vendors/react/components/fragments/Dob.d.ts.map +0 -1
- package/dist/esm/modules/form/vendors/react/components/fragments/Dob.js +0 -5
- package/dist/esm/modules/form/vendors/react/components/fragments/Dob.js.map +0 -1
- package/dist/esm/modules/form/vendors/react/components/fragments/Name.d.ts +0 -2
- package/dist/esm/modules/form/vendors/react/components/fragments/Name.d.ts.map +0 -1
- package/dist/esm/modules/form/vendors/react/components/fragments/Name.js +0 -6
- package/dist/esm/modules/form/vendors/react/components/fragments/Name.js.map +0 -1
- package/dist/umd/895.js +0 -3
- package/dist/umd/895.js.map +0 -1
- /package/dist/umd/{895.js.LICENSE.txt → 955.js.LICENSE.txt} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ocr-incode.js","mappings":"qKAmBO,MAAMA,EAAsB,CACjCC,GACEC,WACAC,eAQF,IAAIC,GAAiB,EAGrB,MAAMC,EAAgB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BAAkB,CAAEM,aAAc,KAAMC,KAAM,SAAWiD,GAAgB,KAAM,CAAG,K","sources":["webpack://OneSdk/./modules/common/vendors/incode/createEventHandlers.ts","webpack://OneSdk/./modules/common/vendors/incode/startCamera.ts","webpack://OneSdk/./modules/common/vendors/incode/index.ts","webpack://OneSdk/./modules/ocr/vendors/Incode/index.ts","webpack://OneSdk/./modules/ocr/vendors/common/createSession.ts","webpack://OneSdk/./modules/ocr/vendors/common/initProcess.ts","webpack://OneSdk/./modules/ocr/vendors/common/statusEvaluators.ts"],"sourcesContent":["import { IDVStatus } from '@frankieone/one-sdk';\nimport type { Events as BiometricsEvents } from '@module/biometrics';\nimport type { EventHub } from '@module/common';\nimport { OneSDKError } from '@module/common';\nimport type {\n IncodeResponse,\n} from '@module/common/vendors/incode/onBoarding.types';\nimport type { Events as OcrEvents } from '@module/ocr';\nimport { OCRStatus } from '@module/types';\n\n/**\n * Creates event handlers for a given EventHub.\n *\n * @param {'ocr' | 'biometrics'} module - The module type for which to create event handlers.\n * @param {object} options - The options for creating event handlers.\n * @param {EventHub<OcrEvents | BiometricsEvents>} options.eventHub - The EventHub for handling events.\n * @param {string} [options.entityId] - An optional entityId parameter.\n * @returns {object} - The event handlers for the specified module ('biometrics' or 'ocr').\n **/\nexport const createEventHandlers = (\n module: 'ocr' | 'biometrics', {\n eventHub,\n entityId,\n }: {\n eventHub: EventHub<OcrEvents | BiometricsEvents>;\n entityId?: string;\n },\n) => {\n\n // A flag indicating whether the event handler should emit error event\n let noAttemptsFlag = false;\n\n // user or environment issues that are not related to a specific workflow\n const genericErrors = [\n 'InternalServerError',\n 'skip',\n 'OSVersionNotSupported',\n 'browserNotSupported',\n ];\n\n /**\n * Event handlers for biometrics-related events.\n *\n * @namespace biometrics\n */\n const biometrics = {\n /**\n * Handles log events for biometrics.\n *\n * @param {IncodeResponse} response - The response object from Incode.\n */\n onLog: (\n { type }: IncodeResponse,\n ): void => {\n if (type === 'noAttemps') { // not a typo, 'noAttemps' comes from Incode SDK\n // we would like to emit this scenario along with an Incode error event\n // update the error state so that a corresponding error can be emitted\n noAttemptsFlag = true;\n }\n },\n /**\n * Handles error events for biometrics.\n *\n * @param {IncodeResponse} response - The response object from Incode.\n */\n onError: (\n { type, payload }: IncodeResponse,\n ): void => {\n // check if error state is being flagged in the log already\n if (noAttemptsFlag) {\n eventHub.emit('detection_failed', {\n message: payload?.message,\n });\n } else if (type === 'permissionDenied') {\n eventHub.emit('input_required', { entityId }, IDVStatus.INTERRUPTED);\n } else if (genericErrors.includes(type)) {\n eventHub.emit('error', new OneSDKError(`Error from vendor SDK 'Incode'`, {\n type,\n payload,\n }));\n }\n },\n };\n\n /**\n * Event handlers for OCR-related events.\n *\n * @namespace ocr\n */\n const ocr = {\n /**\n * Handles log events for OCR.\n *\n * @param {IncodeResponse} response - The response object from Incode.\n */\n onLog: (\n { type, payload }: IncodeResponse,\n ): void => {\n if ([\n 'IDNotDetected',\n 'nothingHappened',\n 'manualCaptureOn',\n 'successCapture',\n 'attemptFailed',\n 'success',\n ].includes(type)) {\n eventHub.emit('info', {\n message: payload?.message,\n payload: { type },\n });\n } else if (type === 'noAttemps') { // not a typo, 'noAttemps' comes from Incode SDK\n // we would like to emit this scenario along with an Incode error event\n // update the error state so that a corresponding error can be emitted\n noAttemptsFlag = true;\n }\n },\n /**\n * Handles error events for OCR.\n *\n * @param {IncodeResponse} response - The response object from Incode.\n */\n onError: (\n { type, payload }: IncodeResponse,\n ): void => {\n // check if error state is being flagged in the log already\n if (noAttemptsFlag) {\n eventHub.emit('detection_failed', {\n message: payload?.message,\n });\n } else if (type === 'permissionDenied') {\n eventHub.emit('input_required',\n {\n documentType: null,\n side: 'front',\n }, OCRStatus.INTERRUPTED, () => ({}));\n } else if (genericErrors.includes(type)) {\n eventHub.emit('error', new OneSDKError(`Error from vendor SDK 'Incode'`, {\n type,\n payload,\n }));\n }\n },\n };\n\n return { biometrics, ocr }[module];\n};\n","import type { EventHub } from '@module/common';\nimport { OneSDKError } from '@module/common';\nimport type {\n IncodeInstance,\n IncodeResponse,\n} from '@module/common/vendors/incode/onBoarding.types';\nimport type { Events } from '@module/ocr';\n\ntype CameraProps = {\n incode: IncodeInstance;\n token: { token: string; interviewId: string };\n eventHub: EventHub<Events>;\n mountElement: HTMLElement;\n onSuccess?: (response: unknown) => void;\n onError: (response: unknown, payload?: unknown) => void;\n onLog: (response: unknown) => void;\n};\n\nexport const startCamera = async (\n purpose: 'biometrics' | 'ocr',\n cameraProps: CameraProps,\n) => {\n if (purpose === 'ocr') {\n return await renderCamera('front', {\n ...cameraProps,\n onSuccess: async ({ skipBackIdCapture }: {\n skipBackIdCapture: boolean;\n }): Promise<void> => {\n // when Incode determines it needs to capture the back of document\n if (!skipBackIdCapture) {\n await renderCamera('back', cameraProps);\n } else {\n cameraProps?.onSuccess({});\n }\n },\n });\n } else if (purpose === 'biometrics') {\n return await renderCamera('selfie', cameraProps);\n }\n throw new OneSDKError('Unknown purpose', { purpose });\n};\n\nconst renderCamera = async (\n type: 'front' | 'back' | 'selfie',\n cameraProps: CameraProps,\n) => {\n const {\n incode,\n token,\n eventHub,\n mountElement,\n onSuccess = () => ({}),\n onError,\n onLog,\n } = cameraProps;\n return new Promise((resolve, reject): void => {\n try {\n incode.renderCamera(type, mountElement, {\n onSuccess: async (response): Promise<void> => {\n onSuccess(response);\n return resolve({});\n },\n onError: (error: IncodeResponse) => {\n onError(error);\n return reject(error);\n },\n onLog: (log: IncodeResponse) => {\n onLog(log);\n },\n token,\n numberOfTries: 3,\n });\n } catch (error) {\n const { message = '' } = error;\n eventHub.emit('error', new OneSDKError(`Error from vendor SDK 'Incode'`, { message }));\n return reject(error);\n }\n });\n};\n","import { loadAsyncAsset } from '@module/common';\nimport type {\n IncodeConfig,\n IncodeInstance,\n} from '@module/common/vendors/incode/onBoarding.types';\n\nexport { createEventHandlers } from './createEventHandlers';\nexport { startCamera } from './startCamera';\nexport * from './onBoarding.types';\n\nexport const install = async ({\n apiURL,\n sdkVersion = '1.69.1',\n}: IncodeConfig & { sdkVersion?: string }): Promise<{\n incode: IncodeInstance;\n}> => {\n // install Incode script from CDN\n await loadAsyncAsset(`https://sdk.incode.com/sdk/onBoarding-${sdkVersion}.js`);\n // instructed by vendor to add `/0/` to the end of the apiURL\n const incode = await createInstance({ apiURL: `${apiURL}/0/` });\n return { incode };\n};\n\nconst createInstance = async ({\n apiURL,\n}: IncodeConfig): Promise<IncodeInstance> => {\n const incode = window.OnBoarding.create({ apiURL });\n await incode.warmup();\n return incode;\n};\n","import { feat } from '@feature-flags';\nimport { OneSDKError } from '@module/common';\nimport { defineWrapper } from '@module/common/modules/defineModule';\nimport type { IncodeSession } from '@module/common/vendors/incode';\nimport {\n createEventHandlers,\n install,\n startCamera,\n} from '@module/common/vendors/incode';\nimport { IDVClient } from '@module/frankie-client/clients/IDVClient';\nimport type { OCRModule } from '@module/ocr';\nimport { createSession } from '@module/ocr/vendors/common/createSession';\nimport {\n initProcessAndEvaluateResults,\n} from '@module/ocr/vendors/common/initProcess';\n\nexport const initialise = defineWrapper<OCRModule>('incode', async (\n shared,\n options,\n) => {\n const {\n frankieClient,\n recipe: { ocr: { provider } },\n localEventHub,\n } = shared;\n const { mountElement, eventHub } = options;\n const idvClient = new IDVClient(frankieClient);\n\n // generate session token from backend\n const idvSession = await createSession<IncodeSession>(idvClient, eventHub);\n // terminate initialising if session failed\n if (!idvSession) {\n localEventHub.emit('loading', false, { message: `Failed while loading session for vendor 'Incode'` });\n return;\n }\n\n const { vendorParameters } = idvSession;\n\n try {\n // initialise Incode with credentials\n const { apiURL, token, interviewId } = vendorParameters;\n const { incode } = await install({\n apiURL,\n sdkVersion: provider.name === 'incode' && provider.sdkVersion,\n });\n\n const { onLog, onError } = createEventHandlers('ocr', { eventHub });\n const cameraProps = {\n incode,\n token: { token, interviewId },\n eventHub,\n mountElement,\n onError,\n onLog,\n };\n // turn on camera to capture the front of document\n const startCameraPromise = startCamera('ocr', {\n ...cameraProps,\n onSuccess: () => {\n eventHub.emit('session_closed');\n\n initProcessAndEvaluateResults(shared, {\n ...options,\n attachReviewScreen: !feat('modules.ocr.containsReviewScreen.incode'),\n });\n },\n });\n eventHub.emit('ready', { domElement: mountElement });\n eventHub.emit('loading', false, { message: `Vendor 'Incode' screen has loaded` });\n await startCameraPromise;\n } catch (error) {\n const { type = null, message = '' } = error;\n eventHub.emit(\n 'error',\n new OneSDKError(`Error from vendor SDK 'Incode'`, {\n type,\n message,\n }),\n );\n eventHub.emit('loading', false, { message: `Failed while executing vendor 'Incode'` });\n }\n\n return {};\n});\n","import type { EventHub } from '@module/common';\nimport type { IDVClient } from '@module/frankie-client/clients/IDVClient';\nimport type { Events } from '@module/ocr/events';\nimport type { _DictionaryWrite } from '@types';\n\n/**\n * Creates a session by obtaining an entity ID, token, and vendor parameters from an IDVClient.\n * It will also emit 'session_data_generated' event to the provided event hub.\n * This function won't throw errors. Instead, it will emit 'session_data_failed_loading' and return null.\n *\n * @param idvClient - The IDVClient instance used to obtain the session data.\n * @param eventHub - The EventHub instance for emitting session-related events.\n * @returns A Promise that resolves with an object containing entityId, token, and vendorParameters upon success, or null if a session couldn't be created\n */\nexport const createSession = async <T extends _DictionaryWrite<unknown>>(\n idvClient: IDVClient,\n eventHub: EventHub<Events>,\n): Promise<{ entityId: string; token: string; vendorParameters: T } | null> => {\n try {\n const { entityId, token, vendorParameters } = await idvClient.getToken<T>();\n eventHub.emit('session_data_generated', {\n session: { entityId, token, vendorParameters },\n });\n return { entityId, token, vendorParameters };\n } catch (error) {\n const { code = null, message = '' } = error;\n eventHub.emit('session_data_failed_loading', { code, message });\n return null;\n }\n};\n","import { feat } from '@feature-flags';\nimport { OneSDKError, mkEventHub } from '@module/common';\nimport type { WrapperParameters } from '@module/common/modules/defineModule';\nimport {\n useFormToReviewResults,\n} from '@module/common/vendors/form/useForm';\nimport type { OCRResults } from '@module/frankie-client/clients/OCRClient';\nimport { OCRClient } from '@module/frankie-client/clients/OCRClient';\nimport type { Events, OCRModule } from '@module/ocr';\nimport type {\n StatusEvaluators,\n} from '@module/ocr/vendors/common/statusEvaluators';\nimport { statusEvaluators } from '@module/ocr/vendors/common/statusEvaluators';\nimport { OCRStatus } from '@module/types';\n\ntype Shared = WrapperParameters<OCRModule>[0];\ntype Options = WrapperParameters<OCRModule>[1] & {\n /** Each vendor wrapper needs to flag if their underlying vendor UI already contains a review screen.\n * If it doesn't provide one, we ALWAYS flag that in 'attachReviewScreen' as true.\n * This value can be manually overriden by recipe configuration (ocr.provideReviewScreen) */\n attachReviewScreen: boolean;\n};\n/**\n * This function will\n * 1) Trigger the OCR processing\n * 2) Fetch the updated individual details\n * 3) Evaluate the OCR status to trigger the appropriate event\n * 4) Initialise the Form for manual review, if required\n *\n * It will also emit loading events at the start and end of the process, as well as between long lasting steps\n * @throws This function doesn't throw exceptions, only error events\n * @param shared\n * @param options\n */\nexport const initProcessAndEvaluateResults = async (\n shared: Shared,\n options: Options,\n): Promise<void> => {\n const { frankieClient, oneSdkInstance, localEventHub } = shared;\n try {\n const ocrClient = new OCRClient(frankieClient);\n\n localEventHub.emit('loading', true, { message: 'Retrieving IDV results' });\n let response: OCRResults = await ocrClient.attachNewOCRDocument();\n // If waiting_ocr_run is returned, try to rerun\n if (response.documentStatus === OCRStatus.WAITING_OCR_RUN) {\n response = await ocrClient.rerun(response.ocrDocument.documentId);\n }\n // Update global state with the latest ocr check outcome\n await oneSdkInstance.individual().search();\n const { ocrDocument, documentStatus } = response;\n const evaluateStatus = statusEvaluators[documentStatus] ?? statusEvaluators.default;\n\n // When receiving results event, initialise Form for user manual review\n const privateEventHub = mkEventHub<Events>();\n const mountElement = options.mountElement;\n const recipeProvideReviewScreen =\n shared.recipe.ocr.provideReviewScreen ?? feat('recipeDefaults.ocr.provideReviewScreen');\n\n privateEventHub.on(\n 'results',\n useFormToReviewResults({\n localEventHub,\n mountElement,\n oneSdkInstance,\n // Based on recipe configuration and if the vendor options determine\n // if Form should be attached\n attachForm: recipeProvideReviewScreen && options.attachReviewScreen,\n }),\n );\n privateEventHub.map(['input_required', 'error'], localEventHub);\n\n evaluateStatus({\n ocrDocument,\n documentStatus,\n ocrClient,\n eventHub: privateEventHub,\n } as StatusEvaluators);\n } catch (e) {\n localEventHub.emit('error', new OneSDKError('Failed submitting and retrieving OCR results', e));\n localEventHub.emit('loading', false, { message: 'Failed retrieving OCR results' });\n }\n};\n","import { OCRStatus } from '@frankieone/one-sdk';\nimport type { EventHub} from '@module/common';\nimport { OneSDKError } from '@module/common';\nimport type { Document } from '@module/common/shared/models/Document';\nimport type { OCRClient } from '@module/frankie-client/clients/OCRClient';\nimport type { Events } from '@module/ocr';\n\nexport interface StatusEvaluators {\n ocrDocument?: Document;\n documentStatus?: OCRStatus;\n ocrClient?: OCRClient;\n eventHub: EventHub<Events>;\n}\n\nexport const statusEvaluators = {\n [OCRStatus.COMPLETE]: ({ ocrDocument, ocrClient, eventHub }: StatusEvaluators) =>\n eventHub.emit('results', { document: ocrDocument, entityId: ocrClient.entityId }),\n [OCRStatus.WAITING_OCR_RUN]: ({ eventHub }: StatusEvaluators) => {\n eventHub.emit(\n 'error',\n new OneSDKError(\n `Two attempts to get OCR results failed with an unresolved \"${OCRStatus.WAITING_OCR_RUN}\". This is a system failure.`,\n { payload: null },\n ),\n );\n },\n [OCRStatus.PROVIDER_OFFLINE]: ({ eventHub }: StatusEvaluators) =>\n eventHub.emit(\n 'error',\n new OneSDKError(\n `Provider is offline. Either switch providers and restart or skip OCR temporarily. Status ${OCRStatus.PROVIDER_OFFLINE}`,\n { payload: null },\n ),\n ),\n default: ({ documentStatus, eventHub }: StatusEvaluators) =>\n eventHub.emit('input_required', { documentType: null, side: 'front' }, documentStatus, () => ({})),\n} as const;\n"],"names":["createEventHandlers","module","eventHub","entityId","noAttemptsFlag","genericErrors","biometrics","onLog","type","onError","payload","emit","message","INTERRUPTED","includes","OneSDKError","ocr","documentType","side","startCamera","purpose","cameraProps","renderCamera","onSuccess","skipBackIdCapture","incode","token","mountElement","Promise","resolve","reject","response","error","log","numberOfTries","install","apiURL","sdkVersion","loadAsyncAsset","createInstance","window","OnBoarding","create","warmup","initialise","shared","options","frankieClient","recipe","provider","localEventHub","idvClient","idvSession","vendorParameters","interviewId","name","startCameraPromise","attachReviewScreen","domElement","createSession","getToken","session","code","initProcessAndEvaluateResults","oneSdkInstance","ocrClient","attachNewOCRDocument","documentStatus","WAITING_OCR_RUN","rerun","ocrDocument","documentId","individual","search","evaluateStatus","default","privateEventHub","mkEventHub","recipeProvideReviewScreen","provideReviewScreen","on","attachForm","map","e","statusEvaluators","COMPLETE","document","PROVIDER_OFFLINE"],"sourceRoot":""}
|
|
1
|
+
{"version":3,"file":"ocr-incode.js","mappings":"qKAmBO,MAAMA,EAAsB,CACjCC,GACEC,WACAC,eAQF,IAAIC,GAAiB,EAGrB,MAAMC,EAAgB,CACpB,sBACA,OACA,wBACA,uBA2GF,MAAO,CAAEC,WAnGU,CAMjBC,MAAO,EACHC,WAEW,cAATA,IAGFJ,GAAiB,EACnB,EAOFK,QAAS,EACLD,OAAME,cAGJN,EACFF,EAASS,KAAK,mBAAoB,CAChCC,QAASF,aAAO,EAAPA,EAASE,UAEF,qBAATJ,EACTN,EAASS,KAAK,iBAAkB,CAAER,YAAY,KAAUU,aAC/CR,EAAcS,SAASN,IAChCN,EAASS,KAAK,QAAS,IAAI,EAAAI,YAAY,iCAAkC,CACvEP,OACAE,YAEJ,GAgEiBM,IAvDT,CAMVT,MAAO,EACHC,OAAME,cAEJ,CACF,gBACA,kBACA,kBACA,iBACA,gBACA,WACAI,SAASN,GACTN,EAASS,KAAK,OAAQ,CACpBC,QAASF,aAAO,EAAPA,EAASE,QAClBF,QAAS,CAAEF,UAEK,cAATA,IAGTJ,GAAiB,EACnB,EAOFK,QAAS,EACLD,OAAME,cAGJN,EACFF,EAASS,KAAK,mBAAoB,CAChCC,QAASF,aAAO,EAAPA,EAASE,UAEF,qBAATJ,EACTN,EAASS,KAAK,iBACZ,CACEM,aAAc,KACdC,KAAM,SAC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/vendors/incode/createEventHandlers.ts","webpack://OneSdk/./modules/common/vendors/incode/startCamera.ts","webpack://OneSdk/./modules/common/vendors/incode/index.ts","webpack://OneSdk/./modules/ocr/vendors/Incode/index.ts","webpack://OneSdk/./modules/ocr/vendors/common/createSession.ts","webpack://OneSdk/./modules/ocr/vendors/common/initProcess.ts","webpack://OneSdk/./modules/ocr/vendors/common/statusEvaluators.ts"],"sourcesContent":["import { IDVStatus } from '@frankieone/one-sdk';\nimport type { Events as BiometricsEvents } from '@module/biometrics';\nimport type { EventHub } from '@module/common';\nimport { OneSDKError } from '@module/common';\nimport type {\n IncodeResponse,\n} from '@module/common/vendors/incode/onBoarding.types';\nimport type { Events as OcrEvents } from '@module/ocr';\nimport { OCRStatus } from '@module/types';\n\n/**\n * Creates event handlers for a given EventHub.\n *\n * @param {'ocr' | 'biometrics'} module - The module type for which to create event handlers.\n * @param {object} options - The options for creating event handlers.\n * @param {EventHub<OcrEvents | BiometricsEvents>} options.eventHub - The EventHub for handling events.\n * @param {string} [options.entityId] - An optional entityId parameter.\n * @returns {object} - The event handlers for the specified module ('biometrics' or 'ocr').\n **/\nexport const createEventHandlers = (\n module: 'ocr' | 'biometrics', {\n eventHub,\n entityId,\n }: {\n eventHub: EventHub<OcrEvents | BiometricsEvents>;\n entityId?: string;\n },\n) => {\n\n // A flag indicating whether the event handler should emit error event\n let noAttemptsFlag = false;\n\n // user or environment issues that are not related to a specific workflow\n const genericErrors = [\n 'InternalServerError',\n 'skip',\n 'OSVersionNotSupported',\n 'browserNotSupported',\n ];\n\n /**\n * Event handlers for biometrics-related events.\n *\n * @namespace biometrics\n */\n const biometrics = {\n /**\n * Handles log events for biometrics.\n *\n * @param {IncodeResponse} response - The response object from Incode.\n */\n onLog: (\n { type }: IncodeResponse,\n ): void => {\n if (type === 'noAttemps') { // not a typo, 'noAttemps' comes from Incode SDK\n // we would like to emit this scenario along with an Incode error event\n // update the error state so that a corresponding error can be emitted\n noAttemptsFlag = true;\n }\n },\n /**\n * Handles error events for biometrics.\n *\n * @param {IncodeResponse} response - The response object from Incode.\n */\n onError: (\n { type, payload }: IncodeResponse,\n ): void => {\n // check if error state is being flagged in the log already\n if (noAttemptsFlag) {\n eventHub.emit('detection_failed', {\n message: payload?.message,\n });\n } else if (type === 'permissionDenied') {\n eventHub.emit('input_required', { entityId }, IDVStatus.INTERRUPTED);\n } else if (genericErrors.includes(type)) {\n eventHub.emit('error', new OneSDKError(`Error from vendor SDK 'Incode'`, {\n type,\n payload,\n }));\n }\n },\n };\n\n /**\n * Event handlers for OCR-related events.\n *\n * @namespace ocr\n */\n const ocr = {\n /**\n * Handles log events for OCR.\n *\n * @param {IncodeResponse} response - The response object from Incode.\n */\n onLog: (\n { type, payload }: IncodeResponse,\n ): void => {\n if ([\n 'IDNotDetected',\n 'nothingHappened',\n 'manualCaptureOn',\n 'successCapture',\n 'attemptFailed',\n 'success',\n ].includes(type)) {\n eventHub.emit('info', {\n message: payload?.message,\n payload: { type },\n });\n } else if (type === 'noAttemps') { // not a typo, 'noAttemps' comes from Incode SDK\n // we would like to emit this scenario along with an Incode error event\n // update the error state so that a corresponding error can be emitted\n noAttemptsFlag = true;\n }\n },\n /**\n * Handles error events for OCR.\n *\n * @param {IncodeResponse} response - The response object from Incode.\n */\n onError: (\n { type, payload }: IncodeResponse,\n ): void => {\n // check if error state is being flagged in the log already\n if (noAttemptsFlag) {\n eventHub.emit('detection_failed', {\n message: payload?.message,\n });\n } else if (type === 'permissionDenied') {\n eventHub.emit('input_required',\n {\n documentType: null,\n side: 'front',\n }, OCRStatus.INTERRUPTED, () => ({}));\n } else if (genericErrors.includes(type)) {\n eventHub.emit('error', new OneSDKError(`Error from vendor SDK 'Incode'`, {\n type,\n payload,\n }));\n }\n },\n };\n\n return { biometrics, ocr }[module];\n};\n","import type { EventHub } from '@module/common';\nimport { OneSDKError } from '@module/common';\nimport type {\n IncodeInstance,\n IncodeResponse,\n IncodeSuccessResponse,\n} from '@module/common/vendors/incode/onBoarding.types';\nimport type { Events } from '@module/ocr';\n\ntype CameraProps = {\n incode: IncodeInstance;\n token: { token: string; interviewId: string };\n eventHub: EventHub<Events>;\n mountElement: HTMLElement;\n onSuccess?: (response: Partial<IncodeSuccessResponse>) => void;\n onError: (response: unknown, payload?: unknown) => void;\n onLog: (response: unknown) => void;\n validate?: ({\n typeOfId,\n countryCode,\n }: Partial<IncodeSuccessResponse>) => boolean;\n};\n\nexport const startCamera = async (\n purpose: 'biometrics' | 'ocr',\n cameraProps: CameraProps,\n) => {\n if (purpose === 'ocr') {\n return await renderCamera('front', {\n ...cameraProps,\n onSuccess: async ({\n skipBackIdCapture,\n typeOfId,\n countryCode,\n }: IncodeSuccessResponse,\n ): Promise<void> => {\n if (!cameraProps?.validate?.({ typeOfId, countryCode })) return;\n // when Incode determines it needs to capture the back of document\n if (!skipBackIdCapture) {\n await renderCamera('back', cameraProps);\n } else {\n cameraProps?.onSuccess?.({});\n }\n },\n });\n } else if (purpose === 'biometrics') {\n return await renderCamera('selfie', cameraProps);\n }\n throw new OneSDKError('Unknown purpose', { purpose });\n};\n\nconst renderCamera = async (\n type: 'front' | 'back' | 'selfie',\n cameraProps: CameraProps,\n) => {\n const {\n incode,\n token,\n eventHub,\n mountElement,\n onSuccess = () => ({}),\n onError,\n onLog,\n } = cameraProps;\n return new Promise((resolve, reject): void => {\n try {\n incode.renderCamera(type, mountElement, {\n onSuccess: async (response: IncodeSuccessResponse): Promise<void> => {\n onSuccess(response);\n return resolve({});\n },\n onError: (error: IncodeResponse) => {\n onError(error);\n return reject(error);\n },\n onLog: (log: IncodeResponse) => {\n onLog(log);\n },\n token,\n numberOfTries: 3,\n });\n } catch (error) {\n const { message = '' } = error;\n eventHub.emit('error', new OneSDKError(`Error from vendor SDK 'Incode'`, { message }));\n return reject(error);\n }\n });\n};\n","import { loadAsyncAsset } from '@module/common';\nimport type {\n IncodeConfig,\n IncodeInstance,\n} from '@module/common/vendors/incode/onBoarding.types';\n\nexport { createEventHandlers } from './createEventHandlers';\nexport { startCamera } from './startCamera';\nexport * from './onBoarding.types';\n\nexport const install = async ({\n apiURL,\n sdkVersion = '1.69.1',\n}: IncodeConfig & { sdkVersion?: string }): Promise<{\n incode: IncodeInstance;\n}> => {\n // install Incode script from CDN\n await loadAsyncAsset(`https://sdk.incode.com/sdk/onBoarding-${sdkVersion}.js`);\n // instructed by vendor to add `/0/` to the end of the apiURL\n const incode = await createInstance({ apiURL: `${apiURL}/0/` });\n return { incode };\n};\n\nconst createInstance = async ({\n apiURL,\n}: IncodeConfig): Promise<IncodeInstance> => {\n const incode = window.OnBoarding.create({ apiURL });\n await incode.warmup();\n return incode;\n};\n","import { feat } from '@feature-flags';\nimport { OCRStatus } from '@frankieone/one-sdk';\nimport { OneSDKError } from '@module/common';\nimport { defineWrapper } from '@module/common/modules/defineModule';\nimport type {\n DocumentType,\n} from '@module/common/shared/models/SupportingDocument';\nimport type { IncodeSession } from '@module/common/vendors/incode';\nimport {\n createEventHandlers,\n install,\n startCamera,\n} from '@module/common/vendors/incode';\nimport { IDVClient } from '@module/frankie-client/clients/IDVClient';\nimport type { OCRModule } from '@module/ocr';\nimport { createSession } from '@module/ocr/vendors/common/createSession';\nimport {\n initProcessAndEvaluateResults,\n} from '@module/ocr/vendors/common/initProcess';\n\nexport const initialise = defineWrapper<OCRModule>('incode', async (\n shared,\n options,\n) => {\n const {\n frankieClient,\n recipe: { ocr: { documents, provider } },\n localEventHub,\n } = shared;\n const { mountElement, eventHub } = options;\n const idvClient = new IDVClient(frankieClient);\n\n // generate session token from backend\n const idvSession = await createSession<IncodeSession>(idvClient, eventHub);\n // terminate initialising if session failed\n if (!idvSession) {\n localEventHub.emit('loading', false, { message: `Failed while loading session for vendor 'Incode'` });\n return;\n }\n\n const { vendorParameters } = idvSession;\n\n try {\n // initialise Incode with credentials\n const { apiURL, token, interviewId } = vendorParameters;\n const { incode } = await install({\n apiURL,\n sdkVersion: provider.name === 'incode' && provider.sdkVersion,\n });\n\n const { onLog, onError } = createEventHandlers('ocr', { eventHub });\n const cameraProps = {\n incode,\n token: { token, interviewId },\n eventHub,\n mountElement,\n onError,\n onLog,\n };\n // turn on camera to capture the front of document\n const startCameraPromise = startCamera('ocr', {\n ...cameraProps,\n validate: ({ typeOfId, countryCode }): boolean => {\n const emitInputRequired = (documentType: DocumentType): void => {\n eventHub.emit('input_required', {\n documentType,\n side: 'front',\n }, OCRStatus.DOCUMENTS_INVALID, () => ({}));\n };\n\n // Check if documents config is given,\n if (!documents) {\n return true; // No documents, validation passes\n }\n\n // Find the accepted document type\n const acceptedDocType = documents.find(({ type }) => type === (incodeDocumentsDict[typeOfId] || typeOfId));\n\n // If no accepted document is matched, validation fails\n if (!acceptedDocType) {\n emitInputRequired(documents[0].type);\n return false;\n }\n\n // If the accepted document does not specify countries, validation passes\n if (!acceptedDocType?.countries) {\n return true;\n }\n\n // If the accepted document specifies countries\n // and the country code is matched, validation passes\n if (acceptedDocType?.countries?.includes(countryCode)) {\n return true;\n }\n\n // validation fails in other cases\n emitInputRequired(acceptedDocType.type);\n return false;\n },\n onSuccess: () => {\n eventHub.emit('session_closed');\n\n initProcessAndEvaluateResults(shared, {\n ...options,\n attachReviewScreen: !feat('modules.ocr.containsReviewScreen.incode'),\n });\n },\n });\n eventHub.emit('ready', { domElement: mountElement });\n eventHub.emit('loading', false, { message: `Vendor 'Incode' screen has loaded` });\n await startCameraPromise;\n } catch (error) {\n const { type = null, message = '' } = error;\n eventHub.emit(\n 'error',\n new OneSDKError(`Error from vendor SDK 'Incode'`, {\n type,\n message,\n }),\n );\n eventHub.emit('loading', false, { message: `Failed while executing vendor 'Incode'` });\n }\n\n return {};\n});\n\nconst incodeDocumentsDict = {\n Passport: 'PASSPORT',\n DriversLicense: 'DRIVERS_LICENCE',\n MedicalCard: 'NATIONAL_HEALTH_ID',\n};\n","import type { EventHub } from '@module/common';\nimport type { IDVClient } from '@module/frankie-client/clients/IDVClient';\nimport type { Events } from '@module/ocr/events';\nimport type { _DictionaryWrite } from '@types';\n\n/**\n * Creates a session by obtaining an entity ID, token, and vendor parameters from an IDVClient.\n * It will also emit 'session_data_generated' event to the provided event hub.\n * This function won't throw errors. Instead, it will emit 'session_data_failed_loading' and return null.\n *\n * @param idvClient - The IDVClient instance used to obtain the session data.\n * @param eventHub - The EventHub instance for emitting session-related events.\n * @returns A Promise that resolves with an object containing entityId, token, and vendorParameters upon success, or null if a session couldn't be created\n */\nexport const createSession = async <T extends _DictionaryWrite<unknown>>(\n idvClient: IDVClient,\n eventHub: EventHub<Events>,\n): Promise<{ entityId: string; token: string; vendorParameters: T } | null> => {\n try {\n const { entityId, token, vendorParameters } = await idvClient.getToken<T>();\n eventHub.emit('session_data_generated', {\n session: { entityId, token, vendorParameters },\n });\n return { entityId, token, vendorParameters };\n } catch (error) {\n const { code = null, message = '' } = error;\n eventHub.emit('session_data_failed_loading', { code, message });\n return null;\n }\n};\n","import { feat } from '@feature-flags';\nimport { OneSDKError, mkEventHub } from '@module/common';\nimport type { WrapperParameters } from '@module/common/modules/defineModule';\nimport {\n useFormToReviewResults,\n} from '@module/common/vendors/form/useForm';\nimport type { OCRResults } from '@module/frankie-client/clients/OCRClient';\nimport { OCRClient } from '@module/frankie-client/clients/OCRClient';\nimport type { Events, OCRModule } from '@module/ocr';\nimport type {\n StatusEvaluators,\n} from '@module/ocr/vendors/common/statusEvaluators';\nimport { statusEvaluators } from '@module/ocr/vendors/common/statusEvaluators';\nimport { OCRStatus } from '@module/types';\n\ntype Shared = WrapperParameters<OCRModule>[0];\ntype Options = WrapperParameters<OCRModule>[1] & {\n /** Each vendor wrapper needs to flag if their underlying vendor UI already contains a review screen.\n * If it doesn't provide one, we ALWAYS flag that in 'attachReviewScreen' as true.\n * This value can be manually overriden by recipe configuration (ocr.provideReviewScreen) */\n attachReviewScreen: boolean;\n};\n/**\n * This function will\n * 1) Trigger the OCR processing\n * 2) Fetch the updated individual details\n * 3) Evaluate the OCR status to trigger the appropriate event\n * 4) Initialise the Form for manual review, if required\n *\n * It will also emit loading events at the start and end of the process, as well as between long lasting steps\n * @throws This function doesn't throw exceptions, only error events\n * @param shared\n * @param options\n */\nexport const initProcessAndEvaluateResults = async (\n shared: Shared,\n options: Options,\n): Promise<void> => {\n const { frankieClient, oneSdkInstance, localEventHub } = shared;\n try {\n const ocrClient = new OCRClient(frankieClient);\n\n localEventHub.emit('loading', true, { message: 'Retrieving IDV results' });\n let response: OCRResults = await ocrClient.attachNewOCRDocument();\n // If waiting_ocr_run is returned, try to rerun\n if (response.documentStatus === OCRStatus.WAITING_OCR_RUN) {\n response = await ocrClient.rerun(response.ocrDocument.documentId);\n }\n // Update global state with the latest ocr check outcome\n await oneSdkInstance.individual().search();\n const { ocrDocument, documentStatus } = response;\n const evaluateStatus = statusEvaluators[documentStatus] ?? statusEvaluators.default;\n\n // When receiving results event, initialise Form for user manual review\n const privateEventHub = mkEventHub<Events>();\n const mountElement = options.mountElement;\n const recipeProvideReviewScreen =\n shared.recipe.ocr.provideReviewScreen ?? feat('recipeDefaults.ocr.provideReviewScreen');\n\n privateEventHub.on(\n 'results',\n useFormToReviewResults({\n localEventHub,\n mountElement,\n oneSdkInstance,\n // Based on recipe configuration and if the vendor options determine\n // if Form should be attached\n attachForm: recipeProvideReviewScreen && options.attachReviewScreen,\n }),\n );\n privateEventHub.map(['input_required', 'error'], localEventHub);\n\n evaluateStatus({\n ocrDocument,\n documentStatus,\n ocrClient,\n eventHub: privateEventHub,\n } as StatusEvaluators);\n } catch (e) {\n localEventHub.emit('error', new OneSDKError('Failed submitting and retrieving OCR results', e));\n localEventHub.emit('loading', false, { message: 'Failed retrieving OCR results' });\n }\n};\n","import { OCRStatus } from '@frankieone/one-sdk';\nimport type { EventHub} from '@module/common';\nimport { OneSDKError } from '@module/common';\nimport type { Document } from '@module/common/shared/models/Document';\nimport type { OCRClient } from '@module/frankie-client/clients/OCRClient';\nimport type { Events } from '@module/ocr';\n\nexport interface StatusEvaluators {\n ocrDocument?: Document;\n documentStatus?: OCRStatus;\n ocrClient?: OCRClient;\n eventHub: EventHub<Events>;\n}\n\nexport const statusEvaluators = {\n [OCRStatus.COMPLETE]: ({ ocrDocument, ocrClient, eventHub }: StatusEvaluators) =>\n eventHub.emit('results', { document: ocrDocument, entityId: ocrClient.entityId }),\n [OCRStatus.WAITING_OCR_RUN]: ({ eventHub }: StatusEvaluators) => {\n eventHub.emit(\n 'error',\n new OneSDKError(\n `Two attempts to get OCR results failed with an unresolved \"${OCRStatus.WAITING_OCR_RUN}\". This is a system failure.`,\n { payload: null },\n ),\n );\n },\n [OCRStatus.PROVIDER_OFFLINE]: ({ eventHub }: StatusEvaluators) =>\n eventHub.emit(\n 'error',\n new OneSDKError(\n `Provider is offline. Either switch providers and restart or skip OCR temporarily. Status ${OCRStatus.PROVIDER_OFFLINE}`,\n { payload: null },\n ),\n ),\n default: ({ documentStatus, eventHub }: StatusEvaluators) =>\n eventHub.emit('input_required', { documentType: null, side: 'front' }, documentStatus, () => ({})),\n} as const;\n"],"names":["createEventHandlers","module","eventHub","entityId","noAttemptsFlag","genericErrors","biometrics","onLog","type","onError","payload","emit","message","INTERRUPTED","includes","OneSDKError","ocr","documentType","side","startCamera","purpose","cameraProps","renderCamera","onSuccess","skipBackIdCapture","typeOfId","countryCode","validate","incode","token","mountElement","Promise","resolve","reject","response","error","log","numberOfTries","install","apiURL","sdkVersion","loadAsyncAsset","createInstance","window","OnBoarding","create","warmup","initialise","shared","options","frankieClient","recipe","documents","provider","localEventHub","idvClient","idvSession","vendorParameters","interviewId","name","startCameraPromise","emitInputRequired","DOCUMENTS_INVALID","acceptedDocType","find","incodeDocumentsDict","countries","attachReviewScreen","domElement","Passport","DriversLicense","MedicalCard","createSession","getToken","session","code","initProcessAndEvaluateResults","oneSdkInstance","ocrClient","attachNewOCRDocument","documentStatus","WAITING_OCR_RUN","rerun","ocrDocument","documentId","individual","search","evaluateStatus","default","privateEventHub","mkEventHub","recipeProvideReviewScreen","provideReviewScreen","on","attachForm","map","e","statusEvaluators","COMPLETE","document","PROVIDER_OFFLINE"],"sourceRoot":""}
|