@zeniai/client-epic-state 5.2.54-betaRD1 → 5.2.55

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 (74) hide show
  1. package/lib/entity/billPay/billTransaction/billTransactionReducer.d.ts +5 -1
  2. package/lib/entity/billPay/billTransaction/billTransactionReducer.js +17 -2
  3. package/lib/entity/invoicing/plan/planSelector.d.ts +9 -0
  4. package/lib/entity/invoicing/plan/planSelector.js +3 -2
  5. package/lib/entity/invoicing/product/productPayload.d.ts +1 -1
  6. package/lib/entity/invoicing/product/productPayload.js +1 -1
  7. package/lib/entity/invoicing/product/productState.d.ts +10 -0
  8. package/lib/entity/jeSchedules/jeSchedulesReducer.d.ts +1 -4
  9. package/lib/entity/jeSchedules/jeSchedulesReducer.js +5 -79
  10. package/lib/epic.d.ts +3 -2
  11. package/lib/epic.js +8 -6
  12. package/lib/esm/entity/billPay/billTransaction/billTransactionReducer.js +16 -1
  13. package/lib/esm/entity/invoicing/plan/planSelector.js +1 -1
  14. package/lib/esm/entity/invoicing/product/productPayload.js +1 -1
  15. package/lib/esm/entity/jeSchedules/jeSchedulesReducer.js +4 -78
  16. package/lib/esm/epic.js +8 -6
  17. package/lib/esm/index.js +5 -5
  18. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulePageEpic.js +1 -14
  19. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulesEpic.js +13 -10
  20. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/initializeJeScheduleLocalDataEpic.js +17 -38
  21. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/retryJeSchedulesEpic.js +1 -17
  22. package/lib/esm/view/expenseAutomationView/reducers/jeSchedulesViewReducer.js +1 -74
  23. package/lib/esm/view/expenseAutomationView/selectors/jeSchedulesViewSelector.js +14 -49
  24. package/lib/esm/view/invoicing/createInvoice/createInvoiceSelector.js +28 -1
  25. package/lib/esm/view/invoicing/editInvoicingCatalogItemDetailView/invoicingCatalogItemFormHelper.js +1 -7
  26. package/lib/esm/view/spendManagement/billPay/billDetailView/billDetailViewReducer.js +87 -1
  27. package/lib/esm/view/spendManagement/billPay/billDetailView/billDetailViewSelector.js +1 -0
  28. package/lib/esm/view/spendManagement/billPay/billDetailView/billDetailViewState.js +4 -0
  29. package/lib/esm/view/spendManagement/billPay/billDetailView/epics/fetchBillRecommendationsEpic.js +97 -0
  30. package/lib/esm/view/spendManagement/billPay/billDetailView/epics/fetchRecommendationsForBill.js +85 -0
  31. package/lib/esm/view/spendManagement/billPay/editBillView/editBillViewReducer.js +18 -1
  32. package/lib/esm/view/spendManagement/billPay/editBillView/editBillViewSelector.js +3 -0
  33. package/lib/esm/view/spendManagement/billPay/editBillView/epics/applyBillRecommendationsToLocalStoreEpic.js +95 -0
  34. package/lib/index.d.ts +5 -5
  35. package/lib/index.js +22 -22
  36. package/lib/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulePageEpic.d.ts +2 -2
  37. package/lib/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulePageEpic.js +0 -13
  38. package/lib/view/expenseAutomationView/epics/jeSchedule/fetchJeSchedulesEpic.js +11 -8
  39. package/lib/view/expenseAutomationView/epics/jeSchedule/initializeJeScheduleLocalDataEpic.js +17 -38
  40. package/lib/view/expenseAutomationView/epics/jeSchedule/retryJeSchedulesEpic.d.ts +2 -2
  41. package/lib/view/expenseAutomationView/epics/jeSchedule/retryJeSchedulesEpic.js +1 -17
  42. package/lib/view/expenseAutomationView/payload/jeSchedulesPayload.d.ts +0 -18
  43. package/lib/view/expenseAutomationView/reducers/jeSchedulesViewReducer.d.ts +3 -10
  44. package/lib/view/expenseAutomationView/reducers/jeSchedulesViewReducer.js +3 -76
  45. package/lib/view/expenseAutomationView/selectorTypes/jeSchedulesSelectorTypes.d.ts +0 -3
  46. package/lib/view/expenseAutomationView/selectors/jeSchedulesViewSelector.js +14 -49
  47. package/lib/view/expenseAutomationView/types/jeSchedulesViewState.d.ts +0 -16
  48. package/lib/view/invoicing/createInvoice/createInvoiceSelector.d.ts +7 -2
  49. package/lib/view/invoicing/createInvoice/createInvoiceSelector.js +28 -1
  50. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/invoicingCatalogItemFormHelper.d.ts +2 -2
  51. package/lib/view/invoicing/editInvoicingCatalogItemDetailView/invoicingCatalogItemFormHelper.js +1 -7
  52. package/lib/view/spendManagement/billPay/billDetailView/billDetailViewPayload.d.ts +19 -0
  53. package/lib/view/spendManagement/billPay/billDetailView/billDetailViewReducer.d.ts +10 -1
  54. package/lib/view/spendManagement/billPay/billDetailView/billDetailViewReducer.js +88 -2
  55. package/lib/view/spendManagement/billPay/billDetailView/billDetailViewSelector.d.ts +1 -0
  56. package/lib/view/spendManagement/billPay/billDetailView/billDetailViewSelector.js +1 -0
  57. package/lib/view/spendManagement/billPay/billDetailView/billDetailViewState.d.ts +7 -0
  58. package/lib/view/spendManagement/billPay/billDetailView/billDetailViewState.js +4 -0
  59. package/lib/view/spendManagement/billPay/billDetailView/epics/fetchBillRecommendationsEpic.d.ts +37 -0
  60. package/lib/view/spendManagement/billPay/billDetailView/epics/fetchBillRecommendationsEpic.js +104 -0
  61. package/lib/view/spendManagement/billPay/billDetailView/epics/fetchRecommendationsForBill.d.ts +24 -0
  62. package/lib/view/spendManagement/billPay/billDetailView/epics/fetchRecommendationsForBill.js +92 -0
  63. package/lib/view/spendManagement/billPay/editBillView/editBillViewReducer.d.ts +4 -1
  64. package/lib/view/spendManagement/billPay/editBillView/editBillViewReducer.js +19 -2
  65. package/lib/view/spendManagement/billPay/editBillView/editBillViewSelector.d.ts +1 -0
  66. package/lib/view/spendManagement/billPay/editBillView/editBillViewSelector.js +3 -0
  67. package/lib/view/spendManagement/billPay/editBillView/epics/applyBillRecommendationsToLocalStoreEpic.d.ts +18 -0
  68. package/lib/view/spendManagement/billPay/editBillView/epics/applyBillRecommendationsToLocalStoreEpic.js +102 -0
  69. package/package.json +1 -1
  70. package/lib/esm/view/expenseAutomationView/epics/jeSchedule/fetchFailedJePostingsEpic.js +0 -39
  71. package/lib/tsconfig.mocks.tsbuildinfo +0 -1
  72. package/lib/tsconfig.typecheck.tsbuildinfo +0 -1
  73. package/lib/view/expenseAutomationView/epics/jeSchedule/fetchFailedJePostingsEpic.d.ts +0 -20
  74. package/lib/view/expenseAutomationView/epics/jeSchedule/fetchFailedJePostingsEpic.js +0 -43
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.applyBillRecommendationsToLocalStoreEpic = void 0;
7
+ const get_1 = __importDefault(require("lodash/get"));
8
+ const rxjs_1 = require("rxjs");
9
+ const operators_1 = require("rxjs/operators");
10
+ const accountListSelector_1 = require("../../../../accountList/accountListSelector");
11
+ const classListSelector_1 = require("../../../../classList/classListSelector");
12
+ const billDetailViewReducer_1 = require("../../billDetailView/billDetailViewReducer");
13
+ const billDetailViewState_1 = require("../../billDetailView/billDetailViewState");
14
+ const editBillViewReducer_1 = require("../editBillViewReducer");
15
+ const initializeBillToLocalStoreEpic_1 = require("./initializeBillToLocalStoreEpic");
16
+ /**
17
+ * Back-fills the edit local store once the standalone recommendations fetch
18
+ * resolves. `initializeBillToLocalStore` reads `transaction.recommendations`
19
+ * exactly once and is guarded against re-running, so the recommendation-derived
20
+ * line data (category/class autofill, `recommendedCategory` / `recommendedClass`
21
+ * behind the "update to" checkbox) has to be recomputed here instead.
22
+ *
23
+ * Recomputes from the entity lines with the same helper the initializer uses, so
24
+ * an untouched line ends up exactly as it would have had the recommendations
25
+ * been present at init time.
26
+ */
27
+ const applyBillRecommendationsToLocalStoreEpic = (actions$, state$) => actions$.pipe((0, operators_1.filter)(billDetailViewReducer_1.fetchBillRecommendationsSuccess.match),
28
+ // The skip paths resolve the status without fetching — a draft whose
29
+ // recommendations came on the bill detail response, or a stage that is not
30
+ // served any. `initializeBillToLocalStore` has already read those, so
31
+ // recomputing here would only reset the line's "update to" selections.
32
+ (0, operators_1.filter)((action) => action.payload.didWriteRecommendations), (0, operators_1.mergeMap)((action) => {
33
+ const { billId } = action.payload;
34
+ const state = state$.value;
35
+ const key = (0, billDetailViewState_1.getBillTransactionDetailKey)(billId);
36
+ const editBillState = (0, get_1.default)(state.editBillDetailViewState.editBillStateById, key, undefined);
37
+ const transaction = (0, get_1.default)(state.billTransactionState.transactionById, billId, undefined);
38
+ const recommendations = transaction?.recommendations;
39
+ if (editBillState == null ||
40
+ transaction == null ||
41
+ transaction.lines == null ||
42
+ recommendations == null ||
43
+ Object.keys(recommendations).length === 0) {
44
+ return rxjs_1.EMPTY;
45
+ }
46
+ const localData = editBillState.billDetailLocalData;
47
+ // The recommendations were requested for the vendor on the bill. If the
48
+ // user has since switched vendors, `fetchVendorAndUpdateBillLocalData`
49
+ // owns the line data and these are stale — leave it alone.
50
+ //
51
+ // Both sides are QBO ids despite the field names suggesting otherwise.
52
+ // `transaction.vendor` is built by `mapVendorBasePayloadToVendorBase`,
53
+ // whose id is `getVendorPayloadIdentifier` = `vendor_id ?? qbo_id`, and
54
+ // on a bill transaction payload `vendor_id` IS the QBO id — the Zeni id
55
+ // rides separately as `zeni_vendor_id`. Verified against live DEV and QA
56
+ // responses, both of which have `vendor_id === qbo_vendor_id`.
57
+ if (localData.vendor?.qboId !== transaction.vendor?.id) {
58
+ return rxjs_1.EMPTY;
59
+ }
60
+ const accountList = (0, accountListSelector_1.getAccountList)(state.accountState, state.accountListState, 'billPayAccountList');
61
+ const classList = (0, classListSelector_1.getClassList)(state.classState, state.classListState);
62
+ const updatesByLineId = {};
63
+ transaction.lines.forEach((line) => {
64
+ // A line whose category/class the user already set keeps their input.
65
+ const localLine = localData.updatesByLineId[line.id];
66
+ if (localLine?.isCategoryOrClassUpdated) {
67
+ return;
68
+ }
69
+ // The helper spreads whatever line it is given into its result, and
70
+ // the reducer replaces the entry wholesale, so the local line has to
71
+ // go in or edits that leave `isCategoryOrClassUpdated` untouched — an
72
+ // amount or description changed while this fetch was in flight — get
73
+ // reverted.
74
+ //
75
+ // Category and class are the exception and come from the ENTITY line,
76
+ // exactly as at init. By now the local line may hold a category the
77
+ // vendor default autofilled when no recommendation was available yet,
78
+ // and the helper reads whatever it is given as the line's original
79
+ // value and will not replace one. Passing that back would leave an
80
+ // untouched line on the vendor default instead of the per-line
81
+ // recommendation, so the back-fill would not match what init would
82
+ // have produced had the recommendations been there all along.
83
+ const localLineWithEntityCategory = localLine == null || hasAccountAndClass(line) === false
84
+ ? line
85
+ : {
86
+ ...localLine,
87
+ account: line.account,
88
+ class: line.class,
89
+ };
90
+ updatesByLineId[line.id] = (0, initializeBillToLocalStoreEpic_1.getLineRecommendationsLocalData)(line.id, localLineWithEntityCategory, recommendations, accountList, classList, localData.vendor);
91
+ });
92
+ if (Object.keys(updatesByLineId).length === 0) {
93
+ return rxjs_1.EMPTY;
94
+ }
95
+ return (0, rxjs_1.of)((0, editBillViewReducer_1.updateBillLineRecommendationsInLocalStore)(billId, updatesByLineId));
96
+ }));
97
+ exports.applyBillRecommendationsToLocalStoreEpic = applyBillRecommendationsToLocalStoreEpic;
98
+ // Only some `Line` members carry a category and class. A guard rather than a
99
+ // cast so a shape change is a compile error, not a silent `undefined`.
100
+ function hasAccountAndClass(line) {
101
+ return 'account' in line;
102
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeniai/client-epic-state",
3
- "version": "5.2.54-betaRD1",
3
+ "version": "5.2.55",
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",
@@ -1,39 +0,0 @@
1
- import { from, of } from 'rxjs';
2
- import { catchError, filter, switchMap, takeUntil } from 'rxjs/operators';
3
- import { updateJESchedules, updateJESchedulesDetails, } from '../../../../entity/jeSchedules/jeSchedulesReducer';
4
- import { createZeniAPIStatus, isSuccessResponse, } from '../../../../responsePayload';
5
- import { clearAll } from '../../../../rootActions';
6
- import { fetchFailedJePostings, fetchFailedJePostingsFailure, fetchFailedJePostingsSuccess, initializeJeScheduleLocalData, } from '../../reducers/jeSchedulesViewReducer';
7
- /**
8
- * Fetches every currently-failing posting for the tenant, on its own endpoint and with no window.
9
- *
10
- * Sends no query at all. The endpoint takes an optional `expected_post_start_date` floor and the
11
- * client deliberately omits it: a failure is outstanding work until someone resolves it, whatever
12
- * month it belongs to, and windowing this list is exactly what kept older failures off the only
13
- * screen that can resolve them.
14
- *
15
- * `switchMap`, not `mergeMap`: there is one list per tenant, so a second trigger supersedes the
16
- * first rather than racing it.
17
- */
18
- export const fetchFailedJePostingsEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(fetchFailedJePostings.match), switchMap(() => zeniAPI
19
- .getJSON(`${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/expenses_automation/failed_je_postings`)
20
- .pipe(switchMap((response) => {
21
- if (!isSuccessResponse(response) || response.data == null) {
22
- return of(fetchFailedJePostingsFailure(response.status));
23
- }
24
- const { je_schedules: failedJeSchedules, scheduled_journal_entries: failedScheduledJournalEntries, } = response.data.failed_je_postings;
25
- // Order matters and matches fetchJeSchedulesEpic: updateJESchedules fans out to the
26
- // vendor / account / class / user entities, updateJESchedulesDetails then attaches the
27
- // journal entries, and only then can initializeJeScheduleLocalData read them back.
28
- return from([
29
- updateJESchedules(failedJeSchedules),
30
- updateJESchedulesDetails(failedJeSchedules, failedScheduledJournalEntries),
31
- initializeJeScheduleLocalData(failedJeSchedules),
32
- fetchFailedJePostingsSuccess(failedJeSchedules, failedScheduledJournalEntries),
33
- ]);
34
- }), catchError((error) => of(fetchFailedJePostingsFailure(createZeniAPIStatus('Unexpected Error', 'fetch failed JE postings REST API call errored out' +
35
- JSON.stringify(error))))),
36
- // A tenant switch clears the store while this request is still in flight. Without this
37
- // the old tenant's rows are written back into the freshly cleared store and stay on
38
- // screen under the new tenant until a manual refresh.
39
- takeUntil(actions$.pipe(filter(clearAll.match))))));