@zeniai/client-epic-state 5.0.84-betaAK3 → 5.0.84-betaAS1

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.
Files changed (61) hide show
  1. package/lib/commonStateTypes/amount.d.ts +0 -1
  2. package/lib/commonStateTypes/amount.js +1 -3
  3. package/lib/commonStateTypes/workingDayHelper.d.ts +0 -9
  4. package/lib/commonStateTypes/workingDayHelper.js +1 -28
  5. package/lib/entity/tenant/clearAllEpic.d.ts +1 -3
  6. package/lib/entity/tenant/clearAllEpic.js +0 -4
  7. package/lib/epic.d.ts +1 -5
  8. package/lib/epic.js +1 -5
  9. package/lib/esm/commonStateTypes/amount.js +0 -1
  10. package/lib/esm/commonStateTypes/workingDayHelper.js +0 -26
  11. package/lib/esm/entity/tenant/clearAllEpic.js +0 -4
  12. package/lib/esm/epic.js +1 -5
  13. package/lib/esm/index.js +3 -8
  14. package/lib/esm/reducer.js +0 -6
  15. package/lib/esm/view/spendManagement/autotransferRules/autoTransferRulesSelector.js +2 -22
  16. package/lib/index.d.ts +6 -15
  17. package/lib/index.js +17 -37
  18. package/lib/reducer.d.ts +0 -6
  19. package/lib/reducer.js +0 -6
  20. package/lib/view/spendManagement/autotransferRules/autoTransferRulesSelector.d.ts +1 -8
  21. package/lib/view/spendManagement/autotransferRules/autoTransferRulesSelector.js +1 -21
  22. package/lib/view/spendManagement/autotransferRules/autoTransferRulesState.d.ts +0 -22
  23. package/lib/view/spendManagement/billPay/internationalWireVerification/internationalWireVerificationState.d.ts +16 -0
  24. package/lib/zeniAPI.d.ts +0 -1
  25. package/package.json +1 -1
  26. package/lib/esm/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowPayload.js +0 -31
  27. package/lib/esm/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowReducer.js +0 -69
  28. package/lib/esm/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowSelector.js +0 -29
  29. package/lib/esm/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowState.js +0 -47
  30. package/lib/esm/view/spendManagement/cashManagement/autoSweepFlow/epics/fetchCashManagementSettingsEpic.js +0 -34
  31. package/lib/esm/view/spendManagement/cashManagement/autoSweepFlow/epics/saveAutoSweepSettingsEpic.js +0 -32
  32. package/lib/esm/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewPayload.js +0 -41
  33. package/lib/esm/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewReducer.js +0 -44
  34. package/lib/esm/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewSelector.js +0 -193
  35. package/lib/esm/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewState.js +0 -5
  36. package/lib/esm/view/spendManagement/cashManagement/cashManagementOverview/epics/fetchCashManagementBannerEpic.js +0 -27
  37. package/lib/esm/view/spendManagement/cashManagement/cashManagementOverview/epics/fetchCashManagementOverviewPageEpic.js +0 -42
  38. package/lib/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowPayload.d.ts +0 -48
  39. package/lib/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowPayload.js +0 -36
  40. package/lib/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowReducer.d.ts +0 -21
  41. package/lib/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowReducer.js +0 -73
  42. package/lib/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowSelector.d.ts +0 -40
  43. package/lib/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowSelector.js +0 -33
  44. package/lib/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowState.d.ts +0 -37
  45. package/lib/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowState.js +0 -53
  46. package/lib/view/spendManagement/cashManagement/autoSweepFlow/epics/fetchCashManagementSettingsEpic.d.ts +0 -14
  47. package/lib/view/spendManagement/cashManagement/autoSweepFlow/epics/fetchCashManagementSettingsEpic.js +0 -38
  48. package/lib/view/spendManagement/cashManagement/autoSweepFlow/epics/saveAutoSweepSettingsEpic.d.ts +0 -7
  49. package/lib/view/spendManagement/cashManagement/autoSweepFlow/epics/saveAutoSweepSettingsEpic.js +0 -36
  50. package/lib/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewPayload.d.ts +0 -32
  51. package/lib/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewPayload.js +0 -46
  52. package/lib/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewReducer.d.ts +0 -15
  53. package/lib/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewReducer.js +0 -48
  54. package/lib/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewSelector.d.ts +0 -35
  55. package/lib/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewSelector.js +0 -198
  56. package/lib/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewState.d.ts +0 -75
  57. package/lib/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewState.js +0 -8
  58. package/lib/view/spendManagement/cashManagement/cashManagementOverview/epics/fetchCashManagementBannerEpic.d.ts +0 -7
  59. package/lib/view/spendManagement/cashManagement/cashManagementOverview/epics/fetchCashManagementBannerEpic.js +0 -31
  60. package/lib/view/spendManagement/cashManagement/cashManagementOverview/epics/fetchCashManagementOverviewPageEpic.d.ts +0 -10
  61. package/lib/view/spendManagement/cashManagement/cashManagementOverview/epics/fetchCashManagementOverviewPageEpic.js +0 -46
