@zeniai/client-epic-state 5.0.75 → 5.0.77-betaAD01

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 (38) hide show
  1. package/lib/entity/aiCfo/aiCfoPayload.d.ts +2 -0
  2. package/lib/entity/aiCfo/aiCfoReducer.d.ts +1 -1
  3. package/lib/entity/aiCfo/aiCfoReducer.js +33 -3
  4. package/lib/entity/aiCfo/aiCfoSelector.js +13 -1
  5. package/lib/entity/aiCfo/aiCfoState.d.ts +2 -0
  6. package/lib/epic.d.ts +4 -1
  7. package/lib/epic.js +4 -1
  8. package/lib/esm/entity/aiCfo/aiCfoReducer.js +32 -2
  9. package/lib/esm/entity/aiCfo/aiCfoSelector.js +13 -1
  10. package/lib/esm/epic.js +4 -1
  11. package/lib/esm/index.js +4 -4
  12. package/lib/esm/view/aiCfoView/aiCfoViewReducer.js +11 -1
  13. package/lib/esm/view/aiCfoView/epics/updateChatSessionPinEpic.js +46 -0
  14. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.js +21 -5
  15. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/refreshBatchDetailsForBatchIdEpic.js +52 -0
  16. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/syncTabsAfterAutomatchEpic.js +56 -0
  17. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.js +13 -9
  18. package/lib/esm/view/expenseAutomationView/reducers/missingReceiptsViewReducer.js +79 -1
  19. package/lib/esm/view/expenseAutomationView/selectors/missingReceiptsSelector.js +2 -0
  20. package/lib/index.d.ts +4 -4
  21. package/lib/index.js +39 -34
  22. package/lib/view/aiCfoView/aiCfoViewReducer.d.ts +4 -1
  23. package/lib/view/aiCfoView/aiCfoViewReducer.js +12 -2
  24. package/lib/view/aiCfoView/epics/updateChatSessionPinEpic.d.ts +8 -0
  25. package/lib/view/aiCfoView/epics/updateChatSessionPinEpic.js +50 -0
  26. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.js +21 -5
  27. package/lib/view/expenseAutomationView/epics/missingReceipts/refreshBatchDetailsForBatchIdEpic.d.ts +18 -0
  28. package/lib/view/expenseAutomationView/epics/missingReceipts/refreshBatchDetailsForBatchIdEpic.js +56 -0
  29. package/lib/view/expenseAutomationView/epics/missingReceipts/syncTabsAfterAutomatchEpic.d.ts +28 -0
  30. package/lib/view/expenseAutomationView/epics/missingReceipts/syncTabsAfterAutomatchEpic.js +60 -0
  31. package/lib/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.d.ts +11 -5
  32. package/lib/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.js +12 -8
  33. package/lib/view/expenseAutomationView/reducers/missingReceiptsViewReducer.d.ts +13 -1
  34. package/lib/view/expenseAutomationView/reducers/missingReceiptsViewReducer.js +81 -2
  35. package/lib/view/expenseAutomationView/selectorTypes/missingReceiptsSelectorTypes.d.ts +12 -0
  36. package/lib/view/expenseAutomationView/selectors/missingReceiptsSelector.js +2 -0
  37. package/lib/view/expenseAutomationView/types/missingReceiptsViewState.d.ts +19 -0
  38. package/package.json +1 -1
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateChatSessionPinEpic = void 0;
4
+ const rxjs_1 = require("rxjs");
5
+ const operators_1 = require("rxjs/operators");
6
+ const aiCfoReducer_1 = require("../../../entity/aiCfo/aiCfoReducer");
7
+ const responsePayload_1 = require("../../../responsePayload");
8
+ const aiCfoViewReducer_1 = require("../aiCfoViewReducer");
9
+ /**
10
+ * TEMP (remove after chat platform pin API is deployed everywhere):
11
+ * When PUT pin/unpin fails, still merge requested pin state so the drawer/navbar UX works
12
+ * against older backends. Revert this file when the platform supports pin or when dropping
13
+ * compatibility — search for `TEMP_PIN_OPTIMISTIC`.
14
+ */
15
+ function buildOptimisticPinPayload_TEMP_PIN_OPTIMISTIC(state, chatSessionId, isPinned) {
16
+ const session = state.aiCfoState.aiCfoByChatSessionId[chatSessionId]?.chatSession;
17
+ if (session == null) {
18
+ return null;
19
+ }
20
+ return {
21
+ chat_session_id: chatSessionId,
22
+ user_id: session.userId,
23
+ created_at: session.createdAt.toISOString(),
24
+ chat_session_summary: session.chatSessionSummary ?? null,
25
+ is_pinned: isPinned,
26
+ pinned_at: isPinned ? new Date().toISOString() : null,
27
+ };
28
+ }
29
+ const updateChatSessionPinEpic = (actions$, state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(aiCfoViewReducer_1.updateChatSessionPin.match), (0, operators_1.switchMap)((action) => {
30
+ const { chatSessionId, isPinned } = action.payload;
31
+ return zeniAPI
32
+ .putAndGetJSON(`${zeniAPI.apiEndPoints.aiCfoMicroServiceBaseUrl}/1.0/sessions/${chatSessionId}`, { is_pinned: isPinned })
33
+ .pipe((0, operators_1.mergeMap)((response) => {
34
+ if ((0, responsePayload_1.isSuccessResponse)(response) && response.data != null) {
35
+ return (0, rxjs_1.of)((0, aiCfoReducer_1.mergeChatSessionFromPutResponse)(response.data));
36
+ }
37
+ // TEMP_PIN_OPTIMISTIC — see comment above
38
+ const synthetic = buildOptimisticPinPayload_TEMP_PIN_OPTIMISTIC(state$.value, chatSessionId, isPinned);
39
+ return synthetic != null
40
+ ? (0, rxjs_1.of)((0, aiCfoReducer_1.mergeChatSessionFromPutResponse)(synthetic))
41
+ : rxjs_1.EMPTY;
42
+ }), (0, operators_1.catchError)(() => {
43
+ // TEMP_PIN_OPTIMISTIC — see comment above
44
+ const synthetic = buildOptimisticPinPayload_TEMP_PIN_OPTIMISTIC(state$.value, chatSessionId, isPinned);
45
+ return synthetic != null
46
+ ? (0, rxjs_1.of)((0, aiCfoReducer_1.mergeChatSessionFromPutResponse)(synthetic))
47
+ : rxjs_1.EMPTY;
48
+ }));
49
+ }));
50
+ exports.updateChatSessionPinEpic = updateChatSessionPinEpic;
@@ -35,10 +35,19 @@ function fetchBatchDetailsByIds(batchIds, zeniAPI) {
35
35
  }
