@zeniai/client-epic-state 5.0.82-betaAK1 → 5.0.82-betaAK2

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.
@@ -11,7 +11,9 @@ export const toSaveAutoSweepSettingsBody = (state) => ({
11
11
  * Map a `GET /cash-management/settings` payload into the slice's writable
12
12
  * fields. Defensive on the frequency (string-from-the-wire → union via
13
13
  * `toAutoSweepFrequency`, falling back to `'weekly'` if the server returns
14
- * something we don't model yet).
14
+ * something we don't model yet). Only the source account *id* is stored
15
+ * here — the full deposit-account payload is published to the entity bucket
16
+ * by the fetch epic.
15
17
  */
16
18
  export const toAutoSweepFlowStatePatch = (payload) => {
17
19
  const currencyCode = payload.source_bank_account.balances?.currency_code;
@@ -19,6 +21,7 @@ export const toAutoSweepFlowStatePatch = (payload) => {
19
21
  return {
20
22
  bufferAmount: toAmount(payload.minimum_buffer_usd, currencyCode ?? 'USD', currencySymbol ?? '$'),
21
23
  frequency: toAutoSweepFrequency(payload.frequency) ?? 'weekly',
24
+ primaryFundingAccountId: payload.source_bank_account.deposit_account_id ?? undefined,
22
25
  settingsId: payload.cash_management_settings_id ?? undefined,
23
26
  };
24
27
  };
@@ -22,6 +22,7 @@ const autoSweepFlow = createSlice({
22
22
  const patch = toAutoSweepFlowStatePatch(action.payload.data);
23
23
  draft.bufferAmount = patch.bufferAmount;
24
24
  draft.frequency = patch.frequency;
25
+ draft.primaryFundingAccountId = patch.primaryFundingAccountId;
25
26
  draft.settingsId = patch.settingsId;
26
27
  draft.fetchState = 'Completed';
27
28
  draft.error = undefined;
@@ -1,15 +1,27 @@
1
+ import { getDepositAccountByDepositAccountId } from '../../../../entity/depositAccount/depositAccountSelector';
2
+ import { mapDepositAccToFundingAccount, } from '../../commonSetup/setupViewSelector';
3
+ import { getTreasuryDetail } from '../../treasury/treasuryList/treasuryDetailSelector';
1
4
  import { bufferAmountToRisk, } from './autoSweepFlowState';
2
5
  export const getAutoSweepFlow = (state) => {
3
- const { bufferAmount, frequency, memo, saveStatus, settingsId, fetchState, error, } = state.autoSweepFlowState;
6
+ const { bufferAmount, frequency, memo, saveStatus, settingsId, primaryFundingAccountId, fetchState, error, } = state.autoSweepFlowState;
7
+ const depositAccount = primaryFundingAccountId != null
8
+ ? getDepositAccountByDepositAccountId(state.depositAccountState, primaryFundingAccountId)
9
+ : undefined;
4
10
  return {
5
11
  fetchState,
6
12
  error,
7
- bufferAmount,
8
- frequency,
9
- memo,
10
- risk: bufferAmountToRisk(bufferAmount.amount),
13
+ formData: {
14
+ bufferAmount,
15
+ frequency,
16
+ memo,
17
+ risk: bufferAmountToRisk(bufferAmount.amount),
18
+ },
19
+ primaryFundingAccount: depositAccount != null
20
+ ? mapDepositAccToFundingAccount(depositAccount)
21
+ : undefined,
11
22
  saveStatus,
12
23
  settingsId,
24
+ treasurySummary: getTreasuryDetail(state).accountSummary,
13
25
  version: 0,
14
26
  };
15
27
  };
@@ -39,6 +39,7 @@ export const initialAutoSweepFlowState = {
39
39
  frequency: 'weekly',
40
40
  memo: '',
41
41
  saveStatus: { fetchState: 'Not-Started', error: undefined },
42
+ primaryFundingAccountId: undefined,
42
43
  settingsId: undefined,
43
44
  fetchState: 'Not-Started',
44
45
  error: undefined,
@@ -1,5 +1,6 @@
1
1
  import { of } from 'rxjs';
2
2
  import { catchError, filter, mergeMap, switchMap } from 'rxjs/operators';
3
+ import { updateDepositAccounts } from '../../../../../entity/depositAccount/depositAccountReducer';
3
4
  import { createZeniAPIStatus, isSuccessResponse, } from '../../../../../responsePayload';
4
5
  import { fetchCashManagementSettings, updateCashManagementSettings, updateCashManagementSettingsFetchStatus, } from '../autoSweepFlowReducer';
5
6
  /**
@@ -15,7 +16,12 @@ export const fetchCashManagementSettingsEpic = (actions$, _state$, zeniAPI) => a
15
16
  .getJSON(`https://dev.api.zeni.ai/cash-management-agent/1.0/cash-management/settings`)
16
17
  .pipe(mergeMap((response) => {
17
18
  if (isSuccessResponse(response) && response.data != null) {
18
- return of(updateCashManagementSettings({ data: response.data }));
19
+ return of(
20
+ // Publish the source deposit account into the shared entity
21
+ // bucket so the selector can hydrate the full `FundingAccount`
22
+ // from `getDepositAccountByDepositAccountId` rather than the
23
+ // auto-sweep slice holding a duplicate copy.
24
+ updateDepositAccounts([response.data.source_bank_account]), updateCashManagementSettings({ data: response.data }));
19
25
  }
20
26
  return of(updateCashManagementSettingsFetchStatus({
21
27
  fetchState: 'Error',
package/lib/index.d.ts CHANGED
@@ -940,7 +940,7 @@ export { DEFAULT_SESSION_CONFIG } from './entity/tenant/sessionTypes';
940
940
  export { fetchCashManagementBanner, fetchCashManagementOverviewPage, } from './view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewReducer';
941
941
  export { clearAutoSweepFlow, fetchCashManagementSettings, saveAutoSweepSettings, updateAutoSweepSettingsFetchStatus, updateCashManagementSettings, updateCashManagementSettingsFetchStatus, } from './view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowReducer';
942
942
  export { getAutoSweepFlow } from './view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowSelector';
943
- export type { AutoSweepFlowSelectorView } from './view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowSelector';
943
+ export type { AutoSweepFlowFormData, AutoSweepFlowSelectorView, } from './view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowSelector';
944
944
  export { RISK_BUFFER_AMOUNT, bufferAmountToRisk, } from './view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowState';
945
945
  export type { AutoSweepFlowState, AutoSweepFrequency, RiskLevel, } from './view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowState';
946
946
  export { CashManagementOverviewBannerSelectorView, CashManagementOverviewSelectorView, CashProjectionPoint, getCashManagementOverview, getCashManagementOverviewBanner, } from './view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewSelector';
@@ -1,5 +1,6 @@
1
1
  import { Amount } from '../../../../commonStateTypes/amount';
2
2
  import { ID } from '../../../../commonStateTypes/common';
3
+ import { DepositAccountPayload } from '../../../../entity/depositAccount/depositAccountPayload';
3
4
  import { ZeniAPIResponse } from '../../../../responsePayload';
4
5
  import { AutoSweepFlowState, AutoSweepFrequency } from './autoSweepFlowState';
5
6
  /**
@@ -16,37 +17,29 @@ export interface SaveAutoSweepSettingsBody {
16
17
  export type SaveAutoSweepSettingsResponse = ZeniAPIResponse<unknown>;
17
18
  export declare const toSaveAutoSweepSettingsBody: (state: Pick<AutoSweepFlowState, "bufferAmount" | "frequency" | "memo">) => SaveAutoSweepSettingsBody;
18
19
  /**
19
- * Subset of the source bank account payload the cash-management settings
20
- * endpoint embeds. Kept narrow on purpose we only consume the fields the
21
- * banner / setup flow needs today (account id + balances + currency). The
22
- * rest of the deposit-account shape is available via the deposit-account
23
- * entity bucket if a caller needs more.
20
+ * `source_bank_account` on the cash-management settings response matches the
21
+ * shared `DepositAccountPayload` shape, so the fetch epic dispatches it into
22
+ * the deposit-account entity bucket and the auto-sweep slice only keeps the
23
+ * id. The selector hydrates the full `FundingAccount` on read.
24
24
  */
25
- export interface CashManagementSettingsSourceBankAccountPayload {
26
- balances?: {
27
- available?: number;
28
- currency_code?: string;
29
- currency_symbol?: string;
30
- current?: number;
31
- hold?: number;
32
- };
33
- deposit_account_id?: string;
34
- }
35
25
  export interface CashManagementSettingsPayload {
36
26
  cash_management_settings_id: string | null;
37
27
  frequency: string;
38
28
  minimum_buffer_usd: number;
39
- source_bank_account: CashManagementSettingsSourceBankAccountPayload;
29
+ source_bank_account: DepositAccountPayload;
40
30
  }
41
31
  export type CashManagementSettingsResponse = ZeniAPIResponse<CashManagementSettingsPayload>;
42
32
  /**
43
33
  * Map a `GET /cash-management/settings` payload into the slice's writable
44
34
  * fields. Defensive on the frequency (string-from-the-wire → union via
45
35
  * `toAutoSweepFrequency`, falling back to `'weekly'` if the server returns
46
- * something we don't model yet).
36
+ * something we don't model yet). Only the source account *id* is stored
37
+ * here — the full deposit-account payload is published to the entity bucket
38
+ * by the fetch epic.
47
39
  */
48
40
  export declare const toAutoSweepFlowStatePatch: (payload: CashManagementSettingsPayload) => {
49
41
  bufferAmount: Amount;
50
42
  frequency: AutoSweepFrequency;
43
+ primaryFundingAccountId?: ID;
51
44
  settingsId?: ID;
52
45
  };
@@ -15,7 +15,9 @@ exports.toSaveAutoSweepSettingsBody = toSaveAutoSweepSettingsBody;
15
15
  * Map a `GET /cash-management/settings` payload into the slice's writable
16
16
  * fields. Defensive on the frequency (string-from-the-wire → union via
17
17
  * `toAutoSweepFrequency`, falling back to `'weekly'` if the server returns
18
- * something we don't model yet).
18
+ * something we don't model yet). Only the source account *id* is stored
19
+ * here — the full deposit-account payload is published to the entity bucket
20
+ * by the fetch epic.
19
21
  */
20
22
  const toAutoSweepFlowStatePatch = (payload) => {
21
23
  const currencyCode = payload.source_bank_account.balances?.currency_code;
@@ -23,6 +25,7 @@ const toAutoSweepFlowStatePatch = (payload) => {
23
25
  return {
24
26
  bufferAmount: (0, amount_1.toAmount)(payload.minimum_buffer_usd, currencyCode ?? 'USD', currencySymbol ?? '$'),
25
27
  frequency: (0, autoSweepFlowState_1.toAutoSweepFrequency)(payload.frequency) ?? 'weekly',
28
+ primaryFundingAccountId: payload.source_bank_account.deposit_account_id ?? undefined,
26
29
  settingsId: payload.cash_management_settings_id ?? undefined,
27
30
  };
28
31
  };
@@ -26,6 +26,7 @@ const autoSweepFlow = (0, toolkit_1.createSlice)({
26
26
  const patch = (0, autoSweepFlowPayload_1.toAutoSweepFlowStatePatch)(action.payload.data);
27
27
  draft.bufferAmount = patch.bufferAmount;
28
28
  draft.frequency = patch.frequency;
29
+ draft.primaryFundingAccountId = patch.primaryFundingAccountId;
29
30
  draft.settingsId = patch.settingsId;
30
31
  draft.fetchState = 'Completed';
31
32
  draft.error = undefined;
@@ -2,15 +2,32 @@ import { Amount } from '../../../../commonStateTypes/amount';
2
2
  import { FetchStateAndError, ID } from '../../../../commonStateTypes/common';
3
3
  import { SelectorView } from '../../../../commonStateTypes/viewAndReport/viewAndReport';
4
4
  import { RootState } from '../../../../reducer';
5
+ import { FundingAccount } from '../../commonSetup/setupViewSelector';
6
+ import { TreasurySummaryWithBalance } from '../../treasury/treasuryList/treasuryDetailState';
5
7
  import { AutoSweepFrequency, RiskLevel } from './autoSweepFlowState';
6
- export interface AutoSweepFlowSelectorView extends SelectorView {
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 {
7
15
  bufferAmount: Amount;
8
16
  frequency: AutoSweepFrequency;
9
17
  memo: string;
10
18
  /** Derived from `bufferAmount` — the matching preset risk level, falling
11
19
  * back to `'moderate'` for custom server-side values. */
12
20
  risk: RiskLevel;
21
+ }
22
+ export interface AutoSweepFlowSelectorView extends SelectorView {
23
+ formData: AutoSweepFlowFormData;
13
24
  saveStatus: FetchStateAndError;
25
+ /** Resolved from `primaryFundingAccountId` against the deposit-account
26
+ * entity bucket. `undefined` until the GET fetch publishes the account. */
27
+ primaryFundingAccount?: FundingAccount;
14
28
  settingsId?: ID;
29
+ /** Treasury account summary used by the setup / review flow to render the
30
+ * destination column. Mirrors `getTreasuryDetail().accountSummary`. */
31
+ treasurySummary?: TreasurySummaryWithBalance;
15
32
  }
16
33
  export declare const getAutoSweepFlow: (state: RootState) => AutoSweepFlowSelectorView;
@@ -1,18 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
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");
4
7
  const autoSweepFlowState_1 = require("./autoSweepFlowState");
5
8
  const getAutoSweepFlow = (state) => {
6
- const { bufferAmount, frequency, memo, saveStatus, settingsId, fetchState, error, } = state.autoSweepFlowState;
9
+ const { bufferAmount, frequency, memo, saveStatus, settingsId, primaryFundingAccountId, fetchState, error, } = state.autoSweepFlowState;
10
+ const depositAccount = primaryFundingAccountId != null
11
+ ? (0, depositAccountSelector_1.getDepositAccountByDepositAccountId)(state.depositAccountState, primaryFundingAccountId)
12
+ : undefined;
7
13
  return {
8
14
  fetchState,
9
15
  error,
10
- bufferAmount,
11
- frequency,
12
- memo,
13
- risk: (0, autoSweepFlowState_1.bufferAmountToRisk)(bufferAmount.amount),
16
+ formData: {
17
+ bufferAmount,
18
+ frequency,
19
+ memo,
20
+ risk: (0, autoSweepFlowState_1.bufferAmountToRisk)(bufferAmount.amount),
21
+ },
22
+ primaryFundingAccount: depositAccount != null
23
+ ? (0, setupViewSelector_1.mapDepositAccToFundingAccount)(depositAccount)
24
+ : undefined,
14
25
  saveStatus,
15
26
  settingsId,
27
+ treasurySummary: (0, treasuryDetailSelector_1.getTreasuryDetail)(state).accountSummary,
16
28
  version: 0,
17
29
  };
18
30
  };
@@ -39,6 +39,13 @@ export interface AutoSweepFlowState extends FetchStateAndError {
39
39
  frequency: AutoSweepFrequency;
40
40
  memo: string;
41
41
  saveStatus: FetchStateAndError;
42
+ /**
43
+ * Deposit-account id of the primary funding account returned by GET
44
+ * `/cash-management/settings`. The selector resolves it against the
45
+ * deposit-account entity bucket via `getDepositAccountByDepositAccountId`
46
+ * and exposes a hydrated `FundingAccount`.
47
+ */
48
+ primaryFundingAccountId?: ID;
42
49
  settingsId?: ID;
43
50
  }
44
51
  export declare const initialAutoSweepFlowState: AutoSweepFlowState;
@@ -45,6 +45,7 @@ exports.initialAutoSweepFlowState = {
45
45
  frequency: 'weekly',
46
46
  memo: '',
47
47
  saveStatus: { fetchState: 'Not-Started', error: undefined },
48
+ primaryFundingAccountId: undefined,
48
49
  settingsId: undefined,
49
50
  fetchState: 'Not-Started',
50
51
  error: undefined,
@@ -1,9 +1,10 @@
1
1
  import { ActionsObservable, StateObservable } from 'redux-observable';
2
2
  import { Observable } from 'rxjs';
3
+ import { updateDepositAccounts } from '../../../../../entity/depositAccount/depositAccountReducer';
3
4
  import { RootState } from '../../../../../reducer';
4
5
  import { ZeniAPI } from '../../../../../zeniAPI';
5
6
  import { fetchCashManagementSettings, updateCashManagementSettings, updateCashManagementSettingsFetchStatus } from '../autoSweepFlowReducer';
6
- export type ActionType = ReturnType<typeof fetchCashManagementSettings> | ReturnType<typeof updateCashManagementSettings> | ReturnType<typeof updateCashManagementSettingsFetchStatus>;
7
+ export type ActionType = ReturnType<typeof fetchCashManagementSettings> | ReturnType<typeof updateCashManagementSettings> | ReturnType<typeof updateCashManagementSettingsFetchStatus> | ReturnType<typeof updateDepositAccounts>;
7
8
  /**
8
9
  * Hits `GET /cash-management/settings` and hydrates the auto-sweep slice
9
10
  * with the server's existing settings (frequency, minimum buffer, settings
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fetchCashManagementSettingsEpic = void 0;
4
4
  const rxjs_1 = require("rxjs");
5
5
  const operators_1 = require("rxjs/operators");
6
+ const depositAccountReducer_1 = require("../../../../../entity/depositAccount/depositAccountReducer");
6
7
  const responsePayload_1 = require("../../../../../responsePayload");
7
8
  const autoSweepFlowReducer_1 = require("../autoSweepFlowReducer");
8
9
  /**
@@ -18,7 +19,12 @@ const fetchCashManagementSettingsEpic = (actions$, _state$, zeniAPI) => actions$
18
19
  .getJSON(`https://dev.api.zeni.ai/cash-management-agent/1.0/cash-management/settings`)
19
20
  .pipe((0, operators_1.mergeMap)((response) => {
20
21
  if ((0, responsePayload_1.isSuccessResponse)(response) && response.data != null) {
21
- return (0, rxjs_1.of)((0, autoSweepFlowReducer_1.updateCashManagementSettings)({ data: response.data }));
22
+ return (0, rxjs_1.of)(
23
+ // Publish the source deposit account into the shared entity
24
+ // bucket so the selector can hydrate the full `FundingAccount`
25
+ // from `getDepositAccountByDepositAccountId` rather than the
26
+ // auto-sweep slice holding a duplicate copy.
27
+ (0, depositAccountReducer_1.updateDepositAccounts)([response.data.source_bank_account]), (0, autoSweepFlowReducer_1.updateCashManagementSettings)({ data: response.data }));
22
28
  }
23
29
  return (0, rxjs_1.of)((0, autoSweepFlowReducer_1.updateCashManagementSettingsFetchStatus)({
24
30
  fetchState: 'Error',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeniai/client-epic-state",
3
- "version": "5.0.82-betaAK1",
3
+ "version": "5.0.82-betaAK2",
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",