@zeniai/client-epic-state 4.19.83 → 4.19.84-betaVR10

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 (116) hide show
  1. package/lib/entity/account/accountPayload.d.ts +2 -0
  2. package/lib/entity/account/accountPayload.js +2 -0
  3. package/lib/entity/account/accountState.d.ts +2 -0
  4. package/lib/entity/company/companyPayload.d.ts +13 -0
  5. package/lib/entity/company/companyPayload.js +21 -0
  6. package/lib/entity/company/companyStateTypes.d.ts +13 -0
  7. package/lib/entity/snackbar/snackbarTypes.d.ts +1 -1
  8. package/lib/entity/snackbar/snackbarTypes.js +1 -0
  9. package/lib/epic.d.ts +12 -1
  10. package/lib/epic.js +12 -1
  11. package/lib/esm/entity/account/accountPayload.js +2 -0
  12. package/lib/esm/entity/chargeCardTransaction/chargeCardTransactionPayload.js +2 -2
  13. package/lib/esm/entity/company/companyPayload.js +21 -0
  14. package/lib/esm/entity/snackbar/snackbarTypes.js +1 -0
  15. package/lib/esm/epic.js +12 -1
  16. package/lib/esm/index.js +13 -8
  17. package/lib/esm/view/companyView/epic/companyPassport/updateCompanyDetailsEpic.js +6 -0
  18. package/lib/esm/view/companyView/types/companyPassport/companyPassportLocalData.js +13 -0
  19. package/lib/esm/view/companyView/types/companyPassportViewPayload.js +55 -12
  20. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/bulkUploadReceiptsEpic.js +28 -0
  21. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/confirmBulkUploadMatchEpic.js +49 -0
  22. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchDetailsEpic.js +40 -0
  23. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchesEpic.js +47 -0
  24. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchCompletedTransactionsEpic.js +61 -0
  25. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchMoreBatchDetailsEpic.js +34 -0
  26. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.js +57 -0
  27. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.js +78 -0
  28. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/uploadMissingReceiptSuccessEpic.js +7 -5
  29. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.js +59 -0
  30. package/lib/esm/view/expenseAutomationView/epics/transactionCategorization/triggerReviewTabRefetchEpic.js +2 -3
  31. package/lib/esm/view/expenseAutomationView/epics/transactionCategorization/uploadTransactionReceiptSuccessEpic.js +24 -0
  32. package/lib/esm/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.js +2 -2
  33. package/lib/esm/view/expenseAutomationView/payload/missingReceiptsPayload.js +173 -1
  34. package/lib/esm/view/expenseAutomationView/reducers/missingReceiptsViewReducer.js +412 -1
  35. package/lib/esm/view/expenseAutomationView/reducers/transactionsViewReducer.js +20 -1
  36. package/lib/esm/view/expenseAutomationView/selectors/missingReceiptsSelector.js +225 -1
  37. package/lib/esm/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +2 -1
  38. package/lib/esm/view/expenseAutomationView/types/missingReceiptsViewState.js +10 -0
  39. package/lib/esm/view/expenseAutomationView/types/transactionsViewState.js +2 -1
  40. package/lib/esm/view/onboardingView/customerView/onboardingCustomerViewSelector.js +22 -4
  41. package/lib/esm/view/spendManagement/chargeCards/chargeCardPaymentHistory/chargeCardPaymentHistoryDownloadSelector.js +2 -2
  42. package/lib/esm/view/spendManagement/chargeCards/chargeCardPaymentHistory/chargeCardPaymentHistorySelector.js +2 -2
  43. package/lib/esm/view/spendManagement/chargeCards/chargeCardRepaymentDetail/chargeCardRepaymentDetailSelector.js +4 -1
  44. package/lib/esm/view/spendManagement/chargeCards/chargeCardRepaymentDetail/fetchChargeCardRepaymentDetailEpic.js +2 -1
  45. package/lib/esm/view/spendManagement/chargeCards/chargeCardRepaymentDetail/initiateChargeCardRepaymentEpic.js +1 -1
  46. package/lib/esm/view/spendManagement/commonSetup/epic/setup/updateBusinessVerificationDetailsEpic.js +67 -1
  47. package/lib/esm/view/spendManagement/commonSetup/epic/setup/updateSetupViewLocalStoreDataEpic.js +16 -2
  48. package/lib/esm/view/spendManagement/commonSetup/setupViewSelector.js +15 -1
  49. package/lib/esm/view/spendManagement/commonSetup/types/businessVerification.js +148 -1
  50. package/lib/esm/view/taskManager/taskDetailView/taskDetailSelector.js +1 -1
  51. package/lib/esm/zeniAPI.js +0 -2
  52. package/lib/index.d.ts +14 -9
  53. package/lib/index.js +90 -45
  54. package/lib/tsconfig.typecheck.tsbuildinfo +1 -0
  55. package/lib/view/companyView/epic/companyPassport/updateCompanyDetailsEpic.js +6 -0
  56. package/lib/view/companyView/types/companyPassport/companyDetailsLocalData.d.ts +13 -0
  57. package/lib/view/companyView/types/companyPassport/companyPassportLocalData.js +13 -0
  58. package/lib/view/companyView/types/companyPassportViewPayload.d.ts +1 -1
  59. package/lib/view/companyView/types/companyPassportViewPayload.js +55 -12
  60. package/lib/view/expenseAutomationView/epics/missingReceipts/bulkUploadReceiptsEpic.d.ts +15 -0
  61. package/lib/view/expenseAutomationView/epics/missingReceipts/bulkUploadReceiptsEpic.js +32 -0
  62. package/lib/view/expenseAutomationView/epics/missingReceipts/confirmBulkUploadMatchEpic.d.ts +7 -0
  63. package/lib/view/expenseAutomationView/epics/missingReceipts/confirmBulkUploadMatchEpic.js +53 -0
  64. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchDetailsEpic.d.ts +8 -0
  65. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchDetailsEpic.js +44 -0
  66. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchesEpic.d.ts +7 -0
  67. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchesEpic.js +51 -0
  68. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchCompletedTransactionsEpic.d.ts +8 -0
  69. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchCompletedTransactionsEpic.js +65 -0
  70. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMoreBatchDetailsEpic.d.ts +8 -0
  71. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMoreBatchDetailsEpic.js +38 -0
  72. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.d.ts +9 -0
  73. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.js +62 -0
  74. package/lib/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.d.ts +14 -0
  75. package/lib/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.js +82 -0
  76. package/lib/view/expenseAutomationView/epics/missingReceipts/uploadMissingReceiptSuccessEpic.js +7 -5
  77. package/lib/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.d.ts +19 -0
  78. package/lib/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.js +64 -0
  79. package/lib/view/expenseAutomationView/epics/transactionCategorization/triggerReviewTabRefetchEpic.js +2 -3
  80. package/lib/view/expenseAutomationView/epics/transactionCategorization/uploadTransactionReceiptSuccessEpic.d.ts +7 -0
  81. package/lib/view/expenseAutomationView/epics/transactionCategorization/uploadTransactionReceiptSuccessEpic.js +28 -0
  82. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
  83. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.js +2 -2
  84. package/lib/view/expenseAutomationView/payload/missingReceiptsPayload.d.ts +118 -0
  85. package/lib/view/expenseAutomationView/payload/missingReceiptsPayload.js +185 -0
  86. package/lib/view/expenseAutomationView/reducers/missingReceiptsViewReducer.d.ts +70 -3
  87. package/lib/view/expenseAutomationView/reducers/missingReceiptsViewReducer.js +414 -2
  88. package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.d.ts +11 -3
  89. package/lib/view/expenseAutomationView/reducers/transactionsViewReducer.js +21 -2
  90. package/lib/view/expenseAutomationView/selectorTypes/missingReceiptsSelectorTypes.d.ts +69 -1
  91. package/lib/view/expenseAutomationView/selectorTypes/transactionsViewSelectorTypes.d.ts +1 -0
  92. package/lib/view/expenseAutomationView/selectors/missingReceiptsSelector.d.ts +1 -1
  93. package/lib/view/expenseAutomationView/selectors/missingReceiptsSelector.js +224 -0
  94. package/lib/view/expenseAutomationView/selectors/transactionCategorizationSelector.js +2 -1
  95. package/lib/view/expenseAutomationView/types/missingReceiptsViewState.d.ts +131 -0
  96. package/lib/view/expenseAutomationView/types/missingReceiptsViewState.js +12 -1
  97. package/lib/view/expenseAutomationView/types/transactionsViewState.d.ts +2 -1
  98. package/lib/view/expenseAutomationView/types/transactionsViewState.js +2 -1
  99. package/lib/view/onboardingView/customerView/onboardingCustomerViewSelector.d.ts +1 -0
  100. package/lib/view/onboardingView/customerView/onboardingCustomerViewSelector.js +22 -3
  101. package/lib/view/spendManagement/chargeCards/chargeCardPaymentHistory/chargeCardPaymentHistoryDownloadSelector.js +2 -2
  102. package/lib/view/spendManagement/chargeCards/chargeCardPaymentHistory/chargeCardPaymentHistorySelector.js +2 -2
  103. package/lib/view/spendManagement/chargeCards/chargeCardRepaymentDetail/chargeCardRepaymentDetailSelector.js +4 -1
  104. package/lib/view/spendManagement/chargeCards/chargeCardRepaymentDetail/fetchChargeCardRepaymentDetailEpic.js +2 -1
  105. package/lib/view/spendManagement/chargeCards/chargeCardRepaymentDetail/initiateChargeCardRepaymentEpic.d.ts +1 -1
  106. package/lib/view/spendManagement/chargeCards/chargeCardRepaymentDetail/initiateChargeCardRepaymentEpic.js +1 -1
  107. package/lib/view/spendManagement/commonSetup/epic/setup/updateBusinessVerificationDetailsEpic.js +67 -1
  108. package/lib/view/spendManagement/commonSetup/epic/setup/updateSetupViewLocalStoreDataEpic.js +16 -2
  109. package/lib/view/spendManagement/commonSetup/setupViewSelector.d.ts +14 -0
  110. package/lib/view/spendManagement/commonSetup/setupViewSelector.js +15 -1
  111. package/lib/view/spendManagement/commonSetup/setupViewState.d.ts +14 -0
  112. package/lib/view/spendManagement/commonSetup/types/businessVerification.d.ts +43 -0
  113. package/lib/view/spendManagement/commonSetup/types/businessVerification.js +150 -0
  114. package/lib/view/taskManager/taskDetailView/taskDetailSelector.js +1 -1
  115. package/lib/zeniAPI.js +0 -2
  116. package/package.json +1 -1
