@zeniai/client-epic-state 5.0.90-beta0ND → 5.0.90-betaAR2

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 (132) hide show
  1. package/lib/commonStateTypes/animations.d.ts +1 -1
  2. package/lib/commonStateTypes/animations.js +0 -1
  3. package/lib/entity/approvalRule/approvalRuleConflict.d.ts +56 -0
  4. package/lib/entity/approvalRule/approvalRuleConflict.js +77 -0
  5. package/lib/entity/approvalRule/approvalRulePayload.d.ts +34 -5
  6. package/lib/entity/approvalRule/approvalRulePayload.js +145 -10
  7. package/lib/entity/approvalRule/approvalRuleSelector.d.ts +25 -1
  8. package/lib/entity/approvalRule/approvalRuleSelector.js +40 -0
  9. package/lib/entity/approvalRule/approvalRuleState.d.ts +59 -7
  10. package/lib/entity/company/companyPayload.d.ts +0 -4
  11. package/lib/entity/company/companyPayload.js +0 -4
  12. package/lib/entity/company/companyStateTypes.d.ts +0 -4
  13. package/lib/entity/paymentAccount/paymentAccountSelector.d.ts +0 -1
  14. package/lib/entity/paymentAccount/paymentAccountSelector.js +0 -4
  15. package/lib/entity/snackbar/snackbarTypes.d.ts +1 -1
  16. package/lib/entity/snackbar/snackbarTypes.js +2 -0
  17. package/lib/entity/tenant/epic/deleteConnectionEpic.d.ts +1 -1
  18. package/lib/entity/tenant/epic/saveAPIKeyConnectionEpic.d.ts +1 -1
  19. package/lib/entity/tenant/epic/saveConnectorCredentialsEpic.d.ts +3 -3
  20. package/lib/entity/tenant/epic/saveOAuthConnectionEpic.d.ts +1 -1
  21. package/lib/entity/tenant/tenantPayload.d.ts +0 -1
  22. package/lib/entity/tenant/tenantReducer.d.ts +25 -38
  23. package/lib/entity/tenant/tenantReducer.js +5 -65
  24. package/lib/entity/tenant/tenantState.d.ts +0 -1
  25. package/lib/epic.d.ts +5 -8
  26. package/lib/epic.js +5 -9
  27. package/lib/esm/commonStateTypes/animations.js +0 -1
  28. package/lib/esm/entity/approvalRule/approvalRuleConflict.js +74 -0
  29. package/lib/esm/entity/approvalRule/approvalRulePayload.js +145 -10
  30. package/lib/esm/entity/approvalRule/approvalRuleSelector.js +35 -0
  31. package/lib/esm/entity/company/companyPayload.js +0 -4
  32. package/lib/esm/entity/paymentAccount/paymentAccountSelector.js +0 -3
  33. package/lib/esm/entity/snackbar/snackbarTypes.js +2 -0
  34. package/lib/esm/entity/tenant/tenantReducer.js +3 -63
  35. package/lib/esm/epic.js +5 -9
  36. package/lib/esm/index.js +13 -14
  37. package/lib/esm/view/fileView/epic/deleteFileEpic.js +2 -2
  38. package/lib/esm/view/fileView/epic/deleteFileListEpic.js +2 -2
  39. package/lib/esm/view/fileView/epic/updateFileNameEpic.js +2 -2
  40. package/lib/esm/view/onboardingView/customerView/onboardingCustomerViewReducer.js +50 -217
  41. package/lib/esm/view/onboardingView/customerView/onboardingCustomerViewSelector.js +1 -7
  42. package/lib/esm/view/onboardingView/customerView/onboardingCustomerViewState.js +0 -12
  43. package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/billPaySetupApproverViewReducer.js +92 -12
  44. package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/epic/deleteBillPayApprovalRuleEpic.js +10 -2
  45. package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/epic/fetchBillPaySetupApproverViewEpic.js +8 -4
  46. package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/epic/initializeBillPaySetupApproverViewUpdateDataEpic.js +11 -7
  47. package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/epic/reorderBillPayApprovalRulesEpic.js +54 -0
  48. package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/epic/saveBillPaySetupApproverViewUpdatesEpic.js +13 -4
  49. package/lib/esm/view/spendManagement/billPay/billPaySetupApproverView/types/commonPayload.js +122 -16
  50. package/lib/esm/view/spendManagement/billPay/editBillView/editBillViewSelector.js +7 -2
  51. package/lib/esm/view/spendManagement/commonSetup/setupViewReducer.js +52 -105
  52. package/lib/esm/view/spendManagement/commonSetup/setupViewSelector.js +1 -6
  53. package/lib/esm/view/spendManagement/reimbursement/remiSetupApproverView/epic/deleteRemiApprovalRuleEpic.js +10 -2
  54. package/lib/esm/view/spendManagement/reimbursement/remiSetupApproverView/epic/fetchRemiSetupApproverViewEpic.js +8 -2
  55. package/lib/esm/view/spendManagement/reimbursement/remiSetupApproverView/epic/initializeRemiSetupApproverViewUpdateDataEpic.js +11 -7
  56. package/lib/esm/view/spendManagement/reimbursement/remiSetupApproverView/epic/reorderRemiApprovalRulesEpic.js +49 -0
  57. package/lib/esm/view/spendManagement/reimbursement/remiSetupApproverView/epic/saveRemiSetupApproverViewUpdatesEpic.js +13 -4
  58. package/lib/esm/view/spendManagement/reimbursement/remiSetupApproverView/remiSetupApproverViewReducer.js +71 -11
  59. package/lib/index.d.ts +15 -17
  60. package/lib/index.js +42 -51
  61. package/lib/view/companyTaskManagerView/companyTaskManagerViewReducer.d.ts +2 -2
  62. package/lib/view/companyView/types/cockpitTypes.d.ts +1 -1
  63. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
  64. package/lib/view/fileView/epic/deleteFileEpic.js +1 -1
  65. package/lib/view/fileView/epic/deleteFileListEpic.js +1 -1
  66. package/lib/view/fileView/epic/updateFileNameEpic.js +1 -1
  67. package/lib/view/onboardingView/customerView/onboardingCustomerViewPayload.d.ts +0 -3
  68. package/lib/view/onboardingView/customerView/onboardingCustomerViewReducer.d.ts +4 -41
  69. package/lib/view/onboardingView/customerView/onboardingCustomerViewReducer.js +51 -219
  70. package/lib/view/onboardingView/customerView/onboardingCustomerViewSelector.d.ts +1 -5
  71. package/lib/view/onboardingView/customerView/onboardingCustomerViewSelector.js +2 -11
  72. package/lib/view/onboardingView/customerView/onboardingCustomerViewState.d.ts +0 -40
  73. package/lib/view/onboardingView/customerView/onboardingCustomerViewState.js +1 -13
  74. package/lib/view/people/peopleTypes.d.ts +1 -1
  75. package/lib/view/spendManagement/billPay/billPaySetupApproverView/billPaySetupApproverViewReducer.d.ts +14 -3
  76. package/lib/view/spendManagement/billPay/billPaySetupApproverView/billPaySetupApproverViewReducer.js +93 -13
  77. package/lib/view/spendManagement/billPay/billPaySetupApproverView/billPaySetupApproverViewState.d.ts +16 -0
  78. package/lib/view/spendManagement/billPay/billPaySetupApproverView/epic/deleteBillPayApprovalRuleEpic.js +10 -2
  79. package/lib/view/spendManagement/billPay/billPaySetupApproverView/epic/fetchBillPaySetupApproverViewEpic.js +8 -4
  80. package/lib/view/spendManagement/billPay/billPaySetupApproverView/epic/initializeBillPaySetupApproverViewUpdateDataEpic.js +10 -6
  81. package/lib/view/spendManagement/billPay/billPaySetupApproverView/epic/reorderBillPayApprovalRulesEpic.d.ts +23 -0
  82. package/lib/view/spendManagement/billPay/billPaySetupApproverView/epic/reorderBillPayApprovalRulesEpic.js +58 -0
  83. package/lib/view/spendManagement/billPay/billPaySetupApproverView/epic/saveBillPaySetupApproverViewUpdatesEpic.js +12 -3
  84. package/lib/view/spendManagement/billPay/billPaySetupApproverView/types/commonPayload.d.ts +50 -1
  85. package/lib/view/spendManagement/billPay/billPaySetupApproverView/types/commonPayload.js +124 -17
  86. package/lib/view/spendManagement/billPay/billPaySetupApproverView/types/commonState.d.ts +31 -5
  87. package/lib/view/spendManagement/billPay/editBillView/editBillViewSelector.js +7 -2
  88. package/lib/view/spendManagement/chargeCards/chargeCardList/chargeCardList.d.ts +1 -1
  89. package/lib/view/spendManagement/commonSetup/setupViewReducer.d.ts +2 -28
  90. package/lib/view/spendManagement/commonSetup/setupViewReducer.js +53 -106
  91. package/lib/view/spendManagement/commonSetup/setupViewSelector.d.ts +2 -7
  92. package/lib/view/spendManagement/commonSetup/setupViewSelector.js +1 -6
  93. package/lib/view/spendManagement/commonSetup/setupViewState.d.ts +0 -19
  94. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/epic/deleteRemiApprovalRuleEpic.js +10 -2
  95. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/epic/fetchRemiSetupApproverViewEpic.js +8 -2
  96. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/epic/initializeRemiSetupApproverViewUpdateDataEpic.js +10 -6
  97. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/epic/reorderRemiApprovalRulesEpic.d.ts +14 -0
  98. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/epic/reorderRemiApprovalRulesEpic.js +53 -0
  99. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/epic/saveRemiSetupApproverViewUpdatesEpic.js +12 -3
  100. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/remiSetupApproverViewReducer.d.ts +14 -3
  101. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/remiSetupApproverViewReducer.js +72 -12
  102. package/lib/view/spendManagement/reimbursement/remiSetupApproverView/remiSetupApproverViewState.d.ts +12 -0
  103. package/lib/view/taskManager/taskListView/taskList.d.ts +3 -3
  104. package/lib/view/transactionDetail/journalEntryLinesViewModel.d.ts +1 -1
  105. package/package.json +1 -1
  106. package/lib/entity/tenant/epic/initEmailConnectOAuthEpic.d.ts +0 -21
  107. package/lib/entity/tenant/epic/initEmailConnectOAuthEpic.js +0 -54
  108. package/lib/esm/entity/tenant/epic/initEmailConnectOAuthEpic.js +0 -50
  109. package/lib/esm/view/onboardingView/customerView/epic/aiAgentsActivation/fetchAiAgentsActivationStatusEpic.js +0 -42
  110. package/lib/esm/view/onboardingView/customerView/epic/customerDetails/acknowledgeOnboardingAiActivationViewedEpic.js +0 -29
  111. package/lib/esm/view/onboardingView/customerView/epic/customerDetails/acknowledgeOnboardingAiFinanceTeamEpic.js +0 -40
  112. package/lib/esm/view/spendManagement/commonSetup/epic/setup/parseUploadedKybDocumentEpic.js +0 -52
  113. package/lib/esm/view/spendManagement/commonSetup/epic/setup/parseUploadedKycDocumentEpic.js +0 -59
  114. package/lib/esm/view/spendManagement/commonSetup/kycKybAutofillActions.js +0 -14
  115. package/lib/esm/view/spendManagement/commonSetup/kycKybParseMapper.js +0 -205
  116. package/lib/esm/view/spendManagement/commonSetup/types/kycKybAutofill.js +0 -28
  117. package/lib/view/onboardingView/customerView/epic/aiAgentsActivation/fetchAiAgentsActivationStatusEpic.d.ts +0 -7
  118. package/lib/view/onboardingView/customerView/epic/aiAgentsActivation/fetchAiAgentsActivationStatusEpic.js +0 -46
  119. package/lib/view/onboardingView/customerView/epic/customerDetails/acknowledgeOnboardingAiActivationViewedEpic.d.ts +0 -8
  120. package/lib/view/onboardingView/customerView/epic/customerDetails/acknowledgeOnboardingAiActivationViewedEpic.js +0 -33
  121. package/lib/view/onboardingView/customerView/epic/customerDetails/acknowledgeOnboardingAiFinanceTeamEpic.d.ts +0 -9
  122. package/lib/view/onboardingView/customerView/epic/customerDetails/acknowledgeOnboardingAiFinanceTeamEpic.js +0 -44
  123. package/lib/view/spendManagement/commonSetup/epic/setup/parseUploadedKybDocumentEpic.d.ts +0 -28
  124. package/lib/view/spendManagement/commonSetup/epic/setup/parseUploadedKybDocumentEpic.js +0 -56
  125. package/lib/view/spendManagement/commonSetup/epic/setup/parseUploadedKycDocumentEpic.d.ts +0 -30
  126. package/lib/view/spendManagement/commonSetup/epic/setup/parseUploadedKycDocumentEpic.js +0 -63
  127. package/lib/view/spendManagement/commonSetup/kycKybAutofillActions.d.ts +0 -33
  128. package/lib/view/spendManagement/commonSetup/kycKybAutofillActions.js +0 -17
  129. package/lib/view/spendManagement/commonSetup/kycKybParseMapper.d.ts +0 -24
  130. package/lib/view/spendManagement/commonSetup/kycKybParseMapper.js +0 -213
  131. package/lib/view/spendManagement/commonSetup/types/kycKybAutofill.d.ts +0 -125
  132. package/lib/view/spendManagement/commonSetup/types/kycKybAutofill.js +0 -32
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.clearBillPaySetupApproverView = exports.setListeningToPusherEvent = exports.clearBillPaySetupApproverViewUpdateData = exports.saveBillPaySetupApproverViewUpdateData = exports.initializeBillPaySetupApproverViewUpdateData = exports.saveBillPaySetupApproverViewUpdatesFailure = exports.saveBillPaySetupApproverViewUpdatesSuccess = exports.saveBillPaySetupApproverViewUpdates = exports.deleteBillPayApprovalRuleFailure = exports.deleteBillPayApprovalRuleSuccess = exports.deleteBillPayApprovalRule = exports.fetchBillPayApproversListFailure = exports.fetchBillPayApproversListSuccess = exports.fetchBillPayApproversList = exports.fetchBillPayApproversDetails = exports.fetchBillPaySetupApproverViewFailure = exports.fetchBillPaySetupApproverViewSuccess = exports.fetchBillPaySetupApproverView = exports.initialState = void 0;
4
+ exports.clearBillPaySetupApproverView = exports.setListeningToPusherEvent = exports.clearBillPaySetupApproverViewUpdateData = exports.saveBillPaySetupApproverViewUpdateData = exports.initializeBillPaySetupApproverViewUpdateData = exports.saveBillPaySetupApproverViewUpdatesFailure = exports.saveBillPaySetupApproverViewUpdatesSuccess = exports.saveBillPaySetupApproverViewUpdates = exports.reorderBillPayApprovalRulesFailure = exports.reorderBillPayApprovalRulesSuccess = exports.reorderBillPayApprovalRules = exports.deleteBillPayApprovalRuleFailure = exports.deleteBillPayApprovalRuleSuccess = exports.deleteBillPayApprovalRule = exports.fetchBillPayApproversListFailure = exports.fetchBillPayApproversListSuccess = exports.fetchBillPayApproversList = exports.fetchBillPayApproversDetails = exports.fetchBillPaySetupApproverViewFailure = exports.fetchBillPaySetupApproverViewSuccess = exports.fetchBillPaySetupApproverView = exports.initialState = void 0;
5
5
  const toolkit_1 = require("@reduxjs/toolkit");
