@zeniai/client-epic-state 5.0.100 → 5.1.0-betaAK1

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.
@@ -90,11 +90,11 @@ interface TenantPayload {
90
90
  user_id: ID;
91
91
  user_last_check_in_time_into_tenant: string;
92
92
  user_role_id: ID;
93
+ capitalizable_account_overrides?: Record<string, number> | null;
93
94
  capitalizable_accounts?: CapitalizableAccountsPayload | null;
94
95
  capitalization_onboarding_dismissed_accounts?: Record<string, true> | null;
95
96
  capitalization_onboarding_shown_for_fixed_asset?: boolean;
96
97
  capitalization_onboarding_shown_for_prepaid?: boolean;
97
- capitalizable_account_overrides?: Record<string, number> | null;
98
98
  master_tos_info?: MasterTOSInfoPayload;
99
99
  reimbursement_info?: UserReimbursementInfoDataPayload;
100
100
  zeni_book_close_date?: string;
@@ -209,8 +209,8 @@ export declare const updateTenants: import("@reduxjs/toolkit").ActionCreatorWith
209
209
  accountId: string;
210
210
  tenantId: ID;
211
211
  }, "tenant/updateTenantCapitalizationOnboardingDismissed">, updateTenantCapitalizationAccountOverride: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
212
- tenantId: ID;
213
212
  accountId: ID;
213
+ tenantId: ID;
214
214
  threshold: number | null;
215
215
  allOverrides?: Record<string, number> | null;
216
216
  }, "tenant/updateTenantCapitalizationAccountOverride">, updateTenantMasterTOSInfo: import("@reduxjs/toolkit").ActionCreatorWithPayload<UserRolePayload, "tenant/updateTenantMasterTOSInfo">, verifyDeviceWithTwoFA: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[otp: any, deviceId: any, userEmail: any, otpChallenge: any], {
@@ -29,7 +29,7 @@ export const updateCapitalizationAccountThresholdEpic = (actions$, state$, zeniA
29
29
  const body = {
30
30
  capitalizable_account_overrides: Object.keys(finalOverrides).length > 0 ? finalOverrides : null,
31
31
  };
32
- if (dismissOnboardingForAccount) {
32
+ if (dismissOnboardingForAccount === true) {
33
33
  body.capitalization_onboarding_dismissed_accounts = { [accountId]: true };
34
34
  }
35
35
  return zeniAPI
@@ -55,7 +55,7 @@ export const updateCapitalizationAccountThresholdEpic = (actions$, state$, zeniA
55
55
  : null)
56
56
  : undefined,
57
57
  }));