@@ -0,0 +1,57 @@
1
+ import { EMPTY, concat, from, of } from 'rxjs';
2
+ import { catchError, filter, mergeMap } from 'rxjs/operators';
3
+ import { updateTransactions } from '../../../../entity/transaction/transactionReducer';
4
+ import { createZeniAPIStatus, isSuccessResponse, } from '../../../../responsePayload';
5
+ import { extractTransactionPayloadsFromBatchFiles, filterBatchListItemsForBatchDetailsFetch, isBatchDetailsApiStatusCompleted, shouldFetchBatchDetailsForBatchId, toBatchDetails, } from '../../payload/missingReceiptsPayload';
6
+ import { batchDetailFetchFailed, fetchBulkUploadBatchDetails, fetchBulkUploadBatchesSuccess, fetchMoreBatchDetailsComplete, setInitialBatchDetailsLoading, storeBatchDetails, } from '../../reducers/missingReceiptsViewReducer';
7
+ const INITIAL_BATCH_PAGE_SIZE = 5;
8
+ export function fetchBatchDetailsByIds(batchIds, zeniAPI) {
9
+ if (batchIds.length === 0) {
10
+ return EMPTY;
11
+ }
12
+ return from(batchIds).pipe(mergeMap((batchId) => zeniAPI
13
+ .getJSON(`${zeniAPI.apiEndPoints.communicationAgentMicroServiceBaseUrl}/1.0/batches/${batchId}`)
14
+ .pipe(mergeMap((response) => {
15
+ if (!isSuccessResponse(response) ||
16
+ response.data == null ||
17
+ !isBatchDetailsApiStatusCompleted(response.data.status)) {
18
+ return EMPTY;
19
+ }
20
+ const actions = [];
21
+ const transactionPayloads = extractTransactionPayloadsFromBatchFiles(response.data.files);
22
+ if (transactionPayloads.length > 0) {
23
+ actions.push(updateTransactions(transactionPayloads, (value) => value.transaction_id));
24
+ }
25
+ actions.push(storeBatchDetails(toBatchDetails(response.data, zeniAPI.apiEndPoints.fileMicroServiceBaseUrl)));
26
+ return from(actions);
27
+ }), catchError((error) => {
28
+ console.error(`Failed to fetch batch details for ${batchId}:`, createZeniAPIStatus('Unexpected Error', 'Fetch batch details errored out: ' +
29
+ JSON.stringify(error)));
30
+ return of(batchDetailFetchFailed({ batchId }));
31
+ })), 5));
32
+ }
33
+ export const fetchMultipleBatchDetailsEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(fetchBulkUploadBatchesSuccess.match), mergeMap((action) => {
34
+ const batchList = action.payload.batchList;
35
+ const { batchDetailsById } = state$.value.expenseAutomationMissingReceiptsViewState.bulkUpload;
36
+ /** Only completed list rows may trigger batch-details API; preserve platform order. */
37
+ const completedBatchesMissingDetails = filterBatchListItemsForBatchDetailsFetch(batchList).filter((batch) => batchDetailsById[batch.batchId] == null);
38
+ const completedBatchIds = completedBatchesMissingDetails.map((batch) => batch.batchId);
39
+ const batchIdsToFetch = completedBatchIds.slice(0, INITIAL_BATCH_PAGE_SIZE);
40
+ if (batchIdsToFetch.length === 0) {
41
+ /**
42
+ * List refresh can complete while no row is `completed` yet (multi-fetch skips), or
43
+ * `currentBatchId` may not appear in the filtered list but still needs `GET /batches/:id`.
44
+ * Fall back to the single-batch-details epic so `phase` and details can resolve.
45
+ */
46
+ const bulkUpload = state$.value.expenseAutomationMissingReceiptsViewState.bulkUpload;
47
+ const currentId = bulkUpload.currentBatchId;
48
+ if (currentId != null &&
49
+ bulkUpload.phase === 'matching' &&
50
+ bulkUpload.batchDetailsById[currentId] == null &&
51
+ shouldFetchBatchDetailsForBatchId(bulkUpload.batchStatusById, bulkUpload.batchListByPeriod, currentId)) {
52
+ return of(fetchBulkUploadBatchDetails());
53
+ }
54
+ return EMPTY;
55
+ }
56
+ return concat(of(setInitialBatchDetailsLoading()), fetchBatchDetailsByIds(batchIdsToFetch, zeniAPI), of(fetchMoreBatchDetailsComplete()));
57
+ }));
@@ -0,0 +1,78 @@
1
+ import { EMPTY, from, merge, of } from 'rxjs';
2
+ import { catchError, debounceTime, filter, mergeMap, switchMap } from 'rxjs/operators';
3
+ import { convertToPeriod } from '../../../../commonStateTypes/timePeriod';
4
+ import { getCurrentTenant } from '../../../../entity/tenant/tenantSelector';
5
+ import { updateTransactions } from '../../../../entity/transaction/transactionReducer';
6
+ import { createZeniAPIStatus, isSuccessResponse, } from '../../../../responsePayload';
7
+ import { supportedTransactionPayloadToManualSearchResult } from '../../payload/missingReceiptsPayload';
8
+ import { searchTransactionsForManualMatch, searchTransactionsForManualMatchFailure, searchTransactionsForManualMatchSuccess, } from '../../reducers/missingReceiptsViewReducer';
9
+ import { toTransactionsSortKey } from '../../types/transactionsViewState';
10
+ /**
11
+ * `auto_categorized` for manual transaction search (Unmatched).
12
+ * Backend contract TBD — align with `fetchTransactionCategorizationEpic` (`selectedTab === 'autoCategorized'`)
13
+ * when the expense-automation API documents the intended filter for this flow.
14
+ */
15
+ export const MANUAL_TRANSACTION_SEARCH_AUTO_CATEGORIZED = false;
16
+ export const searchTransactionsForManualMatchEpic = (actions$, state$, zeniAPI) => {
17
+ const searchActions$ = actions$.pipe(filter(searchTransactionsForManualMatch.match));
18
+ const pagination$ = searchActions$.pipe(filter((a) => a.payload.pageToken != null));
19
+ /**
20
+ * No API for empty or 1-char queries; immediate merge so switchMap cancels any in-flight HTTP.
21
+ */
22
+ const newSearchTooShortOrClear$ = searchActions$.pipe(filter((a) => a.payload.pageToken == null &&
23
+ a.payload.query.trim().length < 2));
24
+ const newSearchDebounced$ = searchActions$.pipe(filter((a) => a.payload.pageToken == null &&
25
+ a.payload.query.trim().length >= 2), debounceTime(300));
26
+ return merge(pagination$, newSearchTooShortOrClear$, newSearchDebounced$).pipe(switchMap((action) => {
27
+ const { query, pageToken } = action.payload;
28
+ if (pageToken == null &&
29
+ query.trim().length < 2) {
30
+ return EMPTY;
31
+ }
32
+ const state = state$.value;
33
+ const { expenseAutomationViewState: { selectedPeriodByTenantId }, expenseAutomationMissingReceiptsViewState: { bulkUpload: { manualSearch, sortKey, sortOrder }, }, } = state;
34
+ const currentTenant = getCurrentTenant(state);
35
+ const selectedPeriod = selectedPeriodByTenantId[currentTenant.tenantId];
36
+ if (selectedPeriod == null) {
37
+ return of(searchTransactionsForManualMatchFailure({
38
+ error: createZeniAPIStatus('Unexpected Error', 'Manual search requires a selected accounting period.'),
39
+ }));
40
+ }
41
+ const period = convertToPeriod(selectedPeriod);
42
+ const queryParam = {
43
+ start_date: period.start,
44
+ end_date: period.end,
45
+ auto_categorized: MANUAL_TRANSACTION_SEARCH_AUTO_CATEGORIZED,
46
+ sort_by: toTransactionsSortKey(sortKey),
47
+ sort_order: sortOrder === 'ascending' ? 'asc' : 'desc',
48
+ page_token: pageToken ?? null,
49
+ page_size: manualSearch.pageSize,
50
+ search_text: query,
51
+ };
52
+ return zeniAPI
53
+ .getJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/expense-automation/transactions?query=${encodeURIComponent(JSON.stringify(queryParam))}`)
54
+ .pipe(mergeMap((response) => {
55
+ if (isSuccessResponse(response) && response.data != null) {
56
+ const { transactions, next_page_token, total_count } = response.data;
57
+ const append = pageToken != null;
58
+ const results = transactions.map(supportedTransactionPayloadToManualSearchResult);
59
+ const actionsOut = [
60
+ updateTransactions(transactions, (value) => value.transaction_id, 'merge'),
61
+ searchTransactionsForManualMatchSuccess({
62
+ append,
63
+ nextPageToken: next_page_token ?? null,
64
+ results,
65
+ totalCount: total_count,
66
+ }),
67
+ ];
68
+ return from(actionsOut);
69
+ }
70
+ return of(searchTransactionsForManualMatchFailure({
71
+ error: response.status,
72
+ }));
73
+ }), catchError((error) => of(searchTransactionsForManualMatchFailure({
74
+ error: createZeniAPIStatus('Unexpected Error', 'Search transactions for manual match errored: ' +
75
+ JSON.stringify(error)),
76
+ }))));
77
+ }));
78
+ };
@@ -12,11 +12,13 @@ export const uploadMissingReceiptSuccessEpic = (actions$, state$) => actions$.pi
12
12
  updateActions.push(updateTransaction(transactionPayload.transaction_id, transactionPayload, updateType));
13
13
  if (currentTenant != null) {
14
14
  const monthEndChecksPeriod = selectedPeriodByTenantId[currentTenant.tenantId];
15
- updateActions.push(fetchMonthEndCloseChecks({
16
- tenantId: currentTenant.tenantId,
17
- period: monthEndChecksPeriod,
18
- refreshViewInBackground: true,
19
- }));
15
+ if (monthEndChecksPeriod != null) {
16
+ updateActions.push(fetchMonthEndCloseChecks({
17
+ tenantId: currentTenant.tenantId,
18
+ period: monthEndChecksPeriod,
19
+ refreshViewInBackground: true,
20
+ }));
21
+ }
20
22
  }
21
23
  return from(updateActions);
22
24
  }));
@@ -0,0 +1,59 @@
1
+ import { EMPTY, from, merge, of, timer } from 'rxjs';
2
+ import { catchError, debounceTime, filter, mergeMap, switchMap, takeUntil, } from 'rxjs/operators';
3
+ import { openSnackbar } from '../../../../entity/snackbar/snackbarReducer';
4
+ import { updateTransactions } from '../../../../entity/transaction/transactionReducer';
5
+ import { isSuccessResponse } from '../../../../responsePayload';
6
+ import { extractTransactionPayloadsFromBatchFiles, isBatchDetailsApiStatusCompleted, toBatchDetails, } from '../../payload/missingReceiptsPayload';
7
+ import { bulkUploadReceiptsSuccess, clearBulkUpload, fetchBulkUploadBatchDetailsSuccess, fetchBulkUploadBatches, pusherBatchStatusUpdate, requestMissingReceiptsTabNavigation, } from '../../reducers/missingReceiptsViewReducer';
8
+ /** First poll after upload; then interval while batch not resolved via Pusher or API. */
9
+ const FALLBACK_FIRST_DELAY_MS = 30000;
10
+ const FALLBACK_POLL_INTERVAL_MS = 10000;
11
+ /**
12
+ * On Pusher batch completion: refresh batch list (then fetchMultipleBatchDetailsEpic runs),
13
+ * and request switching to the Unmatched tab. Debounced to reduce duplicate refreshes.
14
+ */
15
+ export const pusherBatchStatusCompletionEpic = (actions$) => actions$.pipe(filter(pusherBatchStatusUpdate.match), filter((action) => action.payload.status === 'completed'), debounceTime(300), mergeMap(() => from([
16
+ fetchBulkUploadBatches({
17
+ cacheOverride: true,
18
+ invalidateBatchDetailsCache: true,
19
+ }),
20
+ requestMissingReceiptsTabNavigation({ tab: 'unmatched' }),
21
+ ])));
22
+ /**
23
+ * Fallback polling when Pusher is slow or unavailable. Network errors on a poll tick show one
24
+ * error snackbar per upload session (first failure only) so the user is not spammed every
25
+ * interval; Pusher or a later successful poll still completes the flow.
26
+ */
27
+ export const pollBulkUploadBatchStatusEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(bulkUploadReceiptsSuccess.match), mergeMap((action) => {
28
+ const { batchId } = action.payload;
29
+ let pollErrorNotified = false;
30
+ return timer(FALLBACK_FIRST_DELAY_MS, FALLBACK_POLL_INTERVAL_MS).pipe(takeUntil(merge(actions$.pipe(filter(clearBulkUpload.match)), actions$.pipe(filter(pusherBatchStatusUpdate.match), filter((a) => a.payload.batchId === batchId)), actions$.pipe(filter(fetchBulkUploadBatchDetailsSuccess.match), filter((a) => a.payload.batchId === batchId)))), switchMap(() => zeniAPI
31
+ .getJSON(`${zeniAPI.apiEndPoints.communicationAgentMicroServiceBaseUrl}/1.0/batches/${batchId}`)
32
+ .pipe(mergeMap((response) => {
33
+ /** Same batch-details URL; polls until `status` is completed (Pusher may win first). */
34
+ if (isSuccessResponse(response) && response.data != null) {
35
+ if (isBatchDetailsApiStatusCompleted(response.data.status)) {
36
+ const actions = [];
37
+ const transactionPayloads = extractTransactionPayloadsFromBatchFiles(response.data.files);
38
+ if (transactionPayloads.length > 0) {
39
+ actions.push(updateTransactions(transactionPayloads, (value) => value.transaction_id));
40
+ }
41
+ actions.push(fetchBulkUploadBatchDetailsSuccess(toBatchDetails(response.data, zeniAPI.apiEndPoints.fileMicroServiceBaseUrl)));
42
+ actions.push(fetchBulkUploadBatches({ cacheOverride: true }));
43
+ actions.push(requestMissingReceiptsTabNavigation({ tab: 'unmatched' }));
44
+ return from(actions);
45
+ }
46
+ }
47
+ return EMPTY;
48
+ }), catchError(() => {
49
+ if (!pollErrorNotified) {
50
+ pollErrorNotified = true;
51
+ return of(openSnackbar({
52
+ messageSection: 'receipts_upload',
53
+ messageText: 'failed',
54
+ type: 'error',
55
+ }));
56
+ }
57
+ return EMPTY;
58
+ }))));
59
+ }));
@@ -4,15 +4,14 @@ import { convertToPeriod, toAbsoluteDay, } from '../../../../commonStateTypes/ti
4
4
  import { getCurrentTenant } from '../../../../entity/tenant/tenantSelector';
5
5
  import { backgroundRefetchReviewTab, syncTransactionCategorizationFromDetailSave, } from '../../reducers/transactionsViewReducer';
6
6
  export const triggerReviewTabRefetchEpic = (actions$, state$) => actions$.pipe(filter(syncTransactionCategorizationFromDetailSave.match), mergeMap((action) => {
7
- const { pendingReviewLineIds, transactionId, isUncategorizedExpenseCategoryEnabled } = action.payload;
7
+ const { pendingReviewLineIds, transactionId, isUncategorizedExpenseCategoryEnabled, } = action.payload;
8
8
  if (pendingReviewLineIds.length === 0) {
9
9
  return EMPTY;
10
10
  }
11
11
  const state = state$.value;
12
12
  // Only trigger when the transaction was auto-only (not in review tab after reducer ran)
13
13
  const reviewLocalData = state.expenseAutomationTransactionsViewState
14
- .transactionCategorizationView.review
15
- .transactionReviewLocalDataById[transactionId.id];
14
+ .transactionCategorizationView.review.transactionReviewLocalDataById[transactionId.id];
16
15
  if (reviewLocalData != null) {
17
16
  return EMPTY;
18
17
  }
@@ -0,0 +1,24 @@
1
+ import { from } from 'rxjs';
2
+ import { filter, mergeMap } from 'rxjs/operators';
3
+ import { getCurrentTenant } from '../../../../entity/tenant/tenantSelector';
4
+ import { updateTransaction } from '../../../../entity/transaction/transactionReducer';
5
+ import { fetchMonthEndCloseChecks } from '../../../monthEndCloseChecksView/monthEndCloseChecksViewReducer';
6
+ import { uploadTransactionCategorizationReceiptSuccess } from '../../reducers/transactionsViewReducer';
7
+ export const uploadTransactionReceiptSuccessEpic = (actions$, state$) => actions$.pipe(filter(uploadTransactionCategorizationReceiptSuccess.match), mergeMap((action) => {
8
+ const { transactionPayload, updateType } = action.payload;
9
+ const updateActions = [];
10
+ const currentTenant = getCurrentTenant(state$.value);
11
+ const selectedPeriodByTenantId = state$.value.expenseAutomationViewState.selectedPeriodByTenantId;
12
+ updateActions.push(updateTransaction(transactionPayload.transaction_id, transactionPayload, updateType));
13
+ if (currentTenant != null) {
14
+ const monthEndChecksPeriod = selectedPeriodByTenantId[currentTenant.tenantId];
15
+ if (monthEndChecksPeriod != null) {
16
+ updateActions.push(fetchMonthEndCloseChecks({
17
+ tenantId: currentTenant.tenantId,
18
+ period: monthEndChecksPeriod,
19
+ refreshViewInBackground: true,
20
+ }));
21
+ }
22
+ }
23
+ return from(updateActions);
24
+ }));
@@ -41,8 +41,8 @@ export const filterAutoTabLineItems = (tabView, transactionId, updatedTransactio
41
41
  if (localData == null) {
42
42
  return;
43
43
  }
44
- const currentAutoLineIds = localData.transactionReviewLocalData.tabSpecificLineItems
45
- .autoCategorized ?? [];
44
+ const currentAutoLineIds = localData.transactionReviewLocalData.tabSpecificLineItems.autoCategorized ??
45
+ [];
46
46
  const linesById = new Map(updatedTransaction.lines?.map((l) => [l.id, l]));
47
47
  const retainedLineIds = currentAutoLineIds.filter((lineId) => {
48
48
  const line = linesById.get(lineId);
@@ -1 +1,173 @@
1
- export {};
1
+ import { toURL } from '../../../commonPayloadTypes/urlPayload';
2
+ import { getTransactionPayloadAmount, } from '../../../entity/transaction/payloadTypes/transactionPayload';
3
+ // -- Converter functions --
4
+ /**
5
+ * Maps batch-details API `files[].status` strings to canonical {@link BatchFileStatus}.
6
+ * Legacy aliases are supported during rollout; unknown strings map to `failed` so Redux never
7
+ * holds untyped status values.
8
+ */
9
+ export function parseBatchFileStatus(raw) {
10
+ const s = raw.trim().toLowerCase().replace(/-/g, '_');
11
+ switch (s) {
12
+ case 'exact_match':
13
+ case 'matched':
14
+ return 'exact_match';
15
+ case 'possible_matches':
16
+ case 'possible_match':
17
+ case 'possiblematch':
18
+ case 'un_matched':
19
+ case 'unmatched':
20
+ return 'possible_matches';
21
+ case 'no_match':
22
+ case 'nomatch':
23
+ return 'no_match';
24
+ case 'failed':
25
+ return 'failed';
26
+ default:
27
+ return 'failed';
28
+ }
29
+ }
30
+ export function toBatchFile(payload, filesEndPoint) {
31
+ return {
32
+ attachmentId: payload.attachment_id,
33
+ candidates: payload.candidates?.map((c) => ({
34
+ transactionId: c.transaction_id,
35
+ matchScore: c.match_score,
36
+ })),
37
+ fileDownloadUrl: payload.file_id != null && filesEndPoint != null
38
+ ? `${filesEndPoint}/1.0/files/${payload.file_id}?query=${encodeURIComponent(JSON.stringify({ download_file: true }))}`
39
+ : null,
40
+ fileId: payload.file_id,
41
+ filePreviewUrl: payload.file_preview_url,
42
+ filename: payload.filename,
43
+ matchSource: payload.match_source,
44
+ matchedTransactionId: payload.matched_transaction?.transaction_id,
45
+ status: parseBatchFileStatus(payload.status),
46
+ };
47
+ }
48
+ export function extractTransactionPayloadsFromBatchFiles(files) {
49
+ const seen = new Set();
50
+ const payloads = [];
51
+ for (const file of files) {
52
+ if (file.matched_transaction != null) {
53
+ const id = file.matched_transaction.transaction_id;
54
+ if (!seen.has(id)) {
55
+ seen.add(id);
56
+ payloads.push(matchedTransactionPayloadToSupportedTransactionPayload(file.matched_transaction));
57
+ }
58
+ }
59
+ if (file.candidates != null) {
60
+ for (const candidate of file.candidates) {
61
+ const id = candidate.transaction_id;
62
+ if (!seen.has(id)) {
63
+ seen.add(id);
64
+ payloads.push(matchedTransactionPayloadToSupportedTransactionPayload(candidate));
65
+ }
66
+ }
67
+ }
68
+ }
69
+ return payloads;
70
+ }
71
+ function matchedTransactionPayloadToSupportedTransactionPayload(payload) {
72
+ return {
73
+ transaction_id: payload.transaction_id,
74
+ transaction_type: payload.transaction_type ?? 'expense',
75
+ transaction_date: payload.transaction_date ?? '',
76
+ currency_code: payload.currency_code,
77
+ total_amount: payload.amount,
78
+ vendor_name: payload.vendor_name,
79
+ logo: payload.vendor_logo == null ? undefined : toURL(payload.vendor_logo),
80
+ };
81
+ }
82
+ export function toBatchSummary(payload) {
83
+ return {
84
+ failed: payload.failed,
85
+ matched: payload.matched,
86
+ noMatch: payload.no_match,
87
+ possibleMatches: payload.possible_matches,
88
+ total: payload.total,
89
+ };
90
+ }
91
+ export function toBatchDetails(payload, filesEndPoint) {
92
+ return {
93
+ batchId: payload.batch_id,
94
+ createdAt: payload.created_at,
95
+ files: payload.files.map((f) => toBatchFile(f, filesEndPoint)),
96
+ status: payload.status,
97
+ summary: toBatchSummary(payload.summary),
98
+ };
99
+ }
100
+ /** Batch list `status` is a string from the API — compare case-insensitively. */
101
+ export function isBatchListStatusCompleted(status) {
102
+ return status.toLowerCase() === 'completed';
103
+ }
104
+ /**
105
+ * Subset of the get-all-batches (`/batches?query=...`) list that is eligible for
106
+ * `GET /batches/:batchId` details fetches. The stored list may include pending, failed, or other
107
+ * statuses for UI; only `completed` rows should trigger batch-details requests.
108
+ */
109
+ export function filterBatchListItemsForBatchDetailsFetch(batches) {
110
+ return batches.filter((b) => isBatchListStatusCompleted(b.status));
111
+ }
112
+ /**
113
+ * Batch details API response `status` field — only completed payloads should be stored from
114
+ * multi-batch fetch paths (list can be briefly stale vs. live processing state).
115
+ */
116
+ export function isBatchDetailsApiStatusCompleted(status) {
117
+ return status.toLowerCase() === 'completed';
118
+ }
119
+ export function findBatchListItemForBatchId(batchListByPeriod, batchId) {
120
+ for (const list of Object.values(batchListByPeriod)) {
121
+ const found = list.find((b) => b.batchId === batchId);
122
+ if (found != null) {
123
+ return found;
124
+ }
125
+ }
126
+ return undefined;
127
+ }
128
+ /**
129
+ * Whether it is appropriate to call `GET .../batches/:id` for details.
130
+ * Skips when live batch status or batch list row indicates the batch is not completed yet.
131
+ * When status is unknown in both sources, allows the request (e.g. dispatch before list refresh).
132
+ */
133
+ export function shouldFetchBatchDetailsForBatchId(batchStatusById, batchListByPeriod, batchId) {
134
+ const live = batchStatusById[batchId]?.status;
135
+ if (live === 'completed') {
136
+ return true;
137
+ }
138
+ if (live === 'pending' || live === 'processing') {
139
+ return false;
140
+ }
141
+ const listItem = findBatchListItemForBatchId(batchListByPeriod, batchId);
142
+ if (listItem != null && !isBatchListStatusCompleted(listItem.status)) {
143
+ return false;
144
+ }
145
+ return true;
146
+ }
147
+ export function toBatchListItem(payload) {
148
+ return {
149
+ batchId: payload.batch_id,
150
+ createdAt: payload.created_at,
151
+ failedCount: payload.failed_count,
152
+ matchedCount: payload.matched_count,
153
+ noMatchCount: payload.no_match_count,
154
+ possibleMatchesCount: payload.possible_matches_count,
155
+ status: payload.status,
156
+ totalFiles: payload.total_files,
157
+ };
158
+ }
159
+ /** Maps expense-automation transaction rows to manual-search list rows (Unmatched tab). */
160
+ export function supportedTransactionPayloadToManualSearchResult(payload) {
161
+ const amountPayload = getTransactionPayloadAmount(payload);
162
+ return {
163
+ amount: amountPayload.amount,
164
+ currencyCode: amountPayload.currencyCode,
165
+ entityId: payload.vendor_id ?? payload.customer_id ?? '',
166
+ memo: payload.transaction_memo ?? '',
167
+ transactionDate: payload.transaction_date,
168
+ transactionId: payload.transaction_id,
169
+ transactionType: payload.transaction_type,
170
+ vendorName: payload.vendor_name ?? '',
171
+ vendorLogo: toURL(payload.logo)?.href,
172
+ };
173
+ }