@zeniai/client-epic-state 5.0.82-betaAK5 → 5.0.82-betaAK7
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/esm/view/spendManagement/autotransferRules/autoTransferRulesSelector.js +43 -2
- package/lib/esm/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowPayload.js +1 -1
- package/lib/esm/view/spendManagement/cashManagement/autoSweepFlow/epics/saveAutoSweepSettingsEpic.js +8 -4
- package/lib/view/spendManagement/autotransferRules/autoTransferRulesPayload.d.ts +1 -1
- package/lib/view/spendManagement/autotransferRules/autoTransferRulesSelector.d.ts +18 -0
- package/lib/view/spendManagement/autotransferRules/autoTransferRulesSelector.js +45 -3
- package/lib/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowPayload.d.ts +1 -1
- package/lib/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowPayload.js +1 -1
- package/lib/view/spendManagement/cashManagement/autoSweepFlow/epics/saveAutoSweepSettingsEpic.js +8 -4
- package/package.json +1 -1
|
@@ -3,9 +3,50 @@ import { reduceAllFetchState } from '../../../commonStateTypes/reduceFetchState'
|
|
|
3
3
|
import { getAllFundingAccounts, } from '../commonSetup/setupViewSelector';
|
|
4
4
|
import { getAllDepositAccounts } from '../zeniAccounts/depositAccountList/depositAccountListSelector';
|
|
5
5
|
import { getAllPaymentAccounts } from '../zeniAccounts/paymentAccountList/paymentAccountListSelector';
|
|
6
|
+
/**
|
|
7
|
+
* Lifts an `AutoSweepFlowState` into an `AutoTransferRule` so the auto-sweep
|
|
8
|
+
* config surfaces alongside the user's other auto-transfer rules.
|
|
9
|
+
*
|
|
10
|
+
* Mapping notes:
|
|
11
|
+
* - `autoTransferRuleId` reuses `settingsId` from the cash-management
|
|
12
|
+
* settings record. (Different system, but it's the closest stable id we
|
|
13
|
+
* have. Returns `undefined` when no settings have been saved yet.)
|
|
14
|
+
* - `'biweekly'` collapses to `'weekly'` — `AutoTransferRuleFrequency`
|
|
15
|
+
* doesn't model biweekly.
|
|
16
|
+
* - `ruleType` is fixed to `'cash_management'` so the rules-list UI can
|
|
17
|
+
* special-case the row (icon, title, action menu) without confusing it
|
|
18
|
+
* for a regular recurring rule.
|
|
19
|
+
* - Destination is the singleton treasury account, so the id is `null` and
|
|
20
|
+
* the type is `'treasury_account'`.
|
|
21
|
+
*/
|
|
22
|
+
export const mapAutoSweepFlowStateToAutoTransferRule = (state) => {
|
|
23
|
+
if (state.settingsId == null) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
amount: state.bufferAmount.amount,
|
|
28
|
+
autoTransferRuleId: state.settingsId,
|
|
29
|
+
currencyCode: state.bufferAmount.currencyCode,
|
|
30
|
+
currencySymbol: state.bufferAmount.currencySymbol,
|
|
31
|
+
destinationBankAccountId: null,
|
|
32
|
+
destinationBankAccountType: 'treasury_account',
|
|
33
|
+
frequency: state.frequency === 'biweekly' ? 'weekly' : state.frequency,
|
|
34
|
+
isActive: true,
|
|
35
|
+
isDeleted: false,
|
|
36
|
+
lastRunTime: null,
|
|
37
|
+
ruleType: 'cash_management',
|
|
38
|
+
sourceBankAccountId: state.primaryFundingAccountId ?? '',
|
|
39
|
+
sourceBankAccountType: 'deposit_account',
|
|
40
|
+
};
|
|
41
|
+
};
|
|
6
42
|
export const getAutoTransferRules = (state) => {
|
|
7
|
-
const { autotransferRulesState, depositAccountState, paymentAccountState, depositAccountListState, paymentAccountListState, treasuryDetailState, } = state;
|
|
43
|
+
const { autotransferRulesState, autoSweepFlowState, depositAccountState, paymentAccountState, depositAccountListState, paymentAccountListState, treasuryDetailState, } = state;
|
|
8
44
|
const { rules, error, historyByRuleId, ruleUpdateLocalData, ruleUpdateStatusById, ruleDeleteStatusById, createRuleFetchState, autoTransferReviewDetail, } = autotransferRulesState;
|
|
45
|
+
// Surface the auto-sweep config as an additional rule alongside the
|
|
46
|
+
// server-returned rules. Only present when a `settingsId` has been
|
|
47
|
+
// assigned (i.e. the user has saved auto-sweep at least once).
|
|
48
|
+
const autoSweepRule = mapAutoSweepFlowStateToAutoTransferRule(autoSweepFlowState);
|
|
49
|
+
const mergedRules = autoSweepRule != null ? [...rules, autoSweepRule] : rules;
|
|
9
50
|
const depositAccountsView = getAllDepositAccounts(depositAccountState, depositAccountListState);
|
|
10
51
|
const paymentAccountsView = getAllPaymentAccounts(paymentAccountState, paymentAccountListState);
|
|
11
52
|
let transferMoneyParties = [];
|
|
@@ -30,7 +71,7 @@ export const getAutoTransferRules = (state) => {
|
|
|
30
71
|
};
|
|
31
72
|
return {
|
|
32
73
|
autoTransferReviewDetail,
|
|
33
|
-
rules,
|
|
74
|
+
rules: mergedRules,
|
|
34
75
|
ruleUpdateLocalData,
|
|
35
76
|
ruleUpdateStatusById,
|
|
36
77
|
ruleDeleteStatusById,
|
|
@@ -2,7 +2,7 @@ import { toAmount } from '../../../../commonStateTypes/amount';
|
|
|
2
2
|
import { getNextTransferDate } from '../../../../commonStateTypes/workingDayHelper';
|
|
3
3
|
import { toAutoSweepFrequency, } from './autoSweepFlowState';
|
|
4
4
|
export const toSaveAutoSweepSettingsBody = (state) => ({
|
|
5
|
-
|
|
5
|
+
first_run_date: getNextTransferDate(state.frequency).format('YYYY-MM-DD'),
|
|
6
6
|
frequency: state.frequency,
|
|
7
7
|
memo: state.memo,
|
|
8
8
|
minimum_buffer_usd: state.bufferAmount.amount,
|
package/lib/esm/view/spendManagement/cashManagement/autoSweepFlow/epics/saveAutoSweepSettingsEpic.js
CHANGED
|
@@ -3,16 +3,20 @@ import { catchError, filter, mergeMap, switchMap } from 'rxjs/operators';
|
|
|
3
3
|
import { createZeniAPIStatus, isSuccessResponse, } from '../../../../../responsePayload';
|
|
4
4
|
import { toSaveAutoSweepSettingsBody, } from '../autoSweepFlowPayload';
|
|
5
5
|
import { saveAutoSweepSettings, updateAutoSweepSettingsFetchStatus, } from '../autoSweepFlowReducer';
|
|
6
|
+
const SETTINGS_ENDPOINT = 'https://dev.api.zeni.ai/cash-management-agent/1.0/cash-management/settings';
|
|
6
7
|
export const saveAutoSweepSettingsEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(saveAutoSweepSettings.match), switchMap(() => {
|
|
7
|
-
const { bufferAmount, frequency, memo } = state$.value.autoSweepFlowState;
|
|
8
|
+
const { bufferAmount, frequency, memo, settingsId } = state$.value.autoSweepFlowState;
|
|
8
9
|
const payload = toSaveAutoSweepSettingsBody({
|
|
9
10
|
bufferAmount,
|
|
10
11
|
frequency,
|
|
11
12
|
memo,
|
|
12
13
|
});
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
// First-time setup (no settings id from the GET yet) → POST a new
|
|
15
|
+
// record. Subsequent edits update the existing one via PUT.
|
|
16
|
+
const request$ = settingsId == null
|
|
17
|
+
? zeniAPI.postAndGetJSON(SETTINGS_ENDPOINT, payload)
|
|
18
|
+
: zeniAPI.putAndGetJSON(SETTINGS_ENDPOINT, payload);
|
|
19
|
+
return request$.pipe(mergeMap((response) => {
|
|
16
20
|
if (isSuccessResponse(response)) {
|
|
17
21
|
return of(updateAutoSweepSettingsFetchStatus({ fetchState: 'Completed' }));
|
|
18
22
|
}
|
|
@@ -4,7 +4,7 @@ import { ZeniDate } from '../../../zeniDayJS';
|
|
|
4
4
|
import { FundingAccount } from '../commonSetup/setupViewSelector';
|
|
5
5
|
import { TreasuryAccount } from '../treasury/treasuryTransferMoney/treasuryTransferMoneyState';
|
|
6
6
|
import { AutoTransferRule } from './autoTransferRulesState';
|
|
7
|
-
export type AutoTransferRuleType = 'minimum_balance' | 'recurring' | 'percentage_of_balance';
|
|
7
|
+
export type AutoTransferRuleType = 'minimum_balance' | 'recurring' | 'percentage_of_balance' | 'cash_management';
|
|
8
8
|
export type AutoTransferRuleFrequency = 'daily' | 'weekly' | 'monthly';
|
|
9
9
|
export interface DestinationBankAccountMetadataPayload {
|
|
10
10
|
account_id: string;
|
|
@@ -1,12 +1,30 @@
|
|
|
1
1
|
import { FetchState, FetchStateAndError, ID } from '../../../commonStateTypes/common';
|
|
2
2
|
import { SelectorView } from '../../../commonStateTypes/viewAndReport/viewAndReport';
|
|
3
3
|
import { RootState } from '../../../reducer';
|
|
4
|
+
import { AutoSweepFlowState } from '../cashManagement/autoSweepFlow/autoSweepFlowState';
|
|
4
5
|
import { CommonHistoryView } from '../commonHistoryView/commonHistory';
|
|
5
6
|
import { FundingAccount } from '../commonSetup/setupViewSelector';
|
|
6
7
|
import { TreasuryAccount } from '../treasury/treasuryTransferMoney/treasuryTransferMoneyState';
|
|
7
8
|
import { ReviewTransferDetail } from '../zeniAccounts/transferDetail/transferDetailState';
|
|
8
9
|
import { AutoTransferRuleLocalData } from './autoTransferRulesPayload';
|
|
9
10
|
import { AutoTransferRule } from './autoTransferRulesState';
|
|
11
|
+
/**
|
|
12
|
+
* Lifts an `AutoSweepFlowState` into an `AutoTransferRule` so the auto-sweep
|
|
13
|
+
* config surfaces alongside the user's other auto-transfer rules.
|
|
14
|
+
*
|
|
15
|
+
* Mapping notes:
|
|
16
|
+
* - `autoTransferRuleId` reuses `settingsId` from the cash-management
|
|
17
|
+
* settings record. (Different system, but it's the closest stable id we
|
|
18
|
+
* have. Returns `undefined` when no settings have been saved yet.)
|
|
19
|
+
* - `'biweekly'` collapses to `'weekly'` — `AutoTransferRuleFrequency`
|
|
20
|
+
* doesn't model biweekly.
|
|
21
|
+
* - `ruleType` is fixed to `'cash_management'` so the rules-list UI can
|
|
22
|
+
* special-case the row (icon, title, action menu) without confusing it
|
|
23
|
+
* for a regular recurring rule.
|
|
24
|
+
* - Destination is the singleton treasury account, so the id is `null` and
|
|
25
|
+
* the type is `'treasury_account'`.
|
|
26
|
+
*/
|
|
27
|
+
export declare const mapAutoSweepFlowStateToAutoTransferRule: (state: AutoSweepFlowState) => AutoTransferRule | undefined;
|
|
10
28
|
export interface AutoTransferRulesSelectorView extends SelectorView {
|
|
11
29
|
autoTransferReviewDetail: ReviewTransferDetail;
|
|
12
30
|
createRuleFetchState: FetchStateAndError;
|
|
@@ -3,15 +3,57 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getAutoTransferRuleHistory = exports.getAutoTransferRuleById = exports.getAutoTransferRules = void 0;
|
|
6
|
+
exports.getAutoTransferRuleHistory = exports.getAutoTransferRuleById = exports.getAutoTransferRules = exports.mapAutoSweepFlowStateToAutoTransferRule = void 0;
|
|
7
7
|
const get_1 = __importDefault(require("lodash/get"));
|
|
8
8
|
const reduceFetchState_1 = require("../../../commonStateTypes/reduceFetchState");
|
|
9
9
|
const setupViewSelector_1 = require("../commonSetup/setupViewSelector");
|
|
10
10
|
const depositAccountListSelector_1 = require("../zeniAccounts/depositAccountList/depositAccountListSelector");
|
|
11
11
|
const paymentAccountListSelector_1 = require("../zeniAccounts/paymentAccountList/paymentAccountListSelector");
|
|
12
|
+
/**
|
|
13
|
+
* Lifts an `AutoSweepFlowState` into an `AutoTransferRule` so the auto-sweep
|
|
14
|
+
* config surfaces alongside the user's other auto-transfer rules.
|
|
15
|
+
*
|
|
16
|
+
* Mapping notes:
|
|
17
|
+
* - `autoTransferRuleId` reuses `settingsId` from the cash-management
|
|
18
|
+
* settings record. (Different system, but it's the closest stable id we
|
|
19
|
+
* have. Returns `undefined` when no settings have been saved yet.)
|
|
20
|
+
* - `'biweekly'` collapses to `'weekly'` — `AutoTransferRuleFrequency`
|
|
21
|
+
* doesn't model biweekly.
|
|
22
|
+
* - `ruleType` is fixed to `'cash_management'` so the rules-list UI can
|
|
23
|
+
* special-case the row (icon, title, action menu) without confusing it
|
|
24
|
+
* for a regular recurring rule.
|
|
25
|
+
* - Destination is the singleton treasury account, so the id is `null` and
|
|
26
|
+
* the type is `'treasury_account'`.
|
|
27
|
+
*/
|
|
28
|
+
const mapAutoSweepFlowStateToAutoTransferRule = (state) => {
|
|
29
|
+
if (state.settingsId == null) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
amount: state.bufferAmount.amount,
|
|
34
|
+
autoTransferRuleId: state.settingsId,
|
|
35
|
+
currencyCode: state.bufferAmount.currencyCode,
|
|
36
|
+
currencySymbol: state.bufferAmount.currencySymbol,
|
|
37
|
+
destinationBankAccountId: null,
|
|
38
|
+
destinationBankAccountType: 'treasury_account',
|
|
39
|
+
frequency: state.frequency === 'biweekly' ? 'weekly' : state.frequency,
|
|
40
|
+
isActive: true,
|
|
41
|
+
isDeleted: false,
|
|
42
|
+
lastRunTime: null,
|
|
43
|
+
ruleType: 'cash_management',
|
|
44
|
+
sourceBankAccountId: state.primaryFundingAccountId ?? '',
|
|
45
|
+
sourceBankAccountType: 'deposit_account',
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
exports.mapAutoSweepFlowStateToAutoTransferRule = mapAutoSweepFlowStateToAutoTransferRule;
|
|
12
49
|
const getAutoTransferRules = (state) => {
|
|
13
|
-
const { autotransferRulesState, depositAccountState, paymentAccountState, depositAccountListState, paymentAccountListState, treasuryDetailState, } = state;
|
|
50
|
+
const { autotransferRulesState, autoSweepFlowState, depositAccountState, paymentAccountState, depositAccountListState, paymentAccountListState, treasuryDetailState, } = state;
|
|
14
51
|
const { rules, error, historyByRuleId, ruleUpdateLocalData, ruleUpdateStatusById, ruleDeleteStatusById, createRuleFetchState, autoTransferReviewDetail, } = autotransferRulesState;
|
|
52
|
+
// Surface the auto-sweep config as an additional rule alongside the
|
|
53
|
+
// server-returned rules. Only present when a `settingsId` has been
|
|
54
|
+
// assigned (i.e. the user has saved auto-sweep at least once).
|
|
55
|
+
const autoSweepRule = (0, exports.mapAutoSweepFlowStateToAutoTransferRule)(autoSweepFlowState);
|
|
56
|
+
const mergedRules = autoSweepRule != null ? [...rules, autoSweepRule] : rules;
|
|
15
57
|
const depositAccountsView = (0, depositAccountListSelector_1.getAllDepositAccounts)(depositAccountState, depositAccountListState);
|
|
16
58
|
const paymentAccountsView = (0, paymentAccountListSelector_1.getAllPaymentAccounts)(paymentAccountState, paymentAccountListState);
|
|
17
59
|
let transferMoneyParties = [];
|
|
@@ -36,7 +78,7 @@ const getAutoTransferRules = (state) => {
|
|
|
36
78
|
};
|
|
37
79
|
return {
|
|
38
80
|
autoTransferReviewDetail,
|
|
39
|
-
rules,
|
|
81
|
+
rules: mergedRules,
|
|
40
82
|
ruleUpdateLocalData,
|
|
41
83
|
ruleUpdateStatusById,
|
|
42
84
|
ruleDeleteStatusById,
|
|
@@ -9,7 +9,7 @@ import { AutoSweepFlowState, AutoSweepFrequency } from './autoSweepFlowState';
|
|
|
9
9
|
* (the slice tracks the canonical `Amount` value).
|
|
10
10
|
*/
|
|
11
11
|
export type SaveAutoSweepSettingsBody = {
|
|
12
|
-
|
|
12
|
+
first_run_date: string;
|
|
13
13
|
frequency: string;
|
|
14
14
|
memo: string;
|
|
15
15
|
minimum_buffer_usd: number;
|
|
@@ -5,7 +5,7 @@ const amount_1 = require("../../../../commonStateTypes/amount");
|
|
|
5
5
|
const workingDayHelper_1 = require("../../../../commonStateTypes/workingDayHelper");
|
|
6
6
|
const autoSweepFlowState_1 = require("./autoSweepFlowState");
|
|
7
7
|
const toSaveAutoSweepSettingsBody = (state) => ({
|
|
8
|
-
|
|
8
|
+
first_run_date: (0, workingDayHelper_1.getNextTransferDate)(state.frequency).format('YYYY-MM-DD'),
|
|
9
9
|
frequency: state.frequency,
|
|
10
10
|
memo: state.memo,
|
|
11
11
|
minimum_buffer_usd: state.bufferAmount.amount,
|
package/lib/view/spendManagement/cashManagement/autoSweepFlow/epics/saveAutoSweepSettingsEpic.js
CHANGED
|
@@ -6,16 +6,20 @@ const operators_1 = require("rxjs/operators");
|
|
|
6
6
|
const responsePayload_1 = require("../../../../../responsePayload");
|
|
7
7
|
const autoSweepFlowPayload_1 = require("../autoSweepFlowPayload");
|
|
8
8
|
const autoSweepFlowReducer_1 = require("../autoSweepFlowReducer");
|
|
9
|
+
const SETTINGS_ENDPOINT = 'https://dev.api.zeni.ai/cash-management-agent/1.0/cash-management/settings';
|
|
9
10
|
const saveAutoSweepSettingsEpic = (actions$, state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(autoSweepFlowReducer_1.saveAutoSweepSettings.match), (0, operators_1.switchMap)(() => {
|
|
10
|
-
const { bufferAmount, frequency, memo } = state$.value.autoSweepFlowState;
|
|
11
|
+
const { bufferAmount, frequency, memo, settingsId } = state$.value.autoSweepFlowState;
|
|
11
12
|
const payload = (0, autoSweepFlowPayload_1.toSaveAutoSweepSettingsBody)({
|
|
12
13
|
bufferAmount,
|
|
13
14
|
frequency,
|
|
14
15
|
memo,
|
|
15
16
|
});
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
// First-time setup (no settings id from the GET yet) → POST a new
|
|
18
|
+
// record. Subsequent edits update the existing one via PUT.
|
|
19
|
+
const request$ = settingsId == null
|
|
20
|
+
? zeniAPI.postAndGetJSON(SETTINGS_ENDPOINT, payload)
|
|
21
|
+
: zeniAPI.putAndGetJSON(SETTINGS_ENDPOINT, payload);
|
|
22
|
+
return request$.pipe((0, operators_1.mergeMap)((response) => {
|
|
19
23
|
if ((0, responsePayload_1.isSuccessResponse)(response)) {
|
|
20
24
|
return (0, rxjs_1.of)((0, autoSweepFlowReducer_1.updateAutoSweepSettingsFetchStatus)({ fetchState: 'Completed' }));
|
|
21
25
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeniai/client-epic-state",
|
|
3
|
-
"version": "5.0.82-
|
|
3
|
+
"version": "5.0.82-betaAK7",
|
|
4
4
|
"description": "Shared module between Web & Mobile containing required abstractions for state management, async network communication. ",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib/esm/index.js",
|