@@ -1,193 +0,0 @@
1
- import { zeroAmount } from '../../../../commonStateTypes/amount';
2
- import { reduceAllFetchState } from '../../../../commonStateTypes/reduceFetchState';
3
- /**
4
- * Default account type used when the recommend payload has no movement to
5
- * expose yet (e.g. before the first fetch resolves). Callers that care about
6
- * the movement should also gate on `fetchState === 'Completed'`.
7
- */
8
- const DEFAULT_BANK_ACCOUNT_TYPE = 'deposit_account';
9
- const DEFAULT_SUB_MOVEMENT_TYPE = 'push';
10
- export const getCashManagementOverviewBanner = (state) => {
11
- const { banner } = state.cashManagementOverviewState;
12
- const autoSweep = state.autoSweepFlowState;
13
- // The banner today surfaces a single recommended movement (the first one
14
- // returned by the agent). When the agent returns multiple groups/movements
15
- // we'll need to broaden this — for now consumers only render one.
16
- const movement = banner.data?.moneyMovements[0]?.movements[0];
17
- const aggregate = reduceAllFetchState([
18
- { fetchState: banner.fetchState, error: banner.error },
19
- { fetchState: autoSweep.fetchState, error: autoSweep.error },
20
- ]);
21
- return {
22
- fetchState: aggregate.fetchState,
23
- error: aggregate.error,
24
- amount: movement?.amount ?? zeroAmount(),
25
- cashManagementSettingsId: autoSweep.settingsId,
26
- destinationBankAccountId: movement?.destinationBankAccountId ?? '',
27
- destinationBankAccountType: movement?.destinationBankAccountType ?? DEFAULT_BANK_ACCOUNT_TYPE,
28
- reasoning: movement?.reasoning ?? '',
29
- sourceBankAccountId: movement?.sourceBankAccountId ?? '',
30
- sourceBankAccountType: movement?.sourceBankAccountType ?? DEFAULT_BANK_ACCOUNT_TYPE,
31
- subMovementType: movement?.subMovementType ?? DEFAULT_SUB_MOVEMENT_TYPE,
32
- version: 0,
33
- };
34
- };
35
- export const getCashManagementOverview = (state) => {
36
- const { cashManagementOverviewState, depositAccountListState, depositAccountState, paymentAccountListState, paymentAccountState, treasuryDetailState, } = state;
37
- const aggregate = reduceAllFetchState([
38
- {
39
- fetchState: paymentAccountListState.fetchState,
40
- error: paymentAccountListState.error,
41
- },
42
- {
43
- fetchState: depositAccountListState.fetchState,
44
- error: depositAccountListState.error,
45
- },
46
- {
47
- fetchState: treasuryDetailState.fetchState,
48
- error: treasuryDetailState.error,
49
- },
50
- {
51
- fetchState: cashManagementOverviewState.banner.fetchState,
52
- error: cashManagementOverviewState.banner.error,
53
- },
54
- {
55
- fetchState: state.autoSweepFlowState.fetchState,
56
- error: state.autoSweepFlowState.error,
57
- },
58
- ]);
59
- const treasuryBalance = treasuryDetailState.accountSummary?.totalBalance ?? zeroAmount();
60
- const cashBalance = sumCashBalances(paymentAccountListState.paymentAccountIds, paymentAccountState, depositAccountListState.accountIds, depositAccountState);
61
- const totalCash = addAmounts(treasuryBalance, cashBalance);
62
- const bannerData = cashManagementOverviewState.banner.data;
63
- const inflowEvents = bannerData?.inflows ?? [];
64
- const outflowEvents = bannerData?.outflows ?? [];
65
- const totalInFlow = sumEventAmounts(inflowEvents);
66
- const totalOutFlow = sumEventAmounts(outflowEvents);
67
- const cashflow = subtractAmounts(totalInFlow, totalOutFlow);
68
- const projectionData = buildProjectionData(cashBalance, inflowEvents, outflowEvents);
69
- return {
70
- banner: getCashManagementOverviewBanner(state),
71
- cashBalance,
72
- cashflow,
73
- inflowEvents,
74
- outflowEvents,
75
- projectionData,
76
- totalCash,
77
- totalInFlow,
78
- totalOutFlow,
79
- treasuryBalance,
80
- fetchState: aggregate.fetchState,
81
- error: aggregate.error,
82
- version: 0,
83
- };
84
- };
85
- /**
86
- * Walks the inflow / outflow events in chronological order, stepping the
87
- * running balance from today's `cashBalance`. Emits a point per event so the
88
- * chart can render colored markers at each cash event. Events with the same
89
- * payment date are kept as separate steps (preserves the marker count even
90
- * if Recharts overlays them at the same X position).
91
- */
92
- const buildProjectionData = (cashBalance, inflowEvents, outflowEvents) => {
93
- const events = [
94
- ...inflowEvents.map((e) => ({
95
- amount: e.amount,
96
- date: e.paymentDate,
97
- isInflow: true,
98
- })),
99
- ...outflowEvents.map((e) => ({
100
- amount: e.amount,
101
- date: e.paymentDate,
102
- isInflow: false,
103
- })),
104
- ].sort((a, b) => {
105
- const diff = a.date.valueOf() - b.date.valueOf();
106
- if (diff !== 0) {
107
- return diff;
108
- }
109
- // Same-day tie-breaker: apply outflows before inflows so the projection
110
- // shows the worst-case low first, then the recovery — matches the
111
- // "show me the dip" framing on the cash management overview.
112
- if (a.isInflow === b.isInflow) {
113
- return 0;
114
- }
115
- return a.isInflow ? 1 : -1;
116
- });
117
- let balance = cashBalance;
118
- const points = [{ balance, date: 'Today' }];
119
- events.forEach((event) => {
120
- balance = event.isInflow
121
- ? addAmounts(balance, event.amount)
122
- : subtractAmounts(balance, event.amount);
123
- points.push({
124
- balance,
125
- date: event.date.format('MMM D'),
126
- isInflow: event.isInflow ? true : undefined,
127
- isOutflow: event.isInflow ? undefined : true,
128
- });
129
- });
130
- return points;
131
- };
132
- const sumEventAmounts = (events) => events.reduce((acc, event) => addAmounts(acc, event.amount), zeroAmount());
133
- /**
134
- * Subtracts `b` from `a`, sharing the currency-match guard with `addAmounts`.
135
- * Used to compute net cash flow (`inflow - outflow`).
136
- */
137
- const subtractAmounts = (a, b) => {
138
- if (isZeroAmount(b)) {
139
- return { ...a };
140
- }
141
- if (isZeroAmount(a)) {
142
- return { ...b, amount: -b.amount };
143
- }
144
- if (a.currencyCode !== b.currencyCode ||
145
- a.currencySymbol !== b.currencySymbol) {
146
- console.warn(`cashManagementOverview: skipping balance with mismatched currency. Expected ${a.currencyCode} (${a.currencySymbol}), got ${b.currencyCode} (${b.currencySymbol}).`);
147
- return a;
148
- }
149
- return {
150
- amount: a.amount - b.amount,
151
- currencyCode: a.currencyCode,
152
- currencySymbol: a.currencySymbol,
153
- };
154
- };
155
- const isZeroAmount = (a) => a.amount === 0 && a.currencyCode === 'USD' && a.currencySymbol === '$';
156
- /**
157
- * Adds two Amounts. Currencies must match (the seeded zeroAmount() counts as
158
- * "no currency yet" and adopts `b`'s currency). Mismatches return `a`
159
- * unchanged and warn — mixing currencies in a total is a bug, not silent
160
- * conversion.
161
- */
162
- const addAmounts = (a, b) => {
163
- if (isZeroAmount(a)) {
164
- return { ...b };
165
- }
166
- if (a.currencyCode !== b.currencyCode ||
167
- a.currencySymbol !== b.currencySymbol) {
168
- console.warn(`cashManagementOverview: skipping balance with mismatched currency. Expected ${a.currencyCode} (${a.currencySymbol}), got ${b.currencyCode} (${b.currencySymbol}).`);
169
- return a;
170
- }
171
- return {
172
- amount: a.amount + b.amount,
173
- currencyCode: a.currencyCode,
174
- currencySymbol: a.currencySymbol,
175
- };
176
- };
177
- const sumCashBalances = (paymentAccountIds, paymentAccountState, depositAccountIds, depositAccountState) => {
178
- let total = zeroAmount();
179
- paymentAccountIds.forEach((id) => {
180
- const balance = paymentAccountState.paymentAccountByID[id]?.balances
181
- ?.available;
182
- if (balance != null) {
183
- total = addAmounts(total, balance);
184
- }
185
- });
186
- depositAccountIds.forEach((id) => {
187
- const balance = depositAccountState.depositAccountByID[id]?.accountBalance?.available;
188
- if (balance != null) {
189
- total = addAmounts(total, balance);
190
- }
191
- });
192
- return total;
193
- };
@@ -1,5 +0,0 @@
1
- export const initialCashManagementBannerState = {
2
- fetchState: 'Not-Started',
3
- error: undefined,
4
- data: undefined,
5
- };
@@ -1,27 +0,0 @@
1
- import { of } from 'rxjs';
2
- import { catchError, filter, mergeMap, switchMap } from 'rxjs/operators';
3
- import { createZeniAPIStatus, isSuccessResponse, } from '../../../../../responsePayload';
4
- import { fetchCashManagementBanner, updateCashManagementBanner, updateCashManagementBannerFetchStatus, } 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 fetchCashManagementBannerEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(fetchCashManagementBanner.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(updateCashManagementBanner({ data: response.data }));
17
- }
18
- return of(updateCashManagementBannerFetchStatus({
19
- fetchState: 'Error',
20
- error: response.status,
21
- }));
22
- }), catchError((error) => of(updateCashManagementBannerFetchStatus({
23
- fetchState: 'Error',
24
- error: createZeniAPIStatus('Unexpected Error', 'Fetch cash management banner REST API call errored out: ' +
25
- (error?.message ?? String(error))),
26
- }))));
27
- }));
@@ -1,42 +0,0 @@
1
- import { concat, from } from 'rxjs';
2
- import { filter, mergeMap } from 'rxjs/operators';
3
- import { fetchAutoTransferRules } from '../../../autotransferRules/autoTransferRulesReducer';
4
- import { fetchCashManagementSettings } from '../../autoSweepFlow/autoSweepFlowReducer';
5
- import { fetchTreasuryOverviewDetail } from '../../../treasury/treasuryList/treasuryDetailReducer';
6
- import { fetchZeniAccountList } from '../../../zeniAccounts/zeniAccountList/zeniAccountListReducer';
7
- import { fetchCashManagementBanner, fetchCashManagementOverviewPage, } from '../cashManagementOverviewReducer';
8
- export const fetchCashManagementOverviewPageEpic = (actions$, state$) => actions$.pipe(filter(fetchCashManagementOverviewPage.match), mergeMap((action) => {
9
- const { cacheOverride } = action.payload;
10
- const state = state$.value;
11
- const pageActions = [];
12
- if (cacheOverride === true) {
13
- pageActions.push(fetchTreasuryOverviewDetail(true), fetchZeniAccountList(true), fetchCashManagementBanner(), fetchCashManagementSettings(), fetchAutoTransferRules(true));
14
- }
15
- else {
16
- const treasuryDetailState = state.treasuryDetailState;
17
- if (treasuryDetailState.hasValidState() === false &&
18
- treasuryDetailState.fetchState !== 'In-Progress') {
19
- pageActions.push(fetchTreasuryOverviewDetail(false));
20
- }
21
- // zeniAccountListState has no top-level fetchState to dedup against
22
- // (only `newCheckingAccount.fetchState`), and the downstream epic is
23
- // cheap. Always re-dispatch so the summary stays fresh on page entry.
24
- pageActions.push(fetchZeniAccountList(false));
25
- const banner = state.cashManagementOverviewState.banner;
26
- if (banner.fetchState !== 'Completed' &&
27
- banner.fetchState !== 'In-Progress') {
28
- pageActions.push(fetchCashManagementBanner());
29
- }
30
- const autoSweep = state.autoSweepFlowState;
31
- if (autoSweep.fetchState !== 'Completed' &&
32
- autoSweep.fetchState !== 'In-Progress') {
33
- pageActions.push(fetchCashManagementSettings());
34
- }
35
- const autoTransferRules = state.autotransferRulesState;
36
- if (autoTransferRules.fetchState !== 'Completed' &&
37
- autoTransferRules.fetchState !== 'In-Progress') {
38
- pageActions.push(fetchAutoTransferRules(false));
39
- }
40
- }
41
- return concat(from(pageActions));
42
- }));
@@ -1,48 +0,0 @@
1
- import { Amount } from '../../../../commonStateTypes/amount';
2
- import { ID } from '../../../../commonStateTypes/common';
3
- import { DepositAccountPayload } from '../../../../entity/depositAccount/depositAccountPayload';
4
- import { ZeniAPIResponse } from '../../../../responsePayload';
5
- import { ZeniDate } from '../../../../zeniDayJS';
6
- import { AutoSweepFlowState, AutoSweepFrequency } from './autoSweepFlowState';
7
- /**
8
- * Body sent to `PUT /cash-management/settings`. Field names match the
9
- * cash-management-agent contract; `minimum_buffer_usd` is a plain number
10
- * (the slice tracks the canonical `Amount` value).
11
- */
12
- export type SaveAutoSweepSettingsBody = {
13
- first_run_date: string;
14
- frequency: string;
15
- memo: string;
16
- minimum_buffer_usd: number;
17
- };
18
- export type SaveAutoSweepSettingsResponse = ZeniAPIResponse<unknown>;
19
- export declare const toSaveAutoSweepSettingsBody: (state: Pick<AutoSweepFlowState, "bufferAmount" | "frequency" | "memo">) => SaveAutoSweepSettingsBody;
20
- /**
21
- * `source_bank_account` on the cash-management settings response matches the
22
- * shared `DepositAccountPayload` shape, so the fetch epic dispatches it into
23
- * the deposit-account entity bucket and the auto-sweep slice only keeps the
24
- * id. The selector hydrates the full `FundingAccount` on read.
25
- */
26
- export interface CashManagementSettingsPayload {
27
- cash_management_settings_id: string | null;
28
- frequency: string;
29
- minimum_buffer_usd: number;
30
- next_transfer_date: string;
31
- source_bank_account: DepositAccountPayload;
32
- }
33
- export type CashManagementSettingsResponse = ZeniAPIResponse<CashManagementSettingsPayload>;
34
- /**
35
- * Map a `GET /cash-management/settings` payload into the slice's writable
36
- * fields. Defensive on the frequency (string-from-the-wire → union via
37
- * `toAutoSweepFrequency`, falling back to `'weekly'` if the server returns
38
- * something we don't model yet). Only the source account *id* is stored
39
- * here — the full deposit-account payload is published to the entity bucket
40
- * by the fetch epic.
41
- */
42
- export declare const toAutoSweepFlowStatePatch: (payload: CashManagementSettingsPayload) => {
43
- bufferAmount: Amount;
44
- frequency: AutoSweepFrequency;
45
- nextTransferDate?: ZeniDate;
46
- primaryFundingAccountId?: ID;
47
- settingsId?: ID;
48
- };
@@ -1,36 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toAutoSweepFlowStatePatch = exports.toSaveAutoSweepSettingsBody = void 0;
4
- const amount_1 = require("../../../../commonStateTypes/amount");
5
- const workingDayHelper_1 = require("../../../../commonStateTypes/workingDayHelper");
6
- const zeniDayJS_1 = require("../../../../zeniDayJS");
7
- const autoSweepFlowState_1 = require("./autoSweepFlowState");
8
- const toSaveAutoSweepSettingsBody = (state) => ({
9
- first_run_date: (0, workingDayHelper_1.getNextTransferDate)(state.frequency).format('YYYY-MM-DD'),
10
- frequency: state.frequency,
11
- memo: state.memo,
12
- minimum_buffer_usd: state.bufferAmount.amount,
13
- });
14
- exports.toSaveAutoSweepSettingsBody = toSaveAutoSweepSettingsBody;
15
- /**
16
- * Map a `GET /cash-management/settings` payload into the slice's writable
17
- * fields. Defensive on the frequency (string-from-the-wire → union via
18
- * `toAutoSweepFrequency`, falling back to `'weekly'` if the server returns
19
- * something we don't model yet). Only the source account *id* is stored
20
- * here — the full deposit-account payload is published to the entity bucket
21
- * by the fetch epic.
22
- */
23
- const toAutoSweepFlowStatePatch = (payload) => {
24
- const currencyCode = payload.source_bank_account.balances?.currency_code;
25
- const currencySymbol = payload.source_bank_account.balances?.currency_symbol;
26
- return {
27
- bufferAmount: (0, amount_1.toAmount)(payload.minimum_buffer_usd, currencyCode ?? 'USD', currencySymbol ?? '$'),
28
- frequency: (0, autoSweepFlowState_1.toAutoSweepFrequency)(payload.frequency) ?? 'weekly',
29
- nextTransferDate: payload.next_transfer_date != null && payload.next_transfer_date !== ''
30
- ? (0, zeniDayJS_1.date)(payload.next_transfer_date)
31
- : undefined,
32
- primaryFundingAccountId: payload.source_bank_account.deposit_account_id ?? undefined,
33
- settingsId: payload.cash_management_settings_id ?? undefined,
34
- };
35
- };
36
- exports.toAutoSweepFlowStatePatch = toAutoSweepFlowStatePatch;
@@ -1,21 +0,0 @@
1
- import { Amount } from '../../../../commonStateTypes/amount';
2
- import { FetchState } from '../../../../commonStateTypes/common';
3
- import { ZeniAPIStatus } from '../../../../responsePayload';
4
- import { CashManagementSettingsPayload } from './autoSweepFlowPayload';
5
- import { AutoSweepFlowState, AutoSweepFrequency } from './autoSweepFlowState';
6
- export declare const initialState: AutoSweepFlowState;
7
- export declare const fetchCashManagementSettings: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"autoSweepFlow/fetchCashManagementSettings">, updateCashManagementSettings: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
8
- data: CashManagementSettingsPayload;
9
- }, "autoSweepFlow/updateCashManagementSettings">, updateCashManagementSettingsFetchStatus: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
10
- fetchState: FetchState;
11
- error?: ZeniAPIStatus;
12
- }, "autoSweepFlow/updateCashManagementSettingsFetchStatus">, updateAutoSweepDraft: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
13
- bufferAmount: Amount;
14
- frequency: AutoSweepFrequency;
15
- memo: string;
16
- }, "autoSweepFlow/updateAutoSweepDraft">, saveAutoSweepSettings: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"autoSweepFlow/saveAutoSweepSettings">, updateAutoSweepSettingsFetchStatus: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
17
- fetchState: FetchState;
18
- error?: ZeniAPIStatus;
19
- }, "autoSweepFlow/updateAutoSweepSettingsFetchStatus">, clearAutoSweepFlow: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"autoSweepFlow/clearAutoSweepFlow">;
20
- declare const _default: import("redux").Reducer<AutoSweepFlowState>;
21
- export default _default;
@@ -1,73 +0,0 @@
1
- "use strict";
2
- var _a;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.clearAutoSweepFlow = exports.updateAutoSweepSettingsFetchStatus = exports.saveAutoSweepSettings = exports.updateAutoSweepDraft = exports.updateCashManagementSettingsFetchStatus = exports.updateCashManagementSettings = exports.fetchCashManagementSettings = exports.initialState = void 0;
5
- const toolkit_1 = require("@reduxjs/toolkit");
6
- const autoSweepFlowPayload_1 = require("./autoSweepFlowPayload");
7
- const autoSweepFlowState_1 = require("./autoSweepFlowState");
8
- exports.initialState = autoSweepFlowState_1.initialAutoSweepFlowState;
9
- const autoSweepFlow = (0, toolkit_1.createSlice)({
10
- name: 'autoSweepFlow',
11
- initialState: exports.initialState,
12
- reducers: {
13
- /**
14
- * Kicks off `GET /cash-management/settings`. Flips the top-level
15
- * fetchState to `In-Progress`; the fetch epic picks this up.
16
- */
17
- fetchCashManagementSettings(draft) {
18
- draft.fetchState = 'In-Progress';
19
- draft.error = undefined;
20
- },
21
- /**
22
- * Hydrates the form fields with the server-side settings (and stashes
23
- * the settings id for subsequent saves). Marks the GET as `Completed`.
24
- */
25
- updateCashManagementSettings(draft, action) {
26
- const patch = (0, autoSweepFlowPayload_1.toAutoSweepFlowStatePatch)(action.payload.data);
27
- draft.bufferAmount = patch.bufferAmount;
28
- draft.frequency = patch.frequency;
29
- draft.nextTransferDate = patch.nextTransferDate;
30
- draft.primaryFundingAccountId = patch.primaryFundingAccountId;
31
- draft.settingsId = patch.settingsId;
32
- draft.fetchState = 'Completed';
33
- draft.error = undefined;
34
- },
35
- updateCashManagementSettingsFetchStatus(draft, action) {
36
- draft.fetchState = action.payload.fetchState;
37
- draft.error = action.payload.error;
38
- },
39
- /**
40
- * Stage the in-flight form values without submitting them — fired from
41
- * the setup→review transition so other selectors (and devtools) can see
42
- * what the user is about to confirm. Leaves `saveStatus` untouched; the
43
- * actual PUT only kicks off when the user clicks "Confirm Sweep" via
44
- * `saveAutoSweepSettings`.
45
- */
46
- updateAutoSweepDraft(draft, action) {
47
- draft.bufferAmount = action.payload.bufferAmount;
48
- draft.frequency = action.payload.frequency;
49
- draft.memo = action.payload.memo;
50
- },
51
- /**
52
- * Trigger the PUT for the auto-sweep settings already staged via
53
- * `updateAutoSweepDraft`. Carries no payload — flips `saveStatus` to
54
- * `In-Progress` and the save epic reads `bufferAmount` / `frequency` /
55
- * `memo` straight from the slice. Callers must ensure those fields
56
- * reflect the user's latest input before dispatching.
57
- */
58
- saveAutoSweepSettings(draft) {
59
- draft.saveStatus = { fetchState: 'In-Progress', error: undefined };
60
- },
61
- updateAutoSweepSettingsFetchStatus(draft, action) {
62
- draft.saveStatus = {
63
- fetchState: action.payload.fetchState,
64
- error: action.payload.error,
65
- };
66
- },
67
- clearAutoSweepFlow() {
68
- return autoSweepFlowState_1.initialAutoSweepFlowState;
69
- },
70
- },
71
- });
72
- _a = autoSweepFlow.actions, exports.fetchCashManagementSettings = _a.fetchCashManagementSettings, exports.updateCashManagementSettings = _a.updateCashManagementSettings, exports.updateCashManagementSettingsFetchStatus = _a.updateCashManagementSettingsFetchStatus, exports.updateAutoSweepDraft = _a.updateAutoSweepDraft, exports.saveAutoSweepSettings = _a.saveAutoSweepSettings, exports.updateAutoSweepSettingsFetchStatus = _a.updateAutoSweepSettingsFetchStatus, exports.clearAutoSweepFlow = _a.clearAutoSweepFlow;
73
- exports.default = autoSweepFlow.reducer;
@@ -1,40 +0,0 @@
1
- import { Amount } from '../../../../commonStateTypes/amount';
2
- import { FetchStateAndError, ID } from '../../../../commonStateTypes/common';
3
- import { SelectorView } from '../../../../commonStateTypes/viewAndReport/viewAndReport';
4
- import { RootState } from '../../../../reducer';
5
- import { FundingAccount } from '../../commonSetup/setupViewSelector';
6
- import { TreasurySummaryWithBalance } from '../../treasury/treasuryList/treasuryDetailState';
7
- import { AutoSweepFrequency, RiskLevel } from './autoSweepFlowState';
8
- /**
9
- * The editable form state behind `<AutoSweepSetupPage>`. Kept as a nested
10
- * object on the selector view so the screen can pass it through as a single
11
- * unit and the rest of the view (server-derived data + statuses) stays
12
- * separate from "what the user is currently editing".
13
- */
14
- export interface AutoSweepFlowFormData {
15
- bufferAmount: Amount;
16
- frequency: AutoSweepFrequency;
17
- memo: string;
18
- /** Derived from `bufferAmount` — the matching preset risk level, falling
19
- * back to `'moderate'` for custom server-side values. */
20
- risk: RiskLevel;
21
- }
22
- export interface AutoSweepFlowSelectorView extends SelectorView {
23
- formData: AutoSweepFlowFormData;
24
- saveStatus: FetchStateAndError;
25
- /**
26
- * Recommended sweep amount. Sourced from the cash management banner
27
- * (the first money_movements[0].movements[0].amount returned by the
28
- * agent's `/recommend` endpoint). Defaults to zero when the agent
29
- * hasn't returned a movement yet.
30
- */
31
- sweepAmount: Amount;
32
- /** Resolved from `primaryFundingAccountId` against the deposit-account
33
- * entity bucket. `undefined` until the GET fetch publishes the account. */
34
- primaryFundingAccount?: FundingAccount;
35
- settingsId?: ID;
36
- /** Treasury account summary used by the setup / review flow to render the
37
- * destination column. Mirrors `getTreasuryDetail().accountSummary`. */
38
- treasurySummary?: TreasurySummaryWithBalance;
39
- }
40
- export declare const getAutoSweepFlow: (state: RootState) => AutoSweepFlowSelectorView;
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAutoSweepFlow = void 0;
4
- const depositAccountSelector_1 = require("../../../../entity/depositAccount/depositAccountSelector");
5
- const setupViewSelector_1 = require("../../commonSetup/setupViewSelector");
6
- const treasuryDetailSelector_1 = require("../../treasury/treasuryList/treasuryDetailSelector");
7
- const cashManagementOverviewSelector_1 = require("../cashManagementOverview/cashManagementOverviewSelector");
8
- const autoSweepFlowState_1 = require("./autoSweepFlowState");
9
- const getAutoSweepFlow = (state) => {
10
- const { bufferAmount, frequency, memo, saveStatus, settingsId, primaryFundingAccountId, fetchState, error, } = state.autoSweepFlowState;
11
- const depositAccount = primaryFundingAccountId != null
12
- ? (0, depositAccountSelector_1.getDepositAccountByDepositAccountId)(state.depositAccountState, primaryFundingAccountId)
13
- : undefined;
14
- return {
15
- fetchState,
16
- error,
17
- formData: {
18
- bufferAmount,
19
- frequency,
20
- memo,
21
- risk: (0, autoSweepFlowState_1.bufferAmountToRisk)(bufferAmount.amount),
22
- },
23
- primaryFundingAccount: depositAccount != null
24
- ? (0, setupViewSelector_1.mapDepositAccToFundingAccount)(depositAccount)
25
- : undefined,
26
- saveStatus,
27
- settingsId,
28
- sweepAmount: (0, cashManagementOverviewSelector_1.getCashManagementOverviewBanner)(state).amount,
29
- treasurySummary: (0, treasuryDetailSelector_1.getTreasuryDetail)(state).accountSummary,
30
- version: 0,
31
- };
32
- };
33
- exports.getAutoSweepFlow = getAutoSweepFlow;
@@ -1,37 +0,0 @@
1
- import { Amount } from '../../../../commonStateTypes/amount';
2
- import { FetchStateAndError, ID } from '../../../../commonStateTypes/common';
3
- import { ZeniDate } from '../../../../zeniDayJS';
4
- /**
5
- * Cadence at which the auto-sweep transfer fires. Lowercase to match the
6
- * cash-management settings API contract (and the `SweepFrequency` literal
7
- * already used by `<AutoSweepSetupPage>` in web-components).
8
- */
9
- export declare const ALL_AUTO_SWEEP_FREQUENCIES: readonly ["daily", "weekly", "biweekly", "monthly"];
10
- export declare const toAutoSweepFrequency: (v?: string) => "weekly" | "biweekly" | "monthly" | "daily";
11
- export type AutoSweepFrequency = NonNullable<ReturnType<typeof toAutoSweepFrequency>>;
12
- /**
13
- * Risk presets the auto-sweep setup form exposes. Each level maps to a
14
- * canonical minimum-buffer amount (USD). Selecting a level in the UI is
15
- * shorthand for choosing that buffer.
16
- */
17
- export declare const ALL_AUTO_SWEEP_RISK_LEVELS: readonly ["low", "moderate", "high"];
18
- export declare const toAutoSweepRiskLevel: (v?: string) => "high" | "low" | "moderate";
19
- export type RiskLevel = NonNullable<ReturnType<typeof toAutoSweepRiskLevel>>;
20
- export declare const RISK_BUFFER_AMOUNT: Record<RiskLevel, number>;
21
- /**
22
- * Maps a buffer amount back onto the closest preset risk level. Falls back
23
- * to `'moderate'` when the amount doesn't match a known preset (e.g. the
24
- * server returned a custom value). The dropdown in `<AutoSweepSetupPage>`
25
- * uses this so it can pre-select the user's existing band on edit.
26
- */
27
- export declare const bufferAmountToRisk: (amount: number) => RiskLevel;
28
- export interface AutoSweepFlowState extends FetchStateAndError {
29
- bufferAmount: Amount;
30
- frequency: AutoSweepFrequency;
31
- memo: string;
32
- saveStatus: FetchStateAndError;
33
- nextTransferDate?: ZeniDate;
34
- primaryFundingAccountId?: ID;
35
- settingsId?: ID;
36
- }
37
- export declare const initialAutoSweepFlowState: AutoSweepFlowState;
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.initialAutoSweepFlowState = exports.bufferAmountToRisk = exports.RISK_BUFFER_AMOUNT = exports.toAutoSweepRiskLevel = exports.ALL_AUTO_SWEEP_RISK_LEVELS = exports.toAutoSweepFrequency = exports.ALL_AUTO_SWEEP_FREQUENCIES = void 0;
4
- const amount_1 = require("../../../../commonStateTypes/amount");
5
- const stringToUnion_1 = require("../../../../commonStateTypes/stringToUnion");
6
- /**
7
- * Cadence at which the auto-sweep transfer fires. Lowercase to match the
8
- * cash-management settings API contract (and the `SweepFrequency` literal
9
- * already used by `<AutoSweepSetupPage>` in web-components).
10
- */
11
- exports.ALL_AUTO_SWEEP_FREQUENCIES = [
12
- 'daily',
13
- 'weekly',
14
- 'biweekly',
15
- 'monthly',
16
- ];
17
- const toAutoSweepFrequency = (v) => (0, stringToUnion_1.stringToUnion)(v ?? '', exports.ALL_AUTO_SWEEP_FREQUENCIES);
18
- exports.toAutoSweepFrequency = toAutoSweepFrequency;
19
- /**
20
- * Risk presets the auto-sweep setup form exposes. Each level maps to a
21
- * canonical minimum-buffer amount (USD). Selecting a level in the UI is
22
- * shorthand for choosing that buffer.
23
- */
24
- exports.ALL_AUTO_SWEEP_RISK_LEVELS = ['low', 'moderate', 'high'];
25
- const toAutoSweepRiskLevel = (v) => (0, stringToUnion_1.stringToUnion)(v ?? '', exports.ALL_AUTO_SWEEP_RISK_LEVELS);
26
- exports.toAutoSweepRiskLevel = toAutoSweepRiskLevel;
27
- exports.RISK_BUFFER_AMOUNT = {
28
- low: 15000,
29
- moderate: 10000,
30
- high: 5000,
31
- };
32
- /**
33
- * Maps a buffer amount back onto the closest preset risk level. Falls back
34
- * to `'moderate'` when the amount doesn't match a known preset (e.g. the
35
- * server returned a custom value). The dropdown in `<AutoSweepSetupPage>`
36
- * uses this so it can pre-select the user's existing band on edit.
37
- */
38
- const bufferAmountToRisk = (amount) => {
39
- const match = Object.entries(exports.RISK_BUFFER_AMOUNT).find(([, presetAmount]) => presetAmount === amount);
40
- return match != null ? match[0] : 'moderate';
41
- };
42
- exports.bufferAmountToRisk = bufferAmountToRisk;
43
- exports.initialAutoSweepFlowState = {
44
- bufferAmount: (0, amount_1.toAmount)(10000, 'USD', '$'),
45
- frequency: 'weekly',
46
- memo: '',
47
- saveStatus: { fetchState: 'Not-Started', error: undefined },
48
- nextTransferDate: undefined,
49
- primaryFundingAccountId: undefined,
50
- settingsId: undefined,
51
- fetchState: 'Not-Started',
52
- error: undefined,
53
- };
@@ -1,14 +0,0 @@
1
- import { ActionsObservable, StateObservable } from 'redux-observable';
2
- import { Observable } from 'rxjs';
3
- import { updateDepositAccounts } from '../../../../../entity/depositAccount/depositAccountReducer';
4
- import { RootState } from '../../../../../reducer';
5
- import { ZeniAPI } from '../../../../../zeniAPI';
6
- import { fetchCashManagementSettings, updateCashManagementSettings, updateCashManagementSettingsFetchStatus } from '../autoSweepFlowReducer';
7
- export type ActionType = ReturnType<typeof fetchCashManagementSettings> | ReturnType<typeof updateCashManagementSettings> | ReturnType<typeof updateCashManagementSettingsFetchStatus> | ReturnType<typeof updateDepositAccounts>;
8
- /**
9
- * Hits `GET /cash-management/settings` and hydrates the auto-sweep slice
10
- * with the server's existing settings (frequency, minimum buffer, settings
11
- * id). Called from the cash management overview page-fetch epic alongside
12
- * the other top-level fetches.
13
- */
14
- export declare const fetchCashManagementSettingsEpic: (actions$: ActionsObservable<ActionType>, _state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => Observable<ActionType>;