@zeniai/client-epic-state 5.0.55-betaVR1 → 5.0.56

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 (138) hide show
  1. package/lib/commonStateTypes/recommendationBase.d.ts +1 -2
  2. package/lib/commonStateTypes/viewAndReport/viewAndReport.d.ts +2 -2
  3. package/lib/commonStateTypes/viewAndReport/viewAndReport.js +0 -1
  4. package/lib/entity/account/accountState.d.ts +1 -1
  5. package/lib/entity/accountGroup/accountGroupState.d.ts +1 -1
  6. package/lib/entity/class/classReducer.d.ts +4 -4
  7. package/lib/entity/class/classState.d.ts +1 -1
  8. package/lib/entity/forecast/forecastState.d.ts +1 -1
  9. package/lib/entity/project/projectPayload.d.ts +1 -8
  10. package/lib/entity/project/projectPayload.js +1 -15
  11. package/lib/entity/project/projectState.d.ts +2 -4
  12. package/lib/entity/sectionAccountsView/sectionAccountsView.d.ts +1 -1
  13. package/lib/entity/sectionClassesViewV2/sectionClassesView.d.ts +1 -1
  14. package/lib/entity/sectionClassesViewV2/sectionClassesViewReducer.d.ts +2 -2
  15. package/lib/entity/sectionProjectView/sectionProjectView.d.ts +1 -1
  16. package/lib/entity/sectionProjectView/sectionProjectViewReducer.d.ts +2 -2
  17. package/lib/entity/tenant/clearAllEpic.d.ts +1 -2
  18. package/lib/entity/tenant/clearAllEpic.js +0 -2
  19. package/lib/entity/tenant/epic/deleteConnectionEpic.d.ts +1 -1
  20. package/lib/entity/tenant/epic/saveAPIKeyConnectionEpic.d.ts +1 -1
  21. package/lib/entity/tenant/epic/saveOAuthConnectionEpic.d.ts +1 -1
  22. package/lib/entity/tenant/tenantReducer.d.ts +16 -64
  23. package/lib/entity/tenant/tenantReducer.js +7 -86
  24. package/lib/entity/tenant/tenantState.d.ts +1 -3
  25. package/lib/entity/transaction/payloadTypes/transactionLinePayload.d.ts +0 -2
  26. package/lib/entity/transaction/payloadTypes/transactionLinePayload.js +0 -9
  27. package/lib/entity/transaction/payloadTypes/transactionPayload.d.ts +0 -2
  28. package/lib/entity/transaction/payloadTypes/transactionPayload.js +0 -6
  29. package/lib/entity/transaction/stateTypes/transaction.d.ts +0 -2
  30. package/lib/entity/transaction/stateTypes/transactionLine.d.ts +0 -2
  31. package/lib/epic.d.ts +1 -4
  32. package/lib/epic.js +1 -5
  33. package/lib/esm/commonStateTypes/viewAndReport/viewAndReport.js +0 -1
  34. package/lib/esm/entity/project/projectPayload.js +0 -12
  35. package/lib/esm/entity/tenant/clearAllEpic.js +0 -2
  36. package/lib/esm/entity/tenant/tenantReducer.js +5 -84
  37. package/lib/esm/entity/transaction/payloadTypes/transactionLinePayload.js +0 -9
  38. package/lib/esm/entity/transaction/payloadTypes/transactionPayload.js +0 -6
  39. package/lib/esm/epic.js +1 -5
  40. package/lib/esm/index.js +7 -13
  41. package/lib/esm/reducer.js +0 -3
  42. package/lib/esm/view/expenseAutomationView/epics/transactionCategorization/fetchTransactionCategorizationViewEpic.js +0 -8
  43. package/lib/esm/view/expenseAutomationView/epics/transactionCategorization/updateTransactionCategorizationEpic.js +0 -3
  44. package/lib/esm/view/expenseAutomationView/helpers/saveTransactionHelper.js +0 -1
  45. package/lib/esm/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.js +2 -11
  46. package/lib/esm/view/expenseAutomationView/reducers/transactionsViewReducer.js +4 -13
  47. package/lib/esm/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +2 -7
  48. package/lib/esm/view/expenseAutomationView/types/transactionsViewState.js +0 -1
  49. package/lib/esm/view/profitAndLossClassesView/profitAndLossHorizontalEnrichment.js +0 -44
  50. package/lib/esm/view/spendManagement/zeniAccounts/depositAccountDetail/depositAccountDetailSelector.js +1 -1
  51. package/lib/esm/view/spendManagement/zeniAccounts/depositAccountDetail/fetchDepositAccountDetailEpic.js +2 -7
  52. package/lib/esm/view/transactionDetail/epics/saveTransactionHelper.js +0 -1
  53. package/lib/esm/view/transactionDetail/epics/transactionDetailEpic.js +0 -6
  54. package/lib/esm/view/transactionDetail/epics/updateTransactionDetailEpic.js +0 -3
  55. package/lib/esm/view/transactionDetail/transactionDetailSelector.js +2 -14
  56. package/lib/esm/view/transactionList/transactionListReducer.js +2 -83
  57. package/lib/esm/view/transactionList/transactionListState.js +0 -10
  58. package/lib/index.d.ts +9 -17
  59. package/lib/index.js +30 -52
  60. package/lib/reducer.d.ts +0 -3
  61. package/lib/reducer.js +0 -3
  62. package/lib/tsconfig.typecheck.tsbuildinfo +1 -0
  63. package/lib/view/auditReportView/auditReportViewState.d.ts +1 -1
  64. package/lib/view/billPayCard/billPayCardSelector.d.ts +1 -1
  65. package/lib/view/cardBalance/cardBalanceSelector.d.ts +1 -1
  66. package/lib/view/cashBalance/cashBalanceSelector.d.ts +1 -1
  67. package/lib/view/cashInCashOut/cashInCashOutSelector.d.ts +1 -1
  68. package/lib/view/cashPosition/cashPositionSelector.d.ts +1 -1
  69. package/lib/view/dashboard/dashboardReducer.d.ts +2 -2
  70. package/lib/view/expenseAutomationView/epics/transactionCategorization/fetchTransactionCategorizationViewEpic.d.ts +1 -2
  71. package/lib/view/expenseAutomationView/epics/transactionCategorization/fetchTransactionCategorizationViewEpic.js +0 -8
  72. package/lib/view/expenseAutomationView/epics/transactionCategorization/updateTransactionCategorizationEpic.js +0 -3
  73. package/lib/view/expenseAutomationView/helpers/saveTransactionHelper.js +0 -1
  74. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -2
  75. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.js +2 -11
  76. package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.d.ts +1 -3
  77. package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.js +4 -13
  78. package/lib/view/expenseAutomationView/selectorTypes/transactionsViewSelectorTypes.d.ts +0 -3
  79. package/lib/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +1 -6
  80. package/lib/view/expenseAutomationView/types/transactionsViewState.d.ts +1 -4
  81. package/lib/view/expenseAutomationView/types/transactionsViewState.js +0 -1
  82. package/lib/view/financeStatement/financeStatementReducer.d.ts +1 -1
  83. package/lib/view/globalMerchantView/globalMerchantViewReducer.d.ts +2 -2
  84. package/lib/view/profitAndLossClassesView/profitAndLossHorizontalEnrichment.d.ts +1 -15
  85. package/lib/view/profitAndLossClassesView/profitAndLossHorizontalEnrichment.js +0 -45
  86. package/lib/view/reimbursementCard/reimbursementCardSelector.d.ts +1 -1
  87. package/lib/view/reportsResync/reportsResyncReducer.d.ts +2 -2
  88. package/lib/view/spendManagement/zeniAccounts/depositAccountDetail/depositAccountDetailSelector.js +1 -1
  89. package/lib/view/spendManagement/zeniAccounts/depositAccountDetail/fetchDepositAccountDetailEpic.js +2 -7
  90. package/lib/view/tasksCard/tasksCardSelector.d.ts +1 -1
  91. package/lib/view/topEx/topExSelector.d.ts +1 -1
  92. package/lib/view/transactionDetail/epics/saveTransactionHelper.js +0 -1
  93. package/lib/view/transactionDetail/epics/transactionDetailEpic.d.ts +1 -2
  94. package/lib/view/transactionDetail/epics/transactionDetailEpic.js +0 -6
  95. package/lib/view/transactionDetail/epics/updateTransactionDetailEpic.js +0 -3
  96. package/lib/view/transactionDetail/transactionDetailSelector.d.ts +0 -3
  97. package/lib/view/transactionDetail/transactionDetailSelector.js +1 -13
  98. package/lib/view/transactionDetail/transactionDetailState.d.ts +0 -2
  99. package/lib/view/transactionDetail/transactionDetailTypes.d.ts +0 -2
  100. package/lib/view/transactionList/transactionListPayload.d.ts +0 -15
  101. package/lib/view/transactionList/transactionListReducer.d.ts +2 -25
  102. package/lib/view/transactionList/transactionListReducer.js +2 -83
  103. package/lib/view/transactionList/transactionListState.d.ts +0 -15
  104. package/lib/view/transactionList/transactionListState.js +1 -13
  105. package/package.json +2 -2
  106. package/lib/entity/tenant/epic/saveConnectorCredentialsEpic.d.ts +0 -21
  107. package/lib/entity/tenant/epic/saveConnectorCredentialsEpic.js +0 -42
  108. package/lib/esm/entity/tenant/epic/saveConnectorCredentialsEpic.js +0 -38
  109. package/lib/esm/view/projectList/fetchProjectListEpic.js +0 -38
  110. package/lib/esm/view/projectList/projectListPayload.js +0 -1
  111. package/lib/esm/view/projectList/projectListReducer.js +0 -39
  112. package/lib/esm/view/projectList/projectListSelector.js +0 -9
  113. package/lib/esm/view/projectList/projectListState.js +0 -1
  114. package/lib/esm/view/transactionDetail/journalEntryLinesViewModel.js +0 -113
  115. package/lib/esm/view/transactionDetail/journalEntryLinesViewModel.vitest.js +0 -243
  116. package/lib/esm/view/transactionList/fetchTransactionListByProjectEpic.js +0 -45
  117. package/lib/esm/view/transactionList/parallelFetchProjectTransactionListEpic.js +0 -32
  118. package/lib/esm/view/transactionList/transactionListByProjectSelector.js +0 -58
  119. package/lib/view/projectList/fetchProjectListEpic.d.ts +0 -8
  120. package/lib/view/projectList/fetchProjectListEpic.js +0 -42
  121. package/lib/view/projectList/projectListPayload.d.ts +0 -7
  122. package/lib/view/projectList/projectListPayload.js +0 -2
  123. package/lib/view/projectList/projectListReducer.d.ts +0 -9
  124. package/lib/view/projectList/projectListReducer.js +0 -43
  125. package/lib/view/projectList/projectListSelector.d.ts +0 -8
  126. package/lib/view/projectList/projectListSelector.js +0 -13
  127. package/lib/view/projectList/projectListState.d.ts +0 -4
  128. package/lib/view/projectList/projectListState.js +0 -2
  129. package/lib/view/transactionDetail/journalEntryLinesViewModel.d.ts +0 -73
  130. package/lib/view/transactionDetail/journalEntryLinesViewModel.js +0 -124
  131. package/lib/view/transactionDetail/journalEntryLinesViewModel.vitest.d.ts +0 -1
  132. package/lib/view/transactionDetail/journalEntryLinesViewModel.vitest.js +0 -245
  133. package/lib/view/transactionList/fetchTransactionListByProjectEpic.d.ts +0 -8
  134. package/lib/view/transactionList/fetchTransactionListByProjectEpic.js +0 -52
  135. package/lib/view/transactionList/parallelFetchProjectTransactionListEpic.d.ts +0 -6
  136. package/lib/view/transactionList/parallelFetchProjectTransactionListEpic.js +0 -36
  137. package/lib/view/transactionList/transactionListByProjectSelector.d.ts +0 -22
  138. package/lib/view/transactionList/transactionListByProjectSelector.js +0 -66