58
- if (dismissOnboardingForAccount) {
58
+ if (dismissOnboardingForAccount === true) {
59
59
  actions.push(updateTenantCapitalizationOnboardingDismissed({
60
60
  tenantId,
61
61
  accountId,
@@ -17,14 +17,16 @@ export const getAutoSweepFlow = (state) => {
17
17
  : undefined;
18
18
  const risk = bufferAmountToRisk(bufferAmount.amount);
19
19
  // The banner's recommended sweep assumes the default buffer band; shift it
20
- // by the delta between the user's selected band and that default so a
21
- // tighter buffer sweeps more and a looser buffer sweeps less.
20
+ // by the delta between the default buffer and the user's selected band so a
21
+ // tighter buffer (higher risk → smaller buffer) sweeps more and a looser
22
+ // buffer (lower risk → larger buffer) sweeps less. Clamp at zero so a buffer
23
+ // larger than the available surplus never yields a negative sweep.
22
24
  const baseSweepAmount = getCashManagementOverviewBanner(state).amount;
23
25
  const sweepAmount = {
24
26
  ...baseSweepAmount,
25
- amount: baseSweepAmount.amount +
26
- RISK_BUFFER_AMOUNT[risk] -
27
- RISK_BUFFER_AMOUNT[DEFAULT_RISK_LEVEL],
27
+ amount: Math.max(0, baseSweepAmount.amount +
28
+ RISK_BUFFER_AMOUNT[DEFAULT_RISK_LEVEL] -
29
+ RISK_BUFFER_AMOUNT[risk]),
28
30
  };
29
31
  return {
30
32
  fetchState,
@@ -65,7 +65,7 @@ const pickLargestOutflow = (outflows) => {
65
65
  return outflows.reduce((largest, event) => event.amount.amount > largest.amount.amount ? event : largest);
66
66
  };
67
67
  export const getCashManagementOverview = (state) => {
68
- const { cashManagementOverviewState, depositAccountListState, depositAccountState, paymentAccountListState, paymentAccountState, treasuryDetailState, } = state;
68
+ const { cashManagementOverviewState, depositAccountListState, paymentAccountListState, treasuryDetailState, } = state;
69
69
  const aggregate = reduceAllFetchState([
70
70
  {
71
71
  fetchState: paymentAccountListState.fetchState,
@@ -89,7 +89,11 @@ export const getCashManagementOverview = (state) => {
89
89
  },
90
90
  ]);
91
91
  const treasuryBalance = treasuryDetailState.accountSummary?.totalBalance ?? zeroAmount();
92
- const cashBalance = sumCashBalances(paymentAccountListState.paymentAccountIds, paymentAccountState, depositAccountListState.accountIds, depositAccountState);
92
+ const bannerView = getCashManagementOverviewBanner(state);
93
+ // cashBalance is the primary (agent-managed) deposit account's available
94
+ // balance — the account the banner resolves as primaryFundingAccount — not
95
+ // the sum of all cash accounts. Zero until that account resolves.
96
+ const cashBalance = bannerView.primaryFundingAccount?.accountBalance?.available ?? zeroAmount();
93
97
  const totalCash = addAmounts(treasuryBalance, cashBalance);
94
98
  const bannerData = cashManagementOverviewState.banner.data;
95
99
  const inflowEvents = bannerData?.inflows ?? [];
@@ -99,7 +103,7 @@ export const getCashManagementOverview = (state) => {
99
103
  const cashflow = subtractAmounts(totalInFlow, totalOutFlow);
100
104
  const projectionData = buildProjectionData(cashBalance, inflowEvents, outflowEvents);
101
105
  return {
102
- banner: getCashManagementOverviewBanner(state),
106
+ banner: bannerView,
103
107
  cashBalance,
104
108
  cashflow,
105
109
  inflowEvents,
@@ -206,20 +210,3 @@ const addAmounts = (a, b) => {
206
210
  currencySymbol: a.currencySymbol,
207
211
  };
208
212
  };
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
- };
@@ -32,7 +32,7 @@ const updateCapitalizationAccountThresholdEpic = (actions$, state$, zeniAPI) =>
32
32
  const body = {
33
33
  capitalizable_account_overrides: Object.keys(finalOverrides).length > 0 ? finalOverrides : null,
34
34
  };
35
- if (dismissOnboardingForAccount) {
35
+ if (dismissOnboardingForAccount === true) {
36
36
  body.capitalization_onboarding_dismissed_accounts = { [accountId]: true };
37
37
  }
38
38
  return zeniAPI
@@ -58,7 +58,7 @@ const updateCapitalizationAccountThresholdEpic = (actions$, state$, zeniAPI) =>
58
58
  : null)
59
59
  : undefined,
60
60
  }));
61
- if (dismissOnboardingForAccount) {
61
+ if (dismissOnboardingForAccount === true) {
62
62
  actions.push((0, tenantReducer_1.updateTenantCapitalizationOnboardingDismissed)({
63
63
  tenantId,
64
64
  accountId,
@@ -20,14 +20,16 @@ const getAutoSweepFlow = (state) => {
20
20
  : undefined;
21
21
  const risk = (0, autoSweepFlowState_1.bufferAmountToRisk)(bufferAmount.amount);
22
22
  // The banner's recommended sweep assumes the default buffer band; shift it
23
- // by the delta between the user's selected band and that default so a
24
- // tighter buffer sweeps more and a looser buffer sweeps less.
23
+ // by the delta between the default buffer and the user's selected band so a
24
+ // tighter buffer (higher risk → smaller buffer) sweeps more and a looser
25
+ // buffer (lower risk → larger buffer) sweeps less. Clamp at zero so a buffer
26
+ // larger than the available surplus never yields a negative sweep.
25
27
  const baseSweepAmount = (0, cashManagementOverviewSelector_1.getCashManagementOverviewBanner)(state).amount;
26
28
  const sweepAmount = {
27
29
  ...baseSweepAmount,
28
- amount: baseSweepAmount.amount +
29
- autoSweepFlowState_1.RISK_BUFFER_AMOUNT[risk] -
30
- autoSweepFlowState_1.RISK_BUFFER_AMOUNT[DEFAULT_RISK_LEVEL],
30
+ amount: Math.max(0, baseSweepAmount.amount +
31
+ autoSweepFlowState_1.RISK_BUFFER_AMOUNT[DEFAULT_RISK_LEVEL] -
32
+ autoSweepFlowState_1.RISK_BUFFER_AMOUNT[risk]),
31
33
  };
32
34
  return {
33
35
  fetchState,
@@ -69,7 +69,7 @@ const pickLargestOutflow = (outflows) => {
69
69
  return outflows.reduce((largest, event) => event.amount.amount > largest.amount.amount ? event : largest);
70
70
  };
71
71
  const getCashManagementOverview = (state) => {
72
- const { cashManagementOverviewState, depositAccountListState, depositAccountState, paymentAccountListState, paymentAccountState, treasuryDetailState, } = state;
72
+ const { cashManagementOverviewState, depositAccountListState, paymentAccountListState, treasuryDetailState, } = state;
73
73
  const aggregate = (0, reduceFetchState_1.reduceAllFetchState)([
74
74
  {
75
75
  fetchState: paymentAccountListState.fetchState,
@@ -93,7 +93,11 @@ const getCashManagementOverview = (state) => {
93
93
  },
94
94
  ]);
95
95
  const treasuryBalance = treasuryDetailState.accountSummary?.totalBalance ?? (0, amount_1.zeroAmount)();
96
- const cashBalance = sumCashBalances(paymentAccountListState.paymentAccountIds, paymentAccountState, depositAccountListState.accountIds, depositAccountState);
96
+ const bannerView = (0, exports.getCashManagementOverviewBanner)(state);
97
+ // cashBalance is the primary (agent-managed) deposit account's available
98
+ // balance — the account the banner resolves as primaryFundingAccount — not
99
+ // the sum of all cash accounts. Zero until that account resolves.
100
+ const cashBalance = bannerView.primaryFundingAccount?.accountBalance?.available ?? (0, amount_1.zeroAmount)();
97
101
  const totalCash = addAmounts(treasuryBalance, cashBalance);
98
102
  const bannerData = cashManagementOverviewState.banner.data;
99
103
  const inflowEvents = bannerData?.inflows ?? [];
@@ -103,7 +107,7 @@ const getCashManagementOverview = (state) => {
103
107
  const cashflow = subtractAmounts(totalInFlow, totalOutFlow);
104
108
  const projectionData = buildProjectionData(cashBalance, inflowEvents, outflowEvents);
105
109
  return {
106
- banner: (0, exports.getCashManagementOverviewBanner)(state),
110
+ banner: bannerView,
107
111
  cashBalance,
108
112
  cashflow,
109
113
  inflowEvents,
@@ -211,20 +215,3 @@ const addAmounts = (a, b) => {
211
215
  currencySymbol: a.currencySymbol,
212
216
  };
213
217
  };
214
- const sumCashBalances = (paymentAccountIds, paymentAccountState, depositAccountIds, depositAccountState) => {
215
- let total = (0, amount_1.zeroAmount)();
216
- paymentAccountIds.forEach((id) => {
217
- const balance = paymentAccountState.paymentAccountByID[id]?.balances
218
- ?.available;
219
- if (balance != null) {
220
- total = addAmounts(total, balance);
221
- }
222
- });
223
- depositAccountIds.forEach((id) => {
224
- const balance = depositAccountState.depositAccountByID[id]?.accountBalance?.available;
225
- if (balance != null) {
226
- total = addAmounts(total, balance);
227
- }
228
- });
229
- return total;
230
- };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeniai/client-epic-state",
3
- "version": "5.0.100",
3
+ "version": "5.1.0-betaAK1",
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",
@@ -33,40 +33,6 @@
33
33
  "require": "./lib/view/*.js"
34
34
  }
35
35
  },
36
- "scripts": {
37
- "clean": "rimraf lib",
38
- "test:typecheck": "echo 'Typechecking test files...' && NODE_OPTIONS=--max-old-space-size=4096 time tsc -p tsconfig.typecheck.json",
39
- "test:typecheck-modified-files": "chmod +x ./scripts/tsc-modified-files.sh && ./scripts/tsc-modified-files.sh master tsconfig.typecheck.json",
40
- "test": "pnpm lint-modified-files && pnpm test:typecheck-modified-files && vitest run --typecheck",
41
- "test:full": "vitest run --typecheck",
42
- "lint": "eslint . --ext .js,.jsx,.ts,.tsx --max-warnings 0 --fix",
43
- "lint-modified-files": "chmod +x ./scripts/lint-modified-files.sh && ./scripts/lint-modified-files.sh",
44
- "lint:fix-modified-files": "chmod +x ./scripts/lint-modified-files.sh && LINT_FIX=true ./scripts/lint-modified-files.sh",
45
- "tsc-modified-files": "chmod +x ./scripts/tsc-modified-files.sh && ./scripts/tsc-modified-files.sh",
46
- "typecheck": "tsc --noEmit",
47
- "find-dead-code": "ts-prune | grep -v '(used in module)'",
48
- "find-unused-exports": "ts-unused-exports ./tsconfig.json",
49
- "circular-dependency": "npx madge --circular --extensions ts ./src",
50
- "build": "concurrently --kill-others-on-fail --handle-input \"echo 'TypeScript build in progress...' && time tsc && echo 'ESM build...' && tsc -p tsconfig.esm.json\" \"echo 'Running tests and typecheck (incl. lint-modified-files)...' && pnpm test\" && rimraf \"lib/**/__mocks__\" \"lib/**/__testHelpers__\"",
51
- "only-build": "eslint . --ext .js,.jsx,.ts,.tsx && time tsc && tsc -p tsconfig.esm.json && rimraf \"lib/**/__mocks__\" \"lib/**/__testHelpers__\"",
52
- "only-build-dev": "eslint . --ext .js,.jsx,.ts,.tsx && time tsc -p tsconfig.dev.json && tsc -p tsconfig.esm.dev.json && rimraf \"lib/**/__mocks__\" \"lib/**/__testHelpers__\"",
53
- "format": "prettier --write --ignore-unknown \"src/**/*\" && pnpm lint",
54
- "format-watch": "(git diff --name-only --diff-filter=ACM && git ls-files --others --exclude-standard) | grep -E '\\.(ts|tsx)$' | xargs prettier --write",
55
- "check-version": "node ./scripts/check_version.js",
56
- "prepublishOnly": "chmod +x ./scripts/branch_validation.sh && ./scripts/branch_validation.sh && pnpm update-slack-group-topic && pnpm run check-version && pnpm clean && pnpm build",
57
- "version": "git add -A src",
58
- "postversion": "git push && git push --tags",
59
- "check-dependencies": "node ./scripts/check_dependencies.js",
60
- "clean-overrides": "node ./scripts/clean_overrides.js",
61
- "create-release-branch": "chmod +x ./scripts/create_release_branch.sh && ./scripts/create_release_branch.sh",
62
- "bump-update-web-app-cockpit-beta": "chmod +x ./scripts/bump_and_update_web_app_ui_beta.sh && ./scripts/bump_and_update_web_app_ui_beta.sh",
63
- "send-release-notes": "chmod +x ./scripts/send_release_notes.sh && ./scripts/send_release_notes.sh",
64
- "update-slack-group-topic": "chmod +x ./scripts/update-slack-group-topic.sh && ./scripts/update-slack-group-topic.sh",
65
- "build-beta-and-copy": "chmod +x ./scripts/build_and_copy.sh && ./scripts/build_and_copy.sh",
66
- "pr-approvals-update": "chmod +x ./scripts/pr_approvals.sh && ./scripts/pr_approvals.sh",
67
- "raise-pr-automation": "chmod +x ./scripts/raise_pr_automation.sh && ./scripts/raise_pr_automation.sh",
68
- "test:file": "scripts/test-file.sh"
69
- },
70
36
  "files": [
71
37
  "lib/**/*"
72
38
  ],
@@ -137,32 +103,37 @@
137
103
  "dayjs": "^1.10.7",
138
104
  "url-parse": "^1.5.10"
139
105
  },
140
- "pnpm": {
141
- "overrides": {
142
- "@babel/helpers": ">=7.26.10",
143
- "@babel/runtime": ">=7.26.10",
144
- "@babel/traverse": ">=7.23.2",
145
- "@eslint/eslintrc>ajv": ">=6.14.0 <7",
146
- "@eslint/plugin-kit": ">=0.3.4",
147
- "@modelcontextprotocol/sdk": ">=1.25.2",
148
- "ajv": ">=8.18.0",
149
- "body-parser": ">=2.2.1",
150
- "brace-expansion": ">=5.0.6",
151
- "cross-spawn": ">=7.0.5",
152
- "eslint>ajv": ">=6.14.0 <7",
153
- "flatted": ">=3.4.2",
154
- "glob": ">=11.1.0",
155
- "hono": ">=4.11.4",
156
- "immutable": ">=4.3.8 <5",
157
- "js-yaml": ">=4.1.1",
158
- "minimatch": ">=10.2.3",
159
- "picomatch": ">=4.0.4",
160
- "postcss": ">=8.5.12",
161
- "qs": "^6.14.1",
162
- "rollup": ">=4.59.0",
163
- "tough-cookie": "=4.1.3",
164
- "vite": ">=7.3.2 <8",
165
- "yaml": ">=1.10.3"
166
- }
106
+ "scripts": {
107
+ "clean": "rimraf lib",
108
+ "test:typecheck": "echo 'Typechecking test files...' && NODE_OPTIONS=--max-old-space-size=4096 time tsc -p tsconfig.typecheck.json",
109
+ "test:typecheck-modified-files": "chmod +x ./scripts/tsc-modified-files.sh && ./scripts/tsc-modified-files.sh master tsconfig.typecheck.json",
110
+ "test": "pnpm lint-modified-files && pnpm test:typecheck-modified-files && vitest run --typecheck",
111
+ "test:full": "vitest run --typecheck",
112
+ "lint": "eslint . --ext .js,.jsx,.ts,.tsx --max-warnings 0 --fix",
113
+ "lint-modified-files": "chmod +x ./scripts/lint-modified-files.sh && ./scripts/lint-modified-files.sh",
114
+ "lint:fix-modified-files": "chmod +x ./scripts/lint-modified-files.sh && LINT_FIX=true ./scripts/lint-modified-files.sh",
115
+ "tsc-modified-files": "chmod +x ./scripts/tsc-modified-files.sh && ./scripts/tsc-modified-files.sh",
116
+ "typecheck": "tsc --noEmit",
117
+ "find-dead-code": "ts-prune | grep -v '(used in module)'",
118
+ "find-unused-exports": "ts-unused-exports ./tsconfig.json",
119
+ "circular-dependency": "npx madge --circular --extensions ts ./src",
120
+ "build": "concurrently --kill-others-on-fail --handle-input \"echo 'TypeScript build in progress...' && time tsc && echo 'ESM build...' && tsc -p tsconfig.esm.json\" \"echo 'Running tests and typecheck (incl. lint-modified-files)...' && pnpm test\" && rimraf \"lib/**/__mocks__\" \"lib/**/__testHelpers__\"",
121
+ "only-build": "eslint . --ext .js,.jsx,.ts,.tsx && time tsc && tsc -p tsconfig.esm.json && rimraf \"lib/**/__mocks__\" \"lib/**/__testHelpers__\"",
122
+ "only-build-dev": "eslint . --ext .js,.jsx,.ts,.tsx && time tsc -p tsconfig.dev.json && tsc -p tsconfig.esm.dev.json && rimraf \"lib/**/__mocks__\" \"lib/**/__testHelpers__\"",
123
+ "format": "prettier --write --ignore-unknown \"src/**/*\" && pnpm lint",
124
+ "format-watch": "(git diff --name-only --diff-filter=ACM && git ls-files --others --exclude-standard) | grep -E '\\.(ts|tsx)$' | xargs prettier --write",
125
+ "check-version": "node ./scripts/check_version.js",
126
+ "version": "git add -A src",
127
+ "postversion": "git push && git push --tags",
128
+ "check-dependencies": "node ./scripts/check_dependencies.js",
129
+ "clean-overrides": "node ./scripts/clean_overrides.js",
130
+ "create-release-branch": "chmod +x ./scripts/create_release_branch.sh && ./scripts/create_release_branch.sh",
131
+ "bump-update-web-app-cockpit-beta": "chmod +x ./scripts/bump_and_update_web_app_ui_beta.sh && ./scripts/bump_and_update_web_app_ui_beta.sh",
132
+ "send-release-notes": "chmod +x ./scripts/send_release_notes.sh && ./scripts/send_release_notes.sh",
133
+ "update-slack-group-topic": "chmod +x ./scripts/update-slack-group-topic.sh && ./scripts/update-slack-group-topic.sh",
134
+ "build-beta-and-copy": "chmod +x ./scripts/build_and_copy.sh && ./scripts/build_and_copy.sh",
135
+ "pr-approvals-update": "chmod +x ./scripts/pr_approvals.sh && ./scripts/pr_approvals.sh",
136
+ "raise-pr-automation": "chmod +x ./scripts/raise_pr_automation.sh && ./scripts/raise_pr_automation.sh",
137
+ "test:file": "scripts/test-file.sh"
167
138
  }
168
- }
139
+ }