36
36
  const fetchMultipleBatchDetailsEpic = (actions$, state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(missingReceiptsViewReducer_1.fetchBulkUploadBatchesSuccess.match), (0, operators_1.mergeMap)((action) => {
37
37
  const batchList = action.payload.batchList;
38
- const { batchDetailsById } = state$.value.expenseAutomationMissingReceiptsViewState.bulkUpload;
38
+ const bulkUpload = state$.value.expenseAutomationMissingReceiptsViewState.bulkUpload;
39
+ const { batchDetailsById, batchDetailsRevalidating } = bulkUpload;
39
40
  /** Only completed list rows may trigger batch-details API; preserve platform order. */
40
- const completedBatchesMissingDetails = (0, missingReceiptsPayload_1.filterBatchListItemsForBatchDetailsFetch)(batchList).filter((batch) => batchDetailsById[batch.batchId] == null);
41
- const completedBatchIds = completedBatchesMissingDetails.map((batch) => batch.batchId);
41
+ const completedRows = (0, missingReceiptsPayload_1.filterBatchListItemsForBatchDetailsFetch)(batchList);
42
+ /**
43
+ * Stale-while-revalidate: when a manual refresh has set `batchDetailsRevalidating`, refresh
44
+ * every completed list row (replacing entries via `storeBatchDetails` as they arrive). On a
45
+ * normal first fetch we still only request rows whose details are missing.
46
+ */
47
+ const candidateRows = batchDetailsRevalidating === true
48
+ ? completedRows
49
+ : completedRows.filter((batch) => batchDetailsById[batch.batchId] == null);
50
+ const completedBatchIds = candidateRows.map((batch) => batch.batchId);
42
51
  const batchIdsToFetch = completedBatchIds.slice(0, INITIAL_BATCH_PAGE_SIZE);
43
52
  if (batchIdsToFetch.length === 0) {
44
53
  /**
@@ -46,7 +55,6 @@ const fetchMultipleBatchDetailsEpic = (actions$, state$, zeniAPI) => actions$.pi
46
55
  * `currentBatchId` may not appear in the filtered list but still needs `GET /batches/:id`.
47
56
  * Fall back to the single-batch-details epic so `phase` and details can resolve.
48
57
  */
49
- const bulkUpload = state$.value.expenseAutomationMissingReceiptsViewState.bulkUpload;
50
58
  const currentId = bulkUpload.currentBatchId;
51
59
  if (currentId != null &&
52
60
  bulkUpload.phase === 'matching' &&
@@ -54,7 +62,15 @@ const fetchMultipleBatchDetailsEpic = (actions$, state$, zeniAPI) => actions$.pi
54
62
  (0, missingReceiptsPayload_1.shouldFetchBatchDetailsForBatchId)(bulkUpload.batchStatusById, bulkUpload.batchListByPeriod, currentId)) {
55
63
  return (0, rxjs_1.of)((0, missingReceiptsViewReducer_1.fetchBulkUploadBatchDetails)());
56
64
  }
57
- return rxjs_1.EMPTY;
65
+ /**
66
+ * Close the pagination loop so the Unmatched-tab loading heuristic can settle.
67
+ * `fetchMoreBatchDetailsComplete` also clears `batchDetailsRevalidating` and flips
68
+ * `initialBatchDetailsLoaded` to true. Without this, `batchDetailsPaginationState` stays
69
+ * at `Not-Started` forever after a list refresh that finds zero completed rows (or all
70
+ * already cached) — the direct-open-Unmatched-without-upload path used to render an
71
+ * infinite skeleton.
72
+ */
73
+ return (0, rxjs_1.of)((0, missingReceiptsViewReducer_1.fetchMoreBatchDetailsComplete)());
58
74
  }
59
75
  return (0, rxjs_1.concat)((0, rxjs_1.of)((0, missingReceiptsViewReducer_1.setInitialBatchDetailsLoading)()), fetchBatchDetailsByIds(batchIdsToFetch, zeniAPI), (0, rxjs_1.of)((0, missingReceiptsViewReducer_1.fetchMoreBatchDetailsComplete)()));
60
76
  }));
