@zeniai/client-epic-state 4.19.37-betaVR26 → 4.19.37-betaVR3

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 (39) hide show
  1. package/lib/epic.d.ts +1 -2
  2. package/lib/epic.js +1 -2
  3. package/lib/esm/epic.js +1 -2
  4. package/lib/esm/index.js +2 -2
  5. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/bulkUploadReceiptsEpic.js +7 -3
  6. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchDetailsEpic.js +13 -22
  7. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchesEpic.js +1 -7
  8. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchCompletedTransactionsEpic.js +3 -7
  9. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.js +23 -45
  10. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.js +24 -65
  11. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.js +32 -33
  12. package/lib/esm/view/expenseAutomationView/payload/missingReceiptsPayload.js +16 -63
  13. package/lib/esm/view/expenseAutomationView/reducers/missingReceiptsViewReducer.js +26 -153
  14. package/lib/esm/view/expenseAutomationView/selectors/missingReceiptsSelector.js +13 -108
  15. package/lib/index.d.ts +2 -2
  16. package/lib/index.js +32 -36
  17. package/lib/tsconfig.typecheck.tsbuildinfo +1 -0
  18. package/lib/view/expenseAutomationView/epics/missingReceipts/bulkUploadReceiptsEpic.d.ts +5 -2
  19. package/lib/view/expenseAutomationView/epics/missingReceipts/bulkUploadReceiptsEpic.js +6 -2
  20. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchDetailsEpic.js +11 -20
  21. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchesEpic.js +1 -7
  22. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchCompletedTransactionsEpic.js +2 -6
  23. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.d.ts +2 -3
  24. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.js +20 -43
  25. package/lib/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.d.ts +3 -11
  26. package/lib/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.js +22 -63
  27. package/lib/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.d.ts +7 -5
  28. package/lib/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.js +28 -29
  29. package/lib/view/expenseAutomationView/payload/missingReceiptsPayload.d.ts +31 -30
  30. package/lib/view/expenseAutomationView/payload/missingReceiptsPayload.js +18 -69
  31. package/lib/view/expenseAutomationView/reducers/missingReceiptsViewReducer.d.ts +6 -25
  32. package/lib/view/expenseAutomationView/reducers/missingReceiptsViewReducer.js +27 -155
  33. package/lib/view/expenseAutomationView/selectorTypes/missingReceiptsSelectorTypes.d.ts +0 -6
  34. package/lib/view/expenseAutomationView/selectors/missingReceiptsSelector.js +13 -108
  35. package/lib/view/expenseAutomationView/types/missingReceiptsViewState.d.ts +1 -16
  36. package/package.json +2 -2
  37. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchMoreBatchDetailsEpic.js +0 -34
  38. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMoreBatchDetailsEpic.d.ts +0 -8
  39. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMoreBatchDetailsEpic.js +0 -38
@@ -1,57 +1,35 @@
1
- import { EMPTY, concat, from, of } from 'rxjs';
1
+ import { EMPTY, from } from 'rxjs';
2
2
  import { catchError, filter, mergeMap } from 'rxjs/operators';
3
3
  import { updateTransactions } from '../../../../entity/transaction/transactionReducer';
