@zeniai/client-epic-state 4.19.37-betaVR19 → 4.19.37-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 (36) 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 +8 -4
  6. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchDetailsEpic.js +2 -2
  7. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchesEpic.js +1 -6
  8. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchCompletedTransactionsEpic.js +3 -7
  9. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.js +15 -24
  10. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.js +32 -32
  11. package/lib/esm/view/expenseAutomationView/payload/missingReceiptsPayload.js +12 -15
  12. package/lib/esm/view/expenseAutomationView/reducers/missingReceiptsViewReducer.js +13 -73
  13. package/lib/esm/view/expenseAutomationView/selectors/missingReceiptsSelector.js +12 -99
  14. package/lib/index.d.ts +2 -2
  15. package/lib/index.js +32 -36
  16. package/lib/tsconfig.typecheck.tsbuildinfo +1 -0
  17. package/lib/view/expenseAutomationView/epics/missingReceipts/bulkUploadReceiptsEpic.d.ts +5 -2
  18. package/lib/view/expenseAutomationView/epics/missingReceipts/bulkUploadReceiptsEpic.js +7 -3
  19. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchDetailsEpic.js +2 -2
  20. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchesEpic.js +1 -6
  21. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchCompletedTransactionsEpic.js +2 -6
  22. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.d.ts +2 -3
  23. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.js +12 -25
  24. package/lib/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.d.ts +7 -5
  25. package/lib/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.js +28 -28
  26. package/lib/view/expenseAutomationView/payload/missingReceiptsPayload.d.ts +16 -15
  27. package/lib/view/expenseAutomationView/payload/missingReceiptsPayload.js +13 -16
  28. package/lib/view/expenseAutomationView/reducers/missingReceiptsViewReducer.d.ts +3 -12
  29. package/lib/view/expenseAutomationView/reducers/missingReceiptsViewReducer.js +14 -75
  30. package/lib/view/expenseAutomationView/selectorTypes/missingReceiptsSelectorTypes.d.ts +1 -7
  31. package/lib/view/expenseAutomationView/selectors/missingReceiptsSelector.js +12 -99
  32. package/lib/view/expenseAutomationView/types/missingReceiptsViewState.d.ts +2 -10
  33. package/package.json +2 -2
  34. package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchMoreBatchDetailsEpic.js +0 -36
  35. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMoreBatchDetailsEpic.d.ts +0 -8
  36. package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMoreBatchDetailsEpic.js +0 -43
@@ -1,7 +1,7 @@
1
1
  import { ActionsObservable } from 'redux-observable';
2
2
  import { ZeniAPI } from '../../../../zeniAPI';
