@zeniai/client-epic-state 5.1.34 → 5.1.35
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/README.md +3 -1
- package/lib/commonStateTypes/viewAndReport/agingReportStateTypes.d.ts +1 -1
- package/lib/entity/accountRecon/accountReconPayload.d.ts +22 -0
- package/lib/entity/accountRecon/accountReconPayload.js +26 -1
- package/lib/entity/accountRecon/accountReconReducer.d.ts +5 -2
- package/lib/entity/accountRecon/accountReconReducer.js +36 -2
- package/lib/entity/accountRecon/accountReconSelector.d.ts +6 -1
- package/lib/entity/accountRecon/accountReconSelector.js +5 -0
- package/lib/entity/accountRecon/accountReconState.d.ts +22 -0
- package/lib/entity/monthEndCloseChecks/monthEndCloseChecksPayload.d.ts +8 -0
- package/lib/entity/monthEndCloseChecks/monthEndCloseChecksPayload.js +10 -0
- package/lib/entity/monthEndCloseChecks/monthEndCloseChecksState.d.ts +8 -0
- package/lib/epic.d.ts +5 -1
- package/lib/epic.js +5 -1
- package/lib/esm/entity/accountRecon/accountReconPayload.js +26 -1
- package/lib/esm/entity/accountRecon/accountReconReducer.js +35 -1
- package/lib/esm/entity/accountRecon/accountReconSelector.js +5 -0
- package/lib/esm/entity/monthEndCloseChecks/monthEndCloseChecksPayload.js +10 -0
- package/lib/esm/epic.js +5 -1
- package/lib/esm/index.js +5 -5
- package/lib/esm/view/aiCfoView/aiCfoViewReducer.js +29 -3
- package/lib/esm/view/aiCfoView/aiCfoViewSelector.js +11 -0
- package/lib/esm/view/aiCfoView/epics/createSessionAndSubmitEpic.js +2 -2
- package/lib/esm/view/aiCfoView/epics/fetchSkillsEpic.js +34 -0
- package/lib/esm/view/aiCfoView/epics/submitQuestionEpic.js +7 -1
- package/lib/esm/view/expenseAutomationView/epics/accountRecon/parseStatementEpic.js +34 -0
- package/lib/esm/view/expenseAutomationView/epics/accountRecon/reparseStatementEpic.js +31 -0
- package/lib/esm/view/expenseAutomationView/epics/accountRecon/updateStatementInfoEpic.js +57 -0
- package/lib/esm/view/expenseAutomationView/payload/reconciliationPayload.js +153 -0
- package/lib/esm/view/expenseAutomationView/reducers/reconciliationViewReducer.js +188 -9
- package/lib/esm/view/expenseAutomationView/selectors/reconciliationViewSelector.js +27 -0
- package/lib/esm/view/expenseAutomationView/types/reconciliationViewState.js +29 -0
- package/lib/esm/view/onboardingView/cockpitView/epic/initializeOnboardingCustomerViewUpdateDataEpic.js +4 -16
- package/lib/esm/view/onboardingView/cockpitView/onboardingCockpitViewPayload.js +2 -2
- package/lib/index.d.ts +10 -10
- package/lib/index.js +55 -37
- package/lib/view/aiCfoView/aiCfoViewPayload.d.ts +14 -0
- package/lib/view/aiCfoView/aiCfoViewReducer.d.ts +8 -4
- package/lib/view/aiCfoView/aiCfoViewReducer.js +30 -4
- package/lib/view/aiCfoView/aiCfoViewSelector.d.ts +2 -1
- package/lib/view/aiCfoView/aiCfoViewSelector.js +12 -0
- package/lib/view/aiCfoView/aiCfoViewState.d.ts +15 -0
- package/lib/view/aiCfoView/epics/createSessionAndSubmitEpic.js +2 -2
- package/lib/view/aiCfoView/epics/fetchSkillsEpic.d.ts +8 -0
- package/lib/view/aiCfoView/epics/fetchSkillsEpic.js +38 -0
- package/lib/view/aiCfoView/epics/submitQuestionEpic.js +7 -1
- package/lib/view/expenseAutomationView/epics/accountRecon/parseStatementEpic.d.ts +6 -0
- package/lib/view/expenseAutomationView/epics/accountRecon/parseStatementEpic.js +38 -0
- package/lib/view/expenseAutomationView/epics/accountRecon/reparseStatementEpic.d.ts +26 -0
- package/lib/view/expenseAutomationView/epics/accountRecon/reparseStatementEpic.js +35 -0
- package/lib/view/expenseAutomationView/epics/accountRecon/updateStatementInfoEpic.d.ts +27 -0
- package/lib/view/expenseAutomationView/epics/accountRecon/updateStatementInfoEpic.js +61 -0
- package/lib/view/expenseAutomationView/payload/reconciliationPayload.d.ts +176 -10
- package/lib/view/expenseAutomationView/payload/reconciliationPayload.js +159 -0
- package/lib/view/expenseAutomationView/reducers/reconciliationViewReducer.d.ts +53 -3
- package/lib/view/expenseAutomationView/reducers/reconciliationViewReducer.js +190 -10
- package/lib/view/expenseAutomationView/selectorTypes/reconciliationViewSelectorTypes.d.ts +7 -1
- package/lib/view/expenseAutomationView/selectors/reconciliationViewSelector.d.ts +2 -0
- package/lib/view/expenseAutomationView/selectors/reconciliationViewSelector.js +29 -1
- package/lib/view/expenseAutomationView/types/reconciliationViewState.d.ts +175 -0
- package/lib/view/expenseAutomationView/types/reconciliationViewState.js +30 -0
- package/lib/view/onboardingView/cockpitView/epic/initializeOnboardingCustomerViewUpdateDataEpic.js +3 -15
- package/lib/view/onboardingView/cockpitView/onboardingCockpitViewPayload.js +2 -2
- package/lib/view/vendorFiling1099/vendorFiling1099List/vendorFiling1099ListState.d.ts +1 -1
- package/package.json +5 -2
|
@@ -22,3 +22,14 @@ export const getAiCfoView = (state) => {
|
|
|
22
22
|
export function getSuggestedQuestionsForPageContext(state, pageContext) {
|
|
23
23
|
return state.aiCfoViewState?.suggestedQuestionsByPageContext?.[pageContext];
|
|
24
24
|
}
|
|
25
|
+
// Stable fallback so getSkills returns a referentially-stable object when skills
|
|
26
|
+
// state is absent — a fresh literal each call would defeat useSelector identity
|
|
27
|
+
// checks and cause needless re-renders.
|
|
28
|
+
const EMPTY_SKILLS_STATE = {
|
|
29
|
+
fetchState: 'Not-Started',
|
|
30
|
+
error: undefined,
|
|
31
|
+
skills: [],
|
|
32
|
+
};
|
|
33
|
+
export function getSkills(state) {
|
|
34
|
+
return state.aiCfoViewState?.skills ?? EMPTY_SKILLS_STATE;
|
|
35
|
+
}
|
|
@@ -66,7 +66,7 @@ function waitForChannelSubscription(pusherInstance, channelName, timeoutMs = 500
|
|
|
66
66
|
}));
|
|
67
67
|
}
|
|
68
68
|
export const createSessionAndSubmitEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(createSessionAndSubmit.match), switchMap((action) => {
|
|
69
|
-
const { agentId, userId, questionAnswerId, questionId, createdAt, question, files, pageContext, } = action.payload;
|
|
69
|
+
const { agentId, userId, questionAnswerId, questionId, createdAt, question, files, pageContext, macroId, } = action.payload;
|
|
70
70
|
const payload = {
|
|
71
71
|
agent_id: agentId,
|
|
72
72
|
...(pageContext != null && { page_context: pageContext }),
|
|
@@ -113,7 +113,7 @@ export const createSessionAndSubmitEpic = (actions$, _state$, zeniAPI) => action
|
|
|
113
113
|
// This allows fetchChatHistory to run after the question is submitted
|
|
114
114
|
of(createSessionAndSubmitSuccess(),
|
|
115
115
|
// Submit the question after handlers are bound
|
|
116
|
-
submitQuestion(sessionId, questionAnswerId, userId, questionId, createdAt, question, files),
|
|
116
|
+
submitQuestion(sessionId, questionAnswerId, userId, questionId, createdAt, question, files, macroId),
|
|
117
117
|
// Add question payload optimistically after submitQuestion (matches original order)
|
|
118
118
|
// This is idempotent - won't create duplicates if called multiple times
|
|
119
119
|
// submitQuestionEpic will find the question already exists and only update the response
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { of } from 'rxjs';
|
|
2
|
+
import { catchError, filter, mergeMap, switchMap } from 'rxjs/operators';
|
|
3
|
+
import { createZeniAPIStatus, isSuccessResponse } from '../../../responsePayload';
|
|
4
|
+
import { fetchSkills, fetchSkillsFailure, fetchSkillsSuccess, } from '../aiCfoViewReducer';
|
|
5
|
+
const toSkill = (s) => ({
|
|
6
|
+
macroId: s.macro_id,
|
|
7
|
+
name: s.name,
|
|
8
|
+
displayName: s.display_name,
|
|
9
|
+
description: s.description,
|
|
10
|
+
semver: s.semver,
|
|
11
|
+
parameterHints: s.parameter_hints,
|
|
12
|
+
hasScripts: s.has_scripts,
|
|
13
|
+
});
|
|
14
|
+
/** GET {aiCfoMicroServiceBaseUrl}/1.0/skills — chat-visible skills for the `/` menu. */
|
|
15
|
+
export const fetchSkillsEpic = (actions$,
|
|
16
|
+
// state$ intentionally unused: the `/` menu dispatches this once per slash-entry
|
|
17
|
+
// (the composer dedupes), so we always re-fetch the (small, singleton) list.
|
|
18
|
+
_state$, zeniAPI) => actions$.pipe(filter(fetchSkills.match),
|
|
19
|
+
// switchMap: a singleton list endpoint with no key — cancel any in-flight
|
|
20
|
+
// fetch so the latest dispatch wins (no racing writes to `skills`).
|
|
21
|
+
switchMap(() => {
|
|
22
|
+
// aiCfoMicroServiceBaseUrl already targets the chat service (it serves the
|
|
23
|
+
// /1.0/agents/{id} submit route too); /1.0/skills lives on the same service.
|
|
24
|
+
const url = `${zeniAPI.apiEndPoints.aiCfoMicroServiceBaseUrl}/1.0/skills`;
|
|
25
|
+
return zeniAPI.getJSON(url).pipe(mergeMap((response) => {
|
|
26
|
+
if (isSuccessResponse(response) && response.data != null) {
|
|
27
|
+
// Guard the array: a malformed 2xx body without `skills` must not crash .map.
|
|
28
|
+
return of(fetchSkillsSuccess({
|
|
29
|
+
skills: (response.data.skills ?? []).map(toSkill),
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
return of(fetchSkillsFailure(response.status));
|
|
33
|
+
}), catchError((error) => of(fetchSkillsFailure(createZeniAPIStatus('Unexpected Error', 'Fetch skills REST API call failed', error instanceof Error ? { message: error.message } : undefined)))));
|
|
34
|
+
}));
|
|
@@ -4,7 +4,7 @@ import { upsertOrAddQuestionAnswerPayload } from '../../../entity/aiCfo/aiCfoRed
|
|
|
4
4
|
import { createZeniAPIStatus, isSuccessResponse } from '../../../responsePayload';
|
|
5
5
|
import { submitQuestion, submitQuestionFailure, submitQuestionSuccess, } from '../aiCfoViewReducer';
|
|
6
6
|
export const submitQuestionEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(submitQuestion.match), mergeMap((action) => {
|
|
7
|
-
const { questionAnswerId, userId, sessionId, questionId, createdAt, question, files, } = action.payload;
|
|
7
|
+
const { questionAnswerId, userId, sessionId, questionId, createdAt, question, files, macroId, } = action.payload;
|
|
8
8
|
const { aiCfoViewState } = state$.value;
|
|
9
9
|
const { uiState } = aiCfoViewState;
|
|
10
10
|
const agentId = uiState.agentId;
|
|
@@ -17,15 +17,21 @@ export const submitQuestionEpic = (actions$, state$, zeniAPI) => actions$.pipe(f
|
|
|
17
17
|
const formData = new FormData();
|
|
18
18
|
formData.append('chat_session_id', sessionId);
|
|
19
19
|
formData.append('message', question);
|
|
20
|
+
if (macroId != null) {
|
|
21
|
+
formData.append('macro_id', macroId);
|
|
22
|
+
}
|
|
20
23
|
for (const file of files) {
|
|
21
24
|
formData.append('files', file, file.name);
|
|
22
25
|
}
|
|
23
26
|
apiCall = zeniAPI.postFormData(endpoint, formData);
|
|
24
27
|
}
|
|
25
28
|
else {
|
|
29
|
+
// `message` is the display token (e.g. "/flux"); `macro_id` tells the chat
|
|
30
|
+
// service to expand the skill's instructions as the actual agent prompt.
|
|
26
31
|
apiCall = zeniAPI.postAndGetJSON(endpoint, {
|
|
27
32
|
chat_session_id: sessionId,
|
|
28
33
|
message: question,
|
|
34
|
+
...(macroId != null && { macro_id: macroId }),
|
|
29
35
|
});
|
|
30
36
|
}
|
|
31
37
|
return apiCall.pipe(mergeMap((response) => {
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { from, of } from 'rxjs';
|
|
2
|
+
import { catchError, filter, mergeMap, switchMap } from 'rxjs/operators';
|
|
3
|
+
import { createZeniAPIStatus, isSuccessResponse, } from '../../../../responsePayload';
|
|
4
|
+
import { transformParseStatementPayloadToState, } from '../../payload/reconciliationPayload';
|
|
5
|
+
import { parseStatement, parseStatementFailure, parseStatementSuccess, updateParsedStatementData, } from '../../reducers/reconciliationViewReducer';
|
|
6
|
+
export const parseStatementEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(parseStatement.match), switchMap((action) => {
|
|
7
|
+
const { accountId, selectedPeriod, statementUploadId } = action.payload;
|
|
8
|
+
const parseStatementApi$ = zeniAPI.getJSON(`${zeniAPI.apiEndPoints.reconciliationMicroServiceBaseUrl}/2.0/statement-uploads/${statementUploadId}`);
|
|
9
|
+
return parseStatementApi$.pipe(mergeMap((response) => {
|
|
10
|
+
if (isSuccessResponse(response) === true && response.data != null) {
|
|
11
|
+
const actions = [];
|
|
12
|
+
const transformedData = transformParseStatementPayloadToState(response.data);
|
|
13
|
+
actions.push(updateParsedStatementData({
|
|
14
|
+
accountId,
|
|
15
|
+
selectedPeriod,
|
|
16
|
+
parsedStatementData: transformedData,
|
|
17
|
+
}));
|
|
18
|
+
actions.push(parseStatementSuccess({ accountId, selectedPeriod }));
|
|
19
|
+
return from(actions);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
return of(parseStatementFailure({
|
|
23
|
+
accountId,
|
|
24
|
+
selectedPeriod,
|
|
25
|
+
error: response.status,
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
}), catchError((error) => of(parseStatementFailure({
|
|
29
|
+
accountId,
|
|
30
|
+
selectedPeriod,
|
|
31
|
+
error: createZeniAPIStatus('Unexpected Error', 'Parse Statement REST API call errored out ' +
|
|
32
|
+
(error instanceof Error ? error.message : String(error))),
|
|
33
|
+
}))));
|
|
34
|
+
}));
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { from, of } from 'rxjs';
|
|
2
|
+
import { catchError, filter, mergeMap, switchMap } from 'rxjs/operators';
|
|
3
|
+
import { updateAccountReconReparseStatement } from '../../../../entity/accountRecon/accountReconReducer';
|
|
4
|
+
import { toAccountReconKey } from '../../../../entity/accountRecon/accountReconState';
|
|
5
|
+
import { createZeniAPIStatus, isSuccessResponse, } from '../../../../responsePayload';
|
|
6
|
+
import { reparseStatement, reparseStatementFailure, reparseStatementSuccess, } from '../../reducers/reconciliationViewReducer';
|
|
7
|
+
export const reparseStatementEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(reparseStatement.match), switchMap((action) => {
|
|
8
|
+
const { accountId, selectedPeriod, statementUploadId } = action.payload;
|
|
9
|
+
const reparseStatementApi$ = zeniAPI.postAndGetJSON(`${zeniAPI.apiEndPoints.reconciliationMicroServiceBaseUrl}/1.0/reconciliation/statements/${statementUploadId}/reparse`);
|
|
10
|
+
return reparseStatementApi$.pipe(mergeMap((response) => {
|
|
11
|
+
if (isSuccessResponse(response) === true && response.data != null) {
|
|
12
|
+
const accountReconKey = toAccountReconKey(accountId, selectedPeriod);
|
|
13
|
+
return from([
|
|
14
|
+
updateAccountReconReparseStatement(accountReconKey, response.data),
|
|
15
|
+
reparseStatementSuccess({ accountId, selectedPeriod }),
|
|
16
|
+
]);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
return of(reparseStatementFailure({
|
|
20
|
+
accountId,
|
|
21
|
+
selectedPeriod,
|
|
22
|
+
error: response.status,
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
}), catchError((error) => of(reparseStatementFailure({
|
|
26
|
+
accountId,
|
|
27
|
+
selectedPeriod,
|
|
28
|
+
error: createZeniAPIStatus('Unexpected Error', 'Reparse Statement REST API call errored out ' +
|
|
29
|
+
(error instanceof Error ? error.message : String(error))),
|
|
30
|
+
}))));
|
|
31
|
+
}));
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { of } from 'rxjs';
|
|
2
|
+
import { catchError, filter, mergeMap, switchMap } from 'rxjs/operators';
|
|
3
|
+
import { toMonthYearPeriodId } from '../../../../commonStateTypes/timePeriod';
|
|
4
|
+
import { createZeniAPIStatus, isSuccessResponse, } from '../../../../responsePayload';
|
|
5
|
+
import { isStatementDateConflictResponse, toStatementUpdateRequestBody, transformStatementDateConflictToState, transformUpdateStatementInfoPayloadToState, } from '../../payload/reconciliationPayload';
|
|
6
|
+
import { submitStatementUpdate, submitStatementUpdateFailure, submitStatementUpdateSuccess, updateParsedStatementData, } from '../../reducers/reconciliationViewReducer';
|
|
7
|
+
export const updateStatementInfoEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(submitStatementUpdate.match), switchMap((action) => {
|
|
8
|
+
const { accountId, selectedPeriod, statementUploadId } = action.payload;
|
|
9
|
+
const state = state$.value;
|
|
10
|
+
const reconciliationView = state.expenseAutomationReconciliationViewState;
|
|
11
|
+
const accountRecon = reconciliationView.accountReconciliationRecordsBySelectedPeriod[toMonthYearPeriodId(selectedPeriod)]?.reconciliationByAccountID[accountId];
|
|
12
|
+
const localData = accountRecon?.localData?.statementUpdateLocalData;
|
|
13
|
+
if (!localData) {
|
|
14
|
+
return of(submitStatementUpdateFailure({
|
|
15
|
+
accountId,
|
|
16
|
+
selectedPeriod,
|
|
17
|
+
error: createZeniAPIStatus('Missing Data', 'No statement update data found'),
|
|
18
|
+
}));
|
|
19
|
+
}
|
|
20
|
+
const hasInvalidUpdates = localData.statementTransactions.updated.some((txn) => txn.statementTransactionId == null);
|
|
21
|
+
if (hasInvalidUpdates) {
|
|
22
|
+
return of(submitStatementUpdateFailure({
|
|
23
|
+
accountId,
|
|
24
|
+
selectedPeriod,
|
|
25
|
+
error: createZeniAPIStatus('Invalid Data', 'One or more edited transactions are missing statement transaction ids'),
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
const body = toStatementUpdateRequestBody(localData);
|
|
29
|
+
const updateStatementApi$ = zeniAPI.putAndGetJSON(`${zeniAPI.apiEndPoints.reconciliationMicroServiceBaseUrl}/2.0/statement-uploads/${statementUploadId}`, body);
|
|
30
|
+
return updateStatementApi$.pipe(mergeMap((response) => {
|
|
31
|
+
if (isSuccessResponse(response) === true && response.data != null) {
|
|
32
|
+
const parsedStatementData = transformUpdateStatementInfoPayloadToState(response.data);
|
|
33
|
+
return of(updateParsedStatementData({
|
|
34
|
+
accountId,
|
|
35
|
+
selectedPeriod,
|
|
36
|
+
parsedStatementData,
|
|
37
|
+
}), submitStatementUpdateSuccess({
|
|
38
|
+
accountId,
|
|
39
|
+
selectedPeriod,
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
const dateConflict = isStatementDateConflictResponse(response)
|
|
43
|
+
? transformStatementDateConflictToState(response)
|
|
44
|
+
: null;
|
|
45
|
+
return of(submitStatementUpdateFailure({
|
|
46
|
+
accountId,
|
|
47
|
+
selectedPeriod,
|
|
48
|
+
error: response.status,
|
|
49
|
+
dateConflict,
|
|
50
|
+
}));
|
|
51
|
+
}), catchError((error) => of(submitStatementUpdateFailure({
|
|
52
|
+
accountId,
|
|
53
|
+
selectedPeriod,
|
|
54
|
+
error: createZeniAPIStatus('Unexpected Error', 'Update Statement REST API call errored out ' +
|
|
55
|
+
(error instanceof Error ? error.message : String(error))),
|
|
56
|
+
}))));
|
|
57
|
+
}));
|
|
@@ -67,3 +67,156 @@ function createReviewTransactionPayload(accountReconciliationEntity) {
|
|
|
67
67
|
});
|
|
68
68
|
return reviewTransactionsPayload;
|
|
69
69
|
}
|
|
70
|
+
export function isStatementDateConflictResponse(response) {
|
|
71
|
+
return response.status.code === 409 && response.error_code != null;
|
|
72
|
+
}
|
|
73
|
+
function transformStatementUploadPayloadToState(statementUploadPayload) {
|
|
74
|
+
return {
|
|
75
|
+
account: {
|
|
76
|
+
accountId: statementUploadPayload.account.account_id,
|
|
77
|
+
accountName: statementUploadPayload.account.account_name,
|
|
78
|
+
accountType: statementUploadPayload.account.account_type,
|
|
79
|
+
currencyCode: statementUploadPayload.account.currency_code,
|
|
80
|
+
last4Digits: statementUploadPayload.account.last_4_digits,
|
|
81
|
+
},
|
|
82
|
+
file: statementUploadPayload.file != null
|
|
83
|
+
? {
|
|
84
|
+
fileId: statementUploadPayload.file.file_id,
|
|
85
|
+
fileName: statementUploadPayload.file.file_name,
|
|
86
|
+
signedUrl: statementUploadPayload.file.signed_url,
|
|
87
|
+
}
|
|
88
|
+
: null,
|
|
89
|
+
statementMeta: {
|
|
90
|
+
closingBalance: statementUploadPayload.statement_meta.closing_balance,
|
|
91
|
+
openingBalance: statementUploadPayload.statement_meta.opening_balance,
|
|
92
|
+
statementDataStatus: statementUploadPayload.statement_meta.statement_data_status,
|
|
93
|
+
statementEndDate: statementUploadPayload.statement_meta.statement_end_date,
|
|
94
|
+
statementStartDate: statementUploadPayload.statement_meta.statement_start_date,
|
|
95
|
+
statementStatus: statementUploadPayload.statement_meta.statement_status,
|
|
96
|
+
statementUploadId: statementUploadPayload.statement_meta.statement_upload_id,
|
|
97
|
+
totalDeposits: statementUploadPayload.statement_meta.total_deposits,
|
|
98
|
+
totalPayments: statementUploadPayload.statement_meta.total_payments,
|
|
99
|
+
},
|
|
100
|
+
statementTransactions: (statementUploadPayload.statement_transactions ?? []).map((txn) => ({
|
|
101
|
+
amount: txn.amount,
|
|
102
|
+
citations: (txn.citation ?? []).map((c) => ({
|
|
103
|
+
page: c.page,
|
|
104
|
+
pageHeight: c.page_height,
|
|
105
|
+
pageWidth: c.page_width,
|
|
106
|
+
polygon: (c.polygon ?? []).map((point) => ({
|
|
107
|
+
x: point.x,
|
|
108
|
+
y: point.y,
|
|
109
|
+
})),
|
|
110
|
+
referenceText: c.reference_text,
|
|
111
|
+
})),
|
|
112
|
+
isUserAdded: txn.is_user_added,
|
|
113
|
+
isUserEdited: txn.is_user_edited,
|
|
114
|
+
statementTransactionId: txn.statement_transaction_id,
|
|
115
|
+
transactionDate: txn.transaction_date,
|
|
116
|
+
transactionDirection: txn.transaction_direction,
|
|
117
|
+
transactionMemo: txn.transaction_memo,
|
|
118
|
+
})),
|
|
119
|
+
aiSummary: transformAiSummaryPayloadToState(statementUploadPayload.ai_summary),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function transformPreviousReconciliationInfoToState(payload) {
|
|
123
|
+
if (payload == null) {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
endDate: payload.end_date,
|
|
128
|
+
reconciledAt: payload.reconciled_at,
|
|
129
|
+
reconciledByUserId: payload.reconciled_by_user_id,
|
|
130
|
+
reconciliationId: payload.reconciliation_id,
|
|
131
|
+
startDate: payload.start_date,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function transformAiSummaryPayloadToState(aiSummaryPayload) {
|
|
135
|
+
if (aiSummaryPayload == null) {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
const { chain_status: chainStatus } = aiSummaryPayload;
|
|
139
|
+
return {
|
|
140
|
+
accountIdentified: aiSummaryPayload.account_identified,
|
|
141
|
+
transactionsExtracted: aiSummaryPayload.transactions_extracted,
|
|
142
|
+
exceptionsDetected: aiSummaryPayload.exceptions_detected,
|
|
143
|
+
fieldsCaptured: (aiSummaryPayload.fields_captured ?? []).map((field) => ({
|
|
144
|
+
code: field.code,
|
|
145
|
+
label: field.label,
|
|
146
|
+
})),
|
|
147
|
+
chainStatus: {
|
|
148
|
+
code: chainStatus?.code ?? '',
|
|
149
|
+
label: chainStatus?.label ?? '',
|
|
150
|
+
expectedStartDate: chainStatus?.expected_start_date ?? null,
|
|
151
|
+
previousReconciliationInfo: transformPreviousReconciliationInfoToState(chainStatus?.previous_reconciliation_info),
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Builds date-conflict state from a 409 Confirm & Save response.
|
|
157
|
+
* Returns null for non-409 responses or 409s without a recognized error code.
|
|
158
|
+
*/
|
|
159
|
+
export function transformStatementDateConflictToState(response) {
|
|
160
|
+
if (isStatementDateConflictResponse(response) === false) {
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
const previousReconciliationInfo = transformPreviousReconciliationInfoToState(response.previous_reconciliation_info);
|
|
164
|
+
if (response.error_code === 'STATEMENT_RANGE_ALREADY_RECONCILED' &&
|
|
165
|
+
previousReconciliationInfo == null) {
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
if (response.error_code === 'STATEMENT_RANGE_HAS_GAP' &&
|
|
169
|
+
response.expected_start_date == null &&
|
|
170
|
+
previousReconciliationInfo == null) {
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
errorCode: response.error_code,
|
|
175
|
+
expectedStartDate: response.expected_start_date ?? null,
|
|
176
|
+
...(previousReconciliationInfo != null ? { previousReconciliationInfo } : {}),
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
export function transformParseStatementPayloadToState(payload) {
|
|
180
|
+
return {
|
|
181
|
+
statementUpload: transformStatementUploadPayloadToState(payload.statement_upload),
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
export function transformUpdateStatementInfoPayloadToState(payload) {
|
|
185
|
+
return {
|
|
186
|
+
statementUpload: transformStatementUploadPayloadToState(payload.statement_upload),
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
export function transformStatementUpdateStateToPayload(localData) {
|
|
190
|
+
const { statementMeta, statementTransactions } = localData;
|
|
191
|
+
return {
|
|
192
|
+
statement_meta: {
|
|
193
|
+
opening_balance: statementMeta.openingBalance,
|
|
194
|
+
statement_end_date: statementMeta.statementEndDate,
|
|
195
|
+
statement_start_date: statementMeta.statementStartDate,
|
|
196
|
+
total_deposits: statementMeta.totalDeposits,
|
|
197
|
+
total_payments: statementMeta.totalPayments,
|
|
198
|
+
},
|
|
199
|
+
statement_transactions: {
|
|
200
|
+
added: statementTransactions.added.map((txn) => ({
|
|
201
|
+
amount: txn.amount,
|
|
202
|
+
transaction_date: txn.transactionDate,
|
|
203
|
+
transaction_direction: txn.transactionDirection,
|
|
204
|
+
transaction_memo: txn.transactionMemo,
|
|
205
|
+
})),
|
|
206
|
+
deleted_ids: statementTransactions.deletedIds,
|
|
207
|
+
updated: statementTransactions.updated
|
|
208
|
+
.filter((txn) => txn.statementTransactionId != null)
|
|
209
|
+
.map((txn) => ({
|
|
210
|
+
amount: txn.amount,
|
|
211
|
+
statement_transaction_id: txn.statementTransactionId,
|
|
212
|
+
transaction_date: txn.transactionDate,
|
|
213
|
+
transaction_direction: txn.transactionDirection,
|
|
214
|
+
transaction_memo: txn.transactionMemo,
|
|
215
|
+
})),
|
|
216
|
+
},
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
/** API request body for PUT statement-uploads; cast lives here for putAndGetJSON. */
|
|
220
|
+
export function toStatementUpdateRequestBody(localData) {
|
|
221
|
+
return transformStatementUpdateStateToPayload(localData);
|
|
222
|
+
}
|