4
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 = 1;
8
- export function fetchBatchDetailsByIds(batchIds, zeniAPI) {
9
- if (batchIds.length === 0) {
5
+ import { extractTransactionPayloadsFromBatchFiles, toBatchDetails, } from '../../payload/missingReceiptsPayload';
6
+ import { fetchBulkUploadBatchesSuccess, storeBatchDetails, } from '../../reducers/missingReceiptsViewReducer';
7
+ export const fetchMultipleBatchDetailsEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(fetchBulkUploadBatchesSuccess.match), mergeMap((action) => {
8
+ const batchList = action.payload.batchList;
9
+ const { batchDetailsById } = state$.value.expenseAutomationMissingReceiptsViewState.bulkUpload;
10
+ const completedBatchIds = batchList
11
+ .filter((batch) => batch.status === 'completed' &&
12
+ batchDetailsById[batch.batchId] == null)
13
+ .map((batch) => batch.batchId);
14
+ if (completedBatchIds.length === 0) {
10
15
  return EMPTY;
11
16
  }
12
- return from(batchIds).pipe(mergeMap((batchId) => zeniAPI
13
- .getJSON(`${zeniAPI.apiEndPoints.communicationAgentMicroServiceBaseUrl}/1.0/batches/${batchId}`)
17
+ return from(completedBatchIds).pipe(mergeMap((batchId) => zeniAPI
18
+ .getJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/receipts/batches/${batchId}`)
14
19
  .pipe(mergeMap((response) => {
15
- if (!isSuccessResponse(response) ||
16
- response.data == null ||
17
- !isBatchDetailsApiStatusCompleted(response.data.status)) {
18
- return EMPTY;
20
+ if (isSuccessResponse(response) && response.data != null) {
21
+ const actions = [];
22
+ const transactionPayloads = extractTransactionPayloadsFromBatchFiles(response.data.files);
23
+ if (transactionPayloads.length > 0) {
24
+ actions.push(updateTransactions(transactionPayloads, (value) => value.transaction_id));
25
+ }
26
+ actions.push(storeBatchDetails(toBatchDetails(response.data)));
27
+ return from(actions);
19
28
  }
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);
29
+ return EMPTY;
27
30
  }), catchError((error) => {
28
31
  console.error(`Failed to fetch batch details for ${batchId}:`, createZeniAPIStatus('Unexpected Error', 'Fetch batch details errored out: ' +
29
32
  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
33
  return EMPTY;
55
- }
56
- return concat(of(setInitialBatchDetailsLoading()), fetchBatchDetailsByIds(batchIdsToFetch, zeniAPI), of(fetchMoreBatchDetailsComplete()));
34
+ })), 5));
57
35
  }));
@@ -1,68 +1,27 @@
1
- import { 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';
1
+ import { of } from 'rxjs';
2
+ import { catchError, debounceTime, filter, switchMap } from 'rxjs/operators';
6
3
  import { createZeniAPIStatus, isSuccessResponse, } from '../../../../responsePayload';
7
- import { supportedTransactionPayloadToManualSearchResult } from '../../payload/missingReceiptsPayload';
4
+ import { toManualSearchResult, } from '../../payload/missingReceiptsPayload';
8
5
  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
- const newSearch$ = searchActions$.pipe(filter((a) => a.payload.pageToken == null), debounceTime(300));
20
- return merge(pagination$, newSearch$).pipe(switchMap((action) => {
21
- const { query, pageToken } = action.payload;
22
- const state = state$.value;
23
- const { expenseAutomationViewState: { selectedPeriodByTenantId }, expenseAutomationMissingReceiptsViewState: { bulkUpload: { manualSearch, sortKey, sortOrder }, }, } = state;
24
- const currentTenant = getCurrentTenant(state);
25
- const selectedPeriod = selectedPeriodByTenantId[currentTenant.tenantId];
26
- if (selectedPeriod == null) {
27
- return of(searchTransactionsForManualMatchFailure({
28
- error: createZeniAPIStatus('Unexpected Error', 'Manual search requires a selected accounting period.'),
29
- }));
6
+ export const searchTransactionsForManualMatchEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(searchTransactionsForManualMatch.match), debounceTime(300), switchMap((action) => {
7
+ const { query } = action.payload;
8
+ const searchQuery = JSON.stringify({
9
+ search_text: query,
10
+ search_fields: ['date', 'amount', 'vendor_name'],
11
+ });
12
+ const encodedQuery = encodeURIComponent(searchQuery);
13
+ return zeniAPI
14
+ .getJSON(`${zeniAPI.apiEndPoints.searchMicroServiceBaseUrl}/1.0/transaction-search?query=${encodedQuery}`)
15
+ .pipe(switchMap((response) => {
16
+ if (isSuccessResponse(response) && response.data != null) {
17
+ const results = response.data.transactions.map(toManualSearchResult);
18
+ return of(searchTransactionsForManualMatchSuccess(results));
30
19
  }
31
- const period = convertToPeriod(selectedPeriod);
32
- const queryParam = {
33
- start_date: period.start,
34
- end_date: period.end,
35
- auto_categorized: MANUAL_TRANSACTION_SEARCH_AUTO_CATEGORIZED,
36
- sort_by: toTransactionsSortKey(sortKey),
37
- sort_order: sortOrder === 'ascending' ? 'asc' : 'desc',
38
- page_token: pageToken ?? null,
39
- page_size: manualSearch.pageSize,
40
- search_text: query,
41
- };
42
- return zeniAPI
43
- .getJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/expense-automation/transactions?query=${encodeURIComponent(JSON.stringify(queryParam))}`)
44
- .pipe(mergeMap((response) => {
45
- if (isSuccessResponse(response) && response.data != null) {
46
- const { transactions, next_page_token, total_count } = response.data;
47
- const append = pageToken != null;
48
- const results = transactions.map(supportedTransactionPayloadToManualSearchResult);
49
- const actionsOut = [
50
- updateTransactions(transactions, (value) => value.transaction_id, 'merge'),
51
- searchTransactionsForManualMatchSuccess({
52
- append,
53
- nextPageToken: next_page_token ?? null,
54
- results,
55
- totalCount: total_count,
56
- }),
57
- ];
58
- return from(actionsOut);
59
- }
60
- return of(searchTransactionsForManualMatchFailure({
61
- error: response.status,
62
- }));
63
- }), catchError((error) => of(searchTransactionsForManualMatchFailure({
64
- error: createZeniAPIStatus('Unexpected Error', 'Search transactions for manual match errored: ' +
65
- JSON.stringify(error)),
66
- }))));
67
- }));
68
- };
20
+ return of(searchTransactionsForManualMatchFailure({
21
+ error: response.status,
22
+ }));
23
+ }), catchError((error) => of(searchTransactionsForManualMatchFailure({
24
+ error: createZeniAPIStatus('Unexpected Error', 'Search transactions for manual match errored: ' +
25
+ JSON.stringify(error)),
26
+ }))));
27
+ }));
@@ -1,42 +1,41 @@
1
- import { EMPTY, from, merge, of, timer } from 'rxjs';
2
- import { catchError, debounceTime, filter, mergeMap, switchMap, takeUntil, } from 'rxjs/operators';
3
- import { updateTransactions } from '../../../../entity/transaction/transactionReducer';
1
+ import { of, timer } from 'rxjs';
2
+ import { catchError, filter, mergeMap, switchMap, takeUntil, takeWhile, } from 'rxjs/operators';
4
3
  import { isSuccessResponse } from '../../../../responsePayload';