3
- import { bulkUploadReceipts, bulkUploadReceiptsFailure, bulkUploadReceiptsSuccess } from '../../reducers/missingReceiptsViewReducer';
4
- export type ActionType = ReturnType<typeof bulkUploadReceipts> | ReturnType<typeof bulkUploadReceiptsSuccess> | ReturnType<typeof bulkUploadReceiptsFailure>;
3
+ import { bulkUploadReceipts, bulkUploadReceiptsFailure, bulkUploadReceiptsSuccess, updateBulkUploadProgress } from '../../reducers/missingReceiptsViewReducer';
4
+ export type ActionType = ReturnType<typeof bulkUploadReceipts> | ReturnType<typeof bulkUploadReceiptsSuccess> | ReturnType<typeof bulkUploadReceiptsFailure> | ReturnType<typeof updateBulkUploadProgress>;
5
5
  export declare const bulkUploadReceiptsEpic: (actions$: ActionsObservable<ActionType>, _state$: unknown, zeniAPI: ZeniAPI) => import("rxjs").Observable<{
6
6
  payload: {
7
7
  batchId: import("../../../..").ID;
@@ -12,4 +12,7 @@ export declare const bulkUploadReceiptsEpic: (actions$: ActionsObservable<Action
12
12
  error: import("../../../../responsePayload").ZeniAPIStatus;
13
13
  };
14
14
  type: "expenseAutomationMissingReceiptsView/bulkUploadReceiptsFailure";
15
+ } | {
16
+ payload: number;
17
+ type: "expenseAutomationMissingReceiptsView/updateBulkUploadProgress";
15
18
  }>;
@@ -9,11 +9,15 @@ const bulkUploadReceiptsEpic = (actions$, _state$, zeniAPI) => actions$.pipe((0,
9
9
  const { files } = action.payload;
10
10
  const formData = new FormData();
11
11
  for (const file of files) {
12
- formData.append('files', file, file.name);
12
+ formData.append('files[]', file, file.name);
13
13
  }
14
14
  return zeniAPI
15
- .postFormData(`${zeniAPI.apiEndPoints.communicationAgentMicroServiceBaseUrl}/1.0/receipts/bulk-upload`, formData)
16
- .pipe((0, operators_1.mergeMap)((response) => {
15
+ .postFormDataWithProgress(`${zeniAPI.apiEndPoints.communicationAgentMicroServiceBaseUrl}/1.0/receipts/bulk-upload`, formData)
16
+ .pipe((0, operators_1.mergeMap)((event) => {
17
+ if (event.type === 'progress') {
18
+ return (0, rxjs_1.of)((0, missingReceiptsViewReducer_1.updateBulkUploadProgress)(event.percentage));
19
+ }
20
+ const response = event.data;
17
21
  if ((0, responsePayload_1.isSuccessResponse)(response) && response.data != null) {
18
22
  return (0, rxjs_1.of)((0, missingReceiptsViewReducer_1.bulkUploadReceiptsSuccess)({
19
23
  batchId: response.data.batch_id,
@@ -15,7 +15,7 @@ const fetchBulkUploadBatchDetailsEpic = (actions$, state$, zeniAPI) => actions$.
15
15
  }));
16
16
  }
17
17
  return zeniAPI
18
- .getJSON(`${zeniAPI.apiEndPoints.communicationAgentMicroServiceBaseUrl}/1.0/batches/${currentBatchId}`)
18
+ .getJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/receipts/batches/${currentBatchId}`)
19
19
  .pipe((0, operators_1.mergeMap)((response) => {
20
20
  if ((0, responsePayload_1.isSuccessResponse)(response) && response.data != null) {
21
21
  const actions = [];
@@ -23,7 +23,7 @@ const fetchBulkUploadBatchDetailsEpic = (actions$, state$, zeniAPI) => actions$.
23
23
  if (transactionPayloads.length > 0) {
24
24
  actions.push((0, transactionReducer_1.updateTransactions)(transactionPayloads, (value) => value.transaction_id));
25
25
  }
26
- actions.push((0, missingReceiptsViewReducer_1.fetchBulkUploadBatchDetailsSuccess)((0, missingReceiptsPayload_1.toBatchDetails)(response.data, zeniAPI.apiEndPoints.fileMicroServiceBaseUrl)));
26
+ actions.push((0, missingReceiptsViewReducer_1.fetchBulkUploadBatchDetailsSuccess)((0, missingReceiptsPayload_1.toBatchDetails)(response.data)));
27
27
  actions.push((0, missingReceiptsViewReducer_1.fetchBulkUploadBatches)(true));
28
28
  return (0, rxjs_1.from)(actions);
29
29
  }
@@ -23,13 +23,8 @@ const fetchBulkUploadBatchesEpic = (actions$, state$, zeniAPI) => actions$.pipe(
23
23
  }));
24
24
  }
25
25
  const period = (0, timePeriod_1.convertToPeriod)(selectedPeriod);
26
- const queryParam = {
27
- start_date: period.start,
28
- end_date: period.end,
29
- sort_order: 'desc',
30
- };
31
26
  return zeniAPI
32
- .getJSON(`${zeniAPI.apiEndPoints.communicationAgentMicroServiceBaseUrl}/1.0/batches?query=${encodeURIComponent(JSON.stringify(queryParam))}`)
27
+ .getJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/receipts/batches?start_date=${period.start}&end_date=${period.end}`)
33
28
  .pipe((0, operators_1.mergeMap)((response) => {
34
29
  if ((0, responsePayload_1.isSuccessResponse)(response) && response.data != null) {
35
30
  return (0, rxjs_1.of)((0, missingReceiptsViewReducer_1.fetchBulkUploadBatchesSuccess)({
@@ -15,12 +15,8 @@ const fetchCompletedTransactionsEpic = (actions$, state$, zeniAPI) => actions$.p
15
15
  const selectedPeriod = selectedPeriodByTenantId[currentTenant.tenantId];
16
16
  const periodId = (0, timePeriod_1.toMonthYearPeriodId)(selectedPeriod);
17
17
  const isInitialLoad = action.payload.pageToken == null;
18
- const cacheKey = (0, missingReceiptsViewReducer_1.getCompletedTransactionsCacheKey)(periodId, bulkUpload.sortKey, bulkUpload.sortOrder, bulkUpload.completedSubTab);
19
- const existingData = bulkUpload.completedTransactionsByPeriod[cacheKey];
20
- if (isInitialLoad &&
21
- action.payload.cacheOverride !== true &&
22
- existingData != null &&
23
- existingData.transactionIds.length > 0) {
18
+ const existingData = bulkUpload.completedTransactionsByPeriod[periodId];
19
+ if (isInitialLoad && existingData != null && existingData.transactionIds.length > 0) {
24
20
  return (0, rxjs_1.from)([]);
25
21
  }
26
22
  const period = (0, timePeriod_1.convertToPeriod)(selectedPeriod);
@@ -3,7 +3,6 @@ import { Observable } from 'rxjs';
3
3
  import { updateTransactions } from '../../../../entity/transaction/transactionReducer';
4
4
  import { RootState } from '../../../../reducer';
5
5
  import { ZeniAPI } from '../../../../zeniAPI';
6
- import { batchDetailFetchFailed, fetchBulkUploadBatchesSuccess, fetchMoreBatchDetailsComplete, setInitialBatchDetailsLoading, storeBatchDetails } from '../../reducers/missingReceiptsViewReducer';
7
- export type ActionType = ReturnType<typeof fetchBulkUploadBatchesSuccess> | ReturnType<typeof updateTransactions> | ReturnType<typeof storeBatchDetails> | ReturnType<typeof batchDetailFetchFailed> | ReturnType<typeof setInitialBatchDetailsLoading> | ReturnType<typeof fetchMoreBatchDetailsComplete>;
8
- export declare function fetchBatchDetailsByIds(batchIds: string[], zeniAPI: ZeniAPI): Observable<ActionType>;
6
+ import { fetchBulkUploadBatchesSuccess, storeBatchDetails } from '../../reducers/missingReceiptsViewReducer';
7
+ export type ActionType = ReturnType<typeof fetchBulkUploadBatchesSuccess> | ReturnType<typeof updateTransactions> | ReturnType<typeof storeBatchDetails>;
9
8
  export declare const fetchMultipleBatchDetailsEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => Observable<ActionType>;
@@ -1,24 +1,24 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.fetchMultipleBatchDetailsEpic = void 0;
7
- exports.fetchBatchDetailsByIds = fetchBatchDetailsByIds;
8
- const orderBy_1 = __importDefault(require("lodash/orderBy"));
9
4
  const rxjs_1 = require("rxjs");
10
5
  const operators_1 = require("rxjs/operators");
11
6
  const transactionReducer_1 = require("../../../../entity/transaction/transactionReducer");
12
7
  const responsePayload_1 = require("../../../../responsePayload");
13
8
  const missingReceiptsPayload_1 = require("../../payload/missingReceiptsPayload");
14
9
  const missingReceiptsViewReducer_1 = require("../../reducers/missingReceiptsViewReducer");
15
- const INITIAL_BATCH_PAGE_SIZE = 4;
16
- function fetchBatchDetailsByIds(batchIds, zeniAPI) {
17
- if (batchIds.length === 0) {
10
+ const fetchMultipleBatchDetailsEpic = (actions$, state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(missingReceiptsViewReducer_1.fetchBulkUploadBatchesSuccess.match), (0, operators_1.mergeMap)((action) => {
11
+ const batchList = action.payload.batchList;
12
+ const { batchDetailsById } = state$.value.expenseAutomationMissingReceiptsViewState.bulkUpload;
13
+ const completedBatchIds = batchList
14
+ .filter((batch) => batch.status === 'completed' &&
15
+ batchDetailsById[batch.batchId] == null)
16
+ .map((batch) => batch.batchId);
17
+ if (completedBatchIds.length === 0) {
18
18
  return rxjs_1.EMPTY;
19
19
  }
20
- return (0, rxjs_1.from)(batchIds).pipe((0, operators_1.mergeMap)((batchId) => zeniAPI
21
- .getJSON(`${zeniAPI.apiEndPoints.communicationAgentMicroServiceBaseUrl}/1.0/batches/${batchId}`)
20
+ return (0, rxjs_1.from)(completedBatchIds).pipe((0, operators_1.mergeMap)((batchId) => zeniAPI
21
+ .getJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/receipts/batches/${batchId}`)
22
22
  .pipe((0, operators_1.mergeMap)((response) => {
23
23
  if ((0, responsePayload_1.isSuccessResponse)(response) && response.data != null) {
24
24
  const actions = [];
@@ -26,27 +26,14 @@ function fetchBatchDetailsByIds(batchIds, zeniAPI) {
26
26
  if (transactionPayloads.length > 0) {
27
27
  actions.push((0, transactionReducer_1.updateTransactions)(transactionPayloads, (value) => value.transaction_id));
28
28
  }
29
- actions.push((0, missingReceiptsViewReducer_1.storeBatchDetails)((0, missingReceiptsPayload_1.toBatchDetails)(response.data, zeniAPI.apiEndPoints.fileMicroServiceBaseUrl)));
29
+ actions.push((0, missingReceiptsViewReducer_1.storeBatchDetails)((0, missingReceiptsPayload_1.toBatchDetails)(response.data)));
30
30
  return (0, rxjs_1.from)(actions);
31
31
  }
32
32
  return rxjs_1.EMPTY;
33
33
  }), (0, operators_1.catchError)((error) => {
34
34
  console.error(`Failed to fetch batch details for ${batchId}:`, (0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', 'Fetch batch details errored out: ' +
35
35
  JSON.stringify(error)));
36
- return (0, rxjs_1.of)((0, missingReceiptsViewReducer_1.batchDetailFetchFailed)({ batchId }));
37
- })), 5));
38
- }
39
- const fetchMultipleBatchDetailsEpic = (actions$, state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(missingReceiptsViewReducer_1.fetchBulkUploadBatchesSuccess.match), (0, operators_1.mergeMap)((action) => {
40
- const batchList = action.payload.batchList;
41
- const { batchDetailsById } = state$.value.expenseAutomationMissingReceiptsViewState.bulkUpload;
42
- /** Oldest first — matches primary-batch selection in missingReceiptsSelector (chronological). */
43
- const completedBatchesMissingDetails = batchList.filter((batch) => (0, missingReceiptsPayload_1.isBatchListStatusCompleted)(batch.status) &&
44
- batchDetailsById[batch.batchId] == null);
45
- const completedBatchIds = (0, orderBy_1.default)(completedBatchesMissingDetails, (b) => new Date(b.createdAt).valueOf(), 'asc').map((batch) => batch.batchId);
46
- const batchIdsToFetch = completedBatchIds.slice(0, INITIAL_BATCH_PAGE_SIZE);
47
- if (batchIdsToFetch.length === 0) {
48
36
  return rxjs_1.EMPTY;
49
- }
50
- return (0, rxjs_1.concat)((0, rxjs_1.of)((0, missingReceiptsViewReducer_1.setInitialBatchDetailsLoading)()), fetchBatchDetailsByIds(batchIdsToFetch, zeniAPI), (0, rxjs_1.of)((0, missingReceiptsViewReducer_1.fetchMoreBatchDetailsComplete)()));
37
+ })), 5));
51
38
  }));
52
39
  exports.fetchMultipleBatchDetailsEpic = fetchMultipleBatchDetailsEpic;
@@ -1,13 +1,15 @@
1
1
  import { ActionsObservable, StateObservable } from 'redux-observable';
2
2
  import { Observable } from 'rxjs';
3
- import { updateTransactions } from '../../../../entity/transaction/transactionReducer';
4
3
  import { RootState } from '../../../../reducer';
5
4
  import { ZeniAPI } from '../../../../zeniAPI';
6
- import { bulkUploadReceiptsSuccess, clearBulkUpload, fetchBulkUploadBatchDetailsSuccess, fetchBulkUploadBatches, pusherBatchStatusUpdate, requestMissingReceiptsTabNavigation } from '../../reducers/missingReceiptsViewReducer';
7
- export type ActionType = ReturnType<typeof bulkUploadReceiptsSuccess> | ReturnType<typeof pusherBatchStatusUpdate> | ReturnType<typeof fetchBulkUploadBatchDetailsSuccess> | ReturnType<typeof fetchBulkUploadBatches> | ReturnType<typeof requestMissingReceiptsTabNavigation> | ReturnType<typeof updateTransactions> | ReturnType<typeof clearBulkUpload>;
5
+ import { bulkUploadReceiptsSuccess, clearBulkUpload, fetchBulkUploadBatchDetails, pusherBatchStatusUpdate, updateBulkUploadBatchStatus } from '../../reducers/missingReceiptsViewReducer';
6
+ export type ActionType = ReturnType<typeof bulkUploadReceiptsSuccess> | ReturnType<typeof updateBulkUploadBatchStatus> | ReturnType<typeof pusherBatchStatusUpdate> | ReturnType<typeof fetchBulkUploadBatchDetails> | ReturnType<typeof clearBulkUpload>;
8
7
  /**
9
- * On Pusher batch completion: refresh batch list (then fetchMultipleBatchDetailsEpic runs),
10
- * and request switching to the Unmatched tab. Debounced to reduce duplicate refreshes.
8
+ * Watches batch status using two strategies:
9
+ * 1. Pusher (primary): Reacts to `pusherBatchStatusUpdate` dispatched by the UI layer
10
+ * when a Pusher event arrives. Immediately fetches full details on completion.
11
+ * 2. Polling (fallback): Starts a relaxed 10s poll after upload success as a safety net
12
+ * in case the Pusher event is missed. Stops on completion or `clearBulkUpload`.
11
13
  */
12
14
  export declare const pusherBatchStatusCompletionEpic: (actions$: ActionsObservable<ActionType>) => Observable<ActionType>;
13
15
  export declare const pollBulkUploadBatchStatusEpic: (actions$: ActionsObservable<ActionType>, _state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => Observable<ActionType>;
@@ -3,44 +3,44 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.pollBulkUploadBatchStatusEpic = exports.pusherBatchStatusCompletionEpic = void 0;
4
4
  const rxjs_1 = require("rxjs");
5
5
  const operators_1 = require("rxjs/operators");
6
- const transactionReducer_1 = require("../../../../entity/transaction/transactionReducer");
7
6
  const responsePayload_1 = require("../../../../responsePayload");
8
7
  const missingReceiptsPayload_1 = require("../../payload/missingReceiptsPayload");
9
8
  const missingReceiptsViewReducer_1 = require("../../reducers/missingReceiptsViewReducer");
10
- /** First poll after upload; then interval while batch not resolved via Pusher or API. */
11
- const FALLBACK_FIRST_DELAY_MS = 30000;
12
- const FALLBACK_POLL_INTERVAL_MS = 10000;
13
- function isBatchDetailsCompletedStatus(status) {
14
- return status.toLowerCase() === 'completed';
15
- }
16
9
  /**
17
- * On Pusher batch completion: refresh batch list (then fetchMultipleBatchDetailsEpic runs),
18
- * and request switching to the Unmatched tab. Debounced to reduce duplicate refreshes.
10
+ * Watches batch status using two strategies:
11
+ * 1. Pusher (primary): Reacts to `pusherBatchStatusUpdate` dispatched by the UI layer
12
+ * when a Pusher event arrives. Immediately fetches full details on completion.
13
+ * 2. Polling (fallback): Starts a relaxed 10s poll after upload success as a safety net
14
+ * in case the Pusher event is missed. Stops on completion or `clearBulkUpload`.
19
15
  */
20
- 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)([
21
- (0, missingReceiptsViewReducer_1.fetchBulkUploadBatches)(true),
22
- (0, missingReceiptsViewReducer_1.requestMissingReceiptsTabNavigation)({ tab: 'unmatched' }),
23
- ])));
16
+ // Pusher-driven: when Pusher delivers a completed status, fetch details
17
+ 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.mergeMap)(() => (0, rxjs_1.of)((0, missingReceiptsViewReducer_1.fetchBulkUploadBatchDetails)())));
24
18
  exports.pusherBatchStatusCompletionEpic = pusherBatchStatusCompletionEpic;
25
- const pollBulkUploadBatchStatusEpic = (actions$, _state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(missingReceiptsViewReducer_1.bulkUploadReceiptsSuccess.match), (0, operators_1.mergeMap)((action) => {
19
+ // Polling fallback: relaxed interval as safety net
20
+ const FALLBACK_POLL_INTERVAL_MS = 10000;
21
+ const pollBulkUploadBatchStatusEpic = (actions$, _state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(missingReceiptsViewReducer_1.bulkUploadReceiptsSuccess.match), (0, operators_1.switchMap)((action) => {
26
22
  const { batchId } = action.payload;
27
- return (0, rxjs_1.timer)(FALLBACK_FIRST_DELAY_MS, FALLBACK_POLL_INTERVAL_MS).pipe((0, operators_1.takeUntil)((0, rxjs_1.merge)(actions$.pipe((0, operators_1.filter)(missingReceiptsViewReducer_1.clearBulkUpload.match)), actions$.pipe((0, operators_1.filter)(missingReceiptsViewReducer_1.pusherBatchStatusUpdate.match), (0, operators_1.filter)((a) => a.payload.batchId === batchId)), actions$.pipe((0, operators_1.filter)(missingReceiptsViewReducer_1.fetchBulkUploadBatchDetailsSuccess.match), (0, operators_1.filter)((a) => a.payload.batchId === batchId)))), (0, operators_1.switchMap)(() => zeniAPI
28
- .getJSON(`${zeniAPI.apiEndPoints.communicationAgentMicroServiceBaseUrl}/1.0/batches/${batchId}`)
23
+ return (0, rxjs_1.timer)(0, FALLBACK_POLL_INTERVAL_MS).pipe((0, operators_1.takeUntil)(actions$.pipe((0, operators_1.filter)((a) => missingReceiptsViewReducer_1.clearBulkUpload.match(a) ||
24
+ (missingReceiptsViewReducer_1.pusherBatchStatusUpdate.match(a) &&
25
+ a.payload.status === 'completed')))), (0, operators_1.switchMap)(() => zeniAPI
26
+ .getJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/receipts/batches/${batchId}/status`)
29
27
  .pipe((0, operators_1.mergeMap)((response) => {
30
28
  if ((0, responsePayload_1.isSuccessResponse)(response) && response.data != null) {
31
- if (isBatchDetailsCompletedStatus(response.data.status)) {
32
- const actions = [];
33
- const transactionPayloads = (0, missingReceiptsPayload_1.extractTransactionPayloadsFromBatchFiles)(response.data.files);
34
- if (transactionPayloads.length > 0) {
35
- actions.push((0, transactionReducer_1.updateTransactions)(transactionPayloads, (value) => value.transaction_id));
36
- }
37
- actions.push((0, missingReceiptsViewReducer_1.fetchBulkUploadBatchDetailsSuccess)((0, missingReceiptsPayload_1.toBatchDetails)(response.data, zeniAPI.apiEndPoints.fileMicroServiceBaseUrl)));
38
- actions.push((0, missingReceiptsViewReducer_1.fetchBulkUploadBatches)(true));
39
- actions.push((0, missingReceiptsViewReducer_1.requestMissingReceiptsTabNavigation)({ tab: 'unmatched' }));
40
- return (0, rxjs_1.from)(actions);
29
+ const batchStatus = (0, missingReceiptsPayload_1.toBatchStatus)(response.data);
30
+ const actions = [
31
+ (0, missingReceiptsViewReducer_1.updateBulkUploadBatchStatus)(batchStatus),
32
+ ];
33
+ if (batchStatus.status === 'completed') {
34
+ actions.push((0, missingReceiptsViewReducer_1.fetchBulkUploadBatchDetails)());
41
35
  }
36
+ return actions;
37
+ }
38
+ return [];
39
+ }), (0, operators_1.catchError)(() => (0, rxjs_1.of)()))), (0, operators_1.takeWhile)((action) => {
40
+ if (missingReceiptsViewReducer_1.fetchBulkUploadBatchDetails.match(action)) {
41
+ return false;
42
42
  }
43
- return rxjs_1.EMPTY;
44
- }), (0, operators_1.catchError)(() => (0, rxjs_1.of)()))));
43
+ return true;
44
+ }, true));
45
45
  }));
46
46
  exports.pollBulkUploadBatchStatusEpic = pollBulkUploadBatchStatusEpic;
@@ -1,8 +1,7 @@
1
- import { URLPayload } from '../../../commonPayloadTypes/urlPayload';
2
1
  import { TransactionPayload } from '../../../entity/transaction/payloadTypes/transactionPayload';
3
2
  import { SupportedTransactionPayload } from '../../../entity/transaction/transactionState';
4
3
  import { ZeniAPIResponse } from '../../../responsePayload';
5
- import type { BatchDetails, BatchFile, BatchListItem, BatchSummary, ManualSearchResult } from '../types/missingReceiptsViewState';
4
+ import type { BatchDetails, BatchFile, BatchListItem, BatchStatus, BatchSummary, ManualSearchResult } from '../types/missingReceiptsViewState';
6
5
  export interface MissingReceiptsQueryPayload {
7
6
  end_date: string;
8
7
  is_attachment_missing_only: boolean;
@@ -16,17 +15,21 @@ interface MissingReceiptsPayload {
16
15
  transactions: TransactionPayload[];
17
16
  }
18
17
  export type MissingReceiptsResponse = ZeniAPIResponse<MissingReceiptsPayload>;
19
- export interface BatchListQueryPayload {
20
- end_date: string;
21
- sort_order: string;
22
- start_date: string;
23
- }
24
18
  export interface BulkUploadResponsePayload {
25
19
  batch_id: string;
26
20
  status: string;
27
21
  total_files: number;
28
22
  }
29
23
  export type BulkUploadResponse = ZeniAPIResponse<BulkUploadResponsePayload>;
24
+ export interface BatchStatusResponsePayload {
25
+ batch_id: string;
26
+ progress: {
27
+ processed: number;
28
+ total: number;
29
+ };
30
+ status: string;
31
+ }
32
+ export type BatchStatusResponse = ZeniAPIResponse<BatchStatusResponsePayload>;
30
33
  export interface BatchListResponsePayload {
31
34
  batches: BatchListItemPayload[];
32
35
  }
@@ -44,11 +47,11 @@ export type BatchListResponse = ZeniAPIResponse<BatchListResponsePayload>;
44
47
  export interface MatchedTransactionPayload {
45
48
  amount: number;
46
49
  currency_code: string;
47
- transaction_date: string | null;
50
+ transaction_date: string;
48
51
  transaction_id: string;
49
52
  vendor_name: string;
50
53
  transaction_type?: string;
51
- vendor_logo?: URLPayload | null;
54
+ vendor_logo?: string;
52
55
  }
53
56
  export interface MatchCandidatePayload extends MatchedTransactionPayload {
54
57
  match_score: number;
@@ -56,11 +59,10 @@ export interface MatchCandidatePayload extends MatchedTransactionPayload {
56
59
  export interface BatchFilePayload {
57
60
  attachment_id: string;
58
61
  file_id: string;
59
- file_preview_url: string | null;
62
+ file_preview_url: string;
60
63
  filename: string;
61
64
  status: string;
62
65
  candidates?: MatchCandidatePayload[];
63
- match_source?: string;
64
66
  matched_transaction?: MatchedTransactionPayload;
65
67
  }
66
68
  export interface BatchDetailsResponsePayload {
@@ -77,12 +79,11 @@ export interface BatchDetailsResponsePayload {
77
79
  };
78
80
  }
79
81
  export type BatchDetailsResponse = ZeniAPIResponse<BatchDetailsResponsePayload>;
80
- export declare function toBatchFile(payload: BatchFilePayload, filesEndPoint?: string): BatchFile;
82
+ export declare function toBatchFile(payload: BatchFilePayload): BatchFile;
81
83
  export declare function extractTransactionPayloadsFromBatchFiles(files: BatchFilePayload[]): SupportedTransactionPayload[];
82
84
  export declare function toBatchSummary(payload: BatchDetailsResponsePayload['summary']): BatchSummary;
83
- export declare function toBatchDetails(payload: BatchDetailsResponsePayload, filesEndPoint?: string): BatchDetails;
84
- /** Batch list `status` is a string from the API — compare case-insensitively. */
85
- export declare function isBatchListStatusCompleted(status: string): boolean;
85
+ export declare function toBatchStatus(payload: BatchStatusResponsePayload): BatchStatus;
86
+ export declare function toBatchDetails(payload: BatchDetailsResponsePayload): BatchDetails;
86
87
  export declare function toBatchListItem(payload: BatchListItemPayload): BatchListItem;
87
88
  export interface TransactionSearchQueryPayload {
88
89
  search_text: string;
@@ -3,26 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.toBatchFile = toBatchFile;
4
4
  exports.extractTransactionPayloadsFromBatchFiles = extractTransactionPayloadsFromBatchFiles;
5
5
  exports.toBatchSummary = toBatchSummary;
6
+ exports.toBatchStatus = toBatchStatus;
6
7
  exports.toBatchDetails = toBatchDetails;
7
- exports.isBatchListStatusCompleted = isBatchListStatusCompleted;
8
8
  exports.toBatchListItem = toBatchListItem;
9
9
  exports.toManualSearchResult = toManualSearchResult;
10
- const urlPayload_1 = require("../../../commonPayloadTypes/urlPayload");
11
10
  // -- Converter functions --
12
- function toBatchFile(payload, filesEndPoint) {
11
+ function toBatchFile(payload) {
13
12
  return {
14
13
  attachmentId: payload.attachment_id,
15
14
  candidates: payload.candidates?.map((c) => ({
16
15
  transactionId: c.transaction_id,
17
16
  matchScore: c.match_score,
18
17
  })),
19
- fileDownloadUrl: payload.file_id != null && filesEndPoint != null
20
- ? `${filesEndPoint}/1.0/files/${payload.file_id}?query=${encodeURIComponent(JSON.stringify({ download_file: true }))}`
21
- : null,
22
18
  fileId: payload.file_id,
23
19
  filePreviewUrl: payload.file_preview_url,
24
20
  filename: payload.filename,
25
- matchSource: payload.match_source,
26
21
  matchedTransactionId: payload.matched_transaction?.transaction_id,
27
22
  status: payload.status,
28
23
  };
@@ -53,12 +48,11 @@ function extractTransactionPayloadsFromBatchFiles(files) {
53
48
  function matchedTransactionPayloadToSupportedTransactionPayload(payload) {
54
49
  return {
55
50
  transaction_id: payload.transaction_id,
56
- transaction_type: payload.transaction_type ?? 'expense',
57
- transaction_date: payload.transaction_date ?? '',
51
+ transaction_type: payload.transaction_type,
52
+ transaction_date: payload.transaction_date,
58
53
  currency_code: payload.currency_code,
59
54
  total_amount: payload.amount,
60
55
  vendor_name: payload.vendor_name,
61
- logo: payload.vendor_logo == null ? undefined : (0, urlPayload_1.toURL)(payload.vendor_logo),
62
56
  };
63
57
  }
64
58
  function toBatchSummary(payload) {
@@ -70,19 +64,22 @@ function toBatchSummary(payload) {
70
64
  total: payload.total,
71
65
  };
72
66
  }
73
- function toBatchDetails(payload, filesEndPoint) {
67
+ function toBatchStatus(payload) {
68
+ return {
69
+ batchId: payload.batch_id,
70
+ progress: payload.progress,
71
+ status: payload.status,
72
+ };
73
+ }
74
+ function toBatchDetails(payload) {
74
75
  return {
75
76
  batchId: payload.batch_id,
76
77
  createdAt: payload.created_at,
77
- files: payload.files.map((f) => toBatchFile(f, filesEndPoint)),
78
+ files: payload.files.map(toBatchFile),
78
79
  status: payload.status,
79
80
  summary: toBatchSummary(payload.summary),
80
81
  };
81
82
  }
82
- /** Batch list `status` is a string from the API — compare case-insensitively. */
83
- function isBatchListStatusCompleted(status) {
84
- return status.toLowerCase() === 'completed';
85
- }
86
83
  function toBatchListItem(payload) {
87
84
  return {
88
85
  batchId: payload.batch_id,
@@ -6,8 +6,6 @@ import { TransactionPayload } from '../../../entity/transaction/payloadTypes/tra
6
6
  import { SupportedTransactionPayload } from '../../../entity/transaction/transactionState';
7
7
  import { ZeniAPIStatus } from '../../../responsePayload';
8
8
  import type { BatchDetails, BatchListItem, BatchStatus, BulkUploadResultsTab, BulkUploadSortKey, BulkUploadState, CompletedSubTab, ManualSearchResult, MissingReceiptsViewState, MissingReceiptsViewUIState } from '../types/missingReceiptsViewState';
9
- import type { MonthYearPeriodId } from '../../../commonStateTypes/timePeriod';
10
- export declare const getCompletedTransactionsCacheKey: (periodId: MonthYearPeriodId, sortKey: BulkUploadSortKey, sortOrder: SortOrder, subTab: CompletedSubTab) => string;
11
9
  export declare const initialBulkUploadState: BulkUploadState;
12
10
  export declare const initialState: MissingReceiptsViewState;
13
11
  export declare const fetchMissingReceipts: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[period: TimePeriod, minimumTransactionAmount: Amount, cacheOverride?: any, refreshViewInBackground?: any], {
@@ -36,15 +34,9 @@ export declare const fetchMissingReceipts: import("@reduxjs/toolkit").ActionCrea
36
34
  batchId: ID;
37
35
  }, "expenseAutomationMissingReceiptsView/bulkUploadReceiptsSuccess">, bulkUploadReceiptsFailure: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
38
36
  error: ZeniAPIStatus;
39
- }, "expenseAutomationMissingReceiptsView/bulkUploadReceiptsFailure">, pusherBatchStatusUpdate: import("@reduxjs/toolkit").ActionCreatorWithPayload<BatchStatus, "expenseAutomationMissingReceiptsView/pusherBatchStatusUpdate">, requestMissingReceiptsTabNavigation: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
40
- tab: BulkUploadResultsTab;
41
- }, "expenseAutomationMissingReceiptsView/requestMissingReceiptsTabNavigation">, clearMissingReceiptsTabNavigation: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"expenseAutomationMissingReceiptsView/clearMissingReceiptsTabNavigation">, fetchBulkUploadBatchDetails: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"expenseAutomationMissingReceiptsView/fetchBulkUploadBatchDetails">, fetchBulkUploadBatchDetailsSuccess: import("@reduxjs/toolkit").ActionCreatorWithPayload<BatchDetails, "expenseAutomationMissingReceiptsView/fetchBulkUploadBatchDetailsSuccess">, fetchBulkUploadBatchDetailsFailure: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
37
+ }, "expenseAutomationMissingReceiptsView/bulkUploadReceiptsFailure">, updateBulkUploadBatchStatus: import("@reduxjs/toolkit").ActionCreatorWithPayload<BatchStatus, "expenseAutomationMissingReceiptsView/updateBulkUploadBatchStatus">, pusherBatchStatusUpdate: import("@reduxjs/toolkit").ActionCreatorWithPayload<BatchStatus, "expenseAutomationMissingReceiptsView/pusherBatchStatusUpdate">, fetchBulkUploadBatchDetails: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"expenseAutomationMissingReceiptsView/fetchBulkUploadBatchDetails">, fetchBulkUploadBatchDetailsSuccess: import("@reduxjs/toolkit").ActionCreatorWithPayload<BatchDetails, "expenseAutomationMissingReceiptsView/fetchBulkUploadBatchDetailsSuccess">, fetchBulkUploadBatchDetailsFailure: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
42
38
  error: ZeniAPIStatus;
43
- }, "expenseAutomationMissingReceiptsView/fetchBulkUploadBatchDetailsFailure">, storeBatchDetails: import("@reduxjs/toolkit").ActionCreatorWithPayload<BatchDetails, "expenseAutomationMissingReceiptsView/storeBatchDetails">, batchDetailFetchFailed: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
44
- batchId: ID;
45
- }, "expenseAutomationMissingReceiptsView/batchDetailFetchFailed">, setInitialBatchDetailsLoading: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"expenseAutomationMissingReceiptsView/setInitialBatchDetailsLoading">, fetchMoreBatchDetails: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"expenseAutomationMissingReceiptsView/fetchMoreBatchDetails">, fetchMoreBatchDetailsComplete: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"expenseAutomationMissingReceiptsView/fetchMoreBatchDetailsComplete">, fetchMoreBatchDetailsFailure: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
46
- error: ZeniAPIStatus;
47
- }, "expenseAutomationMissingReceiptsView/fetchMoreBatchDetailsFailure">, fetchBulkUploadBatches: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[cacheOverride?: any], {
39
+ }, "expenseAutomationMissingReceiptsView/fetchBulkUploadBatchDetailsFailure">, storeBatchDetails: import("@reduxjs/toolkit").ActionCreatorWithPayload<BatchDetails, "expenseAutomationMissingReceiptsView/storeBatchDetails">, fetchBulkUploadBatches: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[cacheOverride?: any], {
48
40
  cacheOverride: any;
49
41
  }, "expenseAutomationMissingReceiptsView/fetchBulkUploadBatches", never, never>, fetchBulkUploadBatchesSuccess: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
50
42
  batchList: BatchListItem[];
@@ -71,9 +63,8 @@ export declare const fetchMissingReceipts: import("@reduxjs/toolkit").ActionCrea
71
63
  query: string;
72
64
  }, "expenseAutomationMissingReceiptsView/searchTransactionsForManualMatch", never, never>, searchTransactionsForManualMatchSuccess: import("@reduxjs/toolkit").ActionCreatorWithPayload<ManualSearchResult[], "expenseAutomationMissingReceiptsView/searchTransactionsForManualMatchSuccess">, searchTransactionsForManualMatchFailure: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
73
65
  error: ZeniAPIStatus;
74
- }, "expenseAutomationMissingReceiptsView/searchTransactionsForManualMatchFailure">, clearManualSearchResults: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"expenseAutomationMissingReceiptsView/clearManualSearchResults">, fetchCompletedTransactions: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[pageToken?: string | undefined, cacheOverride?: boolean | undefined], {
66
+ }, "expenseAutomationMissingReceiptsView/searchTransactionsForManualMatchFailure">, clearManualSearchResults: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"expenseAutomationMissingReceiptsView/clearManualSearchResults">, fetchCompletedTransactions: import("@reduxjs/toolkit").ActionCreatorWithPreparedPayload<[pageToken?: string | undefined], {
75
67
  pageToken: string | undefined;
76
- cacheOverride: boolean | undefined;
77
68
  }, "expenseAutomationMissingReceiptsView/fetchCompletedTransactions", never, never>, fetchCompletedTransactionsSuccess: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
78
69
  isInitialLoad: boolean;
79
70
  nextPageToken: string | null;