@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,42 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fetchProjectListEpic = void 0;
4
- const rxjs_1 = require("rxjs");
5
- const operators_1 = require("rxjs/operators");
6
- const projectReducer_1 = require("../../entity/project/projectReducer");
7
- const tenantSelector_1 = require("../../entity/tenant/tenantSelector");
8
- const responsePayload_1 = require("../../responsePayload");
9
- const projectListReducer_1 = require("./projectListReducer");
10
- const buildProjectListQuery = (isIncludeDeleted) => {
11
- const query = {
12
- is_deleted: isIncludeDeleted,
13
- sort_by: 'project_name',
14
- sort_order: 'asc',
15
- is_full: true,
16
- };
17
- return `?query=${encodeURIComponent(JSON.stringify(query))}`;
18
- };
19
- const fetchProjectListEpic = (actions$, state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(projectListReducer_1.fetchProjectList.match), (0, operators_1.withLatestFrom)(state$), (0, operators_1.switchMap)(([action, state]) => {
20
- if (!(0, tenantSelector_1.getIsAccountingProjectsEnabled)(state)) {
21
- return (0, rxjs_1.of)((0, projectListReducer_1.updateProjectList)({
22
- status: (0, responsePayload_1.createZeniAPIStatus)('Success', ''),
23
- data: { projects: [] },
24
- }));
25
- }
26
- const { isIncludeDeleted } = action.payload;
27
- const queryParams = buildProjectListQuery(isIncludeDeleted);
28
- return zeniAPI
29
- .getJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/projects${queryParams}`)
30
- .pipe((0, operators_1.mergeMap)((response) => {
31
- if ((0, responsePayload_1.isSuccessResponse)(response)) {
32
- return (0, rxjs_1.of)((0, projectReducer_1.updateProjects)(response.data?.projects ?? []), (0, projectListReducer_1.updateProjectList)(response));
33
- }
34
- else {
35
- return (0, rxjs_1.of)((0, projectListReducer_1.updateProjectListFailure)(response.status));
36
- }
37
- }), (0, operators_1.catchError)((error) => {
38
- return (0, rxjs_1.of)((0, projectListReducer_1.updateProjectListFailure)((0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', 'Fetch Projects REST API call errored out' +
39
- JSON.stringify(error))));
40
- }));
41
- }));
42
- exports.fetchProjectListEpic = fetchProjectListEpic;
@@ -1,7 +0,0 @@
1
- import { ProjectMetadataPayload } from '../../entity/project/projectPayload';
2
- import { ZeniAPIResponse } from '../../responsePayload';
3
- interface ProjectListPayloadData {
4
- projects: ProjectMetadataPayload[];
5
- }
6
- export type ProjectListResponse = ZeniAPIResponse<ProjectListPayloadData>;
7
- export {};
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,9 +0,0 @@
1
- import { ZeniAPIStatus } from '../../responsePayload';
2
- import { ProjectListResponse } from './projectListPayload';
3
- import { ProjectListState } from './projectListState';
4
- export declare const initialState: ProjectListState;
5
- export declare const fetchProjectList: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[isIncludeDeleted?: boolean | undefined], {
6
- isIncludeDeleted: boolean;
7
- }, "projectList/fetchProjectList", never, never>, updateProjectList: import("@reduxjs/toolkit").ActionCreatorWithPayload<ProjectListResponse, "projectList/updateProjectList">, updateProjectListFailure: import("@reduxjs/toolkit").ActionCreatorWithPayload<ZeniAPIStatus<Record<string, unknown>>, "projectList/updateProjectListFailure">, clearProjectList: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"projectList/clearProjectList">;
8
- declare const _default: import("redux").Reducer<ProjectListState>;
9
- export default _default;
@@ -1,43 +0,0 @@
1
- "use strict";
2
- var _a;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.clearProjectList = exports.updateProjectListFailure = exports.updateProjectList = exports.fetchProjectList = exports.initialState = void 0;
5
- const toolkit_1 = require("@reduxjs/toolkit");
6
- exports.initialState = {
7
- fetchState: 'Not-Started',
8
- error: undefined,
9
- projectIds: [],
10
- hasValidState() {
11
- return this.fetchState == 'Completed';
12
- },
13
- };
14
- const projectList = (0, toolkit_1.createSlice)({
15
- name: 'projectList',
16
- initialState: exports.initialState,
17
- reducers: {
18
- fetchProjectList: {
19
- reducer(draft) {
20
- draft.fetchState = 'In-Progress';
21
- draft.error = undefined;
22
- },
23
- prepare(isIncludeDeleted) {
24
- return { payload: { isIncludeDeleted: isIncludeDeleted ?? false } };
25
- },
26
- },
27
- updateProjectList(draft, action) {
28
- draft.projectIds =
29
- action.payload.data?.projects?.map((project) => project.zeni_project_id) ?? [];
30
- draft.fetchState = 'Completed';
31
- draft.error = undefined;
32
- },
33
- updateProjectListFailure(draft, action) {
34
- draft.fetchState = 'Error';
35
- draft.error = action.payload;
36
- },
37
- clearProjectList(draft) {
38
- Object.assign(draft, exports.initialState);
39
- },
40
- },
41
- });
42
- _a = projectList.actions, exports.fetchProjectList = _a.fetchProjectList, exports.updateProjectList = _a.updateProjectList, exports.updateProjectListFailure = _a.updateProjectListFailure, exports.clearProjectList = _a.clearProjectList;
43
- exports.default = projectList.reducer;
@@ -1,8 +0,0 @@
1
- import { SelectorView } from '../../commonStateTypes/viewAndReport/viewAndReport';
2
- import { ProjectState } from '../../entity/project/projectReducer';
3
- import { Project } from '../../entity/project/projectState';
4
- import { ProjectListState } from './projectListState';
5
- export interface ProjectListSelectorView extends SelectorView {
6
- projects: Project[];
7
- }
8
- export declare const getProjectList: (projectState: ProjectState, projectListState: ProjectListState) => ProjectListSelectorView;
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getProjectList = void 0;
4
- const projectSelector_1 = require("../../entity/project/projectSelector");
5
- const getProjectList = (projectState, projectListState) => {
6
- return {
7
- projects: (0, projectSelector_1.getProjectsByIds)(projectState, projectListState.projectIds),
8
- fetchState: projectListState.fetchState,
9
- error: projectListState.error,
10
- version: 0,
11
- };
12
- };
13
- exports.getProjectList = getProjectList;
@@ -1,4 +0,0 @@
1
- import { FetchedState, ID } from '../../commonStateTypes/common';
2
- export interface ProjectListState extends FetchedState {
3
- projectIds: ID[];
4
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,73 +0,0 @@
1
- import { Amount } from '../../commonStateTypes/amount';
2
- import { SortOrder } from '../../commonStateTypes/selectorTypes/sortOrderTypes';
3
- import { JournalEntryTransactionLine, Line, TransactionLineBase } from '../../entity/transaction/stateTypes/transactionLine';
4
- /**
5
- * View-model helpers for the new Journal Entry table view (see
6
- * web-components `journalEntryTable`). Keeps presentation-agnostic
7
- * logic — totals, sort, line-filter — colocated in epic-state so it
8
- * is testable and reusable.
9
- */
10
- export declare const JOURNAL_ENTRY_SORT_KEYS: readonly ["description", "name", "category", "class", "debit", "credit"];
11
- export declare const toJournalEntrySortKey: (v: string) => "name" | "description" | "category" | "class" | "credit" | "debit";
12
- export type JournalEntrySortKey = ReturnType<typeof toJournalEntrySortKey>;
13
- export interface JournalEntryRowSortConfig {
14
- sortKey: JournalEntrySortKey;
15
- sortOrder: SortOrder;
16
- }
17
- export declare const journalEntryDefaultSortConfig: JournalEntryRowSortConfig;
18
- type AmountBearer = Pick<TransactionLineBase, 'amount'>;
19
- /**
20
- * Sums the `amount.amount` field of every line and returns an `Amount`
21
- * whose currencyCode/currencySymbol are taken from the first line.
22
- * Returns `undefined` for an empty list.
23
- *
24
- * Mirrors legacy `calculateTotal` in
25
- * `web-components/src/components/transactionDetail/items/TransactionLinesJournalEntry.tsx`
26
- * but without the `Object.assign` ceremony and with stable currency carry-over.
27
- */
28
- export declare const sumJournalEntryAmounts: (lines: ReadonlyArray<AmountBearer>) => Amount | undefined;
29
- /**
30
- * Splits `lines` by `postingType` into debit/credit totals.
31
- *
32
- * Fixes the operator-precedence bug from legacy
33
- * `calculateCombinedTotalAmount` where
34
- * `totalAmount?.amount ?? 0 + (...) + (...)` parses as
35
- * `totalAmount?.amount ?? (0 + ... + ...)` so the `(...)`'s only get
36
- * added when `totalAmount` is nullish. The new implementation just sums
37
- * every debit (or credit) line including the un/miscategorized ones in
38
- * one pass, so the result is always the true sum.
39
- */
40
- export declare const journalEntryTotalsByPostingSide: (lines: ReadonlyArray<Pick<JournalEntryTransactionLine, "amount" | "postingType">>) => {
41
- creditTotal?: Amount;
42
- debitTotal?: Amount;
43
- };
44
- /**
45
- * Drops `linked_transaction_line` entries — equivalent to legacy
46
- * `filterOutLinkedTransactionLine` in `transactionDetail.helpers.ts`.
47
- */
48
- export declare const filterJournalEntryLinesExcludingLinked: <T extends Pick<Line, "type">>(lines?: ReadonlyArray<T>) => T[];
49
- /**
50
- * Accessor functions resolve the sort value for each column from a
51
- * line. The new table reads display-formatted values from the form
52
- * (selected option label, entity name, etc.), so callers pass in
53
- * accessors that match their `LineInfo` shape rather than baking the
54
- * column-to-form-field mapping into epic-state.
55
- */
56
- export interface JournalEntrySortAccessors<T> {
57
- category: (line: T) => string;
58
- class: (line: T) => string;
59
- credit: (line: T) => number;
60
- debit: (line: T) => number;
61
- description: (line: T) => string;
62
- name: (line: T) => string;
63
- }
64
- /**
65
- * Stable, accessor-driven sort over arbitrary line shapes. Lines that
66
- * resolve to the same key value preserve their original relative order
67
- * thanks to lodash's stable `orderBy`.
68
- *
69
- * Strings are lower-cased before comparison so the order is predictable
70
- * across mixed-case data. Numbers (debit/credit) compare directly.
71
- */
72
- export declare const sortJournalEntryLines: <T>(lines: ReadonlyArray<T>, config: JournalEntryRowSortConfig, accessors: JournalEntrySortAccessors<T>) => T[];
73
- export {};
@@ -1,124 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.sortJournalEntryLines = exports.filterJournalEntryLinesExcludingLinked = exports.journalEntryTotalsByPostingSide = exports.sumJournalEntryAmounts = exports.journalEntryDefaultSortConfig = exports.toJournalEntrySortKey = exports.JOURNAL_ENTRY_SORT_KEYS = void 0;
7
- const orderBy_1 = __importDefault(require("lodash/orderBy"));
8
- const stringToUnion_1 = require("../../commonStateTypes/stringToUnion");
9
- /**
10
- * View-model helpers for the new Journal Entry table view (see
11
- * web-components `journalEntryTable`). Keeps presentation-agnostic
12
- * logic — totals, sort, line-filter — colocated in epic-state so it
13
- * is testable and reusable.
14
- */
15
- // ---------------------------------------------------------------------------
16
- // Sort keys
17
- // ---------------------------------------------------------------------------
18
- exports.JOURNAL_ENTRY_SORT_KEYS = [
19
- 'description',
20
- 'name',
21
- 'category',
22
- 'class',
23
- 'debit',
24
- 'credit',
25
- ];
26
- const toJournalEntrySortKey = (v) => (0, stringToUnion_1.stringToUnion)(v, exports.JOURNAL_ENTRY_SORT_KEYS);
27
- exports.toJournalEntrySortKey = toJournalEntrySortKey;
28
- exports.journalEntryDefaultSortConfig = {
29
- sortKey: 'description',
30
- sortOrder: 'ascending',
31
- };
32
- /**
33
- * Sums the `amount.amount` field of every line and returns an `Amount`
34
- * whose currencyCode/currencySymbol are taken from the first line.
35
- * Returns `undefined` for an empty list.
36
- *
37
- * Mirrors legacy `calculateTotal` in
38
- * `web-components/src/components/transactionDetail/items/TransactionLinesJournalEntry.tsx`
39
- * but without the `Object.assign` ceremony and with stable currency carry-over.
40
- */
41
- const sumJournalEntryAmounts = (lines) => {
42
- if (lines.length === 0) {
43
- return undefined;
44
- }
45
- const first = lines[0].amount;
46
- let total = 0;
47
- for (const line of lines) {
48
- total += line.amount?.amount ?? 0;
49
- }
50
- return {
51
- amount: total,
52
- currencyCode: first?.currencyCode ?? '',
53
- currencySymbol: first?.currencySymbol ?? '',
54
- };
55
- };
56
- exports.sumJournalEntryAmounts = sumJournalEntryAmounts;
57
- /**
58
- * Splits `lines` by `postingType` into debit/credit totals.
59
- *
60
- * Fixes the operator-precedence bug from legacy
61
- * `calculateCombinedTotalAmount` where
62
- * `totalAmount?.amount ?? 0 + (...) + (...)` parses as
63
- * `totalAmount?.amount ?? (0 + ... + ...)` so the `(...)`'s only get
64
- * added when `totalAmount` is nullish. The new implementation just sums
65
- * every debit (or credit) line including the un/miscategorized ones in
66
- * one pass, so the result is always the true sum.
67
- */
68
- const journalEntryTotalsByPostingSide = (lines) => {
69
- const debitLines = [];
70
- const creditLines = [];
71
- for (const line of lines) {
72
- if (line.postingType === 'debit') {
73
- debitLines.push(line);
74
- }
75
- else if (line.postingType === 'credit') {
76
- creditLines.push(line);
77
- }
78
- }
79
- return {
80
- debitTotal: (0, exports.sumJournalEntryAmounts)(debitLines),
81
- creditTotal: (0, exports.sumJournalEntryAmounts)(creditLines),
82
- };
83
- };
84
- exports.journalEntryTotalsByPostingSide = journalEntryTotalsByPostingSide;
85
- // ---------------------------------------------------------------------------
86
- // Filter
87
- // ---------------------------------------------------------------------------
88
- /**
89
- * Drops `linked_transaction_line` entries — equivalent to legacy
90
- * `filterOutLinkedTransactionLine` in `transactionDetail.helpers.ts`.
91
- */
92
- const filterJournalEntryLinesExcludingLinked = (lines) => lines?.filter((line) => line.type !== 'linked_transaction_line') ?? [];
93
- exports.filterJournalEntryLinesExcludingLinked = filterJournalEntryLinesExcludingLinked;
94
- const sortOrderToLodash = (sortOrder) => sortOrder === 'descending' ? 'desc' : 'asc';
95
- /**
96
- * Stable, accessor-driven sort over arbitrary line shapes. Lines that
97
- * resolve to the same key value preserve their original relative order
98
- * thanks to lodash's stable `orderBy`.
99
- *
100
- * Strings are lower-cased before comparison so the order is predictable
101
- * across mixed-case data. Numbers (debit/credit) compare directly.
102
- */
103
- const sortJournalEntryLines = (lines, config, accessors) => {
104
- const accessor = (line) => {
105
- switch (config.sortKey) {
106
- case 'description':
107
- return accessors.description(line).toLowerCase();
108
- case 'name':
109
- return accessors.name(line).toLowerCase();
110
- case 'category':
111
- return accessors.category(line).toLowerCase();
112
- case 'class':
113
- return accessors.class(line).toLowerCase();
114
- case 'debit':
115
- return accessors.debit(line);
116
- case 'credit':
117
- return accessors.credit(line);
118
- default:
119
- return accessors.description(line).toLowerCase();
120
- }
121
- };
122
- return (0, orderBy_1.default)([...lines], [accessor], [sortOrderToLodash(config.sortOrder)]);
123
- };
124
- exports.sortJournalEntryLines = sortJournalEntryLines;
@@ -1,245 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const vitest_1 = require("vitest");
4
- const journalEntryLinesViewModel_1 = require("./journalEntryLinesViewModel");
5
- const usd = (amount) => ({
6
- amount,
7
- currencyCode: 'USD',
8
- currencySymbol: '$',
9
- });
10
- const debit = (n) => ({
11
- amount: usd(n),
12
- postingType: 'debit',
13
- });
14
- const credit = (n) => ({
15
- amount: usd(n),
16
- postingType: 'credit',
17
- });
18
- (0, vitest_1.describe)('sumJournalEntryAmounts', () => {
19
- (0, vitest_1.it)('returns undefined for an empty list', () => {
20
- (0, vitest_1.expect)((0, journalEntryLinesViewModel_1.sumJournalEntryAmounts)([])).toBeUndefined();
21
- });
22
- (0, vitest_1.it)('sums a single line as-is', () => {
23
- (0, vitest_1.expect)((0, journalEntryLinesViewModel_1.sumJournalEntryAmounts)([{ amount: usd(42) }])).toEqual(usd(42));
24
- });
25
- (0, vitest_1.it)('sums multiple lines preserving the first line currency', () => {
26
- const total = (0, journalEntryLinesViewModel_1.sumJournalEntryAmounts)([
27
- { amount: usd(10) },
28
- { amount: usd(20.5) },
29
- { amount: usd(0.5) },
30
- ]);
31
- (0, vitest_1.expect)(total).toEqual(usd(31));
32
- });
33
- (0, vitest_1.it)('treats nullish amount.amount as 0 without crashing', () => {
34
- const total = (0, journalEntryLinesViewModel_1.sumJournalEntryAmounts)([
35
- { amount: usd(10) },
36
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
37
- { amount: { currencyCode: 'USD', currencySymbol: '$' } },
38
- { amount: usd(5) },
39
- ]);
40
- (0, vitest_1.expect)(total).toEqual(usd(15));
41
- });
42
- (0, vitest_1.it)('uses an empty currency code/symbol when first line lacks them', () => {
43
- const total = (0, journalEntryLinesViewModel_1.sumJournalEntryAmounts)([
44
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
45
- { amount: { amount: 7 } },
46
- { amount: usd(3) },
47
- ]);
48
- (0, vitest_1.expect)(total).toEqual({ amount: 10, currencyCode: '', currencySymbol: '' });
49
- });
50
- });
51
- (0, vitest_1.describe)('journalEntryTotalsByPostingSide', () => {
52
- (0, vitest_1.it)('returns undefined totals for an empty list', () => {
53
- (0, vitest_1.expect)((0, journalEntryLinesViewModel_1.journalEntryTotalsByPostingSide)([])).toEqual({
54
- debitTotal: undefined,
55
- creditTotal: undefined,
56
- });
57
- });
58
- (0, vitest_1.it)('sums debits and credits separately when both sides present', () => {
59
- const { debitTotal, creditTotal } = (0, journalEntryLinesViewModel_1.journalEntryTotalsByPostingSide)([
60
- debit(100),
61
- debit(50),
62
- credit(120),
63
- credit(30),
64
- ]);
65
- (0, vitest_1.expect)(debitTotal).toEqual(usd(150));
66
- (0, vitest_1.expect)(creditTotal).toEqual(usd(150));
67
- });
68
- (0, vitest_1.it)('returns only the populated side when one side is missing', () => {
69
- const onlyDebits = (0, journalEntryLinesViewModel_1.journalEntryTotalsByPostingSide)([debit(10), debit(20)]);
70
- (0, vitest_1.expect)(onlyDebits.debitTotal).toEqual(usd(30));
71
- (0, vitest_1.expect)(onlyDebits.creditTotal).toBeUndefined();
72
- const onlyCredits = (0, journalEntryLinesViewModel_1.journalEntryTotalsByPostingSide)([credit(99)]);
73
- (0, vitest_1.expect)(onlyCredits.creditTotal).toEqual(usd(99));
74
- (0, vitest_1.expect)(onlyCredits.debitTotal).toBeUndefined();
75
- });
76
- /**
77
- * Regression test for the operator-precedence bug in legacy
78
- * `calculateCombinedTotalAmount` where
79
- * `totalAmount?.amount ?? 0 + (uncategorized?.amount ?? 0) + (miscategorized?.amount ?? 0)`
80
- * parses as `totalAmount?.amount ?? (0 + ... + ...)`. With the bug,
81
- * an existing `totalAmount` would short-circuit and the uncat/miscat
82
- * pieces would be ignored. The new implementation always adds every
83
- * matching line, so 100 (cat) + 25 (uncat) + 10 (miscat) = 135.
84
- */
85
- (0, vitest_1.it)('does not drop uncategorized/miscategorized contributions (precedence-bug regression)', () => {
86
- const { debitTotal } = (0, journalEntryLinesViewModel_1.journalEntryTotalsByPostingSide)([
87
- debit(100),
88
- debit(25),
89
- debit(10),
90
- ]);
91
- (0, vitest_1.expect)(debitTotal).toEqual(usd(135));
92
- });
93
- (0, vitest_1.it)('ignores lines with neither debit nor credit posting type', () => {
94
- const totals = (0, journalEntryLinesViewModel_1.journalEntryTotalsByPostingSide)([
95
- debit(40),
96
- credit(40),
97
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
98
- { amount: usd(999), postingType: 'unknown' },
99
- ]);
100
- (0, vitest_1.expect)(totals.debitTotal).toEqual(usd(40));
101
- (0, vitest_1.expect)(totals.creditTotal).toEqual(usd(40));
102
- });
103
- });
104
- (0, vitest_1.describe)('filterJournalEntryLinesExcludingLinked', () => {
105
- (0, vitest_1.it)('returns [] for undefined input', () => {
106
- (0, vitest_1.expect)((0, journalEntryLinesViewModel_1.filterJournalEntryLinesExcludingLinked)(undefined)).toEqual([]);
107
- });
108
- (0, vitest_1.it)('filters out linked_transaction_line entries', () => {
109
- const lines = [
110
- { id: 'a', type: 'journal_entry_transaction_line' },
111
- { id: 'b', type: 'linked_transaction_line' },
112
- { id: 'c', type: 'journal_entry_transaction_line' },
113
- ];
114
- const filtered = (0, journalEntryLinesViewModel_1.filterJournalEntryLinesExcludingLinked)(lines);
115
- (0, vitest_1.expect)(filtered).toHaveLength(2);
116
- (0, vitest_1.expect)(filtered[0].id).toBe('a');
117
- (0, vitest_1.expect)(filtered[1].id).toBe('c');
118
- });
119
- (0, vitest_1.it)('returns input unchanged when no linked lines exist', () => {
120
- const lines = [
121
- { id: 'a', type: 'journal_entry_transaction_line' },
122
- { id: 'b', type: 'journal_entry_transaction_line' },
123
- ];
124
- (0, vitest_1.expect)((0, journalEntryLinesViewModel_1.filterJournalEntryLinesExcludingLinked)(lines)).toHaveLength(2);
125
- });
126
- });
127
- (0, vitest_1.describe)('sortJournalEntryLines', () => {
128
- const accessors = {
129
- description: (r) => r.description,
130
- name: (r) => r.name,
131
- category: (r) => r.category,
132
- class: (r) => r.class,
133
- debit: (r) => r.debit,
134
- credit: (r) => r.credit,
135
- };
136
- const rows = [
137
- {
138
- id: '1',
139
- description: 'Beta',
140
- name: 'Acme',
141
- category: 'Rent',
142
- class: 'Ops',
143
- debit: 100,
144
- credit: 0,
145
- },
146
- {
147
- id: '2',
148
- description: 'alpha',
149
- name: 'Beta Co',
150
- category: 'Travel',
151
- class: 'GA',
152
- debit: 200,
153
- credit: 0,
154
- },
155
- {
156
- id: '3',
157
- description: 'Gamma',
158
- name: 'acme',
159
- category: 'Rent',
160
- class: 'Sales',
161
- debit: 0,
162
- credit: 50,
163
- },
164
- ];
165
- (0, vitest_1.it)('exposes every supported sort key via JOURNAL_ENTRY_SORT_KEYS', () => {
166
- (0, vitest_1.expect)([...journalEntryLinesViewModel_1.JOURNAL_ENTRY_SORT_KEYS]).toEqual([
167
- 'description',
168
- 'name',
169
- 'category',
170
- 'class',
171
- 'debit',
172
- 'credit',
173
- ]);
174
- });
175
- (0, vitest_1.it)('sorts by description case-insensitively ascending by default', () => {
176
- const sorted = (0, journalEntryLinesViewModel_1.sortJournalEntryLines)(rows, journalEntryLinesViewModel_1.journalEntryDefaultSortConfig, accessors);
177
- (0, vitest_1.expect)(sorted.map((r) => r.id)).toEqual(['2', '1', '3']);
178
- });
179
- (0, vitest_1.it)('sorts by description descending when configured', () => {
180
- const config = {
181
- sortKey: 'description',
182
- sortOrder: 'descending',
183
- };
184
- const sorted = (0, journalEntryLinesViewModel_1.sortJournalEntryLines)(rows, config, accessors);
185
- (0, vitest_1.expect)(sorted.map((r) => r.id)).toEqual(['3', '1', '2']);
186
- });
187
- vitest_1.it.each([
188
- ['name', 'ascending', ['1', '3', '2']],
189
- ['name', 'descending', ['2', '1', '3']],
190
- ['category', 'ascending', ['1', '3', '2']],
191
- ['class', 'ascending', ['2', '1', '3']],
192
- ['debit', 'ascending', ['3', '1', '2']],
193
- ['debit', 'descending', ['2', '1', '3']],
194
- ['credit', 'ascending', ['1', '2', '3']],
195
- ['credit', 'descending', ['3', '1', '2']],
196
- ])('sorts by %s %s producing the expected order', (key, order, expected) => {
197
- const config = {
198
- sortKey: key,
199
- sortOrder: order,
200
- };
201
- const sorted = (0, journalEntryLinesViewModel_1.sortJournalEntryLines)(rows, config, accessors);
202
- (0, vitest_1.expect)(sorted.map((r) => r.id)).toEqual([...expected]);
203
- });
204
- (0, vitest_1.it)('keeps stable order for ties on the sort key', () => {
205
- const tied = [
206
- {
207
- id: 'a',
208
- description: 'same',
209
- name: '',
210
- category: '',
211
- class: '',
212
- debit: 0,
213
- credit: 0,
214
- },
215
- {
216
- id: 'b',
217
- description: 'same',
218
- name: '',
219
- category: '',
220
- class: '',
221
- debit: 0,
222
- credit: 0,
223
- },
224
- {
225
- id: 'c',
226
- description: 'same',
227
- name: '',
228
- category: '',
229
- class: '',
230
- debit: 0,
231
- credit: 0,
232
- },
233
- ];
234
- const sortedAsc = (0, journalEntryLinesViewModel_1.sortJournalEntryLines)(tied, { sortKey: 'description', sortOrder: 'ascending' }, accessors);
235
- (0, vitest_1.expect)(sortedAsc.map((r) => r.id)).toEqual(['a', 'b', 'c']);
236
- const sortedDesc = (0, journalEntryLinesViewModel_1.sortJournalEntryLines)(tied, { sortKey: 'description', sortOrder: 'descending' }, accessors);
237
- (0, vitest_1.expect)(sortedDesc.map((r) => r.id)).toEqual(['a', 'b', 'c']);
238
- });
239
- (0, vitest_1.it)('does not mutate the input array', () => {
240
- const input = [...rows];
241
- const before = input.map((r) => r.id);
242
- (0, journalEntryLinesViewModel_1.sortJournalEntryLines)(input, { sortKey: 'description', sortOrder: 'descending' }, accessors);
243
- (0, vitest_1.expect)(input.map((r) => r.id)).toEqual(before);
244
- });
245
- });
@@ -1,8 +0,0 @@
1
- import { ActionsObservable, StateObservable } from 'redux-observable';
2
- import { Observable } from 'rxjs';
3
- import { updateTransactions } from '../../entity/transaction/transactionReducer';
4
- import { RootState } from '../../reducer';
5
- import { ZeniAPI } from '../../zeniAPI';
6
- import { fetchProjectTransactionList, updateTransactionListByProject, updateTransactionListByProjectFailure } from './transactionListReducer';
7
- export type ActionType = ReturnType<typeof fetchProjectTransactionList> | ReturnType<typeof updateTransactions> | ReturnType<typeof updateTransactionListByProject> | ReturnType<typeof updateTransactionListByProjectFailure>;
8
- export declare const fetchTransactionListByProjectEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => Observable<ActionType>;
@@ -1,52 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.fetchTransactionListByProjectEpic = void 0;
7
- const js_base64_1 = require("js-base64");
8
- const get_1 = __importDefault(require("lodash/get"));
9
- const rxjs_1 = require("rxjs");
10
- const operators_1 = require("rxjs/operators");
11
- const timePeriod_1 = require("../../commonStateTypes/timePeriod");
12
- const transactionReducer_1 = require("../../entity/transaction/transactionReducer");
13
- const responsePayload_1 = require("../../responsePayload");
14
- const transactionListReducer_1 = require("./transactionListReducer");
15
- const transactionListState_1 = require("./transactionListState");
16
- const fetchTransactionListByProjectEpic = (actions$, state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(transactionListReducer_1.fetchProjectTransactionList.match), (0, operators_1.mergeMap)((action) => {
17
- const state = state$.value;
18
- const key = (0, transactionListState_1.getProjectAcTranKey)(action.payload.accountId, action.payload.accountType, action.payload.projectId, action.payload.period);
19
- const projectTransactions = (0, get_1.default)(state.transactionListState.byProject.transactionListByProjectKey, key, undefined);
20
- if (action.payload.cacheOverride === true ||
21
- projectTransactions == null ||
22
- projectTransactions.hasValidState() === false) {
23
- const queryParam = {
24
- start_date: (0, timePeriod_1.toString)(action.payload.period.start),
25
- end_date: (0, timePeriod_1.toString)(action.payload.period.end),
26
- sort_by: 'create_time',
27
- sort_order: 'desc',
28
- account_id: action.payload.accountId,
29
- account_type: action.payload.accountType,
30
- zeni_project_id: action.payload.projectId,
31
- };
32
- const base64AccountId = (0, js_base64_1.toBase64)(action.payload.accountId);
33
- return zeniAPI
34
- .getJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/accounts/${base64AccountId}/transactions?query=${encodeURIComponent(JSON.stringify(queryParam))}`)
35
- .pipe((0, operators_1.mergeMap)((response) => {
36
- if ((0, responsePayload_1.isSuccessResponse)(response) && response.data != null) {
37
- const updateActions = [];
38
- updateActions.push((0, transactionReducer_1.updateTransactions)(response.data.account.transactions, (value) => value.transaction_id));
39
- updateActions.push((0, transactionListReducer_1.updateTransactionListByProject)(response.data));
40
- return (0, rxjs_1.from)(updateActions);
41
- }
42
- else {
43
- return (0, rxjs_1.of)((0, transactionListReducer_1.updateTransactionListByProjectFailure)(action.payload.accountId, action.payload.accountType, action.payload.projectId, action.payload.period, response.status));
44
- }
45
- }), (0, operators_1.catchError)((error) => (0, rxjs_1.of)((0, transactionListReducer_1.updateTransactionListByProjectFailure)(action.payload.accountId, action.payload.accountType, action.payload.projectId, action.payload.period, (0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', 'fetch transaction list REST API call errored out' +
46
- JSON.stringify(error))))));
47
- }
48
- else {
49
- return (0, rxjs_1.from)([]);
50
- }
51
- }));
52
- exports.fetchTransactionListByProjectEpic = fetchTransactionListByProjectEpic;
@@ -1,6 +0,0 @@
1
- import { ActionsObservable, StateObservable } from 'redux-observable';
2
- import { Observable } from 'rxjs';
3
- import { RootState } from '../../reducer';
4
- import { fetchProjectTransactionList, parallelFetchProjectTransactionList } from './transactionListReducer';
5
- export type ActionType = ReturnType<typeof parallelFetchProjectTransactionList> | ReturnType<typeof fetchProjectTransactionList>;
6
- export declare const parallelFetchProjectTransactionListEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>) => Observable<ActionType>;