@@ -0,0 +1,18 @@
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 { batchDetailFetchFailed, markBatchDetailRefreshAttempted, refreshBatchDetailsForBatchId, storeBatchDetails } from '../../reducers/missingReceiptsViewReducer';
7
+ export type ActionType = ReturnType<typeof refreshBatchDetailsForBatchId> | ReturnType<typeof markBatchDetailRefreshAttempted> | ReturnType<typeof updateTransactions> | ReturnType<typeof storeBatchDetails> | ReturnType<typeof batchDetailFetchFailed>;
8
+ /**
9
+ * Single-batch stale-while-revalidate refresh. Triggered by `pusherBatchStatusCompletionEpic`
10
+ * (and any other path that wants to update one batch without wiping the cache). The response is
11
+ * stored via `storeBatchDetails`, which replaces the entry by `batchId` so the row updates in
12
+ * place — no skeleton, no list reflow.
13
+ *
14
+ * Throttle: `lastBatchDetailRefreshAtById[batchId]` is checked against `TARGETED_REFRESH_DEDUPE_MS`
15
+ * before issuing the call. The marker is emitted first so concurrent dispatches (e.g. Pusher
16
+ * resend during an in-flight request) see the dedupe timestamp and collapse to a single call.
17
+ */
18
+ export declare const refreshBatchDetailsForBatchIdEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => Observable<ActionType>;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.refreshBatchDetailsForBatchIdEpic = void 0;
4
+ const rxjs_1 = require("rxjs");
5
+ const operators_1 = require("rxjs/operators");
6
+ const transactionReducer_1 = require("../../../../entity/transaction/transactionReducer");
7
+ const responsePayload_1 = require("../../../../responsePayload");
8
+ const missingReceiptsPayload_1 = require("../../payload/missingReceiptsPayload");
9
+ const missingReceiptsViewReducer_1 = require("../../reducers/missingReceiptsViewReducer");
10
+ /**
11
+ * Pusher resends the same `completed` event in some cases (reconnect, server retry). Skip a
12
+ * targeted refresh if we issued one for the same batch within this window — the cached details
13
+ * are already fresh, so another `GET /1.0/batches/:id` is wasteful and visually flickers nothing.
14
+ */
15
+ const TARGETED_REFRESH_DEDUPE_MS = 5000;
16
+ /**
17
+ * Single-batch stale-while-revalidate refresh. Triggered by `pusherBatchStatusCompletionEpic`
18
+ * (and any other path that wants to update one batch without wiping the cache). The response is
19
+ * stored via `storeBatchDetails`, which replaces the entry by `batchId` so the row updates in
20
+ * place — no skeleton, no list reflow.
21
+ *
22
+ * Throttle: `lastBatchDetailRefreshAtById[batchId]` is checked against `TARGETED_REFRESH_DEDUPE_MS`
23
+ * before issuing the call. The marker is emitted first so concurrent dispatches (e.g. Pusher
24
+ * resend during an in-flight request) see the dedupe timestamp and collapse to a single call.
25
+ */
26
+ const refreshBatchDetailsForBatchIdEpic = (actions$, state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(missingReceiptsViewReducer_1.refreshBatchDetailsForBatchId.match), (0, operators_1.mergeMap)((action) => {
27
+ const { batchId } = action.payload;
28
+ const now = Date.now();
29
+ const lastAttempt = state$.value.expenseAutomationMissingReceiptsViewState.bulkUpload
30
+ .lastBatchDetailRefreshAtById[batchId];
31
+ if (lastAttempt != null &&
32
+ now - lastAttempt < TARGETED_REFRESH_DEDUPE_MS) {
33
+ return rxjs_1.EMPTY;
34
+ }
35
+ const apiCall = zeniAPI
36
+ .getJSON(`${zeniAPI.apiEndPoints.communicationAgentMicroServiceBaseUrl}/1.0/batches/${batchId}`)
37
+ .pipe((0, operators_1.mergeMap)((response) => {
38
+ if (!(0, responsePayload_1.isSuccessResponse)(response) ||
39
+ response.data == null ||
40
+ !(0, missingReceiptsPayload_1.isBatchDetailsApiStatusCompleted)(response.data.status)) {
41
+ return rxjs_1.EMPTY;
42
+ }
43
+ const actions = [];
44
+ const transactionPayloads = (0, missingReceiptsPayload_1.extractTransactionPayloadsFromBatchFiles)(response.data.files);
45
+ if (transactionPayloads.length > 0) {
46
+ actions.push((0, transactionReducer_1.updateTransactions)(transactionPayloads, (value) => value.transaction_id));
47
+ }
48
+ actions.push((0, missingReceiptsViewReducer_1.storeBatchDetails)((0, missingReceiptsPayload_1.toBatchDetails)(response.data, zeniAPI.apiEndPoints.fileMicroServiceBaseUrl)));
49
+ return (0, rxjs_1.from)(actions);
50
+ }), (0, operators_1.catchError)((error) => {
51
+ console.error(`Failed to refresh batch details for ${batchId}:`, (0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', 'Refresh batch details errored out: ' + JSON.stringify(error)));
52
+ return (0, rxjs_1.of)((0, missingReceiptsViewReducer_1.batchDetailFetchFailed)({ batchId }));
53
+ }));
54
+ return (0, rxjs_1.concat)((0, rxjs_1.of)((0, missingReceiptsViewReducer_1.markBatchDetailRefreshAttempted)({ batchId, timestamp: now })), apiCall);
55
+ }));
56
+ exports.refreshBatchDetailsForBatchIdEpic = refreshBatchDetailsForBatchIdEpic;
@@ -0,0 +1,28 @@
1
+ import { ActionsObservable, StateObservable } from 'redux-observable';
2
+ import { Observable } from 'rxjs';
3
+ import { RootState } from '../../../../reducer';
4
+ import { bulkUploadReceiptsSuccess, clearBulkUpload, fetchBulkUploadBatchDetailsSuccess, fetchCompletedTransactions, fetchMissingReceipts, restoreBulkUploadMatchingState, storeBatchDetails } from '../../reducers/missingReceiptsViewReducer';
5
+ export type ActionType = ReturnType<typeof bulkUploadReceiptsSuccess> | ReturnType<typeof restoreBulkUploadMatchingState> | ReturnType<typeof fetchBulkUploadBatchDetailsSuccess> | ReturnType<typeof storeBatchDetails> | ReturnType<typeof clearBulkUpload> | ReturnType<typeof fetchMissingReceipts> | ReturnType<typeof fetchCompletedTransactions>;
6
+ /**
7
+ * After automatch completes for the active bulk-upload batch, refresh the two
8
+ * caches that are not invalidated by the existing batch-details refresh path:
9
+ * - Missing Receipts list (`transactionIdsBySelectedPeriod`)
10
+ * - Completed transactions cache (`bulkUpload.completedTransactionsByPeriod`)
11
+ *
12
+ * The Unmatched tab is already kept fresh via `pusherBatchStatusCompletionEpic`
13
+ * dispatching `fetchBulkUploadBatches({invalidateBatchDetailsCache: true})`,
14
+ * which feeds `fetchMultipleBatchDetailsEpic` and re-stores batch details.
15
+ *
16
+ * Lifecycle mirrors `bulkUploadMatchResultToastEpic`: trigger on
17
+ * `bulkUploadReceiptsSuccess` (fresh upload) or `restoreBulkUploadMatchingState`
18
+ * (restored session), then wait for the first batch-details action for that
19
+ * batchId — landing as either `fetchBulkUploadBatchDetailsSuccess` or
20
+ * `storeBatchDetails`. `clearBulkUpload` cancels the in-flight wait.
21
+ *
22
+ * Refetches use `cacheOverride: true` to bypass per-tab cache guards, and
23
+ * `fetchMissingReceipts` uses `refreshViewInBackground: true` to keep the
24
+ * existing rows visible while fresh data is in flight (the authoritative
25
+ * server filter `is_attachment_missing_only=true` removes matched rows once
26
+ * the response lands).
27
+ */
28
+ export declare const syncTabsAfterAutomatchEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>) => Observable<ActionType>;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.syncTabsAfterAutomatchEpic = void 0;
4
+ const rxjs_1 = require("rxjs");
5
+ const operators_1 = require("rxjs/operators");
6
+ const timePeriod_1 = require("../../../../commonStateTypes/timePeriod");
7
+ const tenantSelector_1 = require("../../../../entity/tenant/tenantSelector");
8
+ const missingReceiptsViewReducer_1 = require("../../reducers/missingReceiptsViewReducer");
9
+ /**
10
+ * After automatch completes for the active bulk-upload batch, refresh the two
11
+ * caches that are not invalidated by the existing batch-details refresh path:
12
+ * - Missing Receipts list (`transactionIdsBySelectedPeriod`)
13
+ * - Completed transactions cache (`bulkUpload.completedTransactionsByPeriod`)
14
+ *
15
+ * The Unmatched tab is already kept fresh via `pusherBatchStatusCompletionEpic`
16
+ * dispatching `fetchBulkUploadBatches({invalidateBatchDetailsCache: true})`,
17
+ * which feeds `fetchMultipleBatchDetailsEpic` and re-stores batch details.
18
+ *
19
+ * Lifecycle mirrors `bulkUploadMatchResultToastEpic`: trigger on
20
+ * `bulkUploadReceiptsSuccess` (fresh upload) or `restoreBulkUploadMatchingState`
21
+ * (restored session), then wait for the first batch-details action for that
22
+ * batchId — landing as either `fetchBulkUploadBatchDetailsSuccess` or
23
+ * `storeBatchDetails`. `clearBulkUpload` cancels the in-flight wait.
24
+ *
25
+ * Refetches use `cacheOverride: true` to bypass per-tab cache guards, and
26
+ * `fetchMissingReceipts` uses `refreshViewInBackground: true` to keep the
27
+ * existing rows visible while fresh data is in flight (the authoritative
28
+ * server filter `is_attachment_missing_only=true` removes matched rows once
29
+ * the response lands).
30
+ */
31
+ const syncTabsAfterAutomatchEpic = (actions$, state$) => actions$.pipe((0, operators_1.filter)((action) => missingReceiptsViewReducer_1.bulkUploadReceiptsSuccess.match(action) ||
32
+ missingReceiptsViewReducer_1.restoreBulkUploadMatchingState.match(action)), (0, operators_1.switchMap)((uploadAction) => {
33
+ const { batchId } = uploadAction.payload;
34
+ return (0, rxjs_1.merge)(actions$.pipe((0, operators_1.filter)(missingReceiptsViewReducer_1.fetchBulkUploadBatchDetailsSuccess.match)), actions$.pipe((0, operators_1.filter)(missingReceiptsViewReducer_1.storeBatchDetails.match))).pipe((0, operators_1.filter)((a) => a.payload.batchId === batchId), (0, operators_1.take)(1), (0, operators_1.switchMap)((action) => {
35
+ const { summary } = action.payload;
36
+ if (summary.matched <= 0) {
37
+ return rxjs_1.EMPTY;
38
+ }
39
+ const state = state$.value;
40
+ const currentTenant = (0, tenantSelector_1.getCurrentTenant)(state);
41
+ if (currentTenant == null) {
42
+ return rxjs_1.EMPTY;
43
+ }
44
+ const selectedPeriod = state.expenseAutomationViewState.selectedPeriodByTenantId[currentTenant.tenantId];
45
+ if (selectedPeriod == null) {
46
+ return (0, rxjs_1.from)([(0, missingReceiptsViewReducer_1.fetchCompletedTransactions)(undefined, true)]);
47
+ }
48
+ const period = (0, timePeriod_1.convertToPeriod)(selectedPeriod);
49
+ const timePeriodStart = (0, timePeriod_1.toAbsoluteDay)(period.start);
50
+ const timePeriodEnd = (0, timePeriod_1.toAbsoluteDay)(period.end);
51
+ if (timePeriodStart == null || timePeriodEnd == null) {
52
+ return (0, rxjs_1.from)([(0, missingReceiptsViewReducer_1.fetchCompletedTransactions)(undefined, true)]);
53
+ }
54
+ return (0, rxjs_1.from)([
55
+ (0, missingReceiptsViewReducer_1.fetchMissingReceipts)({ start: timePeriodStart, end: timePeriodEnd }, { amount: 75.0, currencyCode: 'USD', currencySymbol: '$' }, true, true),
56
+ (0, missingReceiptsViewReducer_1.fetchCompletedTransactions)(undefined, true),
57
+ ]);
58
+ }), (0, operators_1.takeUntil)(actions$.pipe((0, operators_1.filter)(missingReceiptsViewReducer_1.clearBulkUpload.match))));
59
+ }));
60
+ exports.syncTabsAfterAutomatchEpic = syncTabsAfterAutomatchEpic;
@@ -4,13 +4,19 @@ import { openSnackbar } from '../../../../entity/snackbar/snackbarReducer';
4
4
  import { updateTransactions } from '../../../../entity/transaction/transactionReducer';
5
5
  import { RootState } from '../../../../reducer';
6
6
  import { ZeniAPI } from '../../../../zeniAPI';
7
- import { bulkUploadAutomatchingTimedOut, bulkUploadReceiptsSuccess, clearBulkUpload, fetchBulkUploadBatchDetails, fetchBulkUploadBatchDetailsSuccess, fetchBulkUploadBatches, pusherBatchStatusUpdate, restoreBulkUploadMatchingState } from '../../reducers/missingReceiptsViewReducer';
8
- export type ActionType = ReturnType<typeof bulkUploadReceiptsSuccess> | ReturnType<typeof restoreBulkUploadMatchingState> | ReturnType<typeof pusherBatchStatusUpdate> | ReturnType<typeof fetchBulkUploadBatchDetails> | ReturnType<typeof fetchBulkUploadBatchDetailsSuccess> | ReturnType<typeof fetchBulkUploadBatches> | ReturnType<typeof updateTransactions> | ReturnType<typeof clearBulkUpload> | ReturnType<typeof openSnackbar> | ReturnType<typeof bulkUploadAutomatchingTimedOut>;
7
+ import { bulkUploadAutomatchingTimedOut, bulkUploadReceiptsSuccess, clearBulkUpload, fetchBulkUploadBatchDetails, fetchBulkUploadBatchDetailsSuccess, fetchBulkUploadBatches, pusherBatchStatusUpdate, refreshBatchDetailsForBatchId, restoreBulkUploadMatchingState } from '../../reducers/missingReceiptsViewReducer';
8
+ export type ActionType = ReturnType<typeof bulkUploadReceiptsSuccess> | ReturnType<typeof restoreBulkUploadMatchingState> | ReturnType<typeof pusherBatchStatusUpdate> | ReturnType<typeof fetchBulkUploadBatchDetails> | ReturnType<typeof fetchBulkUploadBatchDetailsSuccess> | ReturnType<typeof fetchBulkUploadBatches> | ReturnType<typeof refreshBatchDetailsForBatchId> | ReturnType<typeof updateTransactions> | ReturnType<typeof clearBulkUpload> | ReturnType<typeof openSnackbar> | ReturnType<typeof bulkUploadAutomatchingTimedOut>;
9
9
  /**
10
- * On Pusher batch completion: refresh batch list (then fetchMultipleBatchDetailsEpic runs).
11
- * Debounced to reduce duplicate refreshes. The post-match tab decision
12
- * (Unmatched vs Completed) is made client-side in `ExpenseAutomationPage` once fresh
10
+ * On Pusher batch completion: refresh the batch list (so summary counts update) and dispatch a
11
+ * targeted single-batch details refresh for the batch that just completed. Stale-while-revalidate:
12
+ * we no longer pass `invalidateBatchDetailsCache: true` existing `batchDetailsById` entries stay
13
+ * on screen and the just-completed row replaces in place via `storeBatchDetails`. The post-match
14
+ * tab decision (Unmatched vs Completed) is made client-side in `ExpenseAutomationPage` once fresh
13
15
  * batch details land -- do not dispatch `requestMissingReceiptsTabNavigation` here.
16
+ *
17
+ * Pusher resend storms (same batch completing twice within the dedupe window) are throttled in
18
+ * `refreshBatchDetailsForBatchIdEpic` via `lastBatchDetailRefreshAtById`, so this epic stays
19
+ * stateless and just forwards the event.
14
20
  */
15
21
  export declare const pusherBatchStatusCompletionEpic: (actions$: ActionsObservable<ActionType>) => Observable<ActionType>;
16
22
  /**
@@ -15,16 +15,20 @@ const FALLBACK_FIRST_DELAY_MS = 30000;
15
15
  const RESTORE_FIRST_DELAY_MS = 5000;
16
16
  const FALLBACK_POLL_INTERVAL_MS = 10000;
17
17
  /**
18
- * On Pusher batch completion: refresh batch list (then fetchMultipleBatchDetailsEpic runs).
19
- * Debounced to reduce duplicate refreshes. The post-match tab decision
20
- * (Unmatched vs Completed) is made client-side in `ExpenseAutomationPage` once fresh
18
+ * On Pusher batch completion: refresh the batch list (so summary counts update) and dispatch a
19
+ * targeted single-batch details refresh for the batch that just completed. Stale-while-revalidate:
20
+ * we no longer pass `invalidateBatchDetailsCache: true` existing `batchDetailsById` entries stay
21
+ * on screen and the just-completed row replaces in place via `storeBatchDetails`. The post-match
22
+ * tab decision (Unmatched vs Completed) is made client-side in `ExpenseAutomationPage` once fresh
21
23
  * batch details land -- do not dispatch `requestMissingReceiptsTabNavigation` here.
24
+ *
25
+ * Pusher resend storms (same batch completing twice within the dedupe window) are throttled in
26
+ * `refreshBatchDetailsForBatchIdEpic` via `lastBatchDetailRefreshAtById`, so this epic stays
27
+ * stateless and just forwards the event.
22
28
  */
23
- const pusherBatchStatusCompletionEpic = (actions$) => actions$.pipe((0, operators_1.filter)(missingReceiptsViewReducer_1.pusherBatchStatusUpdate.match), (0, operators_1.filter)((action) => action.payload.status === 'completed'), (0, operators_1.debounceTime)(300), (0, operators_1.mergeMap)(() => (0, rxjs_1.from)([
24
- (0, missingReceiptsViewReducer_1.fetchBulkUploadBatches)({
25
- cacheOverride: true,
26
- invalidateBatchDetailsCache: true,
27
- }),
29
+ const pusherBatchStatusCompletionEpic = (actions$) => actions$.pipe((0, operators_1.filter)(missingReceiptsViewReducer_1.pusherBatchStatusUpdate.match), (0, operators_1.filter)((action) => action.payload.status === 'completed'), (0, operators_1.debounceTime)(300), (0, operators_1.mergeMap)((action) => (0, rxjs_1.from)([
30
+ (0, missingReceiptsViewReducer_1.fetchBulkUploadBatches)({ cacheOverride: true }),
31
+ (0, missingReceiptsViewReducer_1.refreshBatchDetailsForBatchId)({ batchId: action.payload.batchId }),
28
32
  ])));
29
33
  exports.pusherBatchStatusCompletionEpic = pusherBatchStatusCompletionEpic;
30
34
  /**
@@ -19,6 +19,15 @@ export declare const fetchBulkUploadBatchDetails: import("@reduxjs/toolkit").Act
19
19
  * after a hard refresh. The epic owns the list + details API calls end-to-end.
20
20
  */
21
21
  export declare const restoreBulkUploadAutomatchingOnMount: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"expenseAutomationMissingReceiptsView/restoreBulkUploadAutomatchingOnMount">;
22
+ /**
23
+ * Epic trigger only. Targeted stale-while-revalidate refresh for a single batch's details — used
24
+ * by `pusherBatchStatusCompletionEpic` so a Pusher 'completed' event re-fetches only that one
25
+ * batch instead of wiping the entire `batchDetailsById` cache. The epic dedupes via
26
+ * `lastBatchDetailRefreshAtById` so resend storms don't trigger waves of API calls.
27
+ */
28
+ export declare const refreshBatchDetailsForBatchId: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
29
+ batchId: ID;
30
+ }, string>;
22
31
  export declare const fetchMissingReceipts: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[period: TimePeriod, minimumTransactionAmount: Amount, cacheOverride?: any, refreshViewInBackground?: any], {
23
32
  period: TimePeriod;
24
33
  minimumTransactionAmount: Amount;
@@ -73,7 +82,10 @@ export declare const fetchMissingReceipts: import("@reduxjs/toolkit").ActionCrea
73
82
  }, "expenseAutomationMissingReceiptsView/fetchBulkUploadBatchesSuccess">, fetchBulkUploadBatchesFailure: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
74
83
  error: ZeniAPIStatus;
75
84
  selectedPeriod: MonthYearPeriod;
76
- }, "expenseAutomationMissingReceiptsView/fetchBulkUploadBatchesFailure">, confirmBulkUploadMatch: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[batchId: string, attachmentId: string, transactionId: string, transactionType: string, fileName: string], {
85
+ }, "expenseAutomationMissingReceiptsView/fetchBulkUploadBatchesFailure">, clearBulkUploadBatchDetailsForScopeChange: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"expenseAutomationMissingReceiptsView/clearBulkUploadBatchDetailsForScopeChange">, markBatchDetailRefreshAttempted: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
86
+ batchId: ID;
87
+ timestamp: number;
88
+ }, "expenseAutomationMissingReceiptsView/markBatchDetailRefreshAttempted">, confirmBulkUploadMatch: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[batchId: string, attachmentId: string, transactionId: string, transactionType: string, fileName: string], {
77
89
  batchId: string;
78
90
  attachmentId: string;
79
91
  transactionId: string;
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.fetchCompletedTransactionsFailure = exports.fetchCompletedTransactionsSuccess = exports.fetchCompletedTransactions = exports.acknowledgeBulkUploadConfirmMatchComplete = exports.clearManualSearchResults = exports.searchTransactionsForManualMatchFailure = exports.searchTransactionsForManualMatchSuccess = exports.searchTransactionsForManualMatch = exports.clearBulkUpload = exports.setBulkUploadSortConfig = exports.setBulkUploadCompletedSubTab = exports.setBulkUploadResultsTab = exports.confirmBulkUploadMatchFailure = exports.confirmBulkUploadMatchSuccess = exports.confirmBulkUploadMatch = exports.fetchBulkUploadBatchesFailure = exports.fetchBulkUploadBatchesSuccess = exports.fetchBulkUploadBatches = exports.fetchMoreBatchDetailsFailure = exports.fetchMoreBatchDetailsComplete = exports.fetchMoreBatchDetails = exports.setInitialBatchDetailsLoading = exports.batchDetailFetchFailed = exports.storeBatchDetails = exports.fetchBulkUploadBatchDetailsFailure = exports.fetchBulkUploadBatchDetailsSuccess = exports.clearMissingReceiptsTabNavigation = exports.requestMissingReceiptsTabNavigation = exports.pusherBatchStatusUpdate = exports.bulkUploadAutomatchingTimedOut = exports.restoreBulkUploadMatchingState = exports.bulkUploadReceiptsFailure = exports.bulkUploadReceiptsSuccess = exports.setBulkUploadUploadedFileCount = exports.updateBulkUploadProgress = exports.bulkUploadReceipts = exports.clearExpenseAutomationMissingReceiptsView = exports.markMissingReceiptAsDone = exports.updateMissingReceiptsUIState = exports.updateMissingReceiptUploadState = exports.uploadMissingReceiptSuccess = exports.fetchMissingReceiptsFailure = exports.fetchMissingReceiptsSuccess = exports.fetchMissingReceipts = exports.restoreBulkUploadAutomatchingOnMount = exports.fetchBulkUploadBatchDetails = exports.initialState = exports.initialBulkUploadState = exports.getCompletedTransactionsCacheKey = void 0;
4
+ exports.fetchCompletedTransactions = exports.acknowledgeBulkUploadConfirmMatchComplete = exports.clearManualSearchResults = exports.searchTransactionsForManualMatchFailure = exports.searchTransactionsForManualMatchSuccess = exports.searchTransactionsForManualMatch = exports.clearBulkUpload = exports.setBulkUploadSortConfig = exports.setBulkUploadCompletedSubTab = exports.setBulkUploadResultsTab = exports.confirmBulkUploadMatchFailure = exports.confirmBulkUploadMatchSuccess = exports.confirmBulkUploadMatch = exports.markBatchDetailRefreshAttempted = exports.clearBulkUploadBatchDetailsForScopeChange = exports.fetchBulkUploadBatchesFailure = exports.fetchBulkUploadBatchesSuccess = exports.fetchBulkUploadBatches = exports.fetchMoreBatchDetailsFailure = exports.fetchMoreBatchDetailsComplete = exports.fetchMoreBatchDetails = exports.setInitialBatchDetailsLoading = exports.batchDetailFetchFailed = exports.storeBatchDetails = exports.fetchBulkUploadBatchDetailsFailure = exports.fetchBulkUploadBatchDetailsSuccess = exports.clearMissingReceiptsTabNavigation = exports.requestMissingReceiptsTabNavigation = exports.pusherBatchStatusUpdate = exports.bulkUploadAutomatchingTimedOut = exports.restoreBulkUploadMatchingState = exports.bulkUploadReceiptsFailure = exports.bulkUploadReceiptsSuccess = exports.setBulkUploadUploadedFileCount = exports.updateBulkUploadProgress = exports.bulkUploadReceipts = exports.clearExpenseAutomationMissingReceiptsView = exports.markMissingReceiptAsDone = exports.updateMissingReceiptsUIState = exports.updateMissingReceiptUploadState = exports.uploadMissingReceiptSuccess = exports.fetchMissingReceiptsFailure = exports.fetchMissingReceiptsSuccess = exports.fetchMissingReceipts = exports.refreshBatchDetailsForBatchId = exports.restoreBulkUploadAutomatchingOnMount = exports.fetchBulkUploadBatchDetails = exports.initialState = exports.initialBulkUploadState = exports.getCompletedTransactionsCacheKey = void 0;
5
+ exports.fetchCompletedTransactionsFailure = exports.fetchCompletedTransactionsSuccess = void 0;
5
6
  const toolkit_1 = require("@reduxjs/toolkit");
6
7
  const timePeriod_1 = require("../../../commonStateTypes/timePeriod");
7
8
  const completedSubTab_1 = require("../types/completedSubTab");
@@ -15,6 +16,7 @@ exports.getCompletedTransactionsCacheKey = getCompletedTransactionsCacheKey;
15
16
  exports.initialBulkUploadState = {
16
17
  batchDetailsById: {},
17
18
  batchDetailsPaginationState: { fetchState: 'Not-Started', error: undefined },
19
+ batchDetailsRevalidating: false,
18
20
  batchListByPeriod: {},
19
21
  batchListFetchState: { fetchState: 'Not-Started', error: undefined },
20
22
  batchStatusById: {},
@@ -24,6 +26,8 @@ exports.initialBulkUploadState = {
24
26
  currentBatchId: undefined,
25
27
  currentResultsTab: 'unmatched',
26
28
  failedBatchDetailIds: [],
29
+ initialBatchDetailsLoaded: false,
30
+ lastBatchDetailRefreshAtById: {},
27
31
  manualSearchUiResetKey: 0,
28
32
  manualSearch: {
29
33
  fetchState: { fetchState: 'Not-Started', error: undefined },
@@ -70,6 +74,13 @@ exports.fetchBulkUploadBatchDetails = (0, toolkit_1.createAction)('expenseAutoma
70
74
  * after a hard refresh. The epic owns the list + details API calls end-to-end.
71
75
  */
72
76
  exports.restoreBulkUploadAutomatchingOnMount = (0, toolkit_1.createAction)('expenseAutomationMissingReceiptsView/restoreBulkUploadAutomatchingOnMount');
77
+ /**
78
+ * Epic trigger only. Targeted stale-while-revalidate refresh for a single batch's details — used
79
+ * by `pusherBatchStatusCompletionEpic` so a Pusher 'completed' event re-fetches only that one
80
+ * batch instead of wiping the entire `batchDetailsById` cache. The epic dedupes via
81
+ * `lastBatchDetailRefreshAtById` so resend storms don't trigger waves of API calls.
82
+ */
83
+ exports.refreshBatchDetailsForBatchId = (0, toolkit_1.createAction)('expenseAutomationMissingReceiptsView/refreshBatchDetailsForBatchId');
73
84
  const expenseAutomationMissingReceiptsView = (0, toolkit_1.createSlice)({
74
85
  name: 'expenseAutomationMissingReceiptsView',
75
86
  initialState: exports.initialState,
@@ -256,6 +267,16 @@ const expenseAutomationMissingReceiptsView = (0, toolkit_1.createSlice)({
256
267
  const details = action.payload;
257
268
  draft.bulkUpload.batchDetailsById[details.batchId] = details;
258
269
  draft.bulkUpload.phase = 'completed';
270
+ draft.bulkUpload.initialBatchDetailsLoaded = true;
271
+ /**
272
+ * A successful detail load supersedes any previous failure for this batch — without this,
273
+ * `getPrimaryBatchIdFromBatchListOrder` (and pagination) would keep skipping the batch
274
+ * across the recovery, hiding now-valid Unmatched-tab work.
275
+ */
276
+ const failedIndex = draft.bulkUpload.failedBatchDetailIds.indexOf(details.batchId);
277
+ if (failedIndex >= 0) {
278
+ draft.bulkUpload.failedBatchDetailIds.splice(failedIndex, 1);
279
+ }
259
280
  },
260
281
  fetchBulkUploadBatchDetailsFailure: {
261
282
  reducer(draft) {
@@ -277,6 +298,19 @@ const expenseAutomationMissingReceiptsView = (0, toolkit_1.createSlice)({
277
298
  draft.bulkUpload.currentBatchId === details.batchId) {
278
299
  draft.bulkUpload.phase = 'completed';
279
300
  }
301
+ /** Stale-while-revalidate: any successful detail load means we have rendered data. */
302
+ draft.bulkUpload.initialBatchDetailsLoaded = true;
303
+ /**
304
+ * Stale-while-revalidate recovery: if this batch had previously failed, a successful
305
+ * targeted refresh (Pusher `completed` → `refreshBatchDetailsForBatchIdEpic`) or
306
+ * multi-batch revalidation (manual refresh) supersedes the failure. Selectors that gate
307
+ * on `failedBatchDetailIds` (primary-batch resolution, `hasMoreBatchDetails`) must see the
308
+ * batch as recovered so it can show fresh Unmatched work.
309
+ */
310
+ const failedIndex = draft.bulkUpload.failedBatchDetailIds.indexOf(details.batchId);
311
+ if (failedIndex >= 0) {
312
+ draft.bulkUpload.failedBatchDetailIds.splice(failedIndex, 1);
313
+ }
280
314
  },
281
315
  batchDetailFetchFailed(draft, action) {
282
316
  const { batchId } = action.payload;
@@ -305,6 +339,14 @@ const expenseAutomationMissingReceiptsView = (0, toolkit_1.createSlice)({
305
339
  fetchState: 'Completed',
306
340
  error: undefined,
307
341
  };
342
+ /**
343
+ * Stale-while-revalidate: a completed pagination round means the initial page (or a
344
+ * subsequent revalidation) has fully resolved. Once `initialBatchDetailsLoaded` flips to
345
+ * `true` it stays `true` for the session — only `clearBulkUpload` /
346
+ * `clearBulkUploadBatchDetailsForScopeChange` can reset it.
347
+ */
348
+ draft.bulkUpload.initialBatchDetailsLoaded = true;
349
+ draft.bulkUpload.batchDetailsRevalidating = false;
308
350
  const currentId = draft.bulkUpload.currentBatchId;
309
351
  const currentDetails = currentId != null
310
352
  ? draft.bulkUpload.batchDetailsById[currentId]
@@ -320,12 +362,24 @@ const expenseAutomationMissingReceiptsView = (0, toolkit_1.createSlice)({
320
362
  fetchState: 'Error',
321
363
  error: action.payload.error,
322
364
  };
365
+ draft.bulkUpload.batchDetailsRevalidating = false;
323
366
  },
324
367
  fetchBulkUploadBatches: {
325
368
  reducer(draft, action) {
369
+ /**
370
+ * Manual refresh button (and any other caller passing `invalidateBatchDetailsCache: true`):
371
+ * wipe the details cache, failed-id list, and pagination state so the Unmatched tab drops
372
+ * its existing rows and re-renders the initial-load skeleton while the next list +
373
+ * details fetches resolve. The post-success epic (`fetchMultipleBatchDetailsEpic`) then
374
+ * re-runs the details chain from a clean slate.
375
+ */
326
376
  if (action.payload.invalidateBatchDetailsCache === true) {
327
377
  draft.bulkUpload.batchDetailsById = {};
328
378
  draft.bulkUpload.failedBatchDetailIds = [];
379
+ draft.bulkUpload.batchDetailsPaginationState = {
380
+ fetchState: 'Not-Started',
381
+ error: undefined,
382
+ };
329
383
  }
330
384
  draft.bulkUpload.batchListFetchState = {
331
385
  fetchState: 'In-Progress',
@@ -342,6 +396,31 @@ const expenseAutomationMissingReceiptsView = (0, toolkit_1.createSlice)({
342
396
  };
343
397
  },
344
398
  },
399
+ /**
400
+ * Tenant/period scope change — the new scope's data is genuinely unknown so the existing
401
+ * details cache and `initialBatchDetailsLoaded` flag must be reset (the Unmatched skeleton
402
+ * is acceptable on scope change). Distinct from a stale-while-revalidate refresh.
403
+ */
404
+ clearBulkUploadBatchDetailsForScopeChange(draft) {
405
+ draft.bulkUpload.batchDetailsById = {};
406
+ draft.bulkUpload.failedBatchDetailIds = [];
407
+ draft.bulkUpload.batchDetailsPaginationState = {
408
+ fetchState: 'Not-Started',
409
+ error: undefined,
410
+ };
411
+ draft.bulkUpload.batchDetailsRevalidating = false;
412
+ draft.bulkUpload.initialBatchDetailsLoaded = false;
413
+ draft.bulkUpload.lastBatchDetailRefreshAtById = {};
414
+ },
415
+ /**
416
+ * Records the last time we issued a targeted refresh for `batchId`. Set by
417
+ * `refreshBatchDetailsForBatchIdEpic` before each API call so subsequent Pusher resends in the
418
+ * dedupe window are skipped.
419
+ */
420
+ markBatchDetailRefreshAttempted(draft, action) {
421
+ draft.bulkUpload.lastBatchDetailRefreshAtById[action.payload.batchId] =
422
+ action.payload.timestamp;
423
+ },
345
424
  fetchBulkUploadBatchesSuccess(draft, action) {
346
425
  const periodId = (0, timePeriod_1.toMonthYearPeriodId)(action.payload.selectedPeriod);
347
426
  draft.bulkUpload.batchListByPeriod[periodId] = action.payload.batchList;
@@ -584,7 +663,7 @@ const expenseAutomationMissingReceiptsView = (0, toolkit_1.createSlice)({
584
663
  });
585
664
  _a = expenseAutomationMissingReceiptsView.actions, exports.fetchMissingReceipts = _a.fetchMissingReceipts, exports.fetchMissingReceiptsSuccess = _a.fetchMissingReceiptsSuccess, exports.fetchMissingReceiptsFailure = _a.fetchMissingReceiptsFailure, exports.uploadMissingReceiptSuccess = _a.uploadMissingReceiptSuccess, exports.updateMissingReceiptUploadState = _a.updateMissingReceiptUploadState, exports.updateMissingReceiptsUIState = _a.updateMissingReceiptsUIState, exports.markMissingReceiptAsDone = _a.markMissingReceiptAsDone, exports.clearExpenseAutomationMissingReceiptsView = _a.clearExpenseAutomationMissingReceiptsView,
586
665
  // Bulk Upload
587
- exports.bulkUploadReceipts = _a.bulkUploadReceipts, exports.updateBulkUploadProgress = _a.updateBulkUploadProgress, exports.setBulkUploadUploadedFileCount = _a.setBulkUploadUploadedFileCount, exports.bulkUploadReceiptsSuccess = _a.bulkUploadReceiptsSuccess, exports.bulkUploadReceiptsFailure = _a.bulkUploadReceiptsFailure, exports.restoreBulkUploadMatchingState = _a.restoreBulkUploadMatchingState, exports.bulkUploadAutomatchingTimedOut = _a.bulkUploadAutomatchingTimedOut, exports.pusherBatchStatusUpdate = _a.pusherBatchStatusUpdate, exports.requestMissingReceiptsTabNavigation = _a.requestMissingReceiptsTabNavigation, exports.clearMissingReceiptsTabNavigation = _a.clearMissingReceiptsTabNavigation, exports.fetchBulkUploadBatchDetailsSuccess = _a.fetchBulkUploadBatchDetailsSuccess, exports.fetchBulkUploadBatchDetailsFailure = _a.fetchBulkUploadBatchDetailsFailure, exports.storeBatchDetails = _a.storeBatchDetails, exports.batchDetailFetchFailed = _a.batchDetailFetchFailed, exports.setInitialBatchDetailsLoading = _a.setInitialBatchDetailsLoading, exports.fetchMoreBatchDetails = _a.fetchMoreBatchDetails, exports.fetchMoreBatchDetailsComplete = _a.fetchMoreBatchDetailsComplete, exports.fetchMoreBatchDetailsFailure = _a.fetchMoreBatchDetailsFailure, exports.fetchBulkUploadBatches = _a.fetchBulkUploadBatches, exports.fetchBulkUploadBatchesSuccess = _a.fetchBulkUploadBatchesSuccess, exports.fetchBulkUploadBatchesFailure = _a.fetchBulkUploadBatchesFailure, exports.confirmBulkUploadMatch = _a.confirmBulkUploadMatch, exports.confirmBulkUploadMatchSuccess = _a.confirmBulkUploadMatchSuccess, exports.confirmBulkUploadMatchFailure = _a.confirmBulkUploadMatchFailure, exports.setBulkUploadResultsTab = _a.setBulkUploadResultsTab, exports.setBulkUploadCompletedSubTab = _a.setBulkUploadCompletedSubTab, exports.setBulkUploadSortConfig = _a.setBulkUploadSortConfig, exports.clearBulkUpload = _a.clearBulkUpload, exports.searchTransactionsForManualMatch = _a.searchTransactionsForManualMatch, exports.searchTransactionsForManualMatchSuccess = _a.searchTransactionsForManualMatchSuccess, exports.searchTransactionsForManualMatchFailure = _a.searchTransactionsForManualMatchFailure, exports.clearManualSearchResults = _a.clearManualSearchResults, exports.acknowledgeBulkUploadConfirmMatchComplete = _a.acknowledgeBulkUploadConfirmMatchComplete,
666
+ exports.bulkUploadReceipts = _a.bulkUploadReceipts, exports.updateBulkUploadProgress = _a.updateBulkUploadProgress, exports.setBulkUploadUploadedFileCount = _a.setBulkUploadUploadedFileCount, exports.bulkUploadReceiptsSuccess = _a.bulkUploadReceiptsSuccess, exports.bulkUploadReceiptsFailure = _a.bulkUploadReceiptsFailure, exports.restoreBulkUploadMatchingState = _a.restoreBulkUploadMatchingState, exports.bulkUploadAutomatchingTimedOut = _a.bulkUploadAutomatchingTimedOut, exports.pusherBatchStatusUpdate = _a.pusherBatchStatusUpdate, exports.requestMissingReceiptsTabNavigation = _a.requestMissingReceiptsTabNavigation, exports.clearMissingReceiptsTabNavigation = _a.clearMissingReceiptsTabNavigation, exports.fetchBulkUploadBatchDetailsSuccess = _a.fetchBulkUploadBatchDetailsSuccess, exports.fetchBulkUploadBatchDetailsFailure = _a.fetchBulkUploadBatchDetailsFailure, exports.storeBatchDetails = _a.storeBatchDetails, exports.batchDetailFetchFailed = _a.batchDetailFetchFailed, exports.setInitialBatchDetailsLoading = _a.setInitialBatchDetailsLoading, exports.fetchMoreBatchDetails = _a.fetchMoreBatchDetails, exports.fetchMoreBatchDetailsComplete = _a.fetchMoreBatchDetailsComplete, exports.fetchMoreBatchDetailsFailure = _a.fetchMoreBatchDetailsFailure, exports.fetchBulkUploadBatches = _a.fetchBulkUploadBatches, exports.fetchBulkUploadBatchesSuccess = _a.fetchBulkUploadBatchesSuccess, exports.fetchBulkUploadBatchesFailure = _a.fetchBulkUploadBatchesFailure, exports.clearBulkUploadBatchDetailsForScopeChange = _a.clearBulkUploadBatchDetailsForScopeChange, exports.markBatchDetailRefreshAttempted = _a.markBatchDetailRefreshAttempted, exports.confirmBulkUploadMatch = _a.confirmBulkUploadMatch, exports.confirmBulkUploadMatchSuccess = _a.confirmBulkUploadMatchSuccess, exports.confirmBulkUploadMatchFailure = _a.confirmBulkUploadMatchFailure, exports.setBulkUploadResultsTab = _a.setBulkUploadResultsTab, exports.setBulkUploadCompletedSubTab = _a.setBulkUploadCompletedSubTab, exports.setBulkUploadSortConfig = _a.setBulkUploadSortConfig, exports.clearBulkUpload = _a.clearBulkUpload, exports.searchTransactionsForManualMatch = _a.searchTransactionsForManualMatch, exports.searchTransactionsForManualMatchSuccess = _a.searchTransactionsForManualMatchSuccess, exports.searchTransactionsForManualMatchFailure = _a.searchTransactionsForManualMatchFailure, exports.clearManualSearchResults = _a.clearManualSearchResults, exports.acknowledgeBulkUploadConfirmMatchComplete = _a.acknowledgeBulkUploadConfirmMatchComplete,
588
667
  // Completed Transactions
589
668
  exports.fetchCompletedTransactions = _a.fetchCompletedTransactions, exports.fetchCompletedTransactionsSuccess = _a.fetchCompletedTransactionsSuccess, exports.fetchCompletedTransactionsFailure = _a.fetchCompletedTransactionsFailure;
590
669
  exports.default = expenseAutomationMissingReceiptsView.reducer;
@@ -29,6 +29,12 @@ export interface ResolvedBatchFile {
29
29
  export interface BulkUploadSelectorData {
30
30
  batchDetails: ResolvedBatchDetails | undefined;
31
31
  batchDetailsPaginationState: FetchStateAndError;
32
+ /**
33
+ * True while a stale-while-revalidate refresh of `batchDetailsById` is in flight (e.g. manual
34
+ * refresh button). UI should keep rendering existing data and show only a lightweight refresh
35
+ * indicator — never the full skeleton.
36
+ */
37
+ batchDetailsRevalidating: boolean;
32
38
  batchList: BatchListItem[];
33
39
  batchListFetchState: FetchStateAndError;
34
40
  batchStatus: BatchStatus | undefined;
@@ -37,6 +43,12 @@ export interface BulkUploadSelectorData {
37
43
  confirmMatchStatus: FetchStateAndError;
38
44
  currentResultsTab: BulkUploadResultsTab;
39
45
  hasMoreBatchDetails: boolean;
46
+ /**
47
+ * `true` once the first batch-details page has loaded for the current scope (period/tenant).
48
+ * Stays `true` across refreshes — flips back to `false` only on `clearBulkUpload` or on an
49
+ * explicit scope change. Used by the Unmatched tab to gate the initial-load skeleton.
50
+ */
51
+ initialBatchDetailsLoaded: boolean;
40
52
  manualSearch: ManualSearchState;
41
53
  /** Bumps when manual search state is cleared — remount manual search inputs. */
42
54
  manualSearchUiResetKey: number;
@@ -230,6 +230,8 @@ function getExpenseAutomationMissingReceiptsView(state) {
230
230
  manualSearchUiResetKey: bulkUpload.manualSearchUiResetKey,
231
231
  hasMoreBatchDetails,
232
232
  batchDetailsPaginationState: bulkUpload.batchDetailsPaginationState,
233
+ batchDetailsRevalidating: bulkUpload.batchDetailsRevalidating,
234
+ initialBatchDetailsLoaded: bulkUpload.initialBatchDetailsLoaded,
233
235
  manualSearch: {
234
236
  ...bulkUpload.manualSearch,
235
237
  results: manualSearchResults,
@@ -129,6 +129,13 @@ export interface CompletedTransactionsState {
129
129
  export interface BulkUploadState {
130
130
  batchDetailsById: Record<ID, BatchDetails>;
131
131
  batchDetailsPaginationState: FetchStateAndError;
132
+ /**
133
+ * True while a stale-while-revalidate refresh of `batchDetailsById` is in flight (manual refresh
134
+ * or scope-change replacement). Existing entries are kept on screen during this window; the UI
135
+ * can surface a lightweight refresh indicator. Cleared on `fetchMoreBatchDetailsComplete` /
136
+ * `fetchMoreBatchDetailsFailure`.
137
+ */
138
+ batchDetailsRevalidating: boolean;
132
139
  batchListByPeriod: Record<MonthYearPeriodId, BatchListItem[]>;
133
140
  batchListFetchState: FetchStateAndError;
134
141
  batchStatusById: Record<ID, BatchStatus>;
@@ -137,6 +144,18 @@ export interface BulkUploadState {
137
144
  confirmMatchStatus: FetchStateAndError;
138
145
  currentResultsTab: BulkUploadResultsTab;
139
146
  failedBatchDetailIds: ID[];
147
+ /**
148
+ * Set to `true` once the first batch-details page has resolved (success or empty completion).
149
+ * Drives stale-while-revalidate: the Unmatched skeleton is shown only while this is `false`.
150
+ * Reset only by `clearBulkUpload` or by an explicit scope-change (period/tenant) clear.
151
+ */
152
+ initialBatchDetailsLoaded: boolean;
153
+ /**
154
+ * Last time `GET /1.0/batches/:id` was issued for a given batch via the targeted refresh epic.
155
+ * Used to throttle Pusher resend storms — repeat completion events for the same batchId within
156
+ * the dedupe window are dropped.
157
+ */
158
+ lastBatchDetailRefreshAtById: Record<ID, number>;
140
159
  /**
141
160
  * Incremented when manual search Redux state is cleared so Unmatched `ManualSearchInput`
142
161
  * instances remount and drop local query text.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeniai/client-epic-state",
3
- "version": "5.0.75",
3
+ "version": "5.0.77-betaAD01",
4
4
  "description": "Shared module between Web & Mobile containing required abstractions for state management, async network communication. ",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/esm/index.js",