@zeniai/client-epic-state 4.19.37-betaVR27 → 4.19.37-betaVR3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/epic.d.ts +1 -2
- package/lib/epic.js +1 -2
- package/lib/esm/epic.js +1 -2
- package/lib/esm/index.js +2 -2
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/bulkUploadReceiptsEpic.js +7 -3
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/confirmBulkUploadMatchEpic.js +2 -2
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchDetailsEpic.js +13 -22
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchesEpic.js +1 -7
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchCompletedTransactionsEpic.js +3 -7
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.js +23 -45
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.js +24 -65
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.js +32 -33
- package/lib/esm/view/expenseAutomationView/payload/missingReceiptsPayload.js +16 -63
- package/lib/esm/view/expenseAutomationView/reducers/missingReceiptsViewReducer.js +26 -163
- package/lib/esm/view/expenseAutomationView/selectors/missingReceiptsSelector.js +13 -109
- package/lib/index.d.ts +2 -2
- package/lib/index.js +32 -37
- package/lib/tsconfig.typecheck.tsbuildinfo +1 -0
- package/lib/view/expenseAutomationView/epics/missingReceipts/bulkUploadReceiptsEpic.d.ts +5 -2
- package/lib/view/expenseAutomationView/epics/missingReceipts/bulkUploadReceiptsEpic.js +6 -2
- package/lib/view/expenseAutomationView/epics/missingReceipts/confirmBulkUploadMatchEpic.js +1 -1
- package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchDetailsEpic.js +11 -20
- package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchesEpic.js +1 -7
- package/lib/view/expenseAutomationView/epics/missingReceipts/fetchCompletedTransactionsEpic.js +2 -6
- package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.d.ts +2 -3
- package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.js +20 -43
- package/lib/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.d.ts +3 -11
- package/lib/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.js +22 -63
- package/lib/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.d.ts +7 -5
- package/lib/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.js +28 -29
- package/lib/view/expenseAutomationView/payload/missingReceiptsPayload.d.ts +31 -30
- package/lib/view/expenseAutomationView/payload/missingReceiptsPayload.js +18 -69
- package/lib/view/expenseAutomationView/reducers/missingReceiptsViewReducer.d.ts +6 -25
- package/lib/view/expenseAutomationView/reducers/missingReceiptsViewReducer.js +27 -165
- package/lib/view/expenseAutomationView/selectorTypes/missingReceiptsSelectorTypes.d.ts +0 -8
- package/lib/view/expenseAutomationView/selectors/missingReceiptsSelector.js +13 -109
- package/lib/view/expenseAutomationView/types/missingReceiptsViewState.d.ts +1 -21
- package/package.json +2 -2
- package/lib/esm/view/expenseAutomationView/epics/missingReceipts/fetchMoreBatchDetailsEpic.js +0 -34
- package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMoreBatchDetailsEpic.d.ts +0 -8
- package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMoreBatchDetailsEpic.js +0 -38
|
@@ -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
|
}>;
|
|
@@ -12,8 +12,12 @@ const bulkUploadReceiptsEpic = (actions$, _state$, zeniAPI) => actions$.pipe((0,
|
|
|
12
12
|
formData.append('files', file, file.name);
|
|
13
13
|
}
|
|
14
14
|
return zeniAPI
|
|
15
|
-
.
|
|
16
|
-
.pipe((0, operators_1.mergeMap)((
|
|
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,
|
|
@@ -6,7 +6,7 @@ const operators_1 = require("rxjs/operators");
|
|
|
6
6
|
const snackbarReducer_1 = require("../../../../entity/snackbar/snackbarReducer");
|
|
7
7
|
const responsePayload_1 = require("../../../../responsePayload");
|
|
8
8
|
const missingReceiptsViewReducer_1 = require("../../reducers/missingReceiptsViewReducer");
|
|
9
|
-
const confirmBulkUploadMatchEpic = (actions$, _state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(missingReceiptsViewReducer_1.confirmBulkUploadMatch.match), (0, operators_1.
|
|
9
|
+
const confirmBulkUploadMatchEpic = (actions$, _state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(missingReceiptsViewReducer_1.confirmBulkUploadMatch.match), (0, operators_1.mergeMap)((action) => {
|
|
10
10
|
const { batchId, attachmentId, transactionId, transactionType, fileName } = action.payload;
|
|
11
11
|
return zeniAPI
|
|
12
12
|
.postAndGetJSON(`${zeniAPI.apiEndPoints.communicationAgentMicroServiceBaseUrl}/1.0/receipts/manual-match`, {
|
package/lib/view/expenseAutomationView/epics/missingReceipts/fetchBulkUploadBatchDetailsEpic.js
CHANGED
|
@@ -8,35 +8,26 @@ const responsePayload_1 = require("../../../../responsePayload");
|
|
|
8
8
|
const missingReceiptsPayload_1 = require("../../payload/missingReceiptsPayload");
|
|
9
9
|
const missingReceiptsViewReducer_1 = require("../../reducers/missingReceiptsViewReducer");
|
|
10
10
|
const fetchBulkUploadBatchDetailsEpic = (actions$, state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(missingReceiptsViewReducer_1.fetchBulkUploadBatchDetails.match), (0, operators_1.mergeMap)(() => {
|
|
11
|
-
const
|
|
12
|
-
const { currentBatchId } = bulkUpload;
|
|
11
|
+
const { currentBatchId } = state$.value.expenseAutomationMissingReceiptsViewState.bulkUpload;
|
|
13
12
|
if (currentBatchId == null) {
|
|
14
13
|
return (0, rxjs_1.of)((0, missingReceiptsViewReducer_1.fetchBulkUploadBatchDetailsFailure)({
|
|
15
14
|
error: (0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', 'No current batch ID available'),
|
|
16
15
|
}));
|
|
17
16
|
}
|
|
18
|
-
if (!(0, missingReceiptsPayload_1.shouldFetchBatchDetailsForBatchId)(bulkUpload.batchStatusById, bulkUpload.batchListByPeriod, currentBatchId)) {
|
|
19
|
-
return rxjs_1.EMPTY;
|
|
20
|
-
}
|
|
21
17
|
return zeniAPI
|
|
22
|
-
.getJSON(`${zeniAPI.apiEndPoints.
|
|
18
|
+
.getJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/receipts/batches/${currentBatchId}`)
|
|
23
19
|
.pipe((0, operators_1.mergeMap)((response) => {
|
|
24
|
-
if (
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (
|
|
28
|
-
|
|
20
|
+
if ((0, responsePayload_1.isSuccessResponse)(response) && response.data != null) {
|
|
21
|
+
const actions = [];
|
|
22
|
+
const transactionPayloads = (0, missingReceiptsPayload_1.extractTransactionPayloadsFromBatchFiles)(response.data.files);
|
|
23
|
+
if (transactionPayloads.length > 0) {
|
|
24
|
+
actions.push((0, transactionReducer_1.updateTransactions)(transactionPayloads, (value) => value.transaction_id));
|
|
29
25
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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));
|
|
26
|
+
actions.push((0, missingReceiptsViewReducer_1.fetchBulkUploadBatchDetailsSuccess)((0, missingReceiptsPayload_1.toBatchDetails)(response.data)));
|
|
27
|
+
actions.push((0, missingReceiptsViewReducer_1.fetchBulkUploadBatches)(true));
|
|
28
|
+
return (0, rxjs_1.from)(actions);
|
|
36
29
|
}
|
|
37
|
-
|
|
38
|
-
actions.push((0, missingReceiptsViewReducer_1.fetchBulkUploadBatches)(true));
|
|
39
|
-
return (0, rxjs_1.from)(actions);
|
|
30
|
+
return (0, rxjs_1.of)((0, missingReceiptsViewReducer_1.fetchBulkUploadBatchDetailsFailure)({ error: response.status }));
|
|
40
31
|
}), (0, operators_1.catchError)((error) => (0, rxjs_1.of)((0, missingReceiptsViewReducer_1.fetchBulkUploadBatchDetailsFailure)({
|
|
41
32
|
error: (0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', 'Fetch batch details errored out: ' + JSON.stringify(error)),
|
|
42
33
|
}))));
|
|
@@ -23,16 +23,10 @@ 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.
|
|
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
|
-
/** Full list (all statuses) for UI; batch-details epics filter to `completed` only. */
|
|
36
30
|
return (0, rxjs_1.of)((0, missingReceiptsViewReducer_1.fetchBulkUploadBatchesSuccess)({
|
|
37
31
|
batchList: response.data.batches.map(missingReceiptsPayload_1.toBatchListItem),
|
|
38
32
|
selectedPeriod,
|
package/lib/view/expenseAutomationView/epics/missingReceipts/fetchCompletedTransactionsEpic.js
CHANGED
|
@@ -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
|
|
19
|
-
|
|
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);
|
package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.d.ts
CHANGED
|
@@ -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 {
|
|
7
|
-
export type ActionType = ReturnType<typeof
|
|
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>;
|
package/lib/view/expenseAutomationView/epics/missingReceipts/fetchMultipleBatchDetailsEpic.js
CHANGED
|
@@ -1,62 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.fetchMultipleBatchDetailsEpic = void 0;
|
|
4
|
-
exports.fetchBatchDetailsByIds = fetchBatchDetailsByIds;
|
|
5
4
|
const rxjs_1 = require("rxjs");
|
|
6
5
|
const operators_1 = require("rxjs/operators");
|
|
7
6
|
const transactionReducer_1 = require("../../../../entity/transaction/transactionReducer");
|
|
8
7
|
const responsePayload_1 = require("../../../../responsePayload");
|
|
9
8
|
const missingReceiptsPayload_1 = require("../../payload/missingReceiptsPayload");
|
|
10
9
|
const missingReceiptsViewReducer_1 = require("../../reducers/missingReceiptsViewReducer");
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
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) {
|
|
14
18
|
return rxjs_1.EMPTY;
|
|
15
19
|
}
|
|
16
|
-
return (0, rxjs_1.from)(
|
|
17
|
-
.getJSON(`${zeniAPI.apiEndPoints.
|
|
20
|
+
return (0, rxjs_1.from)(completedBatchIds).pipe((0, operators_1.mergeMap)((batchId) => zeniAPI
|
|
21
|
+
.getJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/receipts/batches/${batchId}`)
|
|
18
22
|
.pipe((0, operators_1.mergeMap)((response) => {
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
if ((0, responsePayload_1.isSuccessResponse)(response) && response.data != null) {
|
|
24
|
+
const actions = [];
|
|
25
|
+
const transactionPayloads = (0, missingReceiptsPayload_1.extractTransactionPayloadsFromBatchFiles)(response.data.files);
|
|
26
|
+
if (transactionPayloads.length > 0) {
|
|
27
|
+
actions.push((0, transactionReducer_1.updateTransactions)(transactionPayloads, (value) => value.transaction_id));
|
|
28
|
+
}
|
|
29
|
+
actions.push((0, missingReceiptsViewReducer_1.storeBatchDetails)((0, missingReceiptsPayload_1.toBatchDetails)(response.data)));
|
|
30
|
+
return (0, rxjs_1.from)(actions);
|
|
23
31
|
}
|
|
24
|
-
|
|
25
|
-
const transactionPayloads = (0, missingReceiptsPayload_1.extractTransactionPayloadsFromBatchFiles)(response.data.files);
|
|
26
|
-
if (transactionPayloads.length > 0) {
|
|
27
|
-
actions.push((0, transactionReducer_1.updateTransactions)(transactionPayloads, (value) => value.transaction_id));
|
|
28
|
-
}
|
|
29
|
-
actions.push((0, missingReceiptsViewReducer_1.storeBatchDetails)((0, missingReceiptsPayload_1.toBatchDetails)(response.data, zeniAPI.apiEndPoints.fileMicroServiceBaseUrl)));
|
|
30
|
-
return (0, rxjs_1.from)(actions);
|
|
32
|
+
return rxjs_1.EMPTY;
|
|
31
33
|
}), (0, operators_1.catchError)((error) => {
|
|
32
34
|
console.error(`Failed to fetch batch details for ${batchId}:`, (0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', 'Fetch batch details errored out: ' +
|
|
33
35
|
JSON.stringify(error)));
|
|
34
|
-
return (0, rxjs_1.of)((0, missingReceiptsViewReducer_1.batchDetailFetchFailed)({ batchId }));
|
|
35
|
-
})), 5));
|
|
36
|
-
}
|
|
37
|
-
const fetchMultipleBatchDetailsEpic = (actions$, state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(missingReceiptsViewReducer_1.fetchBulkUploadBatchesSuccess.match), (0, operators_1.mergeMap)((action) => {
|
|
38
|
-
const batchList = action.payload.batchList;
|
|
39
|
-
const { batchDetailsById } = state$.value.expenseAutomationMissingReceiptsViewState.bulkUpload;
|
|
40
|
-
/** Only completed list rows may trigger batch-details API; preserve platform order. */
|
|
41
|
-
const completedBatchesMissingDetails = (0, missingReceiptsPayload_1.filterBatchListItemsForBatchDetailsFetch)(batchList).filter((batch) => batchDetailsById[batch.batchId] == null);
|
|
42
|
-
const completedBatchIds = completedBatchesMissingDetails.map((batch) => batch.batchId);
|
|
43
|
-
const batchIdsToFetch = completedBatchIds.slice(0, INITIAL_BATCH_PAGE_SIZE);
|
|
44
|
-
if (batchIdsToFetch.length === 0) {
|
|
45
|
-
/**
|
|
46
|
-
* List refresh can complete while no row is `completed` yet (multi-fetch skips), or
|
|
47
|
-
* `currentBatchId` may not appear in the filtered list but still needs `GET /batches/:id`.
|
|
48
|
-
* Fall back to the single-batch-details epic so `phase` and details can resolve.
|
|
49
|
-
*/
|
|
50
|
-
const bulkUpload = state$.value.expenseAutomationMissingReceiptsViewState.bulkUpload;
|
|
51
|
-
const currentId = bulkUpload.currentBatchId;
|
|
52
|
-
if (currentId != null &&
|
|
53
|
-
bulkUpload.phase === 'matching' &&
|
|
54
|
-
bulkUpload.batchDetailsById[currentId] == null &&
|
|
55
|
-
(0, missingReceiptsPayload_1.shouldFetchBatchDetailsForBatchId)(bulkUpload.batchStatusById, bulkUpload.batchListByPeriod, currentId)) {
|
|
56
|
-
return (0, rxjs_1.of)((0, missingReceiptsViewReducer_1.fetchBulkUploadBatchDetails)());
|
|
57
|
-
}
|
|
58
36
|
return rxjs_1.EMPTY;
|
|
59
|
-
}
|
|
60
|
-
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));
|
|
61
38
|
}));
|
|
62
39
|
exports.fetchMultipleBatchDetailsEpic = fetchMultipleBatchDetailsEpic;
|
|
@@ -1,14 +1,6 @@
|
|
|
1
|
-
import { ActionsObservable
|
|
1
|
+
import { ActionsObservable } from 'redux-observable';
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
|
-
import { updateTransactions } from '../../../../entity/transaction/transactionReducer';
|
|
4
|
-
import { RootState } from '../../../../reducer';
|
|
5
3
|
import { ZeniAPI } from '../../../../zeniAPI';
|
|
6
4
|
import { searchTransactionsForManualMatch, searchTransactionsForManualMatchFailure, searchTransactionsForManualMatchSuccess } from '../../reducers/missingReceiptsViewReducer';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* Backend contract TBD — align with `fetchTransactionCategorizationEpic` (`selectedTab === 'autoCategorized'`)
|
|
10
|
-
* when the expense-automation API documents the intended filter for this flow.
|
|
11
|
-
*/
|
|
12
|
-
export declare const MANUAL_TRANSACTION_SEARCH_AUTO_CATEGORIZED = false;
|
|
13
|
-
export type ActionType = ReturnType<typeof searchTransactionsForManualMatch> | ReturnType<typeof searchTransactionsForManualMatchSuccess> | ReturnType<typeof searchTransactionsForManualMatchFailure> | ReturnType<typeof updateTransactions>;
|
|
14
|
-
export declare const searchTransactionsForManualMatchEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => Observable<ActionType>;
|
|
5
|
+
export type ActionType = ReturnType<typeof searchTransactionsForManualMatch> | ReturnType<typeof searchTransactionsForManualMatchSuccess> | ReturnType<typeof searchTransactionsForManualMatchFailure>;
|
|
6
|
+
export declare const searchTransactionsForManualMatchEpic: (actions$: ActionsObservable<ActionType>, _state$: unknown, zeniAPI: ZeniAPI) => Observable<ActionType>;
|
package/lib/view/expenseAutomationView/epics/missingReceipts/searchTransactionsForManualMatchEpic.js
CHANGED
|
@@ -1,72 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.searchTransactionsForManualMatchEpic =
|
|
3
|
+
exports.searchTransactionsForManualMatchEpic = void 0;
|
|
4
4
|
const rxjs_1 = require("rxjs");
|
|
5
5
|
const operators_1 = require("rxjs/operators");
|
|
6
|
-
const timePeriod_1 = require("../../../../commonStateTypes/timePeriod");
|
|
7
|
-
const tenantSelector_1 = require("../../../../entity/tenant/tenantSelector");
|
|
8
|
-
const transactionReducer_1 = require("../../../../entity/transaction/transactionReducer");
|
|
9
6
|
const responsePayload_1 = require("../../../../responsePayload");
|
|
10
7
|
const missingReceiptsPayload_1 = require("../../payload/missingReceiptsPayload");
|
|
11
8
|
const missingReceiptsViewReducer_1 = require("../../reducers/missingReceiptsViewReducer");
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const state = state$.value;
|
|
26
|
-
const { expenseAutomationViewState: { selectedPeriodByTenantId }, expenseAutomationMissingReceiptsViewState: { bulkUpload: { manualSearch, sortKey, sortOrder }, }, } = state;
|
|
27
|
-
const currentTenant = (0, tenantSelector_1.getCurrentTenant)(state);
|
|
28
|
-
const selectedPeriod = selectedPeriodByTenantId[currentTenant.tenantId];
|
|
29
|
-
if (selectedPeriod == null) {
|
|
30
|
-
return (0, rxjs_1.of)((0, missingReceiptsViewReducer_1.searchTransactionsForManualMatchFailure)({
|
|
31
|
-
error: (0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', 'Manual search requires a selected accounting period.'),
|
|
32
|
-
}));
|
|
9
|
+
const searchTransactionsForManualMatchEpic = (actions$, _state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(missingReceiptsViewReducer_1.searchTransactionsForManualMatch.match), (0, operators_1.debounceTime)(300), (0, operators_1.switchMap)((action) => {
|
|
10
|
+
const { query } = action.payload;
|
|
11
|
+
const searchQuery = JSON.stringify({
|
|
12
|
+
search_text: query,
|
|
13
|
+
search_fields: ['date', 'amount', 'vendor_name'],
|
|
14
|
+
});
|
|
15
|
+
const encodedQuery = encodeURIComponent(searchQuery);
|
|
16
|
+
return zeniAPI
|
|
17
|
+
.getJSON(`${zeniAPI.apiEndPoints.searchMicroServiceBaseUrl}/1.0/transaction-search?query=${encodedQuery}`)
|
|
18
|
+
.pipe((0, operators_1.switchMap)((response) => {
|
|
19
|
+
if ((0, responsePayload_1.isSuccessResponse)(response) && response.data != null) {
|
|
20
|
+
const results = response.data.transactions.map(missingReceiptsPayload_1.toManualSearchResult);
|
|
21
|
+
return (0, rxjs_1.of)((0, missingReceiptsViewReducer_1.searchTransactionsForManualMatchSuccess)(results));
|
|
33
22
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
page_size: manualSearch.pageSize,
|
|
43
|
-
search_text: query,
|
|
44
|
-
};
|
|
45
|
-
return zeniAPI
|
|
46
|
-
.getJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/expense-automation/transactions?query=${encodeURIComponent(JSON.stringify(queryParam))}`)
|
|
47
|
-
.pipe((0, operators_1.mergeMap)((response) => {
|
|
48
|
-
if ((0, responsePayload_1.isSuccessResponse)(response) && response.data != null) {
|
|
49
|
-
const { transactions, next_page_token, total_count } = response.data;
|
|
50
|
-
const append = pageToken != null;
|
|
51
|
-
const results = transactions.map(missingReceiptsPayload_1.supportedTransactionPayloadToManualSearchResult);
|
|
52
|
-
const actionsOut = [
|
|
53
|
-
(0, transactionReducer_1.updateTransactions)(transactions, (value) => value.transaction_id, 'merge'),
|
|
54
|
-
(0, missingReceiptsViewReducer_1.searchTransactionsForManualMatchSuccess)({
|
|
55
|
-
append,
|
|
56
|
-
nextPageToken: next_page_token ?? null,
|
|
57
|
-
results,
|
|
58
|
-
totalCount: total_count,
|
|
59
|
-
}),
|
|
60
|
-
];
|
|
61
|
-
return (0, rxjs_1.from)(actionsOut);
|
|
62
|
-
}
|
|
63
|
-
return (0, rxjs_1.of)((0, missingReceiptsViewReducer_1.searchTransactionsForManualMatchFailure)({
|
|
64
|
-
error: response.status,
|
|
65
|
-
}));
|
|
66
|
-
}), (0, operators_1.catchError)((error) => (0, rxjs_1.of)((0, missingReceiptsViewReducer_1.searchTransactionsForManualMatchFailure)({
|
|
67
|
-
error: (0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', 'Search transactions for manual match errored: ' +
|
|
68
|
-
JSON.stringify(error)),
|
|
69
|
-
}))));
|
|
70
|
-
}));
|
|
71
|
-
};
|
|
23
|
+
return (0, rxjs_1.of)((0, missingReceiptsViewReducer_1.searchTransactionsForManualMatchFailure)({
|
|
24
|
+
error: response.status,
|
|
25
|
+
}));
|
|
26
|
+
}), (0, operators_1.catchError)((error) => (0, rxjs_1.of)((0, missingReceiptsViewReducer_1.searchTransactionsForManualMatchFailure)({
|
|
27
|
+
error: (0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', 'Search transactions for manual match errored: ' +
|
|
28
|
+
JSON.stringify(error)),
|
|
29
|
+
}))));
|
|
30
|
+
}));
|
|
72
31
|
exports.searchTransactionsForManualMatchEpic = searchTransactionsForManualMatchEpic;
|
package/lib/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.d.ts
CHANGED
|
@@ -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,
|
|
7
|
-
export type ActionType = ReturnType<typeof bulkUploadReceiptsSuccess> | ReturnType<typeof
|
|
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
|
-
*
|
|
10
|
-
*
|
|
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>;
|
package/lib/view/expenseAutomationView/epics/missingReceipts/watchBulkUploadBatchStatusEpic.js
CHANGED
|
@@ -3,45 +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
9
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
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`.
|
|
16
15
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
cacheOverride: true,
|
|
20
|
-
invalidateBatchDetailsCache: true,
|
|
21
|
-
}),
|
|
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
|
-
|
|
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)(
|
|
28
|
-
|
|
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
|
-
/** Same batch-details URL; polls until `status` is completed (Pusher may win first). */
|
|
31
28
|
if ((0, responsePayload_1.isSuccessResponse)(response) && response.data != null) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
actions.push((0, missingReceiptsViewReducer_1.fetchBulkUploadBatchDetailsSuccess)((0, missingReceiptsPayload_1.toBatchDetails)(response.data, zeniAPI.apiEndPoints.fileMicroServiceBaseUrl)));
|
|
39
|
-
actions.push((0, missingReceiptsViewReducer_1.fetchBulkUploadBatches)(true));
|
|
40
|
-
actions.push((0, missingReceiptsViewReducer_1.requestMissingReceiptsTabNavigation)({ tab: 'unmatched' }));
|
|
41
|
-
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)());
|
|
42
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;
|
|
43
42
|
}
|
|
44
|
-
return
|
|
45
|
-
}
|
|
43
|
+
return true;
|
|
44
|
+
}, true));
|
|
46
45
|
}));
|
|
47
46
|
exports.pollBulkUploadBatchStatusEpic = pollBulkUploadBatchStatusEpic;
|
|
@@ -2,7 +2,6 @@ import { URLPayload } from '../../../commonPayloadTypes/urlPayload';
|
|
|
2
2
|
import { TransactionPayload } from '../../../entity/transaction/payloadTypes/transactionPayload';
|
|
3
3
|
import { SupportedTransactionPayload } from '../../../entity/transaction/transactionState';
|
|
4
4
|
import { ZeniAPIResponse } from '../../../responsePayload';
|
|
5
|
-
import type { MonthYearPeriodId } from '../../../commonStateTypes/timePeriod';
|
|
6
5
|
import type { BatchDetails, BatchFile, BatchListItem, BatchStatus, BatchSummary, ManualSearchResult } from '../types/missingReceiptsViewState';
|
|
7
6
|
export interface MissingReceiptsQueryPayload {
|
|
8
7
|
end_date: string;
|
|
@@ -17,17 +16,21 @@ interface MissingReceiptsPayload {
|
|
|
17
16
|
transactions: TransactionPayload[];
|
|
18
17
|
}
|
|
19
18
|
export type MissingReceiptsResponse = ZeniAPIResponse<MissingReceiptsPayload>;
|
|
20
|
-
export interface BatchListQueryPayload {
|
|
21
|
-
end_date: string;
|
|
22
|
-
sort_order: string;
|
|
23
|
-
start_date: string;
|
|
24
|
-
}
|
|
25
19
|
export interface BulkUploadResponsePayload {
|
|
26
20
|
batch_id: string;
|
|
27
21
|
status: string;
|
|
28
22
|
total_files: number;
|
|
29
23
|
}
|
|
30
24
|
export type BulkUploadResponse = ZeniAPIResponse<BulkUploadResponsePayload>;
|
|
25
|
+
export interface BatchStatusResponsePayload {
|
|
26
|
+
batch_id: string;
|
|
27
|
+
progress: {
|
|
28
|
+
processed: number;
|
|
29
|
+
total: number;
|
|
30
|
+
};
|
|
31
|
+
status: string;
|
|
32
|
+
}
|
|
33
|
+
export type BatchStatusResponse = ZeniAPIResponse<BatchStatusResponsePayload>;
|
|
31
34
|
export interface BatchListResponsePayload {
|
|
32
35
|
batches: BatchListItemPayload[];
|
|
33
36
|
}
|
|
@@ -78,33 +81,31 @@ export interface BatchDetailsResponsePayload {
|
|
|
78
81
|
};
|
|
79
82
|
}
|
|
80
83
|
export type BatchDetailsResponse = ZeniAPIResponse<BatchDetailsResponsePayload>;
|
|
81
|
-
export declare function toBatchFile(payload: BatchFilePayload
|
|
84
|
+
export declare function toBatchFile(payload: BatchFilePayload): BatchFile;
|
|
82
85
|
export declare function extractTransactionPayloadsFromBatchFiles(files: BatchFilePayload[]): SupportedTransactionPayload[];
|
|
83
86
|
export declare function toBatchSummary(payload: BatchDetailsResponsePayload['summary']): BatchSummary;
|
|
84
|
-
export declare function
|
|
85
|
-
|
|
86
|
-
export declare function isBatchListStatusCompleted(status: string): boolean;
|
|
87
|
-
/**
|
|
88
|
-
* Subset of the get-all-batches (`/batches?query=...`) list that is eligible for
|
|
89
|
-
* `GET /batches/:batchId` details fetches. The stored list may include pending, failed, or other
|
|
90
|
-
* statuses for UI; only `completed` rows should trigger batch-details requests.
|
|
91
|
-
*/
|
|
92
|
-
export declare function filterBatchListItemsForBatchDetailsFetch(batches: BatchListItem[]): BatchListItem[];
|
|
93
|
-
/**
|
|
94
|
-
* Batch details API response `status` field — only completed payloads should be stored from
|
|
95
|
-
* multi-batch fetch paths (list can be briefly stale vs. live processing state).
|
|
96
|
-
*/
|
|
97
|
-
export declare function isBatchDetailsApiStatusCompleted(status: string): boolean;
|
|
98
|
-
export declare function findBatchListItemForBatchId(batchListByPeriod: Record<MonthYearPeriodId, BatchListItem[]>, batchId: string): BatchListItem | undefined;
|
|
99
|
-
/**
|
|
100
|
-
* Whether it is appropriate to call `GET .../batches/:id` for details.
|
|
101
|
-
* Skips when live batch status or batch list row indicates the batch is not completed yet.
|
|
102
|
-
* When status is unknown in both sources, allows the request (e.g. dispatch before list refresh).
|
|
103
|
-
*/
|
|
104
|
-
export declare function shouldFetchBatchDetailsForBatchId(batchStatusById: Record<string, BatchStatus>, batchListByPeriod: Record<MonthYearPeriodId, BatchListItem[]>, batchId: string): boolean;
|
|
87
|
+
export declare function toBatchStatus(payload: BatchStatusResponsePayload): BatchStatus;
|
|
88
|
+
export declare function toBatchDetails(payload: BatchDetailsResponsePayload): BatchDetails;
|
|
105
89
|
export declare function toBatchListItem(payload: BatchListItemPayload): BatchListItem;
|
|
106
|
-
|
|
107
|
-
|
|
90
|
+
export interface TransactionSearchQueryPayload {
|
|
91
|
+
search_text: string;
|
|
92
|
+
search_fields?: string[];
|
|
93
|
+
}
|
|
94
|
+
export interface TransactionSearchItemPayload {
|
|
95
|
+
amount: number;
|
|
96
|
+
currency: string;
|
|
97
|
+
entity_id: string;
|
|
98
|
+
memo: string;
|
|
99
|
+
transaction_date: string;
|
|
100
|
+
transaction_id: string;
|
|
101
|
+
transaction_type: string;
|
|
102
|
+
vendor_name: string;
|
|
103
|
+
}
|
|
104
|
+
export interface TransactionSearchResponsePayload {
|
|
105
|
+
transactions: TransactionSearchItemPayload[];
|
|
106
|
+
}
|
|
107
|
+
export type TransactionSearchResponse = ZeniAPIResponse<TransactionSearchResponsePayload>;
|
|
108
|
+
export declare function toManualSearchResult(payload: TransactionSearchItemPayload): ManualSearchResult;
|
|
108
109
|
export interface CompletedTransactionsQueryPayload {
|
|
109
110
|
end_date?: string;
|
|
110
111
|
match_type?: string;
|