{"version":3,"file":"application-9c16d437.js","sources":["../../../client-app/src/common/services/o2Service/pollForApplicationState.ts","../../../client-app/src/common/models/application.ts"],"sourcesContent":["import { sleep } from '../../lib/utils';\nimport { default as service } from '.';\nimport { logErrorToServerside } from '../serverSideLogging';\n\nconst polloveride = localStorage.getItem('poll-duration');\n\nconst POLL_DURATION = polloveride ? parseInt(polloveride, 10) : 30_000;\n\ntype StatusType = Awaited>;\nexport default async function pollForApplicationState(\n applicationId: string,\n applicantId: null | string,\n condition: (applicationStatus: StatusType) => boolean\n) {\n const duration = POLL_DURATION;\n const startTime = Date.now();\n let controller: AbortController | null = null;\n let now = startTime;\n let res: StatusType = null;\n do {\n controller && controller.abort();\n controller = new AbortController();\n try {\n res = await service.status(applicationId, applicantId, controller.signal);\n if (res && condition(res)) {\n return res;\n }\n } catch (ex) {\n logErrorToServerside(`Error getting status`, applicationId, null, ex, 'O2');\n }\n await sleep(2000);\n now = Date.now();\n } while (now - startTime < duration);\n\n return undefined;\n}\n","import { GTMLoanStatus } from '@n2-common/lib/gtm';\nimport { NavigateFunction } from 'react-router-dom';\nimport { ApplicationPaths, navigateToStep } from '@n2-common/applicationPages/ApplicationFormsHelpers';\n\nexport const OutcomeValues = ['Approve', 'Cancelled', 'Decline', 'Error', 'Pending'] as const;\nexport type Outcome = typeof OutcomeValues[number];\nexport type PostLoanApplicationResult =\n | { outcome: Outcome; applicationId: string }\n | { outcome: 'Redirect'; applicationId: string; applicantId: string };\n\nexport const outcomeToECommerceStatus = (outCome: Outcome): GTMLoanStatus => {\n switch (outCome) {\n case 'Approve':\n return 'approved';\n case 'Decline':\n return 'declined';\n }\n return 'not set';\n};\n\nexport function shouldBeTracked(outcome: Outcome) {\n return outcomeToECommerceStatus(outcome) !== 'not set';\n}\n\nexport function redirect(result: PostLoanApplicationResult, navigate: NavigateFunction) {\n switch (result.outcome) {\n case 'Approve':\n case 'Pending': // This is taking too long - we redirect to landingpage, and let that take over polling\n location.assign(`${location.protocol}//${location.host}/application/${result.applicationId}/offer`);\n break;\n\n case 'Cancelled':\n navigateToStep(ApplicationPaths.canceled, result.applicationId, navigate, null);\n break;\n\n case 'Decline':\n navigateToStep(ApplicationPaths.declined, result.applicationId, navigate, null);\n break;\n\n case 'Error':\n navigateToStep(ApplicationPaths.error, result.applicationId, navigate, null);\n break;\n\n case 'Redirect':\n location.assign(`${location.protocol}//${location.host}/application/${result.applicationId}/${result.applicantId}/offer`);\n break;\n }\n}\n\nexport function redirectSecure(result: PostLoanApplicationResult) {\n switch (result.outcome) {\n case 'Approve':\n case 'Pending': // This is taking too long - we redirect to landingpage, and let that take over polling\n location.assign(`${location.protocol}//${location.host}/application/${result.applicationId}/offer`);\n break;\n case 'Redirect':\n location.assign(`${location.protocol}//${location.host}/application/secure/${result.applicationId}/${result.applicantId}/offer`);\n break;\n\n case 'Cancelled':\n case 'Decline':\n location.assign(`${location.protocol}//${location.host}/application/${result.applicationId}/rejected`);\n break;\n\n case 'Error':\n throw new Error('Not implemented');\n }\n}\n"],"names":["polloveride","POLL_DURATION","pollForApplicationState","applicationId","applicantId","condition","duration","startTime","controller","now","res","service","ex","logErrorToServerside","sleep","OutcomeValues","outcomeToECommerceStatus","outCome","shouldBeTracked","outcome","redirect","result","navigate","navigateToStep","ApplicationPaths","redirectSecure"],"mappings":"8GAIA,MAAMA,EAAc,aAAa,QAAQ,eAAe,EAElDC,EAAgBD,EAAc,SAASA,EAAa,EAAE,EAAI,IAGlC,eAAAE,EAC1BC,EACAC,EACAC,EACF,CACE,MAAMC,EAAWL,EACXM,EAAY,KAAK,MACvB,IAAIC,EAAqC,KACrCC,EAAMF,EACNG,EAAkB,KACnB,EAAA,CACCF,GAAcA,EAAW,QACzBA,EAAa,IAAI,gBACb,GAAA,CAEI,GADJE,EAAM,MAAMC,EAAQ,OAAOR,EAAeC,EAAaI,EAAW,MAAM,EACpEE,GAAOL,EAAUK,CAAG,EACb,OAAAA,QAENE,EAAI,CACTC,EAAqB,uBAAwBV,EAAe,KAAMS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