@zeniai/client-epic-state 4.19.87-beta2AD → 4.19.87-betaVR2

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 (88) hide show
  1. package/lib/entity/aiCfo/aiCfoSelector.d.ts +2 -1
  2. package/lib/entity/snackbar/snackbarTypes.d.ts +1 -1
  3. package/lib/entity/snackbar/snackbarTypes.js +1 -0
  4. package/lib/epic.d.ts +10 -2
  5. package/lib/epic.js +10 -2
  6. package/lib/esm/entity/snackbar/snackbarTypes.js +1 -0
  7. package/lib/esm/epic.js +10 -2
  8. package/lib/esm/index.js +10 -4
  9. package/lib/esm/view/aiCfoView/aiCfoViewReducer.js +1 -83
  10. package/lib/esm/view/aiCfoView/aiCfoViewSelector.js +2 -8
  11. package/lib/esm/view/expenseAutomationView/bulkUploadTiming.js +10 -0
  12. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/bulkUploadReceiptsEpic.js +29 -0
  13. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/confirmBulkUploadMatchEpic.js +49 -0
  14. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchDetailsEpic.js +40 -0
  15. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchesEpic.js +47 -0
  16. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchCompletedTransactionsEpic.js +61 -0
  17. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchMoreBatchDetailsEpic.js +34 -0
  18. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.js +57 -0
  19. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.js +78 -0
  20. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.js +82 -0
  21. package/lib/esm/view/expenseAutomationView/payload/missingReceiptsPayload.js +189 -1
  22. package/lib/esm/view/expenseAutomationView/reducers/missingReceiptsViewReducer.js +426 -2
  23. package/lib/esm/view/expenseAutomationView/selectors/missingReceiptsSelector.js +246 -1
  24. package/lib/esm/view/expenseAutomationView/types/missingReceiptsViewState.js +39 -0
  25. package/lib/esm/view/spendManagement/billPay/billList/billListSelector.js +0 -10
  26. package/lib/esm/view/spendManagement/billPay/billList/billListState.js +0 -1
  27. package/lib/esm/view/spendManagement/chargeCards/chargeCardList/chargeCardList.js +0 -1
  28. package/lib/esm/view/spendManagement/chargeCards/chargeCardList/chargeCardListSelector.js +0 -2
  29. package/lib/esm/view/spendManagement/reimbursement/remiListView/remiListSelector.js +0 -12
  30. package/lib/esm/view/spendManagement/reimbursement/remiListView/remiListState.js +0 -1
  31. package/lib/esm/view/taskManager/taskDetailView/taskDetailSelector.js +2 -2
  32. package/lib/esm/zeniAPI.js +0 -2
  33. package/lib/index.d.ts +9 -8
  34. package/lib/index.js +80 -38
  35. package/lib/view/aiCfoView/aiCfoViewPayload.d.ts +0 -11
  36. package/lib/view/aiCfoView/aiCfoViewReducer.d.ts +1 -15
  37. package/lib/view/aiCfoView/aiCfoViewReducer.js +2 -84
  38. package/lib/view/aiCfoView/aiCfoViewSelector.d.ts +1 -4
  39. package/lib/view/aiCfoView/aiCfoViewSelector.js +2 -9
  40. package/lib/view/aiCfoView/aiCfoViewState.d.ts +0 -22
  41. package/lib/view/auditReportView/auditReportViewState.d.ts +1 -1
  42. package/lib/view/expenseAutomationView/bulkUploadTiming.d.ts +10 -0
  43. package/lib/view/expenseAutomationView/bulkUploadTiming.js +13 -0
  44. package/lib/view/expenseAutomationView/epics/missingReceipts/bulkUploadReceiptsEpic.d.ts +18 -0
  45. package/lib/view/expenseAutomationView/epics/missingReceipts/bulkUploadReceiptsEpic.js +33 -0
  46. package/lib/view/expenseAutomationView/epics/missingReceipts/confirmBulkUploadMatchEpic.d.ts +7 -0
  47. package/lib/view/expenseAutomationView/epics/missingReceipts/confirmBulkUploadMatchEpic.js +53 -0
  48. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchDetailsEpic.d.ts +8 -0
  49. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchDetailsEpic.js +44 -0
  50. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchesEpic.d.ts +7 -0
  51. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchesEpic.js +51 -0
  52. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchCompletedTransactionsEpic.d.ts +8 -0
  53. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchCompletedTransactionsEpic.js +65 -0
  54. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMoreBatchDetailsEpic.d.ts +8 -0
  55. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMoreBatchDetailsEpic.js +38 -0
  56. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.d.ts +9 -0
  57. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.js +62 -0
  58. package/lib/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.d.ts +14 -0
  59. package/lib/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.js +82 -0
  60. package/lib/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.d.ts +25 -0
  61. package/lib/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.js +88 -0
  62. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
  63. package/lib/view/expenseAutomationView/payload/missingReceiptsPayload.d.ts +118 -0
  64. package/lib/view/expenseAutomationView/payload/missingReceiptsPayload.js +201 -0
  65. package/lib/view/expenseAutomationView/reducers/missingReceiptsViewReducer.d.ts +76 -3
  66. package/lib/view/expenseAutomationView/reducers/missingReceiptsViewReducer.js +427 -2
  67. package/lib/view/expenseAutomationView/selectorTypes/missingReceiptsSelectorTypes.d.ts +69 -1
  68. package/lib/view/expenseAutomationView/selectors/missingReceiptsSelector.d.ts +1 -1
  69. package/lib/view/expenseAutomationView/selectors/missingReceiptsSelector.js +245 -0
  70. package/lib/view/expenseAutomationView/types/missingReceiptsViewState.d.ts +142 -0
  71. package/lib/view/expenseAutomationView/types/missingReceiptsViewState.js +49 -1
  72. package/lib/view/spendManagement/billPay/billList/billListSelector.js +0 -10
  73. package/lib/view/spendManagement/billPay/billList/billListState.d.ts +1 -1
  74. package/lib/view/spendManagement/billPay/billList/billListState.js +0 -1
  75. package/lib/view/spendManagement/chargeCards/chargeCardList/chargeCardList.d.ts +1 -1
  76. package/lib/view/spendManagement/chargeCards/chargeCardList/chargeCardList.js +0 -1
  77. package/lib/view/spendManagement/chargeCards/chargeCardList/chargeCardListSelector.js +0 -2
  78. package/lib/view/spendManagement/reimbursement/remiListView/remiListSelector.d.ts +0 -1
  79. package/lib/view/spendManagement/reimbursement/remiListView/remiListSelector.js +0 -12
  80. package/lib/view/spendManagement/reimbursement/remiListView/remiListState.d.ts +1 -1
  81. package/lib/view/spendManagement/reimbursement/remiListView/remiListState.js +0 -1
  82. package/lib/view/taskManager/taskDetailView/taskDetailSelector.js +2 -2
  83. package/lib/zeniAPI.js +0 -2
  84. package/package.json +2 -2
  85. package/lib/esm/view/aiCfoView/epics/fetchSuggestedQuestionsEpic.js +0 -26
  86. package/lib/tsconfig.typecheck.tsbuildinfo +0 -1
  87. package/lib/view/aiCfoView/epics/fetchSuggestedQuestionsEpic.d.ts +0 -8
  88. package/lib/view/aiCfoView/epics/fetchSuggestedQuestionsEpic.js +0 -30