5
- import { extractTransactionPayloadsFromBatchFiles, isBatchDetailsApiStatusCompleted, toBatchDetails, } from '../../payload/missingReceiptsPayload';
6
- import { bulkUploadReceiptsSuccess, clearBulkUpload, fetchBulkUploadBatchDetailsSuccess, fetchBulkUploadBatches, pusherBatchStatusUpdate, requestMissingReceiptsTabNavigation, } from '../../reducers/missingReceiptsViewReducer';
7
- /** First poll after upload; then interval while batch not resolved via Pusher or API. */
8
- const FALLBACK_FIRST_DELAY_MS = 30000;
9
- const FALLBACK_POLL_INTERVAL_MS = 10000;
4
+ import { toBatchStatus, } from '../../payload/missingReceiptsPayload';
5
+ import { bulkUploadReceiptsSuccess, clearBulkUpload, fetchBulkUploadBatchDetails, pusherBatchStatusUpdate, updateBulkUploadBatchStatus, } from '../../reducers/missingReceiptsViewReducer';
10
6
  /**
11
- * On Pusher batch completion: refresh batch list (then fetchMultipleBatchDetailsEpic runs),
12
- * and request switching to the Unmatched tab. Debounced to reduce duplicate refreshes.
7
+ * Watches batch status using two strategies:
8
+ * 1. Pusher (primary): Reacts to `pusherBatchStatusUpdate` dispatched by the UI layer
9
+ * when a Pusher event arrives. Immediately fetches full details on completion.
10
+ * 2. Polling (fallback): Starts a relaxed 10s poll after upload success as a safety net
11
+ * in case the Pusher event is missed. Stops on completion or `clearBulkUpload`.
13
12
  */