@@ -1,38 +0,0 @@
1
- import { from } from 'rxjs';
2
- import { catchError, filter, mergeMap, switchMap } from 'rxjs/operators';
3
- import { createZeniAPIStatus, isSuccessResponse } from '../../../responsePayload';
4
- import { saveConnectorCredentials, saveConnectorCredentialsFailure, saveConnectorCredentialsSuccess, } from '../tenantReducer';
5
- // Backs the new POST /1.0/connectors/<slug>/credentials endpoint used by
6
- // Phase 1 connectors (Stripe + Mercury api_key, PayPal client_credentials).
7
- // The endpoint is slug-keyed and creates-or-updates the Connection row, so the
8
- // FE doesn't need a connection_id in the URL. The credentials payload is
9
- // connector-specific (api_key, or client_id+client_secret) and is forwarded
10
- // verbatim to the BE — connector-side validation lives in
11
- // prepare_credential_update_args on the tenant service.
12
- export const saveConnectorCredentialsEpic = (actions$,
13
- // Underscore prefix marks the parameter as intentionally unused today but
14
- // names what it will become — when we wire an in-progress guard (so a
15
- // second save click can't `switchMap`-cancel an in-flight save and leave
16
- // the BE in an indeterminate state), drop the underscore and read state
17
- // here.
18
- _state$, zeniAPI) => actions$.pipe(filter(saveConnectorCredentials.match), switchMap((action) => zeniAPI
19
- .postAndGetJSON(`${zeniAPI.apiEndPoints.tenantMicroServiceBaseUrl}/1.0/connectors/${action.payload.connectionName}/credentials`, action.payload.credentials, { 'zeni-tenant-id': action.payload.tenantId })
20
- .pipe(mergeMap((response) => {
21
- if (isSuccessResponse(response) && response.data != null) {
22
- return from([
23
- saveConnectorCredentialsSuccess(action.payload.tenantId, action.payload.connectionType, action.payload.connectionName, response.data),
24
- ]);
25
- }
26
- const status = response.status ??
27
- createZeniAPIStatus('Failed to save connection. Please try again.');
28
- return from([
29
- saveConnectorCredentialsFailure(action.payload.tenantId, action.payload.connectionName, status),
30
- ]);
31
- }), catchError((error) => {
32
- const message = error instanceof Error
33
- ? error.message
34
- : 'Unexpected error saving connection.';
35
- return from([
36
- saveConnectorCredentialsFailure(action.payload.tenantId, action.payload.connectionName, createZeniAPIStatus(message)),
37
- ]);
38
- }))));
@@ -1,38 +0,0 @@
1
- import { of } from 'rxjs';
2
- import { catchError, filter, mergeMap, switchMap, withLatestFrom, } from 'rxjs/operators';
3
- import { updateProjects } from '../../entity/project/projectReducer';
4
- import { getIsAccountingProjectsEnabled } from '../../entity/tenant/tenantSelector';
5
- import { createZeniAPIStatus, isSuccessResponse } from '../../responsePayload';
6
- import { fetchProjectList, updateProjectList, updateProjectListFailure, } from './projectListReducer';
7
- const buildProjectListQuery = (isIncludeDeleted) => {
8
- const query = {
9
- is_deleted: isIncludeDeleted,
10
- sort_by: 'project_name',
11
- sort_order: 'asc',
12
- is_full: true,
13
- };
14
- return `?query=${encodeURIComponent(JSON.stringify(query))}`;
15
- };
16
- export const fetchProjectListEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(fetchProjectList.match), withLatestFrom(state$), switchMap(([action, state]) => {
17
- if (!getIsAccountingProjectsEnabled(state)) {
18
- return of(updateProjectList({
19
- status: createZeniAPIStatus('Success', ''),
20
- data: { projects: [] },
21
- }));
22
- }
23
- const { isIncludeDeleted } = action.payload;
24
- const queryParams = buildProjectListQuery(isIncludeDeleted);
25
- return zeniAPI
26
- .getJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/projects${queryParams}`)
27
- .pipe(mergeMap((response) => {
28
- if (isSuccessResponse(response)) {
29
- return of(updateProjects(response.data?.projects ?? []), updateProjectList(response));
30
- }
31
- else {
32
- return of(updateProjectListFailure(response.status));
33
- }
34
- }), catchError((error) => {
35
- return of(updateProjectListFailure(createZeniAPIStatus('Unexpected Error', 'Fetch Projects REST API call errored out' +
36
- JSON.stringify(error))));
37
- }));
38
- }));
@@ -1 +0,0 @@
1
- export {};
@@ -1,39 +0,0 @@
1
- import { createSlice } from '@reduxjs/toolkit';
2
- export const initialState = {
3
- fetchState: 'Not-Started',
4
- error: undefined,
5
- projectIds: [],
6
- hasValidState() {
7
- return this.fetchState == 'Completed';
8
- },
9
- };
10
- const projectList = createSlice({
11
- name: 'projectList',
12
- initialState,
13
- reducers: {
14
- fetchProjectList: {
15
- reducer(draft) {
16
- draft.fetchState = 'In-Progress';
17
- draft.error = undefined;
18
- },
19
- prepare(isIncludeDeleted) {
20
- return { payload: { isIncludeDeleted: isIncludeDeleted ?? false } };
21
- },
22
- },
23
- updateProjectList(draft, action) {
24
- draft.projectIds =
25
- action.payload.data?.projects?.map((project) => project.zeni_project_id) ?? [];
26
- draft.fetchState = 'Completed';
27
- draft.error = undefined;
28
- },
29
- updateProjectListFailure(draft, action) {
30
- draft.fetchState = 'Error';
31
- draft.error = action.payload;
32
- },
33
- clearProjectList(draft) {
34
- Object.assign(draft, initialState);
35
- },
36
- },
37
- });
38
- export const { fetchProjectList, updateProjectList, updateProjectListFailure, clearProjectList, } = projectList.actions;
39
- export default projectList.reducer;
@@ -1,9 +0,0 @@
1
- import { getProjectsByIds } from '../../entity/project/projectSelector';
2
- export const getProjectList = (projectState, projectListState) => {
3
- return {
4
- projects: getProjectsByIds(projectState, projectListState.projectIds),
5
- fetchState: projectListState.fetchState,
6
- error: projectListState.error,
7
- version: 0,
8
- };
9
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,113 +0,0 @@
1
- import orderBy from 'lodash/orderBy';
2
- import { stringToUnion } from '../../commonStateTypes/stringToUnion';
3
- /**
4
- * View-model helpers for the new Journal Entry table view (see
5
- * web-components `journalEntryTable`). Keeps presentation-agnostic
6
- * logic — totals, sort, line-filter — colocated in epic-state so it
7
- * is testable and reusable.
8
- */
9
- // ---------------------------------------------------------------------------
10
- // Sort keys
11
- // ---------------------------------------------------------------------------
12
- export const JOURNAL_ENTRY_SORT_KEYS = [
13
- 'description',
14
- 'name',
15
- 'category',
16
- 'class',
17
- 'debit',
18
- 'credit',
19
- ];
20
- export const toJournalEntrySortKey = (v) => stringToUnion(v, JOURNAL_ENTRY_SORT_KEYS);
21
- export const journalEntryDefaultSortConfig = {
22
- sortKey: 'description',
23
- sortOrder: 'ascending',
24
- };
25
- /**
26
- * Sums the `amount.amount` field of every line and returns an `Amount`
27
- * whose currencyCode/currencySymbol are taken from the first line.
28
- * Returns `undefined` for an empty list.
29
- *
30
- * Mirrors legacy `calculateTotal` in
31
- * `web-components/src/components/transactionDetail/items/TransactionLinesJournalEntry.tsx`
32
- * but without the `Object.assign` ceremony and with stable currency carry-over.
33
- */
34
- export const sumJournalEntryAmounts = (lines) => {
35
- if (lines.length === 0) {
36
- return undefined;
37
- }
38
- const first = lines[0].amount;
39
- let total = 0;
40
- for (const line of lines) {
41
- total += line.amount?.amount ?? 0;
42
- }
43
- return {
44
- amount: total,
45
- currencyCode: first?.currencyCode ?? '',
46
- currencySymbol: first?.currencySymbol ?? '',
47
- };
48
- };
49
- /**
50
- * Splits `lines` by `postingType` into debit/credit totals.
51
- *
52
- * Fixes the operator-precedence bug from legacy
53
- * `calculateCombinedTotalAmount` where
54
- * `totalAmount?.amount ?? 0 + (...) + (...)` parses as
55
- * `totalAmount?.amount ?? (0 + ... + ...)` so the `(...)`'s only get
56
- * added when `totalAmount` is nullish. The new implementation just sums
57
- * every debit (or credit) line including the un/miscategorized ones in
58
- * one pass, so the result is always the true sum.
59
- */
60
- export const journalEntryTotalsByPostingSide = (lines) => {
61
- const debitLines = [];
62
- const creditLines = [];
63
- for (const line of lines) {
64
- if (line.postingType === 'debit') {
65
- debitLines.push(line);
66
- }
67
- else if (line.postingType === 'credit') {
68
- creditLines.push(line);
69
- }
70
- }
71
- return {
72
- debitTotal: sumJournalEntryAmounts(debitLines),
73
- creditTotal: sumJournalEntryAmounts(creditLines),
74
- };
75
- };
76
- // ---------------------------------------------------------------------------
77
- // Filter
78
- // ---------------------------------------------------------------------------
79
- /**
80
- * Drops `linked_transaction_line` entries — equivalent to legacy
81
- * `filterOutLinkedTransactionLine` in `transactionDetail.helpers.ts`.
82
- */
83
- export const filterJournalEntryLinesExcludingLinked = (lines) => lines?.filter((line) => line.type !== 'linked_transaction_line') ?? [];
84
- const sortOrderToLodash = (sortOrder) => sortOrder === 'descending' ? 'desc' : 'asc';
85
- /**
86
- * Stable, accessor-driven sort over arbitrary line shapes. Lines that
87
- * resolve to the same key value preserve their original relative order
88
- * thanks to lodash's stable `orderBy`.
89
- *
90
- * Strings are lower-cased before comparison so the order is predictable
91
- * across mixed-case data. Numbers (debit/credit) compare directly.
92
- */
93
- export const sortJournalEntryLines = (lines, config, accessors) => {
94
- const accessor = (line) => {
95
- switch (config.sortKey) {
96
- case 'description':
97
- return accessors.description(line).toLowerCase();
98
- case 'name':
99
- return accessors.name(line).toLowerCase();
100
- case 'category':
101
- return accessors.category(line).toLowerCase();
102
- case 'class':
103
- return accessors.class(line).toLowerCase();
104
- case 'debit':
105
- return accessors.debit(line);
106
- case 'credit':
107
- return accessors.credit(line);
108
- default:
109
- return accessors.description(line).toLowerCase();
110
- }
111
- };
112
- return orderBy([...lines], [accessor], [sortOrderToLodash(config.sortOrder)]);
113
- };
@@ -1,243 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { JOURNAL_ENTRY_SORT_KEYS, filterJournalEntryLinesExcludingLinked, journalEntryDefaultSortConfig, journalEntryTotalsByPostingSide, sortJournalEntryLines, sumJournalEntryAmounts, } from './journalEntryLinesViewModel';
3
- const usd = (amount) => ({
4
- amount,
5
- currencyCode: 'USD',
6
- currencySymbol: '$',
7
- });
8
- const debit = (n) => ({
9
- amount: usd(n),
10
- postingType: 'debit',
11
- });
12
- const credit = (n) => ({
13
- amount: usd(n),
14
- postingType: 'credit',
15
- });
16
- describe('sumJournalEntryAmounts', () => {
17
- it('returns undefined for an empty list', () => {
18
- expect(sumJournalEntryAmounts([])).toBeUndefined();
19
- });
20
- it('sums a single line as-is', () => {
21
- expect(sumJournalEntryAmounts([{ amount: usd(42) }])).toEqual(usd(42));
22
- });
23
- it('sums multiple lines preserving the first line currency', () => {
24
- const total = sumJournalEntryAmounts([
25
- { amount: usd(10) },
26
- { amount: usd(20.5) },
27
- { amount: usd(0.5) },
28
- ]);
29
- expect(total).toEqual(usd(31));
30
- });
31
- it('treats nullish amount.amount as 0 without crashing', () => {
32
- const total = sumJournalEntryAmounts([
33
- { amount: usd(10) },
34
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
- { amount: { currencyCode: 'USD', currencySymbol: '$' } },
36
- { amount: usd(5) },
37
- ]);
38
- expect(total).toEqual(usd(15));
39
- });
40
- it('uses an empty currency code/symbol when first line lacks them', () => {
41
- const total = sumJournalEntryAmounts([
42
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
43
- { amount: { amount: 7 } },
44
- { amount: usd(3) },
45
- ]);
46
- expect(total).toEqual({ amount: 10, currencyCode: '', currencySymbol: '' });
47
- });
48
- });
49
- describe('journalEntryTotalsByPostingSide', () => {
50
- it('returns undefined totals for an empty list', () => {
51
- expect(journalEntryTotalsByPostingSide([])).toEqual({
52
- debitTotal: undefined,
53
- creditTotal: undefined,
54
- });
55
- });
56
- it('sums debits and credits separately when both sides present', () => {
57
- const { debitTotal, creditTotal } = journalEntryTotalsByPostingSide([
58
- debit(100),
59
- debit(50),
60
- credit(120),
61
- credit(30),
62
- ]);
63
- expect(debitTotal).toEqual(usd(150));
64
- expect(creditTotal).toEqual(usd(150));
65
- });
66
- it('returns only the populated side when one side is missing', () => {
67
- const onlyDebits = journalEntryTotalsByPostingSide([debit(10), debit(20)]);
68
- expect(onlyDebits.debitTotal).toEqual(usd(30));
69
- expect(onlyDebits.creditTotal).toBeUndefined();
70
- const onlyCredits = journalEntryTotalsByPostingSide([credit(99)]);
71
- expect(onlyCredits.creditTotal).toEqual(usd(99));
72
- expect(onlyCredits.debitTotal).toBeUndefined();
73
- });
74
- /**
75
- * Regression test for the operator-precedence bug in legacy
76
- * `calculateCombinedTotalAmount` where
77
- * `totalAmount?.amount ?? 0 + (uncategorized?.amount ?? 0) + (miscategorized?.amount ?? 0)`
78
- * parses as `totalAmount?.amount ?? (0 + ... + ...)`. With the bug,
79
- * an existing `totalAmount` would short-circuit and the uncat/miscat
80
- * pieces would be ignored. The new implementation always adds every
81
- * matching line, so 100 (cat) + 25 (uncat) + 10 (miscat) = 135.
82
- */
83
- it('does not drop uncategorized/miscategorized contributions (precedence-bug regression)', () => {
84
- const { debitTotal } = journalEntryTotalsByPostingSide([
85
- debit(100),
86
- debit(25),
87
- debit(10),
88
- ]);
89
- expect(debitTotal).toEqual(usd(135));
90
- });
91
- it('ignores lines with neither debit nor credit posting type', () => {
92
- const totals = journalEntryTotalsByPostingSide([
93
- debit(40),
94
- credit(40),
95
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
96
- { amount: usd(999), postingType: 'unknown' },
97
- ]);
98
- expect(totals.debitTotal).toEqual(usd(40));
99
- expect(totals.creditTotal).toEqual(usd(40));
100
- });
101
- });
102
- describe('filterJournalEntryLinesExcludingLinked', () => {
103
- it('returns [] for undefined input', () => {
104
- expect(filterJournalEntryLinesExcludingLinked(undefined)).toEqual([]);
105
- });
106
- it('filters out linked_transaction_line entries', () => {
107
- const lines = [
108
- { id: 'a', type: 'journal_entry_transaction_line' },
109
- { id: 'b', type: 'linked_transaction_line' },
110
- { id: 'c', type: 'journal_entry_transaction_line' },
111
- ];
112
- const filtered = filterJournalEntryLinesExcludingLinked(lines);
113
- expect(filtered).toHaveLength(2);
114
- expect(filtered[0].id).toBe('a');
115
- expect(filtered[1].id).toBe('c');
116
- });
117
- it('returns input unchanged when no linked lines exist', () => {
118
- const lines = [
119
- { id: 'a', type: 'journal_entry_transaction_line' },
120
- { id: 'b', type: 'journal_entry_transaction_line' },
121
- ];
122
- expect(filterJournalEntryLinesExcludingLinked(lines)).toHaveLength(2);
123
- });
124
- });
125
- describe('sortJournalEntryLines', () => {
126
- const accessors = {
127
- description: (r) => r.description,
128
- name: (r) => r.name,
129
- category: (r) => r.category,
130
- class: (r) => r.class,
131
- debit: (r) => r.debit,
132
- credit: (r) => r.credit,
133
- };
134
- const rows = [
135
- {
136
- id: '1',
137
- description: 'Beta',
138
- name: 'Acme',
139
- category: 'Rent',
140
- class: 'Ops',
141
- debit: 100,
142
- credit: 0,
143
- },
144
- {
145
- id: '2',
146
- description: 'alpha',
147
- name: 'Beta Co',
148
- category: 'Travel',
149
- class: 'GA',
150
- debit: 200,
151
- credit: 0,
152
- },
153
- {
154
- id: '3',
155
- description: 'Gamma',
156
- name: 'acme',
157
- category: 'Rent',
158
- class: 'Sales',
159
- debit: 0,
160
- credit: 50,
161
- },
162
- ];
163
- it('exposes every supported sort key via JOURNAL_ENTRY_SORT_KEYS', () => {
164
- expect([...JOURNAL_ENTRY_SORT_KEYS]).toEqual([
165
- 'description',
166
- 'name',
167
- 'category',
168
- 'class',
169
- 'debit',
170
- 'credit',
171
- ]);
172
- });
173
- it('sorts by description case-insensitively ascending by default', () => {
174
- const sorted = sortJournalEntryLines(rows, journalEntryDefaultSortConfig, accessors);
175
- expect(sorted.map((r) => r.id)).toEqual(['2', '1', '3']);
176
- });
177
- it('sorts by description descending when configured', () => {
178
- const config = {
179
- sortKey: 'description',
180
- sortOrder: 'descending',
181
- };
182
- const sorted = sortJournalEntryLines(rows, config, accessors);
183
- expect(sorted.map((r) => r.id)).toEqual(['3', '1', '2']);
184
- });
185
- it.each([
186
- ['name', 'ascending', ['1', '3', '2']],
187
- ['name', 'descending', ['2', '1', '3']],
188
- ['category', 'ascending', ['1', '3', '2']],
189
- ['class', 'ascending', ['2', '1', '3']],
190
- ['debit', 'ascending', ['3', '1', '2']],
191
- ['debit', 'descending', ['2', '1', '3']],
192
- ['credit', 'ascending', ['1', '2', '3']],
193
- ['credit', 'descending', ['3', '1', '2']],
194
- ])('sorts by %s %s producing the expected order', (key, order, expected) => {
195
- const config = {
196
- sortKey: key,
197
- sortOrder: order,
198
- };
199
- const sorted = sortJournalEntryLines(rows, config, accessors);
200
- expect(sorted.map((r) => r.id)).toEqual([...expected]);
201
- });
202
- it('keeps stable order for ties on the sort key', () => {
203
- const tied = [
204
- {
205
- id: 'a',
206
- description: 'same',
207
- name: '',
208
- category: '',
209
- class: '',
210
- debit: 0,
211
- credit: 0,
212
- },
213
- {
214
- id: 'b',
215
- description: 'same',
216
- name: '',
217
- category: '',
218
- class: '',
219
- debit: 0,
220
- credit: 0,
221
- },
222
- {
223
- id: 'c',
224
- description: 'same',
225
- name: '',
226
- category: '',
227
- class: '',
228
- debit: 0,
229
- credit: 0,
230
- },
231
- ];
232
- const sortedAsc = sortJournalEntryLines(tied, { sortKey: 'description', sortOrder: 'ascending' }, accessors);
233
- expect(sortedAsc.map((r) => r.id)).toEqual(['a', 'b', 'c']);
234
- const sortedDesc = sortJournalEntryLines(tied, { sortKey: 'description', sortOrder: 'descending' }, accessors);
235
- expect(sortedDesc.map((r) => r.id)).toEqual(['a', 'b', 'c']);
236
- });
237
- it('does not mutate the input array', () => {
238
- const input = [...rows];
239
- const before = input.map((r) => r.id);
240
- sortJournalEntryLines(input, { sortKey: 'description', sortOrder: 'descending' }, accessors);
241
- expect(input.map((r) => r.id)).toEqual(before);
242
- });
243
- });
@@ -1,45 +0,0 @@
1
- import { toBase64 } from 'js-base64';
2
- import lodashGet from 'lodash/get';
3
- import { from, of } from 'rxjs';
4
- import { catchError, filter, mergeMap } from 'rxjs/operators';
5
- import { toString } from '../../commonStateTypes/timePeriod';
6
- import { updateTransactions } from '../../entity/transaction/transactionReducer';
7
- import { createZeniAPIStatus, isSuccessResponse } from '../../responsePayload';
8
- import { fetchProjectTransactionList, updateTransactionListByProject, updateTransactionListByProjectFailure, } from './transactionListReducer';
9
- import { getProjectAcTranKey } from './transactionListState';
10
- export const fetchTransactionListByProjectEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(fetchProjectTransactionList.match), mergeMap((action) => {
11
- const state = state$.value;
12
- const key = getProjectAcTranKey(action.payload.accountId, action.payload.accountType, action.payload.projectId, action.payload.period);
13
- const projectTransactions = lodashGet(state.transactionListState.byProject.transactionListByProjectKey, key, undefined);
14
- if (action.payload.cacheOverride === true ||
15
- projectTransactions == null ||
16
- projectTransactions.hasValidState() === false) {
17
- const queryParam = {
18
- start_date: toString(action.payload.period.start),
19
- end_date: toString(action.payload.period.end),
20
- sort_by: 'create_time',
21
- sort_order: 'desc',
22
- account_id: action.payload.accountId,
23
- account_type: action.payload.accountType,
24
- zeni_project_id: action.payload.projectId,
25
- };
26
- const base64AccountId = toBase64(action.payload.accountId);
27
- return zeniAPI
28
- .getJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/accounts/${base64AccountId}/transactions?query=${encodeURIComponent(JSON.stringify(queryParam))}`)
29
- .pipe(mergeMap((response) => {
30
- if (isSuccessResponse(response) && response.data != null) {
31
- const updateActions = [];
32
- updateActions.push(updateTransactions(response.data.account.transactions, (value) => value.transaction_id));
33
- updateActions.push(updateTransactionListByProject(response.data));
34
- return from(updateActions);
35
- }
36
- else {
37
- return of(updateTransactionListByProjectFailure(action.payload.accountId, action.payload.accountType, action.payload.projectId, action.payload.period, response.status));
38
- }
39
- }), catchError((error) => of(updateTransactionListByProjectFailure(action.payload.accountId, action.payload.accountType, action.payload.projectId, action.payload.period, createZeniAPIStatus('Unexpected Error', 'fetch transaction list REST API call errored out' +
40
- JSON.stringify(error))))));
41
- }
42
- else {
43
- return from([]);
44
- }
45
- }));
@@ -1,32 +0,0 @@
1
- import { from } from 'rxjs';
2
- import { filter, mergeMap } from 'rxjs/operators';
3
- import { splitPeriod } from './parallelFetchClassTransactionListEpic';
4
- import { fetchProjectTransactionList, parallelFetchProjectTransactionList, } from './transactionListReducer';
5
- import { getProjectAcTranKey, } from './transactionListState';
6
- export const parallelFetchProjectTransactionListEpic = (actions$, state$) => actions$.pipe(filter(parallelFetchProjectTransactionList.match), mergeMap((action) => {
7
- const state = state$.value.transactionListState;
8
- const timePeriods = splitPeriod(action.payload.period);
9
- const filteredTimePeriods = timePeriods.filter((value) => {
10
- if (action.payload.cacheOverride === false) {
11
- return (isDataAvailableOrFetching(state.byProject, action.payload.accountId, action.payload.accountType, action.payload.projectId, value) === false);
12
- }
13
- else {
14
- return true;
15
- }
16
- });
17
- if (filteredTimePeriods.length > 12) {
18
- console.error('Only maximum 12 parallel fetch are allowed!');
19
- return from([]);
20
- }
21
- else {
22
- const fetchActions = filteredTimePeriods.map((period) => fetchProjectTransactionList(action.payload.accountId, action.payload.accountType, action.payload.projectId, period, true));
23
- return from(fetchActions);
24
- }
25
- }));
26
- function isDataAvailableOrFetching(state, accountId, accountType, projectId, period) {
27
- const key = getProjectAcTranKey(accountId, accountType, projectId, period);
28
- const projectTransactions = state.transactionListByProjectKey[key];
29
- return (projectTransactions != null &&
30
- (projectTransactions.fetchState === 'In-Progress' ||
31
- projectTransactions.hasValidState()));
32
- }
@@ -1,58 +0,0 @@
1
- import flatMap from 'lodash/flatMap';
2
- import recordGet from 'lodash/get';
3
- import orderBy from 'lodash/orderBy';
4
- import { getSupportedTransactionById } from '../../entity/transaction/transactionSelector';
5
- import { splitPeriod } from './parallelFetchAccountTransactionListEpic';
6
- import { isAnyFetchCompleted, reduceFetchState, } from './reduceTransactionListFetchState';
7
- import { getProjectAcKey, getProjectAcTranKey, } from './transactionListState';
8
- export const getTransactionListByProject = (transactionState, transactionListState, accountId, accountType, projectId, timeframe, filterByTimePeriod) => {
9
- const timePeriods = splitPeriod(filterByTimePeriod); // Note: Split by months.
10
- const accountTransactions = timePeriods
11
- .map((thisTimePeriod) => {
12
- const key = getProjectAcTranKey(accountId, accountType, projectId, thisTimePeriod);
13
- return recordGet(transactionListState.byProject.transactionListByProjectKey, key, undefined);
14
- })
15
- .filter((acTransaction) => acTransaction != null);
16
- let account = undefined;
17
- if (accountTransactions.length > 0) {
18
- account = accountTransactions[0].account;
19
- }
20
- const fetchState = reduceFetchState(accountTransactions);
21
- let transactions = [];
22
- if (isAnyFetchCompleted(accountTransactions)) {
23
- const allTransactionIDs = flatMap(accountTransactions, (value) => value.transactionIDs);
24
- const transactionsUnsorted = allTransactionIDs
25
- .map((transactionId) => getSupportedTransactionById(transactionState, transactionId))
26
- .filter((value) => {
27
- if (value == null) {
28
- console.error("Can't have null transaction at this stage!");
29
- }
30
- return value != null;
31
- });
32
- transactions = orderBy(transactionsUnsorted, (value) => value.date.valueOf(), 'desc');
33
- }
34
- const key = getProjectAcKey(accountId, accountType, projectId);
35
- const uiState = recordGet(transactionListState.byProject.transactionListUIStateByProjectKey, key, {});
36
- return {
37
- reportId: 'transaction_list_of_account_by_project',
38
- reportTitle: 'Transaction List of Account By Project',
39
- version: 1,
40
- status: undefined,
41
- fetchState: fetchState.fetchState,
42
- error: fetchState.error,
43
- timeframe,
44
- filterByTimePeriod,
45
- accountId,
46
- accountType,
47
- projectId,
48
- account,
49
- transactionOrder: 'descending_transaction_date',
50
- transactions,
51
- uiState,
52
- latestTransactionId: transactionListState.latestTransactionId,
53
- };
54
- };
55
- export const getTransactionListUIStateByProjectKey = (transactionListState, accountId, accountType, projectId) => {
56
- const key = getProjectAcKey(accountId, accountType, projectId);
57
- return recordGet(transactionListState.byProject.transactionListUIStateByProjectKey, key, undefined);
58
- };
@@ -1,8 +0,0 @@
1
- import { ActionsObservable, StateObservable } from 'redux-observable';
2
- import { Observable } from 'rxjs';
3
- import { updateProjects } from '../../entity/project/projectReducer';
4
- import { RootState } from '../../reducer';
5
- import { ZeniAPI } from '../../zeniAPI';
6
- import { fetchProjectList, updateProjectList, updateProjectListFailure } from './projectListReducer';
7
- export type ActionType = ReturnType<typeof fetchProjectList> | ReturnType<typeof updateProjects> | ReturnType<typeof updateProjectList> | ReturnType<typeof updateProjectListFailure>;
8
- export declare const fetchProjectListEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => Observable<ActionType>;