6
6
  exports.initialState = {
7
7
  fetchState: 'Not-Started',
@@ -17,6 +17,7 @@ exports.initialState = {
17
17
  newApprovalRuleId: undefined,
18
18
  approvalRulesDeleteStatusById: {},
19
19
  billPaySetupApproverViewUpdateData: undefined,
20
+ reorderStatus: { fetchState: 'Not-Started', error: undefined },
20
21
  hasValidState() {
21
22
  return this.fetchState === 'Completed';
22
23
  },
@@ -30,8 +31,11 @@ const billPaySetupApproverView = (0, toolkit_1.createSlice)({
30
31
  draft.fetchState = 'In-Progress';
31
32
  draft.error = undefined;
32
33
  },
33
- prepare(cacheOverride = false, includeUserRoles = true) {
34
- return { payload: { cacheOverride, includeUserRoles } };
34
+ // Approval Rules 3.0 `useV3` arrives from the screen connector
35
+ // (`approval_rule_v3_config` dynamic config) and picks the v1 vs
36
+ // v2 endpoint in the fetch epic.
37
+ prepare(cacheOverride = false, includeUserRoles = true, useV3 = false) {
38
+ return { payload: { cacheOverride, includeUserRoles, useV3 } };
35
39
  },
36
40
  },
37
41
  fetchBillPaySetupApproverViewSuccess: {
@@ -116,8 +120,11 @@ const billPaySetupApproverView = (0, toolkit_1.createSlice)({
116
120
  error: undefined,
117
121
  };
118
122
  },
119
- prepare(approvalRuleId) {
120
- return { payload: { approvalRuleId } };
123
+ // Approval Rules 3.0 — `useV3` flows from the screen connector
124
+ // (`approval_rule_v3_config` dynamic config) so the delete epic
125
+ // can pick the v1 vs v2 endpoint.
126
+ prepare(approvalRuleId, useV3 = false) {
127
+ return { payload: { approvalRuleId, useV3 } };
121
128
  },
122
129
  },
123
130
  deleteBillPayApprovalRuleSuccess: {
@@ -149,13 +156,86 @@ const billPaySetupApproverView = (0, toolkit_1.createSlice)({
149
156
  };
150
157
  },
151
158
  },
152
- saveBillPaySetupApproverViewUpdates(draft) {
153
- if (draft.billPaySetupApproverViewUpdateData != null) {
154
- draft.billPaySetupApproverViewUpdateData.updateStatus = {
155
- fetchState: 'In-Progress',
156
- error: undefined,
157
- };
158
- }
159
+ /**
160
+ * Approval Rules 3.0 list-page drag-and-drop reorder.
161
+ *
162
+ * The trigger action carries the desired ordering as an ID list.
163
+ * The reducer optimistically replaces 'approvalRuleIds' so the
164
+ * list page renders the new order immediately; the epic then
165
+ * fires the PUT and either confirms (success — pulls updated
166
+ * priorities from the response) or recovers (failure — refetches
167
+ * the view so we don't strand a stale local order).
168
+ */
169
+ reorderBillPayApprovalRules: {
170
+ reducer(draft, action) {
171
+ const { approvalRuleIds } = action.payload;
172
+ draft.reorderStatus = { fetchState: 'In-Progress', error: undefined };
173
+ // Stash the pre-reorder order so 'Failure' can restore it
174
+ // synchronously. The epic's refetch on failure remains as a
175
+ // safety net (covers cases where the server's truth has
176
+ // drifted from the local snapshot), but the snappy UX path
177
+ // is the in-memory rollback.
178
+ draft.reorderRollbackIds = draft.approvalRuleIds;
179
+ // Optimistic: render new order immediately. On failure, the
180
+ // reducer restores 'reorderRollbackIds' and the epic refetch
181
+ // reconciles any drift.
182
+ draft.approvalRuleIds = approvalRuleIds;
183
+ },
184
+ prepare(approvalRuleIds, useV3 = false) {
185
+ return { payload: { approvalRuleIds, useV3 } };
186
+ },
187
+ },
188
+ reorderBillPayApprovalRulesSuccess: {
189
+ reducer(draft, action) {
190
+ const { approvalRuleIds } = action.payload;
191
+ draft.reorderStatus = { fetchState: 'Completed', error: undefined };
192
+ // The API response is authoritative — overwrite with the
193
+ // server's reported order in case it normalised anything.
194
+ draft.approvalRuleIds = approvalRuleIds;
195
+ // Reorder succeeded — discard the snapshot so the next
196
+ // reorder starts from this committed order.
197
+ draft.reorderRollbackIds = undefined;
198
+ },
199
+ prepare(approvalRuleIds) {
200
+ return { payload: { approvalRuleIds } };
201
+ },
202
+ },
203
+ reorderBillPayApprovalRulesFailure: {
204
+ reducer(draft, action) {
205
+ const { status } = action.payload;
206
+ draft.reorderStatus = { fetchState: 'Error', error: status };
207
+ // Restore the snapshot taken on the trigger reducer before
208
+ // the optimistic mutation. The epic still fires a refetch
209
+ // alongside the failure action for cross-tab drift recovery,
210
+ // but locally the user sees their last good order instantly.
211
+ if (draft.reorderRollbackIds != null) {
212
+ draft.approvalRuleIds = draft.reorderRollbackIds;
213
+ draft.reorderRollbackIds = undefined;
214
+ }
215
+ },
216
+ prepare(status) {
217
+ return { payload: { status } };
218
+ },
219
+ },
220
+ saveBillPaySetupApproverViewUpdates: {
221
+ // Approval Rules 3.0 — `useV3` is sourced from the
222
+ // `approval_rule_v3_config` dynamic config in the screen
223
+ // connector. The reducer doesn't read it (the field only
224
+ // matters in the save epic), but it must be declared so the
225
+ // action's payload type is correctly inferred for downstream
226
+ // consumers.
227
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
228
+ reducer(draft, _action) {
229
+ if (draft.billPaySetupApproverViewUpdateData != null) {
230
+ draft.billPaySetupApproverViewUpdateData.updateStatus = {
231
+ fetchState: 'In-Progress',
232
+ error: undefined,
233
+ };
234
+ }
235
+ },
236
+ prepare(useV3) {
237
+ return { payload: { useV3 } };
238
+ },
159
239
  },
160
240
  saveBillPaySetupApproverViewUpdatesSuccess: {
161
241
  reducer(draft, action) {
@@ -244,5 +324,5 @@ const billPaySetupApproverView = (0, toolkit_1.createSlice)({
244
324
  },
245
325
  },
246
326
  });
247
- _a = billPaySetupApproverView.actions, exports.fetchBillPaySetupApproverView = _a.fetchBillPaySetupApproverView, exports.fetchBillPaySetupApproverViewSuccess = _a.fetchBillPaySetupApproverViewSuccess, exports.fetchBillPaySetupApproverViewFailure = _a.fetchBillPaySetupApproverViewFailure, exports.fetchBillPayApproversDetails = _a.fetchBillPayApproversDetails, exports.fetchBillPayApproversList = _a.fetchBillPayApproversList, exports.fetchBillPayApproversListSuccess = _a.fetchBillPayApproversListSuccess, exports.fetchBillPayApproversListFailure = _a.fetchBillPayApproversListFailure, exports.deleteBillPayApprovalRule = _a.deleteBillPayApprovalRule, exports.deleteBillPayApprovalRuleSuccess = _a.deleteBillPayApprovalRuleSuccess, exports.deleteBillPayApprovalRuleFailure = _a.deleteBillPayApprovalRuleFailure, exports.saveBillPaySetupApproverViewUpdates = _a.saveBillPaySetupApproverViewUpdates, exports.saveBillPaySetupApproverViewUpdatesSuccess = _a.saveBillPaySetupApproverViewUpdatesSuccess, exports.saveBillPaySetupApproverViewUpdatesFailure = _a.saveBillPaySetupApproverViewUpdatesFailure, exports.initializeBillPaySetupApproverViewUpdateData = _a.initializeBillPaySetupApproverViewUpdateData, exports.saveBillPaySetupApproverViewUpdateData = _a.saveBillPaySetupApproverViewUpdateData, exports.clearBillPaySetupApproverViewUpdateData = _a.clearBillPaySetupApproverViewUpdateData, exports.setListeningToPusherEvent = _a.setListeningToPusherEvent, exports.clearBillPaySetupApproverView = _a.clearBillPaySetupApproverView;
327
+ _a = billPaySetupApproverView.actions, exports.fetchBillPaySetupApproverView = _a.fetchBillPaySetupApproverView, exports.fetchBillPaySetupApproverViewSuccess = _a.fetchBillPaySetupApproverViewSuccess, exports.fetchBillPaySetupApproverViewFailure = _a.fetchBillPaySetupApproverViewFailure, exports.fetchBillPayApproversDetails = _a.fetchBillPayApproversDetails, exports.fetchBillPayApproversList = _a.fetchBillPayApproversList, exports.fetchBillPayApproversListSuccess = _a.fetchBillPayApproversListSuccess, exports.fetchBillPayApproversListFailure = _a.fetchBillPayApproversListFailure, exports.deleteBillPayApprovalRule = _a.deleteBillPayApprovalRule, exports.deleteBillPayApprovalRuleSuccess = _a.deleteBillPayApprovalRuleSuccess, exports.deleteBillPayApprovalRuleFailure = _a.deleteBillPayApprovalRuleFailure, exports.reorderBillPayApprovalRules = _a.reorderBillPayApprovalRules, exports.reorderBillPayApprovalRulesSuccess = _a.reorderBillPayApprovalRulesSuccess, exports.reorderBillPayApprovalRulesFailure = _a.reorderBillPayApprovalRulesFailure, exports.saveBillPaySetupApproverViewUpdates = _a.saveBillPaySetupApproverViewUpdates, exports.saveBillPaySetupApproverViewUpdatesSuccess = _a.saveBillPaySetupApproverViewUpdatesSuccess, exports.saveBillPaySetupApproverViewUpdatesFailure = _a.saveBillPaySetupApproverViewUpdatesFailure, exports.initializeBillPaySetupApproverViewUpdateData = _a.initializeBillPaySetupApproverViewUpdateData, exports.saveBillPaySetupApproverViewUpdateData = _a.saveBillPaySetupApproverViewUpdateData, exports.clearBillPaySetupApproverViewUpdateData = _a.clearBillPaySetupApproverViewUpdateData, exports.setListeningToPusherEvent = _a.setListeningToPusherEvent, exports.clearBillPaySetupApproverView = _a.clearBillPaySetupApproverView;
248
328
  exports.default = billPaySetupApproverView.reducer;
@@ -9,8 +9,24 @@ export interface BillPaySetupApproverViewState extends FetchedState {
9
9
  attributes: AttributeType[];
10
10
  fetchStatus: FetchStateAndError;
11
11
  };
12
+ /**
13
+ * Tracks the in-flight status of the list-page reorder PUT
14
+ * (approval-rules-v2/reorder). The reducer optimistically updates
15
+ * 'approvalRuleIds' on the trigger action. On Failure the reducer
16
+ * restores the snapshot below before the epic's safety-net refetch
17
+ * fires, so the UI bounces back to the user's last good order
18
+ * without waiting for a network roundtrip.
19
+ */
20
+ reorderStatus: FetchStateAndError;
12
21
  affectedEntityIds?: ID[];
13
22
  billPaySetupApproverViewUpdateData?: ApproverViewUpdateData;
14
23
  listeningToPusherEvent?: boolean;
15
24
  newApprovalRuleId?: ID;
25
+ /**
26
+ * Pre-reorder snapshot of 'approvalRuleIds'. Stashed on the trigger
27
+ * reducer right before the optimistic mutation and consumed on
28
+ * Failure to restore the previous order. Cleared on Success so the
29
+ * next reorder starts from a clean slate.
30
+ */
31
+ reorderRollbackIds?: ID[];
16
32
  }
@@ -9,9 +9,17 @@ const userReducer_1 = require("../../../../../entity/user/userReducer");
9
9
  const responsePayload_1 = require("../../../../../responsePayload");
10
10
  const billPaySetupApproverViewReducer_1 = require("../billPaySetupApproverViewReducer");
11
11
  const deleteBillPayApprovalRuleEpic = (actions$, _state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(billPaySetupApproverViewReducer_1.deleteBillPayApprovalRule.match), (0, operators_1.switchMap)((action) => {
12
- const { approvalRuleId } = action.payload;
12
+ const { approvalRuleId, useV3 } = action.payload;
13
+ // Approval Rules 3.0 — flag-gated endpoint selection.
14
+ // Explicit `=== true` keeps `strict-boolean-expressions` happy
15
+ // when RTK's payload type widens to `any` in some configs.
16
+ const endpoint = useV3 === true
17
+ ? `${zeniAPI.apiEndPoints.approvalMicroServiceBaseUrl}/1.0/bill-pay/approval-rules-v2`
18
+ : `${zeniAPI.apiEndPoints.approvalMicroServiceBaseUrl}/1.0/bill-pay/approval-rules`;
13
19
  return zeniAPI
14
- .deleteAndGetJSON(`${zeniAPI.apiEndPoints.approvalMicroServiceBaseUrl}/1.0/bill-pay/approval-rules`, { approval_rule_id: approvalRuleId })
20
+ .deleteAndGetJSON(endpoint, {
21
+ approval_rule_id: approvalRuleId,
22
+ })
15
23
  .pipe((0, operators_1.mergeMap)((response) => {
16
24
  if ((0, responsePayload_1.isSuccessResponse)(response) && response.data != null) {
17
25
  const approvalRuleIds = response.data.approval_rules.map((approvalRule) => approvalRule.approval_rule_id);
@@ -9,7 +9,7 @@ const userReducer_1 = require("../../../../../entity/user/userReducer");
9
9
  const responsePayload_1 = require("../../../../../responsePayload");
10
10
  const billPaySetupApproverViewReducer_1 = require("../billPaySetupApproverViewReducer");
11
11
  const fetchBillPaySetupApproverViewEpic = (actions$, state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(billPaySetupApproverViewReducer_1.fetchBillPaySetupApproverView.match), (0, operators_1.switchMap)((action) => {
12
- const { cacheOverride } = action.payload;
12
+ const { cacheOverride, useV3 } = action.payload;
13
13
  const { billPaySetupApproverViewState, approvalRuleState } = state$.value;
14
14
  const approvalRules = (0, approvalRuleSelector_1.getApprovalRulesByIds)(approvalRuleState, billPaySetupApproverViewState.approvalRuleIds);
15
15
  if (cacheOverride === true ||
@@ -17,9 +17,13 @@ const fetchBillPaySetupApproverViewEpic = (actions$, state$, zeniAPI) => actions
17
17
  billPaySetupApproverViewState.approvalRuleIds.length ||
18
18
  (billPaySetupApproverViewState.hasValidState() === false &&
19
19
  billPaySetupApproverViewState.fetchState !== 'In-Progress')) {
20
- return zeniAPI
21
- .getJSON(`${zeniAPI.apiEndPoints.approvalMicroServiceBaseUrl}/1.0/bill-pay/approval-rules`)
22
- .pipe((0, operators_1.mergeMap)((response) => {
20
+ // Approval Rules 3.0 — flag-gated endpoint selection.
21
+ // Explicit `=== true` keeps `strict-boolean-expressions` happy
22
+ // when RTK's payload type widens to `any` in some configs.
23
+ const endpoint = useV3 === true
24
+ ? `${zeniAPI.apiEndPoints.approvalMicroServiceBaseUrl}/1.0/bill-pay/approval-rules-v2`
25
+ : `${zeniAPI.apiEndPoints.approvalMicroServiceBaseUrl}/1.0/bill-pay/approval-rules`;
26
+ return zeniAPI.getJSON(endpoint).pipe((0, operators_1.mergeMap)((response) => {
23
27
  if ((0, responsePayload_1.isSuccessResponse)(response) && response.data != null) {
24
28
  const approvalRuleIds = response.data.approval_rules.map((approvalRule) => approvalRule.approval_rule_id);
25
29
  const actions = [
@@ -11,16 +11,20 @@ const initializeBillPaySetupApproverViewUpdateDataEpic = (actions$, state$) => a
11
11
  if (approvalRuleId != null) {
12
12
  const approvalRule = (0, approvalRuleSelector_1.getApprovalRuleById)(state$.value.approvalRuleState, approvalRuleId);
13
13
  if (approvalRule != null) {
14
- const criteria = approvalRule.criteria[0];
15
- const range = criteria?.range;
16
14
  const billPaySetupApproverViewUpdateData = {
17
15
  approvalRuleId,
18
16
  steps: approvalRule.steps,
19
17
  criteria: {
20
- rangeType: criteria?.rangeType,
21
- rangeEntity: criteria?.rangeEntity,
22
- range,
18
+ amount: (0, approvalRuleSelector_1.getAmountCriteria)(approvalRule.criteria),
19
+ vendor: (0, approvalRuleSelector_1.getVendorCriteria)(approvalRule.criteria),
20
+ department: (0, approvalRuleSelector_1.getDepartmentCriteria)(approvalRule.criteria),
23
21
  },
22
+ // Approval Rules 3.0 — seed rule-level fields so the form can
23
+ // round-trip them on edit. Each may be undefined on legacy rules.
24
+ name: approvalRule.name,
25
+ description: approvalRule.description,
26
+ separationOfDuties: approvalRule.separationOfDuties,
27
+ isFallback: approvalRule.isFallback,
24
28
  };
25
29
  fetchActions.push((0, billPaySetupApproverViewReducer_1.clearBillPaySetupApproverViewUpdateData)(), (0, billPaySetupApproverViewReducer_1.saveBillPaySetupApproverViewUpdateData)(billPaySetupApproverViewUpdateData));
26
30
  }
@@ -28,7 +32,7 @@ const initializeBillPaySetupApproverViewUpdateDataEpic = (actions$, state$) => a
28
32
  else {
29
33
  const billPaySetupApproverViewCreateData = {
30
34
  steps: [],
31
- criteria: undefined,
35
+ criteria: {},
32
36
  };
33
37
  fetchActions.push((0, billPaySetupApproverViewReducer_1.clearBillPaySetupApproverViewUpdateData)(), (0, billPaySetupApproverViewReducer_1.saveBillPaySetupApproverViewUpdateData)(billPaySetupApproverViewCreateData));
34
38
  }
@@ -0,0 +1,23 @@
1
+ import { ActionsObservable, StateObservable } from 'redux-observable';
2
+ import { Observable } from 'rxjs';
3
+ import { updateApprovalRules } from '../../../../../entity/approvalRule/approvalRuleReducer';
4
+ import { openSnackbar } from '../../../../../entity/snackbar/snackbarReducer';
5
+ import { RootState } from '../../../../../reducer';
6
+ import { ZeniAPI } from '../../../../../zeniAPI';
7
+ import { fetchBillPaySetupApproverView, reorderBillPayApprovalRules, reorderBillPayApprovalRulesFailure, reorderBillPayApprovalRulesSuccess } from '../billPaySetupApproverViewReducer';
8
+ /**
9
+ * Approval Rules 3.0 — list-page drag-and-drop reorder.
10
+ *
11
+ * PUT /bill-pay/approval-rules-v2/reorder with the new ID order in
12
+ * 'rule_ids'. Returns the updated 'approval_rules' (with refreshed
13
+ * priorities). The reducer optimistically updated 'approvalRuleIds'
14
+ * on the trigger action, so:
15
+ * - on success: dispatch the updated approval rule payloads into
16
+ * the entity slice, then 'Success' to normalise the slice's
17
+ * ordered ID list to whatever the server returned.
18
+ * - on failure: snackbar + dispatch 'fetchBillPaySetupApproverView'
19
+ * with cacheOverride to roll the optimistic state back to server
20
+ * truth.
21
+ */
22
+ export type ActionType = ReturnType<typeof reorderBillPayApprovalRules> | ReturnType<typeof reorderBillPayApprovalRulesSuccess> | ReturnType<typeof reorderBillPayApprovalRulesFailure> | ReturnType<typeof updateApprovalRules> | ReturnType<typeof fetchBillPaySetupApproverView> | ReturnType<typeof openSnackbar>;
23
+ export declare const reorderBillPayApprovalRulesEpic: (actions$: ActionsObservable<ActionType>, _state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => Observable<ActionType>;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.reorderBillPayApprovalRulesEpic = void 0;
4
+ const rxjs_1 = require("rxjs");
5
+ const operators_1 = require("rxjs/operators");
6
+ const approvalRuleReducer_1 = require("../../../../../entity/approvalRule/approvalRuleReducer");
7
+ const snackbarReducer_1 = require("../../../../../entity/snackbar/snackbarReducer");
8
+ const responsePayload_1 = require("../../../../../responsePayload");
9
+ const billPaySetupApproverViewReducer_1 = require("../billPaySetupApproverViewReducer");
10
+ const reorderBillPayApprovalRulesEpic = (actions$, _state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(billPaySetupApproverViewReducer_1.reorderBillPayApprovalRules.match), (0, operators_1.switchMap)((action) => {
11
+ const { approvalRuleIds, useV3 } = action.payload;
12
+ // Approval Rules 3.0 — flag-gated endpoint selection. Mirrors
13
+ // the pattern used by delete + fetch epics: the v3 dev host
14
+ // until the production base URL ships the v2 reorder route.
15
+ const endpoint = `${zeniAPI.apiEndPoints.approvalMicroServiceBaseUrl}/1.0/bill-pay/approval-rules-v2/reorder`;
16
+ return zeniAPI
17
+ .putAndGetJSON(endpoint, {
18
+ rule_ids: approvalRuleIds,
19
+ })
20
+ .pipe((0, operators_1.mergeMap)((response) => {
21
+ if ((0, responsePayload_1.isSuccessResponse)(response) && response.data != null) {
22
+ const serverOrderedIds = response.data.approval_rules.map((approvalRule) => approvalRule.approval_rule_id);
23
+ const actions = [
24
+ (0, approvalRuleReducer_1.updateApprovalRules)(response.data.approval_rules),
25
+ (0, billPaySetupApproverViewReducer_1.reorderBillPayApprovalRulesSuccess)(serverOrderedIds),
26
+ (0, snackbarReducer_1.openSnackbar)({
27
+ messageSection: `bill_pay_approval_reorder`,
28
+ messageText: 'success',
29
+ type: 'success',
30
+ }),
31
+ ];
32
+ return (0, rxjs_1.from)(actions);
33
+ }
34
+ else {
35
+ const recovery = [
36
+ (0, billPaySetupApproverViewReducer_1.reorderBillPayApprovalRulesFailure)(response.status),
37
+ (0, snackbarReducer_1.openSnackbar)({
38
+ messageSection: `bill_pay_approval_reorder`,
39
+ messageText: 'failed',
40
+ type: 'error',
41
+ }),
42
+ // Refetch to revert the optimistic order to server truth.
43
+ (0, billPaySetupApproverViewReducer_1.fetchBillPaySetupApproverView)(true, true, useV3),
44
+ ];
45
+ return (0, rxjs_1.from)(recovery);
46
+ }
47
+ }), (0, operators_1.catchError)((error) => (0, rxjs_1.from)([
48
+ (0, billPaySetupApproverViewReducer_1.reorderBillPayApprovalRulesFailure)((0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', 'Reorder Bill Pay Approval Rules errored out' +
49
+ JSON.stringify(error))),
50
+ (0, snackbarReducer_1.openSnackbar)({
51
+ messageSection: `bill_pay_approval_reorder`,
52
+ messageText: 'failed',
53
+ type: 'error',
54
+ }),
55
+ (0, billPaySetupApproverViewReducer_1.fetchBillPaySetupApproverView)(true, true, useV3),
56
+ ])));
57
+ }));
58
+ exports.reorderBillPayApprovalRulesEpic = reorderBillPayApprovalRulesEpic;
@@ -9,14 +9,23 @@ const userReducer_1 = require("../../../../../entity/user/userReducer");
9
9
  const responsePayload_1 = require("../../../../../responsePayload");
10
10
  const billPaySetupApproverViewReducer_1 = require("../billPaySetupApproverViewReducer");
11
11
  const commonPayload_1 = require("../types/commonPayload");
12
- const saveBillPaySetupApproverViewUpdatesEpic = (actions$, state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(billPaySetupApproverViewReducer_1.saveBillPaySetupApproverViewUpdates.match), (0, operators_1.switchMap)(() => {
12
+ const saveBillPaySetupApproverViewUpdatesEpic = (actions$, state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(billPaySetupApproverViewReducer_1.saveBillPaySetupApproverViewUpdates.match), (0, operators_1.switchMap)((action) => {
13
13
  const { billPaySetupApproverViewState } = state$.value;
14
14
  const billPaySetupApproverViewUpdateData = billPaySetupApproverViewState.billPaySetupApproverViewUpdateData;
15
15
  if (billPaySetupApproverViewUpdateData != null &&
16
16
  billPaySetupApproverViewUpdateData.data != null) {
17
- const payload = (0, commonPayload_1.toApprovalChangableInfoPayload)(billPaySetupApproverViewUpdateData.data);
17
+ // Approval Rules 3.0 — gate URL + write-side payload mapper on
18
+ // the `approval_rule_v3_config` dynamic config. `useV3` arrives
19
+ // on the action payload from the screen connector.
20
+ const { useV3 } = action.payload;
21
+ const payload = useV3
22
+ ? (0, commonPayload_1.toApprovalChangableInfoPayload)(billPaySetupApproverViewUpdateData.data)
23
+ : (0, commonPayload_1.toApprovalChangableInfoPayloadV1)(billPaySetupApproverViewUpdateData.data);
24
+ const endpoint = useV3
25
+ ? `${zeniAPI.apiEndPoints.approvalMicroServiceBaseUrl}/1.0/bill-pay/approval-rules-v2`
26
+ : `${zeniAPI.apiEndPoints.approvalMicroServiceBaseUrl}/1.0/bill-pay/approval-rules`;
18
27
  return zeniAPI
19
- .postAndGetJSON(`${zeniAPI.apiEndPoints.approvalMicroServiceBaseUrl}/1.0/bill-pay/approval-rules`, payload)
28
+ .postAndGetJSON(endpoint, payload)
20
29
  .pipe((0, operators_1.mergeMap)((response) => {
21
30
  if ((0, responsePayload_1.isSuccessResponse)(response) && response.data != null) {
22
31
  const approvalRuleIds = response.data.approval_rules.map((approvalRule) => approvalRule.approval_rule_id);
@@ -14,9 +14,58 @@ interface ApproverViewStepPayload extends Omit<StepPayload, 'actors'> {
14
14
  }
15
15
  interface ApprovalUpdatableInfoPayload {
16
16
  approval_rule_id: ID;
17
- criteria: CriteriaPayload[];
17
+ criteria: CriteriaPayload;
18
18
  is_applicable_on_pending_approval_entity: boolean;
19
19
  steps: ApproverViewStepPayload[];
20
+ description?: string;
21
+ is_fallback?: boolean;
22
+ is_separation_of_duty_enabled?: boolean;
23
+ /**
24
+ * Approval Rules 3.0 — rule-level wire fields. The backend accepts these
25
+ * as optional today; once 3.0 ships they become first-class. The SoD
26
+ * field name matches the GET response shape (confirmed with backend),
27
+ * so the same identifier flows both directions on the wire.
28
+ */
29
+ name?: string;
30
+ }
31
+ /**
32
+ * V1 / pre-3.0 wire shape. Kept so the rollback flag (gated by
33
+ * `approval_rule_v3_config` dynamic config) can target the original
34
+ * `/approval-rules` endpoint with the legacy `{rangeType, rangeEntity, range}`
35
+ * criteria. None of the 3.0 rule-level fields are sent.
36
+ */
37
+ interface ApprovalUpdatableInfoPayloadV1 {
38
+ criteria: {
39
+ range: {
40
+ max: {
41
+ amount: number;
42
+ currencyCode: string;
43
+ currencySymbol: string;
44
+ };
45
+ min: {
46
+ amount: number;
47
+ currencyCode: string;
48
+ currencySymbol: string;
49
+ };
50
+ };
51
+ rangeEntity: 'currency';
52
+ rangeType: 'range';
53
+ };
54
+ is_applicable_on_pending_approval_entity: boolean;
55
+ steps: ApproverViewStepPayload[];
56
+ approval_rule_id?: ID;
20
57
  }
21
58
  export declare const toApprovalChangableInfoPayload: (approverViewUpdateData: ApprovalRuleUpdateData | ApprovalRuleCreateData) => Partial<ApprovalUpdatableInfoPayload>;
59
+ /**
60
+ * V1 wire mapper — used when `approval_rule_v3_config` resolves to OFF
61
+ * for the current tenant. Translates the form-side amount criteria into
62
+ * the legacy `{rangeType, rangeEntity, range: {min, max}}` shape. The
63
+ * V1 backend does not understand vendor / department criteria or the
64
+ * rule-level 3.0 fields, so those are dropped on the wire.
65
+ *
66
+ * The form-side amount slot is always read as a `range`-style criteria
67
+ * here: V1 schemas only supported ranges, so an absent `min` or `max`
68
+ * falls back to `0` / `Number.MAX_SAFE_INTEGER`.
69
+ */
70
+ export declare const toApprovalChangableInfoPayloadV1: (approverViewUpdateData: ApprovalRuleUpdateData | ApprovalRuleCreateData) => Partial<ApprovalUpdatableInfoPayloadV1>;
22
71
  export {};
@@ -1,23 +1,51 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toApprovalChangableInfoPayload = void 0;
3
+ exports.toApprovalChangableInfoPayloadV1 = exports.toApprovalChangableInfoPayload = void 0;
4
4
  const toApprovalChangableInfoPayload = (approverViewUpdateData) => {
5
- let criteriaPayload = [];
5
+ // Form-side criteria is a structured object with optional slots for
6
+ // amount / vendor / department; flatten it into the wire format's
7
+ // `conditions[]` array.
8
+ let criteriaPayload;
6
9
  if (approverViewUpdateData.criteria != null) {
7
- const criteria = approverViewUpdateData.criteria;
8
- const { rangeType, rangeEntity, range } = criteria;
9
- const { min, max } = range;
10
- const { currencyCode, currencySymbol } = min;
11
- criteriaPayload = [
12
- {
13
- type: rangeType,
14
- range_entity: rangeEntity,
15
- min: min.amount,
16
- max: max?.amount ?? null,
17
- currency_code: currencyCode,
18
- currency_symbol: currencySymbol,
19
- },
20
- ];
10
+ const { amount, vendor, department } = approverViewUpdateData.criteria;
11
+ const conditions = [];
12
+ if (amount?.min != null) {
13
+ conditions.push({
14
+ field: 'amount',
15
+ type: 'gte',
16
+ value: amount.min.amount,
17
+ });
18
+ }
19
+ if (amount?.max != null) {
20
+ conditions.push({
21
+ field: 'amount',
22
+ type: 'lte',
23
+ value: amount.max.amount,
24
+ });
25
+ }
26
+ if (vendor != null && vendor.vendorIds.length > 0) {
27
+ conditions.push({
28
+ field: 'vendor_id',
29
+ type: vendor.operator === 'is_not' ? 'not_in' : 'in',
30
+ value: vendor.vendorIds,
31
+ });
32
+ }
33
+ if (department != null && department.departmentIds.length > 0) {
34
+ conditions.push({
35
+ field: 'department_id',
36
+ type: department.operator === 'is_not' ? 'not_in' : 'in',
37
+ value: department.departmentIds,
38
+ });
39
+ }
40
+ if (conditions.length > 0) {
41
+ const currency = amount?.min ?? amount?.max ?? null;
42
+ criteriaPayload = {
43
+ conditions,
44
+ criteria_operator: 'and',
45
+ currency_code: currency?.currencyCode ?? 'USD',
46
+ currency_symbol: currency?.currencySymbol ?? '$',
47
+ };
48
+ }
21
49
  }
22
50
  const steps = approverViewUpdateData.steps.map((step) => {
23
51
  return {
@@ -38,13 +66,92 @@ const toApprovalChangableInfoPayload = (approverViewUpdateData) => {
38
66
  });
39
67
  const isUpdate = approverViewUpdateData.approvalRuleId != null;
40
68
  const payload = {
41
- criteria: criteriaPayload,
42
69
  steps,
43
70
  is_applicable_on_pending_approval_entity: approverViewUpdateData.isApplicableOnPendingApprovalEntity ?? true,
44
71
  };
72
+ if (criteriaPayload != null) {
73
+ payload.criteria = criteriaPayload;
74
+ }
75
+ // Approval Rules 3.0 — surface rule-level fields when the form set them.
76
+ // Send only what the user actually entered: an undefined value means
77
+ // "no opinion" and stays off the wire.
78
+ if (approverViewUpdateData.name != null) {
79
+ payload.name = approverViewUpdateData.name;
80
+ }
81
+ if (approverViewUpdateData.description != null) {
82
+ payload.description = approverViewUpdateData.description;
83
+ }
84
+ if (approverViewUpdateData.separationOfDuties != null) {
85
+ payload.is_separation_of_duty_enabled =
86
+ approverViewUpdateData.separationOfDuties;
87
+ }
88
+ if (approverViewUpdateData.isFallback != null) {
89
+ payload.is_fallback = approverViewUpdateData.isFallback;
90
+ }
45
91
  if (isUpdate) {
46
92
  payload.approval_rule_id = approverViewUpdateData.approvalRuleId;
47
93
  }
48
94
  return payload;
49
95
  };
50
96
  exports.toApprovalChangableInfoPayload = toApprovalChangableInfoPayload;
97
+ /**
98
+ * V1 wire mapper — used when `approval_rule_v3_config` resolves to OFF
99
+ * for the current tenant. Translates the form-side amount criteria into
100
+ * the legacy `{rangeType, rangeEntity, range: {min, max}}` shape. The
101
+ * V1 backend does not understand vendor / department criteria or the
102
+ * rule-level 3.0 fields, so those are dropped on the wire.
103
+ *
104
+ * The form-side amount slot is always read as a `range`-style criteria
105
+ * here: V1 schemas only supported ranges, so an absent `min` or `max`
106
+ * falls back to `0` / `Number.MAX_SAFE_INTEGER`.
107
+ */
108
+ const toApprovalChangableInfoPayloadV1 = (approverViewUpdateData) => {
109
+ const amount = approverViewUpdateData.criteria?.amount;
110
+ const minAmount = amount?.min;
111
+ const maxAmount = amount?.max;
112
+ const currencyCode = minAmount?.currencyCode ?? maxAmount?.currencyCode ?? 'USD';
113
+ const currencySymbol = minAmount?.currencySymbol ?? maxAmount?.currencySymbol ?? '$';
114
+ const steps = approverViewUpdateData.steps.map((step) => {
115
+ return {
116
+ action: step.action,
117
+ operator: step.operator,
118
+ actors: step.actors
119
+ .filter((actor) => actor.subType !== 'admin')
120
+ .map((actor) => {
121
+ return {
122
+ type: actor.type,
123
+ id: actor.userId ?? null,
124
+ sub_type: actor.subType ?? null,
125
+ id_type: actor.idType ?? null,
126
+ is_implicit_actor: actor.isImplicitActor ?? false,
127
+ };
128
+ }),
129
+ };
130
+ });
131
+ const isUpdate = approverViewUpdateData.approvalRuleId != null;
132
+ const payload = {
133
+ steps,
134
+ is_applicable_on_pending_approval_entity: approverViewUpdateData.isApplicableOnPendingApprovalEntity ?? true,
135
+ criteria: {
136
+ rangeType: 'range',
137
+ rangeEntity: 'currency',
138
+ range: {
139
+ min: {
140
+ amount: minAmount?.amount ?? 0,
141
+ currencyCode,
142
+ currencySymbol,
143
+ },
144
+ max: {
145
+ amount: maxAmount?.amount ?? Number.MAX_SAFE_INTEGER,
146
+ currencyCode,
147
+ currencySymbol,
148
+ },
149
+ },
150
+ },
151
+ };
152
+ if (isUpdate) {
153
+ payload.approval_rule_id = approverViewUpdateData.approvalRuleId;
154
+ }
155
+ return payload;
156
+ };
157
+ exports.toApprovalChangableInfoPayloadV1 = toApprovalChangableInfoPayloadV1;
@@ -1,19 +1,45 @@
1
1
  import { FetchStateAndError, ID } from '../../../../../commonStateTypes/common';
2
- import { Criteria, Step } from '../../../../../entity/approvalRule/approvalRuleState';
2
+ import { AmountCriteria, DepartmentCriteria, Step, VendorCriteria } from '../../../../../entity/approvalRule/approvalRuleState';
3
3
  export type ApprovalUpdateActionType = 'approval_create' | 'approval_update';
4
4
  export interface ApproverViewUpdateData {
5
5
  type: ApprovalUpdateActionType;
6
6
  updateStatus: FetchStateAndError;
7
7
  data?: ApprovalRuleUpdateData | ApprovalRuleCreateData;
8
8
  }
9
- export interface ApprovalRuleUpdateData {
9
+ /**
10
+ * Form-side criteria shape used by the rule create/edit form.
11
+ *
12
+ * Each condition kind gets its own optional slot, mirroring how the UI
13
+ * edits them as distinct rows. At most one of each kind is present; this
14
+ * matches the design constraint that each condition type can be added once.
15
+ */
16
+ export interface ApprovalRuleFormCriteria {
17
+ amount?: AmountCriteria;
18
+ department?: DepartmentCriteria;
19
+ vendor?: VendorCriteria;
20
+ }
21
+ /**
22
+ * Rule-level fields shared by both create and update flows.
23
+ *
24
+ * These come from the 3.0 design: the form now owns a name, an optional
25
+ * description, an optional Separation-of-Duties toggle, and a flag that
26
+ * marks the rule as the org-wide fallback rule. They live alongside
27
+ * criteria/steps but are not part of either.
28
+ */
29
+ export interface ApprovalRuleFormBase {
30
+ description?: string;
31
+ isFallback?: boolean;
32
+ name?: string;
33
+ separationOfDuties?: boolean;
34
+ }
35
+ export interface ApprovalRuleUpdateData extends ApprovalRuleFormBase {
10
36
  approvalRuleId: ID;
11
- criteria: Criteria;
37
+ criteria: ApprovalRuleFormCriteria;
12
38
  steps: Step[];
13
39
  isApplicableOnPendingApprovalEntity?: boolean;
14
40
  }
15
- export interface ApprovalRuleCreateData {
16
- criteria: Criteria;
41
+ export interface ApprovalRuleCreateData extends ApprovalRuleFormBase {
42
+ criteria: ApprovalRuleFormCriteria;
17
43
  steps: Step[];
18
44
  isApplicableOnPendingApprovalEntity?: boolean;
19
45
  }