14
- export const pusherBatchStatusCompletionEpic = (actions$) => actions$.pipe(filter(pusherBatchStatusUpdate.match), filter((action) => action.payload.status === 'completed'), debounceTime(300), mergeMap(() => from([
15
- fetchBulkUploadBatches({
16
- cacheOverride: true,
17
- invalidateBatchDetailsCache: true,
18
- }),
19
- requestMissingReceiptsTabNavigation({ tab: 'unmatched' }),
20
- ])));
21
- export const pollBulkUploadBatchStatusEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(bulkUploadReceiptsSuccess.match), mergeMap((action) => {
13
+ // Pusher-driven: when Pusher delivers a completed status, fetch details
14
+ export const pusherBatchStatusCompletionEpic = (actions$) => actions$.pipe(filter(pusherBatchStatusUpdate.match), filter((action) => action.payload.status === 'completed'), mergeMap(() => of(fetchBulkUploadBatchDetails())));
15
+ // Polling fallback: relaxed interval as safety net
16
+ const FALLBACK_POLL_INTERVAL_MS = 10000;
17
+ export const pollBulkUploadBatchStatusEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(bulkUploadReceiptsSuccess.match), switchMap((action) => {
22
18
  const { batchId } = action.payload;
23
- 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
24
- .getJSON(`${zeniAPI.apiEndPoints.communicationAgentMicroServiceBaseUrl}/1.0/batches/${batchId}`)
19
+ return timer(0, FALLBACK_POLL_INTERVAL_MS).pipe(takeUntil(actions$.pipe(filter((a) => clearBulkUpload.match(a) ||
20
+ (pusherBatchStatusUpdate.match(a) &&
21
+ a.payload.status === 'completed')))), switchMap(() => zeniAPI
22
+ .getJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/receipts/batches/${batchId}/status`)
25
23
  .pipe(mergeMap((response) => {
26
- /** Same batch-details URL; polls until `status` is completed (Pusher may win first). */
27
24
  if (isSuccessResponse(response) && response.data != null) {
28
- if (isBatchDetailsApiStatusCompleted(response.data.status)) {
29
- const actions = [];
30
- const transactionPayloads = extractTransactionPayloadsFromBatchFiles(response.data.files);
31
- if (transactionPayloads.length > 0) {
32
- actions.push(updateTransactions(transactionPayloads, (value) => value.transaction_id));
33
- }
34
- actions.push(fetchBulkUploadBatchDetailsSuccess(toBatchDetails(response.data, zeniAPI.apiEndPoints.fileMicroServiceBaseUrl)));
35
- actions.push(fetchBulkUploadBatches(true));
36
- actions.push(requestMissingReceiptsTabNavigation({ tab: 'unmatched' }));
37
- return from(actions);
25
+ const batchStatus = toBatchStatus(response.data);
26
+ const actions = [
27
+ updateBulkUploadBatchStatus(batchStatus),
28
+ ];
29
+ if (batchStatus.status === 'completed') {
30
+ actions.push(fetchBulkUploadBatchDetails());
38
31
  }
32
+ return actions;
33
+ }
34
+ return [];
35
+ }), catchError(() => of()))), takeWhile((action) => {
36
+ if (fetchBulkUploadBatchDetails.match(action)) {
37
+ return false;
39
38
  }
40
- return EMPTY;
41
- }), catchError(() => of()))));
39
+ return true;
40
+ }, true));
42
41
  }));
@@ -1,16 +1,12 @@
1
1
  import { toURL } from '../../../commonPayloadTypes/urlPayload';
2
- import { getTransactionPayloadAmount, } from '../../../entity/transaction/payloadTypes/transactionPayload';
3
2
  // -- Converter functions --
4
- export function toBatchFile(payload, filesEndPoint) {
3
+ export function toBatchFile(payload) {
5
4
  return {
6
5
  attachmentId: payload.attachment_id,
7
6
  candidates: payload.candidates?.map((c) => ({
8
7
  transactionId: c.transaction_id,
9
8
  matchScore: c.match_score,
10
9
  })),
11
- fileDownloadUrl: payload.file_id != null && filesEndPoint != null
12
- ? `${filesEndPoint}/1.0/files/${payload.file_id}?query=${encodeURIComponent(JSON.stringify({ download_file: true }))}`
13
- : null,
14
10
  fileId: payload.file_id,
15
11
  filePreviewUrl: payload.file_preview_url,
16
12
  filename: payload.filename,
@@ -62,62 +58,22 @@ export function toBatchSummary(payload) {
62
58
  total: payload.total,
63
59
  };
64
60
  }
65
- export function toBatchDetails(payload, filesEndPoint) {
61
+ export function toBatchStatus(payload) {
62
+ return {
63
+ batchId: payload.batch_id,
64
+ progress: payload.progress,
65
+ status: payload.status,
66
+ };
67
+ }
68
+ export function toBatchDetails(payload) {
66
69
  return {
67
70
  batchId: payload.batch_id,
68
71
  createdAt: payload.created_at,
69
- files: payload.files.map((f) => toBatchFile(f, filesEndPoint)),
72
+ files: payload.files.map(toBatchFile),
70
73
  status: payload.status,
71
74
  summary: toBatchSummary(payload.summary),
72
75
  };
73
76
  }
74
- /** Batch list `status` is a string from the API — compare case-insensitively. */
75
- export function isBatchListStatusCompleted(status) {
76
- return status.toLowerCase() === 'completed';
77
- }
78
- /**
79
- * Subset of the get-all-batches (`/batches?query=...`) list that is eligible for
80
- * `GET /batches/:batchId` details fetches. The stored list may include pending, failed, or other
81
- * statuses for UI; only `completed` rows should trigger batch-details requests.
82
- */
83
- export function filterBatchListItemsForBatchDetailsFetch(batches) {
84
- return batches.filter((b) => isBatchListStatusCompleted(b.status));
85
- }
86
- /**
87
- * Batch details API response `status` field — only completed payloads should be stored from
88
- * multi-batch fetch paths (list can be briefly stale vs. live processing state).
89
- */
90
- export function isBatchDetailsApiStatusCompleted(status) {
91
- return status.toLowerCase() === 'completed';
92
- }
93
- export function findBatchListItemForBatchId(batchListByPeriod, batchId) {
94
- for (const list of Object.values(batchListByPeriod)) {
95
- const found = list.find((b) => b.batchId === batchId);
96
- if (found != null) {
97
- return found;
98
- }
99
- }
100
- return undefined;
101
- }
102
- /**
103
- * Whether it is appropriate to call `GET .../batches/:id` for details.
104
- * Skips when live batch status or batch list row indicates the batch is not completed yet.
105
- * When status is unknown in both sources, allows the request (e.g. dispatch before list refresh).
106
- */
107
- export function shouldFetchBatchDetailsForBatchId(batchStatusById, batchListByPeriod, batchId) {
108
- const live = batchStatusById[batchId]?.status;
109
- if (live === 'completed') {
110
- return true;
111
- }
112
- if (live === 'pending' || live === 'processing') {
113
- return false;
114
- }
115
- const listItem = findBatchListItemForBatchId(batchListByPeriod, batchId);
116
- if (listItem != null && !isBatchListStatusCompleted(listItem.status)) {
117
- return false;
118
- }
119
- return true;
120
- }
121
77
  export function toBatchListItem(payload) {
122
78
  return {
123
79
  batchId: payload.batch_id,
@@ -130,18 +86,15 @@ export function toBatchListItem(payload) {
130
86
  totalFiles: payload.total_files,
131
87
  };
132
88
  }
133
- /** Maps expense-automation transaction rows to manual-search list rows (Unmatched tab). */
134
- export function supportedTransactionPayloadToManualSearchResult(payload) {
135
- const amountPayload = getTransactionPayloadAmount(payload);
89
+ export function toManualSearchResult(payload) {
136
90
  return {
137
- amount: amountPayload.amount,
138
- currencyCode: amountPayload.currencyCode,
139
- entityId: payload.vendor_id ?? payload.customer_id ?? '',
140
- memo: payload.transaction_memo ?? '',
91
+ amount: payload.amount,
92
+ currencyCode: payload.currency,
93
+ entityId: payload.entity_id,
94
+ memo: payload.memo,
141
95
  transactionDate: payload.transaction_date,
142
96
  transactionId: payload.transaction_id,
143
97
  transactionType: payload.transaction_type,
144
- vendorName: payload.vendor_name ?? '',
145
- vendorLogo: toURL(payload.logo)?.href,
98
+ vendorName: payload.vendor_name,
146
99
  };
147
100
  }