@@ -0,0 +1,82 @@
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 { BULK_UPLOAD_AUTOMATCHING_TIMEOUT_MS } from '../../bulkUploadTiming';
7
+ import { extractTransactionPayloadsFromBatchFiles, isBatchDetailsApiStatusCompleted, toBatchDetails, } from '../../payload/missingReceiptsPayload';
8
+ import { bulkUploadAutomatchingTimedOut, bulkUploadReceiptsSuccess, clearBulkUpload, fetchBulkUploadBatchDetailsSuccess, fetchBulkUploadBatches, pusherBatchStatusUpdate, requestMissingReceiptsTabNavigation, } from '../../reducers/missingReceiptsViewReducer';
9
+ /** First poll after upload; then interval while batch not resolved via Pusher or API. */
10
+ const FALLBACK_FIRST_DELAY_MS = 30000;
11
+ const FALLBACK_POLL_INTERVAL_MS = 10000;
12
+ /**
13
+ * On Pusher batch completion: refresh batch list (then fetchMultipleBatchDetailsEpic runs),
14
+ * and request switching to the Unmatched tab. Debounced to reduce duplicate refreshes.
15
+ */
16
+ export const pusherBatchStatusCompletionEpic = (actions$) => actions$.pipe(filter(pusherBatchStatusUpdate.match), filter((action) => action.payload.status === 'completed'), debounceTime(300), mergeMap(() => from([
17
+ fetchBulkUploadBatches({
18
+ cacheOverride: true,
19
+ invalidateBatchDetailsCache: true,
20
+ }),
21
+ requestMissingReceiptsTabNavigation({ tab: 'unmatched' }),
22
+ ])));
23
+ /**
24
+ * If Pusher and batch-details are delayed beyond {@link BULK_UPLOAD_AUTOMATCHING_TIMEOUT_MS},
25
+ * force `phase` to `completed` (dismiss automatching banner) and refresh the batch list.
26
+ * Cancels when the batch completes normally, bulk state is cleared, or another upload supersedes.
27
+ */
28
+ export const bulkUploadAutomatchingTimeoutEpic = (actions$, state$) => actions$.pipe(filter(bulkUploadReceiptsSuccess.match), mergeMap((action) => {
29
+ const { batchId } = action.payload;
30
+ return timer(BULK_UPLOAD_AUTOMATCHING_TIMEOUT_MS).pipe(mergeMap(() => {
31
+ const bulk = state$.value.expenseAutomationMissingReceiptsViewState.bulkUpload;
32
+ if (bulk.phase !== 'matching' ||
33
+ bulk.currentBatchId !== batchId) {
34
+ return EMPTY;
35
+ }
36
+ // eslint-disable-next-line no-console
37
+ console.warn('[bulk-upload] Automatching wait exceeded timeout; releasing UI', { batchId });
38
+ return from([
39
+ bulkUploadAutomatchingTimedOut(batchId),
40
+ fetchBulkUploadBatches({ cacheOverride: true }),
41
+ ]);
42
+ }), takeUntil(merge(actions$.pipe(filter(clearBulkUpload.match)), actions$.pipe(filter(pusherBatchStatusUpdate.match), filter((a) => a.payload.batchId === batchId &&
43
+ a.payload.status === 'completed')), actions$.pipe(filter(fetchBulkUploadBatchDetailsSuccess.match), filter((a) => a.payload.batchId === batchId)))));
44
+ }));
45
+ /**
46
+ * Fallback polling when Pusher is slow or unavailable. Network errors on a poll tick show one
47
+ * error snackbar per upload session (first failure only) so the user is not spammed every
48
+ * interval; Pusher or a later successful poll still completes the flow.
49
+ */
50
+ export const pollBulkUploadBatchStatusEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(bulkUploadReceiptsSuccess.match), mergeMap((action) => {
51
+ const { batchId } = action.payload;
52
+ let pollErrorNotified = false;
53
+ return timer(FALLBACK_FIRST_DELAY_MS, FALLBACK_POLL_INTERVAL_MS).pipe(takeUntil(merge(actions$.pipe(filter(clearBulkUpload.match)), actions$.pipe(filter(pusherBatchStatusUpdate.match), filter((action) => action.payload.batchId === batchId)), actions$.pipe(filter(fetchBulkUploadBatchDetailsSuccess.match), filter((action) => action.payload.batchId === batchId)), actions$.pipe(filter(bulkUploadAutomatchingTimedOut.match), filter((action) => action.payload.batchId === batchId)))), switchMap(() => zeniAPI
54
+ .getJSON(`${zeniAPI.apiEndPoints.communicationAgentMicroServiceBaseUrl}/1.0/batches/${batchId}`)
55
+ .pipe(mergeMap((response) => {
56
+ /** Same batch-details URL; polls until `status` is completed (Pusher may win first). */
57
+ if (isSuccessResponse(response) && response.data != null) {
58
+ if (isBatchDetailsApiStatusCompleted(response.data.status)) {
59
+ const actions = [];
60
+ const transactionPayloads = extractTransactionPayloadsFromBatchFiles(response.data.files);
61
+ if (transactionPayloads.length > 0) {
62
+ actions.push(updateTransactions(transactionPayloads, (value) => value.transaction_id));
63
+ }
64
+ actions.push(fetchBulkUploadBatchDetailsSuccess(toBatchDetails(response.data, zeniAPI.apiEndPoints.fileMicroServiceBaseUrl)));
65
+ actions.push(fetchBulkUploadBatches({ cacheOverride: true }));
66
+ actions.push(requestMissingReceiptsTabNavigation({ tab: 'unmatched' }));
67
+ return from(actions);
68
+ }
69
+ }
70
+ return EMPTY;
71
+ }), catchError(() => {
72
+ if (!pollErrorNotified) {
73
+ pollErrorNotified = true;
74
+ return of(openSnackbar({
75
+ messageSection: 'receipts_upload',
76
+ messageText: 'failed',
77
+ type: 'error',
78
+ }));
79
+ }
80
+ return EMPTY;
81
+ }))));
82
+ }));
@@ -1 +1,189 @@
1
- export {};
1
+ import { toURL } from '../../../commonPayloadTypes/urlPayload';
2
+ import { toAmount } from '../../../commonStateTypes/amount';
3
+ import { getTransactionPayloadAmount, } from '../../../entity/transaction/payloadTypes/transactionPayload';
4
+ import { toBatchFileStatus, toBatchStatusValue, toMatchSource, } from '../types/missingReceiptsViewState';
5
+ // -- Converter functions --
6
+ /**
7
+ * Maps batch-details API `files[].status` strings to canonical {@link BatchFileStatus}.
8
+ * Legacy aliases are supported during rollout; unknown strings map to `failed` so Redux never
9
+ * holds untyped status values.
10
+ */
11
+ export function parseBatchFileStatus(raw) {
12
+ const normalizedStatus = raw.trim().toLowerCase().replace(/-/g, '_');
13
+ switch (normalizedStatus) {
14
+ case 'exact_match':
15
+ case 'matched':
16
+ return 'exact_match';
17
+ case 'possible_matches':
18
+ case 'possible_match':
19
+ case 'possiblematch':
20
+ case 'un_matched':
21
+ case 'unmatched':
22
+ return 'possible_matches';
23
+ case 'no_match':
24
+ case 'nomatch':
25
+ return 'no_match';
26
+ case 'failed':
27
+ return 'failed';
28
+ default:
29
+ return 'failed';
30
+ }
31
+ }
32
+ export function toBatchFile(payload, filesEndPoint) {
33
+ return {
34
+ attachmentId: payload.attachment_id,
35
+ candidates: payload.candidates?.map((candidate) => ({
36
+ transactionId: candidate.transaction_id,
37
+ matchScore: candidate.match_score,
38
+ })),
39
+ fileDownloadUrl: payload.file_id != null && filesEndPoint != null
40
+ ? `${filesEndPoint}/1.0/files/${payload.file_id}?query=${encodeURIComponent(JSON.stringify({ download_file: true }))}`
41
+ : null,
42
+ fileId: payload.file_id,
43
+ filePreviewUrl: payload.file_preview_url,
44
+ filename: payload.filename,
45
+ matchSource: payload.match_source != null
46
+ ? toMatchSource(payload.match_source)
47
+ : undefined,
48
+ matchedTransactionId: payload.matched_transaction?.transaction_id,
49
+ status: toBatchFileStatus(payload.status),
50
+ };
51
+ }
52
+ export function extractTransactionPayloadsFromBatchFiles(files) {
53
+ const seen = new Set();
54
+ const payloads = [];
55
+ for (const file of files) {
56
+ if (file.matched_transaction != null) {
57
+ const id = file.matched_transaction.transaction_id;
58
+ if (!seen.has(id)) {
59
+ seen.add(id);
60
+ payloads.push(matchedTransactionPayloadToSupportedTransactionPayload(file.matched_transaction));
61
+ }
62
+ }
63
+ if (file.candidates != null) {
64
+ for (const candidate of file.candidates) {
65
+ const id = candidate.transaction_id;
66
+ if (!seen.has(id)) {
67
+ seen.add(id);
68
+ payloads.push(matchedTransactionPayloadToSupportedTransactionPayload(candidate));
69
+ }
70
+ }
71
+ }
72
+ }
73
+ return payloads;
74
+ }
75
+ function matchedTransactionPayloadToSupportedTransactionPayload(payload) {
76
+ return {
77
+ transaction_id: payload.transaction_id,
78
+ transaction_type: payload.transaction_type ?? 'expense',
79
+ transaction_date: payload.transaction_date ?? '',
80
+ currency_code: payload.currency_code,
81
+ total_amount: payload.amount,
82
+ vendor_name: payload.vendor_name,
83
+ logo: payload.vendor_logo == null ? undefined : toURL(payload.vendor_logo),
84
+ };
85
+ }
86
+ export function toBatchSummary(payload) {
87
+ return {
88
+ failed: payload.failed,
89
+ matched: payload.matched,
90
+ noMatch: payload.no_match,
91
+ possibleMatches: payload.possible_matches,
92
+ total: payload.total,
93
+ };
94
+ }
95
+ export function toBatchDetails(payload, filesEndPoint) {
96
+ return {
97
+ batchId: payload.batch_id,
98
+ createdAt: payload.created_at,
99
+ files: payload.files.map((file) => toBatchFile(file, filesEndPoint)),
100
+ status: toBatchStatusValue(payload.status),
101
+ summary: toBatchSummary(payload.summary),
102
+ };
103
+ }
104
+ /** Batch list `status` is a string from the API — compare case-insensitively. */
105
+ export function isBatchListStatusCompleted(status) {
106
+ return status.toLowerCase() === 'completed';
107
+ }
108
+ /**
109
+ * Subset of the get-all-batches (`/batches?query=...`) list that is eligible for
110
+ * `GET /batches/:batchId` details fetches. The stored list may include pending, failed, or other
111
+ * statuses for UI; only `completed` rows should trigger batch-details requests.
112
+ */
113
+ export function filterBatchListItemsForBatchDetailsFetch(batches) {
114
+ return batches.filter((batch) => isBatchListStatusCompleted(batch.status));
115
+ }
116
+ /**
117
+ * Batch details API response `status` field — only completed payloads should be stored from
118
+ * multi-batch fetch paths (list can be briefly stale vs. live processing state).
119
+ */
120
+ export function isBatchDetailsApiStatusCompleted(status) {
121
+ return status.toLowerCase() === 'completed';
122
+ }
123
+ export function findBatchListItemForBatchId(batchListByPeriod, batchId) {
124
+ for (const list of Object.values(batchListByPeriod)) {
125
+ const found = list.find((batch) => batch.batchId === batchId);
126
+ if (found != null) {
127
+ return found;
128
+ }
129
+ }
130
+ return undefined;
131
+ }
132
+ /**
133
+ * Whether it is appropriate to call `GET .../batches/:id` for details.
134
+ * Skips when live batch status or batch list row indicates the batch is not completed yet.
135
+ * When status is unknown in both sources, allows the request (e.g. dispatch before list refresh).
136
+ */
137
+ export function shouldFetchBatchDetailsForBatchId(batchStatusById, batchListByPeriod, batchId) {
138
+ const live = batchStatusById[batchId]?.status;
139
+ if (live === 'completed') {
140
+ return true;
141
+ }
142
+ if (live === 'pending' || live === 'processing') {
143
+ return false;
144
+ }
145
+ const listItem = findBatchListItemForBatchId(batchListByPeriod, batchId);
146
+ if (listItem != null && !isBatchListStatusCompleted(listItem.status)) {
147
+ return false;
148
+ }
149
+ return true;
150
+ }
151
+ export function toBatchListItem(payload) {
152
+ return {
153
+ batchId: payload.batch_id,
154
+ createdAt: payload.created_at,
155
+ failedCount: payload.failed_count,
156
+ matchedCount: payload.matched_count,
157
+ noMatchCount: payload.no_match_count,
158
+ possibleMatchesCount: payload.possible_matches_count,
159
+ status: payload.status,
160
+ totalFiles: payload.total_files,
161
+ };
162
+ }
163
+ /**
164
+ * Amount shown in the Unmatched tab manual-search list: **first line only** when `lines` exist.
165
+ * Falls back to transaction-level totals via {@link getTransactionPayloadAmount} when there is
166
+ * no line or no line amount (same currency fields as the rest of the transaction payload).
167
+ */
168
+ function getManualSearchListAmountFromPayload(payload) {
169
+ const lineAmount = payload.lines?.[0]?.amount;
170
+ if (lineAmount != null) {
171
+ return toAmount(lineAmount, payload.currency_code, payload.currency_symbol);
172
+ }
173
+ return getTransactionPayloadAmount(payload);
174
+ }
175
+ /** Maps expense-automation transaction rows to manual-search list rows (Unmatched tab). */
176
+ export function supportedTransactionPayloadToManualSearchResult(payload) {
177
+ const amountPayload = getManualSearchListAmountFromPayload(payload);
178
+ return {
179
+ amount: amountPayload.amount,
180
+ currencyCode: amountPayload.currencyCode,
181
+ entityId: payload.vendor_id ?? payload.customer_id ?? '',
182
+ memo: payload.transaction_memo ?? '',
183
+ transactionDate: payload.transaction_date,
184
+ transactionId: payload.transaction_id,
185
+ transactionType: payload.transaction_type,
186
+ vendorName: payload.vendor_name ?? '',
187
+ vendorLogo: toURL(payload.logo)?.href,
188
+ };
189
+ }