@zeniai/client-epic-state 5.0.95 → 5.0.97
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/lib/commonStateTypes/amount.d.ts +1 -0
- package/lib/commonStateTypes/amount.js +9 -1
- package/lib/commonStateTypes/workingDayHelper.d.ts +9 -0
- package/lib/commonStateTypes/workingDayHelper.js +28 -1
- package/lib/entity/tenant/clearAllEpic.d.ts +3 -1
- package/lib/entity/tenant/clearAllEpic.js +4 -0
- package/lib/epic.d.ts +7 -1
- package/lib/epic.js +7 -1
- package/lib/esm/commonStateTypes/amount.js +7 -0
- package/lib/esm/commonStateTypes/workingDayHelper.js +26 -0
- package/lib/esm/entity/tenant/clearAllEpic.js +4 -0
- package/lib/esm/epic.js +7 -1
- package/lib/esm/index.js +7 -2
- package/lib/esm/reducer.js +6 -0
- package/lib/esm/view/spendManagement/autotransferRules/autoTransferRulesSelector.js +22 -2
- package/lib/esm/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowPayload.js +29 -0
- package/lib/esm/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowReducer.js +78 -0
- package/lib/esm/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowSelector.js +47 -0
- package/lib/esm/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowState.js +47 -0
- package/lib/esm/view/spendManagement/cashManagement/autoSweepFlow/epics/fetchCashManagementSettingsEpic.js +34 -0
- package/lib/esm/view/spendManagement/cashManagement/autoSweepFlow/epics/saveAutoSweepSettingsEpic.js +32 -0
- package/lib/esm/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewPayload.js +54 -0
- package/lib/esm/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewReducer.js +92 -0
- package/lib/esm/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewSelector.js +225 -0
- package/lib/esm/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewState.js +10 -0
- package/lib/esm/view/spendManagement/cashManagement/cashManagementOverview/epics/fetchCashManagementBannerEpic.js +23 -0
- package/lib/esm/view/spendManagement/cashManagement/cashManagementOverview/epics/fetchCashManagementOverviewPageEpic.js +36 -0
- package/lib/esm/view/spendManagement/cashManagement/cashManagementOverview/epics/fetchCashManagementRecommendationEpic.js +27 -0
- package/lib/esm/view/spendManagement/cashManagement/cashManagementOverview/epics/fetchRecentTransferEpic.js +28 -0
- package/lib/index.d.ts +12 -3
- package/lib/index.js +37 -17
- package/lib/reducer.d.ts +6 -0
- package/lib/reducer.js +6 -0
- package/lib/view/spendManagement/autotransferRules/autoTransferRulesSelector.d.ts +8 -1
- package/lib/view/spendManagement/autotransferRules/autoTransferRulesSelector.js +21 -1
- package/lib/view/spendManagement/autotransferRules/autoTransferRulesState.d.ts +22 -0
- package/lib/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowPayload.d.ts +47 -0
- package/lib/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowPayload.js +34 -0
- package/lib/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowReducer.d.ts +23 -0
- package/lib/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowReducer.js +82 -0
- package/lib/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowSelector.d.ts +40 -0
- package/lib/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowSelector.js +51 -0
- package/lib/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowState.d.ts +37 -0
- package/lib/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowState.js +53 -0
- package/lib/view/spendManagement/cashManagement/autoSweepFlow/epics/fetchCashManagementSettingsEpic.d.ts +14 -0
- package/lib/view/spendManagement/cashManagement/autoSweepFlow/epics/fetchCashManagementSettingsEpic.js +38 -0
- package/lib/view/spendManagement/cashManagement/autoSweepFlow/epics/saveAutoSweepSettingsEpic.d.ts +7 -0
- package/lib/view/spendManagement/cashManagement/autoSweepFlow/epics/saveAutoSweepSettingsEpic.js +36 -0
- package/lib/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewPayload.d.ts +56 -0
- package/lib/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewPayload.js +60 -0
- package/lib/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewReducer.d.ts +22 -0
- package/lib/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewReducer.js +96 -0
- package/lib/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewSelector.d.ts +59 -0
- package/lib/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewSelector.js +230 -0
- package/lib/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewState.d.ts +122 -0
- package/lib/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewState.js +13 -0
- package/lib/view/spendManagement/cashManagement/cashManagementOverview/epics/fetchCashManagementBannerEpic.d.ts +7 -0
- package/lib/view/spendManagement/cashManagement/cashManagementOverview/epics/fetchCashManagementBannerEpic.js +27 -0
- package/lib/view/spendManagement/cashManagement/cashManagementOverview/epics/fetchCashManagementOverviewPageEpic.d.ts +9 -0
- package/lib/view/spendManagement/cashManagement/cashManagementOverview/epics/fetchCashManagementOverviewPageEpic.js +40 -0
- package/lib/view/spendManagement/cashManagement/cashManagementOverview/epics/fetchCashManagementRecommendationEpic.d.ts +7 -0
- package/lib/view/spendManagement/cashManagement/cashManagementOverview/epics/fetchCashManagementRecommendationEpic.js +31 -0
- package/lib/view/spendManagement/cashManagement/cashManagementOverview/epics/fetchRecentTransferEpic.d.ts +15 -0
- package/lib/view/spendManagement/cashManagement/cashManagementOverview/epics/fetchRecentTransferEpic.js +32 -0
- package/lib/zeniAPI.d.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { createSlice } from '@reduxjs/toolkit';
|
|
2
|
+
import { toCashManagementBannerData, toCashManagementTransfer, } from './cashManagementOverviewPayload';
|
|
3
|
+
import { initialCashManagementBannerState, initialCashManagementRecentTransferState, } from './cashManagementOverviewState';
|
|
4
|
+
export const initialState = {
|
|
5
|
+
banner: initialCashManagementBannerState,
|
|
6
|
+
recentTransfer: initialCashManagementRecentTransferState,
|
|
7
|
+
};
|
|
8
|
+
const cashManagementOverview = createSlice({
|
|
9
|
+
name: 'cashManagementOverview',
|
|
10
|
+
initialState,
|
|
11
|
+
reducers: {
|
|
12
|
+
fetchCashManagementOverviewPage: {
|
|
13
|
+
reducer() { },
|
|
14
|
+
prepare(cacheOverride) {
|
|
15
|
+
return { payload: { cacheOverride } };
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
/**
|
|
19
|
+
* Public banner-fetch entry point. Triggers an orchestrator epic that
|
|
20
|
+
* fans out to the recommend, settings, and recent-transfer API calls
|
|
21
|
+
* in parallel. No reducer-side state change — each inner action drives
|
|
22
|
+
* its own sub-state.
|
|
23
|
+
*
|
|
24
|
+
* `cacheOverride === true` forces all three inner fetches regardless
|
|
25
|
+
* of current slice state; `false` keeps the per-slice dedup so repeat
|
|
26
|
+
* dispatches are no-ops once a slice is loaded or in-flight.
|
|
27
|
+
*/
|
|
28
|
+
fetchCashManagementBanner: {
|
|
29
|
+
reducer() { },
|
|
30
|
+
prepare(cacheOverride) {
|
|
31
|
+
return { payload: { cacheOverride } };
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
/**
|
|
35
|
+
* Internal trigger for the recommend API (`/cash-agent/recommend`).
|
|
36
|
+
* Dispatched by the orchestrator; not exported.
|
|
37
|
+
*/
|
|
38
|
+
fetchCashManagementRecommendation(draft) {
|
|
39
|
+
// Keep `draft.banner.data` so the projection chart renders the last
|
|
40
|
+
// good payload while the refetch is in flight, instead of flickering
|
|
41
|
+
// to the empty/skeleton state on every page revisit.
|
|
42
|
+
draft.banner.fetchState = 'In-Progress';
|
|
43
|
+
draft.banner.error = undefined;
|
|
44
|
+
},
|
|
45
|
+
updateCashManagementRecommendation(draft, action) {
|
|
46
|
+
draft.banner = {
|
|
47
|
+
fetchState: 'Completed',
|
|
48
|
+
error: undefined,
|
|
49
|
+
data: toCashManagementBannerData(action.payload.data),
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
updateCashManagementRecommendationFetchStatus(draft, action) {
|
|
53
|
+
draft.banner = {
|
|
54
|
+
...draft.banner,
|
|
55
|
+
fetchState: action.payload.fetchState,
|
|
56
|
+
error: action.payload.error,
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
/**
|
|
60
|
+
* Internal trigger for the recent-transfer API
|
|
61
|
+
* (`/cash-management/transfers`). Dispatched by the orchestrator; not
|
|
62
|
+
* exported.
|
|
63
|
+
*/
|
|
64
|
+
fetchRecentTransfer(draft) {
|
|
65
|
+
// Same anti-flicker pattern as the recommend fetch: keep prior data
|
|
66
|
+
// while the refetch is in flight.
|
|
67
|
+
draft.recentTransfer.fetchState = 'In-Progress';
|
|
68
|
+
draft.recentTransfer.error = undefined;
|
|
69
|
+
},
|
|
70
|
+
updateRecentTransfer(draft, action) {
|
|
71
|
+
draft.recentTransfer = {
|
|
72
|
+
fetchState: 'Completed',
|
|
73
|
+
error: undefined,
|
|
74
|
+
data: action.payload.data != null
|
|
75
|
+
? toCashManagementTransfer(action.payload.data)
|
|
76
|
+
: undefined,
|
|
77
|
+
};
|
|
78
|
+
},
|
|
79
|
+
updateRecentTransferFetchStatus(draft, action) {
|
|
80
|
+
draft.recentTransfer = {
|
|
81
|
+
...draft.recentTransfer,
|
|
82
|
+
fetchState: action.payload.fetchState,
|
|
83
|
+
error: action.payload.error,
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
clearCashManagementOverview(draft) {
|
|
87
|
+
Object.assign(draft, initialState);
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
export const { fetchCashManagementOverviewPage, fetchCashManagementBanner, fetchCashManagementRecommendation, updateCashManagementRecommendation, updateCashManagementRecommendationFetchStatus, fetchRecentTransfer, updateRecentTransfer, updateRecentTransferFetchStatus, clearCashManagementOverview, } = cashManagementOverview.actions;
|
|
92
|
+
export default cashManagementOverview.reducer;
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { zeroAmount } from '../../../../commonStateTypes/amount';
|
|
2
|
+
import { reduceAllFetchState } from '../../../../commonStateTypes/reduceFetchState';
|
|
3
|
+
import { getDepositAccountByDepositAccountId } from '../../../../entity/depositAccount/depositAccountSelector';
|
|
4
|
+
import { mapDepositAccToFundingAccount, } from '../../commonSetup/setupViewSelector';
|
|
5
|
+
/**
|
|
6
|
+
* Default account type used when the recommend payload has no movement to
|
|
7
|
+
* expose yet (e.g. before the first fetch resolves). Callers that care about
|
|
8
|
+
* the movement should also gate on `fetchState === 'Completed'`.
|
|
9
|
+
*/
|
|
10
|
+
const DEFAULT_BANK_ACCOUNT_TYPE = 'deposit_account';
|
|
11
|
+
const DEFAULT_SUB_MOVEMENT_TYPE = 'push';
|
|
12
|
+
export const getCashManagementOverviewBanner = (state) => {
|
|
13
|
+
const { banner, recentTransfer } = state.cashManagementOverviewState;
|
|
14
|
+
const autoSweep = state.autoSweepFlowState;
|
|
15
|
+
// The banner today surfaces a single recommended movement (the first one
|
|
16
|
+
// returned by the agent). When the agent returns multiple groups/movements
|
|
17
|
+
// we'll need to broaden this — for now consumers only render one.
|
|
18
|
+
const movement = banner.data?.moneyMovements[0]?.movements[0];
|
|
19
|
+
const aggregate = reduceAllFetchState([
|
|
20
|
+
{ fetchState: banner.fetchState, error: banner.error },
|
|
21
|
+
{ fetchState: autoSweep.fetchState, error: autoSweep.error },
|
|
22
|
+
{ fetchState: recentTransfer.fetchState, error: recentTransfer.error },
|
|
23
|
+
]);
|
|
24
|
+
const subMovementType = movement?.subMovementType ?? DEFAULT_SUB_MOVEMENT_TYPE;
|
|
25
|
+
// The "primary" account is the deposit-account side of the movement —
|
|
26
|
+
// source for a push (money leaving primary → treasury) and destination
|
|
27
|
+
// for a pull (money returning to primary).
|
|
28
|
+
const primaryAccountId = subMovementType === 'pull'
|
|
29
|
+
? movement?.destinationBankAccountId
|
|
30
|
+
: movement?.sourceBankAccountId;
|
|
31
|
+
const primaryDepositAccount = primaryAccountId != null && primaryAccountId !== ''
|
|
32
|
+
? getDepositAccountByDepositAccountId(state.depositAccountState, primaryAccountId)
|
|
33
|
+
: undefined;
|
|
34
|
+
const primaryFundingAccount = primaryDepositAccount != null
|
|
35
|
+
? mapDepositAccToFundingAccount(primaryDepositAccount)
|
|
36
|
+
: undefined;
|
|
37
|
+
// For pull, surface the largest outflow in the horizon as the
|
|
38
|
+
// "triggering" event. This is a heuristic — the agent doesn't tag a
|
|
39
|
+
// specific outflow today, but the largest one is the most likely cause
|
|
40
|
+
// of the buffer breach and matches what the design wants to highlight.
|
|
41
|
+
const triggeringOutflow = subMovementType === 'pull'
|
|
42
|
+
? pickLargestOutflow(banner.data?.outflows)
|
|
43
|
+
: undefined;
|
|
44
|
+
return {
|
|
45
|
+
fetchState: aggregate.fetchState,
|
|
46
|
+
error: aggregate.error,
|
|
47
|
+
amount: movement?.amount ?? zeroAmount(),
|
|
48
|
+
cashManagementSettingsId: autoSweep.settingsId,
|
|
49
|
+
destinationBankAccountId: movement?.destinationBankAccountId ?? '',
|
|
50
|
+
destinationBankAccountType: movement?.destinationBankAccountType ?? DEFAULT_BANK_ACCOUNT_TYPE,
|
|
51
|
+
reasoning: movement?.reasoning ?? '',
|
|
52
|
+
sourceBankAccountId: movement?.sourceBankAccountId ?? '',
|
|
53
|
+
sourceBankAccountType: movement?.sourceBankAccountType ?? DEFAULT_BANK_ACCOUNT_TYPE,
|
|
54
|
+
subMovementType,
|
|
55
|
+
primaryFundingAccount,
|
|
56
|
+
triggeringOutflow,
|
|
57
|
+
recentTransfer: recentTransfer.data,
|
|
58
|
+
version: 0,
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
const pickLargestOutflow = (outflows) => {
|
|
62
|
+
if (outflows == null || outflows.length === 0) {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
return outflows.reduce((largest, event) => event.amount.amount > largest.amount.amount ? event : largest);
|
|
66
|
+
};
|
|
67
|
+
export const getCashManagementOverview = (state) => {
|
|
68
|
+
const { cashManagementOverviewState, depositAccountListState, depositAccountState, paymentAccountListState, paymentAccountState, treasuryDetailState, } = state;
|
|
69
|
+
const aggregate = reduceAllFetchState([
|
|
70
|
+
{
|
|
71
|
+
fetchState: paymentAccountListState.fetchState,
|
|
72
|
+
error: paymentAccountListState.error,
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
fetchState: depositAccountListState.fetchState,
|
|
76
|
+
error: depositAccountListState.error,
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
fetchState: treasuryDetailState.fetchState,
|
|
80
|
+
error: treasuryDetailState.error,
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
fetchState: cashManagementOverviewState.banner.fetchState,
|
|
84
|
+
error: cashManagementOverviewState.banner.error,
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
fetchState: state.autoSweepFlowState.fetchState,
|
|
88
|
+
error: state.autoSweepFlowState.error,
|
|
89
|
+
},
|
|
90
|
+
]);
|
|
91
|
+
const treasuryBalance = treasuryDetailState.accountSummary?.totalBalance ?? zeroAmount();
|
|
92
|
+
const cashBalance = sumCashBalances(paymentAccountListState.paymentAccountIds, paymentAccountState, depositAccountListState.accountIds, depositAccountState);
|
|
93
|
+
const totalCash = addAmounts(treasuryBalance, cashBalance);
|
|
94
|
+
const bannerData = cashManagementOverviewState.banner.data;
|
|
95
|
+
const inflowEvents = bannerData?.inflows ?? [];
|
|
96
|
+
const outflowEvents = bannerData?.outflows ?? [];
|
|
97
|
+
const totalInFlow = sumEventAmounts(inflowEvents);
|
|
98
|
+
const totalOutFlow = sumEventAmounts(outflowEvents);
|
|
99
|
+
const cashflow = subtractAmounts(totalInFlow, totalOutFlow);
|
|
100
|
+
const projectionData = buildProjectionData(cashBalance, inflowEvents, outflowEvents);
|
|
101
|
+
return {
|
|
102
|
+
banner: getCashManagementOverviewBanner(state),
|
|
103
|
+
cashBalance,
|
|
104
|
+
cashflow,
|
|
105
|
+
inflowEvents,
|
|
106
|
+
outflowEvents,
|
|
107
|
+
projectionData,
|
|
108
|
+
totalCash,
|
|
109
|
+
totalInFlow,
|
|
110
|
+
totalOutFlow,
|
|
111
|
+
treasuryBalance,
|
|
112
|
+
fetchState: aggregate.fetchState,
|
|
113
|
+
error: aggregate.error,
|
|
114
|
+
version: 0,
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Walks the inflow / outflow events in chronological order, stepping the
|
|
119
|
+
* running balance from today's `cashBalance`. Emits a point per event so the
|
|
120
|
+
* chart can render colored markers at each cash event. Events with the same
|
|
121
|
+
* payment date are kept as separate steps (preserves the marker count even
|
|
122
|
+
* if Recharts overlays them at the same X position).
|
|
123
|
+
*/
|
|
124
|
+
const buildProjectionData = (cashBalance, inflowEvents, outflowEvents) => {
|
|
125
|
+
const events = [
|
|
126
|
+
...inflowEvents.map((e) => ({
|
|
127
|
+
amount: e.amount,
|
|
128
|
+
date: e.paymentDate,
|
|
129
|
+
isInflow: true,
|
|
130
|
+
})),
|
|
131
|
+
...outflowEvents.map((e) => ({
|
|
132
|
+
amount: e.amount,
|
|
133
|
+
date: e.paymentDate,
|
|
134
|
+
isInflow: false,
|
|
135
|
+
})),
|
|
136
|
+
].sort((a, b) => {
|
|
137
|
+
const diff = a.date.valueOf() - b.date.valueOf();
|
|
138
|
+
if (diff !== 0) {
|
|
139
|
+
return diff;
|
|
140
|
+
}
|
|
141
|
+
// Same-day tie-breaker: apply outflows before inflows so the projection
|
|
142
|
+
// shows the worst-case low first, then the recovery — matches the
|
|
143
|
+
// "show me the dip" framing on the cash management overview.
|
|
144
|
+
if (a.isInflow === b.isInflow) {
|
|
145
|
+
return 0;
|
|
146
|
+
}
|
|
147
|
+
return a.isInflow ? 1 : -1;
|
|
148
|
+
});
|
|
149
|
+
let balance = cashBalance;
|
|
150
|
+
const points = [{ balance, date: 'Today' }];
|
|
151
|
+
events.forEach((event) => {
|
|
152
|
+
balance = event.isInflow
|
|
153
|
+
? addAmounts(balance, event.amount)
|
|
154
|
+
: subtractAmounts(balance, event.amount);
|
|
155
|
+
points.push({
|
|
156
|
+
balance,
|
|
157
|
+
date: event.date.format('MMM D'),
|
|
158
|
+
isInflow: event.isInflow ? true : undefined,
|
|
159
|
+
isOutflow: event.isInflow ? undefined : true,
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
return points;
|
|
163
|
+
};
|
|
164
|
+
const sumEventAmounts = (events) => events.reduce((acc, event) => addAmounts(acc, event.amount), zeroAmount());
|
|
165
|
+
/**
|
|
166
|
+
* Subtracts `b` from `a`, sharing the currency-match guard with `addAmounts`.
|
|
167
|
+
* Used to compute net cash flow (`inflow - outflow`).
|
|
168
|
+
*/
|
|
169
|
+
const subtractAmounts = (a, b) => {
|
|
170
|
+
if (isZeroAmount(b)) {
|
|
171
|
+
return { ...a };
|
|
172
|
+
}
|
|
173
|
+
if (isZeroAmount(a)) {
|
|
174
|
+
return { ...b, amount: -b.amount };
|
|
175
|
+
}
|
|
176
|
+
if (a.currencyCode !== b.currencyCode ||
|
|
177
|
+
a.currencySymbol !== b.currencySymbol) {
|
|
178
|
+
console.warn(`cashManagementOverview: skipping balance with mismatched currency. Expected ${a.currencyCode} (${a.currencySymbol}), got ${b.currencyCode} (${b.currencySymbol}).`);
|
|
179
|
+
return a;
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
amount: a.amount - b.amount,
|
|
183
|
+
currencyCode: a.currencyCode,
|
|
184
|
+
currencySymbol: a.currencySymbol,
|
|
185
|
+
};
|
|
186
|
+
};
|
|
187
|
+
const isZeroAmount = (a) => a.amount === 0 && a.currencyCode === 'USD' && a.currencySymbol === '$';
|
|
188
|
+
/**
|
|
189
|
+
* Adds two Amounts. Currencies must match (the seeded zeroAmount() counts as
|
|
190
|
+
* "no currency yet" and adopts `b`'s currency). Mismatches return `a`
|
|
191
|
+
* unchanged and warn — mixing currencies in a total is a bug, not silent
|
|
192
|
+
* conversion.
|
|
193
|
+
*/
|
|
194
|
+
const addAmounts = (a, b) => {
|
|
195
|
+
if (isZeroAmount(a)) {
|
|
196
|
+
return { ...b };
|
|
197
|
+
}
|
|
198
|
+
if (a.currencyCode !== b.currencyCode ||
|
|
199
|
+
a.currencySymbol !== b.currencySymbol) {
|
|
200
|
+
console.warn(`cashManagementOverview: skipping balance with mismatched currency. Expected ${a.currencyCode} (${a.currencySymbol}), got ${b.currencyCode} (${b.currencySymbol}).`);
|
|
201
|
+
return a;
|
|
202
|
+
}
|
|
203
|
+
return {
|
|
204
|
+
amount: a.amount + b.amount,
|
|
205
|
+
currencyCode: a.currencyCode,
|
|
206
|
+
currencySymbol: a.currencySymbol,
|
|
207
|
+
};
|
|
208
|
+
};
|
|
209
|
+
const sumCashBalances = (paymentAccountIds, paymentAccountState, depositAccountIds, depositAccountState) => {
|
|
210
|
+
let total = zeroAmount();
|
|
211
|
+
paymentAccountIds.forEach((id) => {
|
|
212
|
+
const balance = paymentAccountState.paymentAccountByID[id]?.balances
|
|
213
|
+
?.available;
|
|
214
|
+
if (balance != null) {
|
|
215
|
+
total = addAmounts(total, balance);
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
depositAccountIds.forEach((id) => {
|
|
219
|
+
const balance = depositAccountState.depositAccountByID[id]?.accountBalance?.available;
|
|
220
|
+
if (balance != null) {
|
|
221
|
+
total = addAmounts(total, balance);
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
return total;
|
|
225
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { from } from 'rxjs';
|
|
2
|
+
import { filter, mergeMap } from 'rxjs/operators';
|
|
3
|
+
import { fetchCashManagementSettings } from '../../autoSweepFlow/autoSweepFlowReducer';
|
|
4
|
+
import { fetchCashManagementBanner, fetchCashManagementRecommendation, fetchRecentTransfer, } from '../cashManagementOverviewReducer';
|
|
5
|
+
export const fetchCashManagementBannerEpic = (actions$, state$) => actions$.pipe(filter(fetchCashManagementBanner.match), mergeMap((action) => {
|
|
6
|
+
const { cacheOverride } = action.payload;
|
|
7
|
+
const state = state$.value;
|
|
8
|
+
const actions = [];
|
|
9
|
+
if (cacheOverride === true ||
|
|
10
|
+
needsFetch(state.cashManagementOverviewState.banner.fetchState)) {
|
|
11
|
+
actions.push(fetchCashManagementRecommendation());
|
|
12
|
+
}
|
|
13
|
+
if (cacheOverride === true ||
|
|
14
|
+
needsFetch(state.autoSweepFlowState.fetchState)) {
|
|
15
|
+
actions.push(fetchCashManagementSettings());
|
|
16
|
+
}
|
|
17
|
+
if (cacheOverride === true ||
|
|
18
|
+
needsFetch(state.cashManagementOverviewState.recentTransfer.fetchState)) {
|
|
19
|
+
actions.push(fetchRecentTransfer());
|
|
20
|
+
}
|
|
21
|
+
return from(actions);
|
|
22
|
+
}));
|
|
23
|
+
const needsFetch = (fetchState) => fetchState !== 'Completed' && fetchState !== 'In-Progress';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { concat, from } from 'rxjs';
|
|
2
|
+
import { filter, mergeMap } from 'rxjs/operators';
|
|
3
|
+
import { fetchAutoTransferRules } from '../../../autotransferRules/autoTransferRulesReducer';
|
|
4
|
+
import { fetchTreasuryOverviewDetail } from '../../../treasury/treasuryList/treasuryDetailReducer';
|
|
5
|
+
import { fetchZeniAccountList } from '../../../zeniAccounts/zeniAccountList/zeniAccountListReducer';
|
|
6
|
+
import { fetchCashManagementBanner, fetchCashManagementOverviewPage, } from '../cashManagementOverviewReducer';
|
|
7
|
+
export const fetchCashManagementOverviewPageEpic = (actions$, state$) => actions$.pipe(filter(fetchCashManagementOverviewPage.match), mergeMap((action) => {
|
|
8
|
+
const { cacheOverride } = action.payload;
|
|
9
|
+
const state = state$.value;
|
|
10
|
+
const pageActions = [];
|
|
11
|
+
if (cacheOverride === true) {
|
|
12
|
+
// Banner orchestrator (fetchCashManagementBannerEpic) fans out to
|
|
13
|
+
// recommendation + settings + recent-transfer internally.
|
|
14
|
+
pageActions.push(fetchTreasuryOverviewDetail(true), fetchZeniAccountList(true), fetchCashManagementBanner(true), fetchAutoTransferRules(true));
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
const treasuryDetailState = state.treasuryDetailState;
|
|
18
|
+
if (treasuryDetailState.hasValidState() === false &&
|
|
19
|
+
treasuryDetailState.fetchState !== 'In-Progress') {
|
|
20
|
+
pageActions.push(fetchTreasuryOverviewDetail(false));
|
|
21
|
+
}
|
|
22
|
+
// zeniAccountListState has no top-level fetchState to dedup against
|
|
23
|
+
// (only `newCheckingAccount.fetchState`), and the downstream epic is
|
|
24
|
+
// cheap. Always re-dispatch so the summary stays fresh on page entry.
|
|
25
|
+
pageActions.push(fetchZeniAccountList(false));
|
|
26
|
+
// Banner orchestrator handles its own per-slice dedup across
|
|
27
|
+
// recommendation, settings, and recent-transfer.
|
|
28
|
+
pageActions.push(fetchCashManagementBanner(false));
|
|
29
|
+
const autoTransferRules = state.autotransferRulesState;
|
|
30
|
+
if (autoTransferRules.fetchState !== 'Completed' &&
|
|
31
|
+
autoTransferRules.fetchState !== 'In-Progress') {
|
|
32
|
+
pageActions.push(fetchAutoTransferRules(false));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return concat(from(pageActions));
|
|
36
|
+
}));
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { of } from 'rxjs';
|
|
2
|
+
import { catchError, filter, mergeMap, switchMap } from 'rxjs/operators';
|
|
3
|
+
import { createZeniAPIStatus, isSuccessResponse, } from '../../../../../responsePayload';
|
|
4
|
+
import { fetchCashManagementRecommendation, updateCashManagementRecommendation, updateCashManagementRecommendationFetchStatus, } from '../cashManagementOverviewReducer';
|
|
5
|
+
/**
|
|
6
|
+
* Hits the cash agent's recommend endpoint and stores the full response on
|
|
7
|
+
* the banner state — `inflows[]`, `outflows[]`, and `money_movements[]` all
|
|
8
|
+
* live there, so consumers can read them directly without an entity-bucket
|
|
9
|
+
* lookup.
|
|
10
|
+
*/
|
|
11
|
+
const DEFAULT_RECOMMEND_HORIZON_DAYS = 30;
|
|
12
|
+
export const fetchCashManagementRecommendationEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(fetchCashManagementRecommendation.match), switchMap(() => {
|
|
13
|
+
const endpoint = `${zeniAPI.apiEndPoints.cashManagementAgentBaseUrl}/1.0/cash-agent/recommend?horizon_days=${DEFAULT_RECOMMEND_HORIZON_DAYS}`;
|
|
14
|
+
return zeniAPI.getJSON(endpoint).pipe(mergeMap((response) => {
|
|
15
|
+
if (isSuccessResponse(response) && response.data != null) {
|
|
16
|
+
return of(updateCashManagementRecommendation({ data: response.data }));
|
|
17
|
+
}
|
|
18
|
+
return of(updateCashManagementRecommendationFetchStatus({
|
|
19
|
+
fetchState: 'Error',
|
|
20
|
+
error: response.status,
|
|
21
|
+
}));
|
|
22
|
+
}), catchError((error) => of(updateCashManagementRecommendationFetchStatus({
|
|
23
|
+
fetchState: 'Error',
|
|
24
|
+
error: createZeniAPIStatus('Unexpected Error', 'Fetch cash management recommendation REST API call errored out: ' +
|
|
25
|
+
(error?.message ?? String(error))),
|
|
26
|
+
}))));
|
|
27
|
+
}));
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { of } from 'rxjs';
|
|
2
|
+
import { catchError, filter, mergeMap, switchMap } from 'rxjs/operators';
|
|
3
|
+
import { createZeniAPIStatus, isSuccessResponse, } from '../../../../../responsePayload';
|
|
4
|
+
import { fetchRecentTransfer, updateRecentTransfer, updateRecentTransferFetchStatus, } from '../cashManagementOverviewReducer';
|
|
5
|
+
/**
|
|
6
|
+
* Hits `GET /cash-management/transfers` and stores the most recent actual
|
|
7
|
+
* cash-management transfer on `recentTransfer.data`. Used by the banner
|
|
8
|
+
* surface to render the "transfer scheduled / in-progress / complete"
|
|
9
|
+
* variant for existing users who have a settings id. The API returns the
|
|
10
|
+
* single most-relevant transfer under `transfer`; that field is optional
|
|
11
|
+
* (fresh users with no transfer history get `undefined`).
|
|
12
|
+
*/
|
|
13
|
+
export const fetchRecentTransferEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(fetchRecentTransfer.match), switchMap(() => {
|
|
14
|
+
const endpoint = `${zeniAPI.apiEndPoints.cashManagementAgentBaseUrl}/1.0/cash-management/transfers/latest`;
|
|
15
|
+
return zeniAPI.getJSON(endpoint).pipe(mergeMap((response) => {
|
|
16
|
+
if (isSuccessResponse(response) && response.data != null) {
|
|
17
|
+
return of(updateRecentTransfer({ data: response.data.transfer }));
|
|
18
|
+
}
|
|
19
|
+
return of(updateRecentTransferFetchStatus({
|
|
20
|
+
fetchState: 'Error',
|
|
21
|
+
error: response.status,
|
|
22
|
+
}));
|
|
23
|
+
}), catchError((error) => of(updateRecentTransferFetchStatus({
|
|
24
|
+
fetchState: 'Error',
|
|
25
|
+
error: createZeniAPIStatus('Unexpected Error', 'Fetch recent cash-management transfer REST API call errored out: ' +
|
|
26
|
+
(error?.message ?? String(error))),
|
|
27
|
+
}))));
|
|
28
|
+
}));
|
package/lib/index.d.ts
CHANGED
|
@@ -38,7 +38,7 @@ import { TimeframeTick, TimeframeTickWithMetaData, mapTimePeriodtoTimeframeTick,
|
|
|
38
38
|
import { AgingDateSelectionType, AgingDetailReportInvoice, AgingDetailReportUIState, AgingReportId, AgingReportInvoice, AgingReportSortKey, AgingReportUIState } from './commonStateTypes/viewAndReport/agingReportStateTypes';
|
|
39
39
|
import { isAgingReport, isCashFlowOrBalanceSheetReport, isDashboardClassesViewReport, isDashboardReport, isFluxAnalysisOpExReport, isOpExByVendorReport, isPAndLClassesViewReport, isPAndLProjectViewReport, isPAndLReport } from './commonStateTypes/viewAndReport/reportIDHelper';
|
|
40
40
|
import { PageToken, Report, ReportFormat, ReportID, ReportIDPlusForecastID, SelectorReport, SelectorView, View, toReportFormatStrict, toReportID } from './commonStateTypes/viewAndReport/viewAndReport';
|
|
41
|
-
import { PAYMENT_BUSINESS_DAYS, filterDays, getNextNthWorkingDay, getPreviousNthWorkingDay, getYearsList, holidaysFormatted, isHoliday, isHolidayToday } from './commonStateTypes/workingDayHelper';
|
|
41
|
+
import { PAYMENT_BUSINESS_DAYS, filterDays, getNextNthWorkingDay, getNextTransferDate, getPreviousNthWorkingDay, getYearsList, holidaysFormatted, isHoliday, isHolidayToday } from './commonStateTypes/workingDayHelper';
|
|
42
42
|
import { AccountFilterOption, AccountReport, AccountWithBalanceReport, getAllAccounts, getTransactionFilterAccountOptions } from './entity/account/accountSelector';
|
|
43
43
|
import { Account, AccountBase, AccountType, RecommendedAccountBase, ReconciliationAccountSourceType, StatementCloseDay, toAccountType, toReconciliationAccountSource } from './entity/account/accountState';
|
|
44
44
|
import { NestedAccountReport } from './entity/account/subAccountSelector';
|
|
@@ -830,7 +830,7 @@ export { Merchant };
|
|
|
830
830
|
export { fetchEditRemiDetailPage, fetchRecommendationsAndUpdateMerchantRecommendations, fetchRemiAndInitializeLocalStore, initializeRemiToLocalStore, saveRemiUpdatesToLocalStore, fetchCurrencyConversionValue, discardRemiUpdatesInLocalStore, removeFileFromRemiUpdatesInLocalStore, saveRemiDetail, saveRemiSuccessOrFailure, parseReceiptsToRemi, clearEditRemiViewDetail, updateAddRemiAutoFields, updateUploadFetchState, updateTentativeMerchantNames, clearTentativeMerchantName, updateReimbursementType, updateHomeCurrencyConversion, clearAddRemiAutoFields, };
|
|
831
831
|
export { AnimationFileName };
|
|
832
832
|
export { reduceFetchState, reduceFetchStateParallelTimeframes, reduceAnyFetchState, reduceAllFetchState, reduceAnyCompletedFetchState, isAnyFetchInProgress, isAllFetchCompleted, SortOrder, ALL_FILE_TYPES, FileType, toFileTypeStrict, };
|
|
833
|
-
export { getNextNthWorkingDay, getPreviousNthWorkingDay, isHolidayToday, filterDays, getYearsList, isHoliday, holidaysFormatted, PAYMENT_BUSINESS_DAYS, };
|
|
833
|
+
export { getNextNthWorkingDay, getNextTransferDate, getPreviousNthWorkingDay, isHolidayToday, filterDays, getYearsList, isHoliday, holidaysFormatted, PAYMENT_BUSINESS_DAYS, };
|
|
834
834
|
export { CustomerRatingCodeType, TeamRatingCodeType };
|
|
835
835
|
export { CustomerSatisfactionInfo };
|
|
836
836
|
export { fetchCompanyOnboardingView, fetchQBOConnectionPool, updateQBOConnectionPoolExternalConnection, fetchOnboardingCompletedCompanies, saveOnboardingCustomerCompletedStatus, ProductType, ProductGroupType, toProductType, toProductTypeStrict, ProductInfo, getOnboardingCockpitView, getNewOnboardingCustomerView, getOnboardingEmailGroup, initializeOnboardingCustomerViewUpdateData, clearOnboardingCustomerViewUpdateData, saveOnboardingCustomerViewUpdateData, updateOnboardingCustomerListUIState, updateCustomerCreationStatus, updateStatusAfterOnboardingCompleted, saveOnboardingCustomerViewUpdates, saveOnboardingCustomerNotes, saveOnboardingCustomerDataInLocalStore, updateOnboardingCustomerDataInLocalStore, NewOnboardingCustomer, OnboardingCustomer, OnboardingCockpitView, NewOnboardingCustomerView, NewOnboardingCustomerLocalData, OnboardingCustomerCompletedStatus, OnboardingCustomerListUIState, QBOConnectionPool, CustomerCreationStatus, OnboardingCompanyDetails, resetNewOnboardedCustomerId, sendOnboardingCustomerViewInvite, retryBankAccountConnectionForOnboarding, };
|
|
@@ -965,7 +965,7 @@ export { TreasuryTaxLettersSelectorView, getTreasuryTaxLetters, } from './view/s
|
|
|
965
965
|
export { TreasuryTransactionStatus } from './view/spendManagement/treasury/treasuryList/treasuryDetailPayload';
|
|
966
966
|
export { fetchAutoTransferRules, createAutoTransferRule, updateAutoTransferRule, deleteAutoTransferRule, fetchAutoTransferRuleHistory, fetchAutoTransferReviewDetail, updateRuleLocalData, clearRuleUpdateLocalData, } from './view/spendManagement/autotransferRules/autoTransferRulesReducer';
|
|
967
967
|
export { AutoTransferRulesSelectorView, getAutoTransferRules, getAutoTransferRuleById, getAutoTransferRuleHistory, } from './view/spendManagement/autotransferRules/autoTransferRulesSelector';
|
|
968
|
-
export { AutoTransferRule } from './view/spendManagement/autotransferRules/autoTransferRulesState';
|
|
968
|
+
export { AutoTransferRule, CashManagementRule, } from './view/spendManagement/autotransferRules/autoTransferRulesState';
|
|
969
969
|
export { AutoTransferRuleType, AutoTransferRuleFrequency, AutoTransferRuleLocalData, } from './view/spendManagement/autotransferRules/autoTransferRulesPayload';
|
|
970
970
|
export type { TransactionActivityLog } from './entity/transactionActivityLog/transactionActivityLogState';
|
|
971
971
|
export { BULK_UPLOAD_AUTOMATCHING_TIMEOUT_MS, BULK_UPLOAD_BAR_COMPLETE_HOLD_MS, } from './view/expenseAutomationView/helpers/bulkUploadTiming';
|
|
@@ -975,3 +975,12 @@ export { UserGroup } from './entity/userGroups/userGroupsState';
|
|
|
975
975
|
export { SessionManager } from './entity/tenant/SessionManager';
|
|
976
976
|
export type { SessionCallbacks, SessionConfig, } from './entity/tenant/sessionTypes';
|
|
977
977
|
export { DEFAULT_SESSION_CONFIG } from './entity/tenant/sessionTypes';
|
|
978
|
+
export { fetchCashManagementBanner, fetchCashManagementOverviewPage, } from './view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewReducer';
|
|
979
|
+
export { clearAutoSweepFlow, saveAutoSweepSettings, updateAutoSweepDraft, updateAutoSweepRisk, updateAutoSweepSettingsFetchStatus, updateCashManagementSettings, updateCashManagementSettingsFetchStatus, } from './view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowReducer';
|
|
980
|
+
export { getAutoSweepFlow } from './view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowSelector';
|
|
981
|
+
export type { AutoSweepFlowFormData, AutoSweepFlowSelectorView, } from './view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowSelector';
|
|
982
|
+
export { RISK_BUFFER_AMOUNT, bufferAmountToRisk, } from './view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowState';
|
|
983
|
+
export type { AutoSweepFlowState, AutoSweepFrequency, RiskLevel, } from './view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowState';
|
|
984
|
+
export { getCashManagementOverview, getCashManagementOverviewBanner, } from './view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewSelector';
|
|
985
|
+
export type { CashManagementOverviewBannerSelectorView, CashManagementOverviewSelectorView, CashProjectionPoint, } from './view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewSelector';
|
|
986
|
+
export type { CashManagementScenario, CashManagementTransfer, CashManagementTransferStatus, UpcomingPaymentEvent, UpcomingPaymentEventAccountType, } from './view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewState';
|