@zeniai/client-epic-state 5.0.82 → 5.0.83-betaRR0

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 (139) hide show
  1. package/lib/common/aiCfo/aiCfoSuggestedQuestionsPageContext.d.ts +1 -1
  2. package/lib/entity/aiCfo/aiCfoPayload.d.ts +140 -1
  3. package/lib/entity/aiCfo/aiCfoReducer.d.ts +23 -2
  4. package/lib/entity/aiCfo/aiCfoReducer.js +328 -5
  5. package/lib/entity/aiCfo/aiCfoSelector.d.ts +13 -1
  6. package/lib/entity/aiCfo/aiCfoSelector.js +28 -1
  7. package/lib/entity/aiCfo/aiCfoState.d.ts +225 -4
  8. package/lib/entity/aiCfo/aiCfoState.js +30 -1
  9. package/lib/entity/cardPolicy/cardPolicyPayload.d.ts +277 -0
  10. package/lib/entity/cardPolicy/cardPolicyPayload.js +143 -0
  11. package/lib/entity/cardPolicy/cardPolicyReducer.d.ts +19 -0
  12. package/lib/entity/cardPolicy/cardPolicyReducer.js +175 -0
  13. package/lib/entity/cardPolicy/cardPolicySelector.d.ts +32 -0
  14. package/lib/entity/cardPolicy/cardPolicySelector.js +99 -0
  15. package/lib/entity/cardPolicy/cardPolicyState.d.ts +205 -0
  16. package/lib/entity/cardPolicy/cardPolicyState.js +14 -0
  17. package/lib/entity/cardPolicy/extractPolicyDocumentEpic.d.ts +18 -0
  18. package/lib/entity/cardPolicy/extractPolicyDocumentEpic.js +68 -0
  19. package/lib/entity/cardPolicy/fetchCardPolicyVendorOptionsEpic.d.ts +26 -0
  20. package/lib/entity/cardPolicy/fetchCardPolicyVendorOptionsEpic.js +47 -0
  21. package/lib/entity/cardPolicy/policyDocumentExtractionToRecommendationBridgeEpic.d.ts +25 -0
  22. package/lib/entity/cardPolicy/policyDocumentExtractionToRecommendationBridgeEpic.js +39 -0
  23. package/lib/entity/cardPolicy/policyRecommendationFromUploadEpic.d.ts +23 -0
  24. package/lib/entity/cardPolicy/policyRecommendationFromUploadEpic.js +104 -0
  25. package/lib/entity/jeSchedules/jeSchedulesTypes.d.ts +1 -1
  26. package/lib/entity/monthEndCloseChecks/monthEndCloseChecksState.d.ts +1 -1
  27. package/lib/entity/snackbar/snackbarTypes.d.ts +1 -1
  28. package/lib/entity/snackbar/snackbarTypes.js +3 -0
  29. package/lib/entity/tenant/clearAllEpic.d.ts +6 -2
  30. package/lib/entity/tenant/clearAllEpic.js +8 -0
  31. package/lib/epic.d.ts +11 -1
  32. package/lib/epic.js +11 -1
  33. package/lib/esm/entity/aiCfo/aiCfoReducer.js +328 -5
  34. package/lib/esm/entity/aiCfo/aiCfoSelector.js +26 -1
  35. package/lib/esm/entity/aiCfo/aiCfoState.js +27 -0
  36. package/lib/esm/entity/cardPolicy/cardPolicyPayload.js +130 -0
  37. package/lib/esm/entity/cardPolicy/cardPolicyReducer.js +171 -0
  38. package/lib/esm/entity/cardPolicy/cardPolicySelector.js +75 -0
  39. package/lib/esm/entity/cardPolicy/cardPolicyState.js +9 -0
  40. package/lib/esm/entity/cardPolicy/extractPolicyDocumentEpic.js +64 -0
  41. package/lib/esm/entity/cardPolicy/fetchCardPolicyVendorOptionsEpic.js +43 -0
  42. package/lib/esm/entity/cardPolicy/policyDocumentExtractionToRecommendationBridgeEpic.js +35 -0
  43. package/lib/esm/entity/cardPolicy/policyRecommendationFromUploadEpic.js +100 -0
  44. package/lib/esm/entity/snackbar/snackbarTypes.js +3 -0
  45. package/lib/esm/entity/tenant/clearAllEpic.js +8 -0
  46. package/lib/esm/epic.js +11 -1
  47. package/lib/esm/index.js +26 -8
  48. package/lib/esm/reducer.js +12 -0
  49. package/lib/esm/view/aiCfoView/aiCfoViewReducer.js +6 -3
  50. package/lib/esm/view/aiCfoView/epics/createSessionAndSubmitEpic.js +5 -2
  51. package/lib/esm/view/aiCfoView/epics/createSessionEpic.js +2 -1
  52. package/lib/esm/view/aiCfoView/epics/fetchSuggestedQuestionsEpic.js +12 -2
  53. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailReducer.js +70 -0
  54. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailSelector.js +22 -0
  55. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailState.js +1 -0
  56. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/fetchCardPolicyDetailEpic.js +56 -0
  57. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/updateCardPolicyEpic.js +49 -0
  58. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/archiveCardPolicyEpic.js +42 -0
  59. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListReducer.js +72 -0
  60. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListSelector.js +21 -0
  61. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListState.js +1 -0
  62. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/fetchCardPolicyListEpic.js +56 -0
  63. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyReducer.js +45 -0
  64. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicySelector.js +39 -0
  65. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyState.js +1 -0
  66. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyTemplateEpic.js +53 -0
  67. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/fetchCardPolicyMccCategoriesEpic.js +25 -0
  68. package/lib/esm/view/spendManagement/chargeCards/chargeCardList/chargeCardListSelector.js +25 -0
  69. package/lib/esm/view/spendManagement/chargeCards/issueChargeCard/aiCardCreationFormDraftTypes.js +1 -0
  70. package/lib/esm/view/spendManagement/chargeCards/issueChargeCard/buildAiCardCreationFormDraftSeed.js +62 -0
  71. package/lib/esm/view/spendManagement/chargeCards/issueChargeCard/deriveAiCardRowsFromTeams.js +47 -0
  72. package/lib/esm/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardEpic.js +2 -2
  73. package/lib/esm/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardReducer.js +62 -4
  74. package/lib/esm/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardSelector.js +61 -0
  75. package/lib/esm/view/spendManagement/chargeCards/issueChargeCard/toIssueChargeCardLocalDataFromDraft.js +69 -0
  76. package/lib/index.d.ts +25 -8
  77. package/lib/index.js +139 -13
  78. package/lib/reducer.d.ts +12 -0
  79. package/lib/reducer.js +12 -0
  80. package/lib/view/aiCfoView/aiCfoViewReducer.d.ts +11 -2
  81. package/lib/view/aiCfoView/aiCfoViewReducer.js +6 -3
  82. package/lib/view/aiCfoView/epics/createSessionAndSubmitEpic.js +5 -2
  83. package/lib/view/aiCfoView/epics/createSessionEpic.js +2 -1
  84. package/lib/view/aiCfoView/epics/fetchSuggestedQuestionsEpic.d.ts +8 -1
  85. package/lib/view/aiCfoView/epics/fetchSuggestedQuestionsEpic.js +12 -2
  86. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
  87. package/lib/view/expenseAutomationView/types/reconciliationViewState.d.ts +1 -1
  88. package/lib/view/people/peopleTypes.d.ts +1 -1
  89. package/lib/view/scheduleView/scheduleListView/scheduleListTypes.d.ts +1 -1
  90. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailReducer.d.ts +14 -0
  91. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailReducer.js +74 -0
  92. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailSelector.d.ts +21 -0
  93. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailSelector.js +28 -0
  94. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailState.d.ts +25 -0
  95. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailState.js +2 -0
  96. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/fetchCardPolicyDetailEpic.d.ts +19 -0
  97. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/fetchCardPolicyDetailEpic.js +60 -0
  98. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/updateCardPolicyEpic.d.ts +18 -0
  99. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/updateCardPolicyEpic.js +53 -0
  100. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/archiveCardPolicyEpic.d.ts +16 -0
  101. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/archiveCardPolicyEpic.js +46 -0
  102. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListReducer.d.ts +15 -0
  103. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListReducer.js +76 -0
  104. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListSelector.d.ts +21 -0
  105. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListSelector.js +27 -0
  106. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListState.d.ts +19 -0
  107. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListState.js +2 -0
  108. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/fetchCardPolicyListEpic.d.ts +19 -0
  109. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/fetchCardPolicyListEpic.js +60 -0
  110. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyReducer.d.ts +13 -0
  111. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyReducer.js +49 -0
  112. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicySelector.d.ts +32 -0
  113. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicySelector.js +46 -0
  114. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyState.d.ts +45 -0
  115. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyState.js +2 -0
  116. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyTemplateEpic.d.ts +25 -0
  117. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyTemplateEpic.js +57 -0
  118. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/fetchCardPolicyMccCategoriesEpic.d.ts +15 -0
  119. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/fetchCardPolicyMccCategoriesEpic.js +29 -0
  120. package/lib/view/spendManagement/chargeCards/chargeCardList/chargeCardList.d.ts +1 -1
  121. package/lib/view/spendManagement/chargeCards/chargeCardList/chargeCardListSelector.d.ts +14 -0
  122. package/lib/view/spendManagement/chargeCards/chargeCardList/chargeCardListSelector.js +27 -1
  123. package/lib/view/spendManagement/chargeCards/issueChargeCard/aiCardCreationFormDraftTypes.d.ts +79 -0
  124. package/lib/view/spendManagement/chargeCards/issueChargeCard/aiCardCreationFormDraftTypes.js +2 -0
  125. package/lib/view/spendManagement/chargeCards/issueChargeCard/buildAiCardCreationFormDraftSeed.d.ts +25 -0
  126. package/lib/view/spendManagement/chargeCards/issueChargeCard/buildAiCardCreationFormDraftSeed.js +66 -0
  127. package/lib/view/spendManagement/chargeCards/issueChargeCard/deriveAiCardRowsFromTeams.d.ts +26 -0
  128. package/lib/view/spendManagement/chargeCards/issueChargeCard/deriveAiCardRowsFromTeams.js +51 -0
  129. package/lib/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardEpic.d.ts +2 -2
  130. package/lib/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardEpic.js +1 -1
  131. package/lib/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardReducer.d.ts +12 -2
  132. package/lib/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardReducer.js +63 -5
  133. package/lib/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardSelector.d.ts +42 -0
  134. package/lib/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardSelector.js +68 -1
  135. package/lib/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardState.d.ts +18 -0
  136. package/lib/view/spendManagement/chargeCards/issueChargeCard/toIssueChargeCardLocalDataFromDraft.d.ts +11 -0
  137. package/lib/view/spendManagement/chargeCards/issueChargeCard/toIssueChargeCardLocalDataFromDraft.js +73 -0
  138. package/lib/view/taskManager/taskListView/taskListReducer.d.ts +1 -1
  139. package/package.json +1 -1
@@ -0,0 +1,171 @@
1
+ import { createSlice } from '@reduxjs/toolkit';
2
+ import { toCardPolicyTemplate, toCardPolicyVendorSearchOption, toExtractedCardPolicyRules, toMccCategory, } from './cardPolicyPayload';
3
+ // `buildVendorChipId(name)` calls `name.trim().toLowerCase()`; empty/whitespace names would crash or collapse into one colliding chip-id.
4
+ const isUsableMerchantName = (name) => typeof name === 'string' && name.trim() !== '';
5
+ const initialPolicyDocumentExtractionState = {
6
+ fetchState: 'Not-Started',
7
+ error: undefined,
8
+ extractedRules: undefined,
9
+ uploadedFileName: undefined,
10
+ };
11
+ const initialPolicyRecommendationFromUploadState = {
12
+ fetchState: 'Not-Started',
13
+ answerId: undefined,
14
+ chatSessionId: undefined,
15
+ error: undefined,
16
+ };
17
+ const initialVendorSearchState = {
18
+ fetchState: 'Not-Started',
19
+ searchString: '',
20
+ vendors: [],
21
+ error: undefined,
22
+ };
23
+ export const initialState = {
24
+ cardPolicyTemplateById: {},
25
+ mccCategories: [],
26
+ mccCategoriesError: undefined,
27
+ mccCategoriesFetchState: 'Not-Started',
28
+ policyDocumentExtraction: initialPolicyDocumentExtractionState,
29
+ policyRecommendationFromUpload: initialPolicyRecommendationFromUploadState,
30
+ suggestedAllowCategories: [],
31
+ suggestedAllowMerchants: [],
32
+ suggestedBlockCategories: [],
33
+ suggestedBlockMerchants: [],
34
+ vendorSearch: initialVendorSearchState,
35
+ cardPolicyStats: undefined,
36
+ };
37
+ const cardPolicy = createSlice({
38
+ name: 'cardPolicy',
39
+ initialState,
40
+ reducers: {
41
+ fetchCardPolicyMccCategories(draft) {
42
+ draft.mccCategoriesFetchState = 'In-Progress';
43
+ draft.mccCategoriesError = undefined;
44
+ },
45
+ updateCardPolicyMccCategories(draft, action) {
46
+ draft.mccCategories = (action.payload.categories ?? []).map(toMccCategory);
47
+ // BE-suggested seeds pre-populate the chip cloud; `isUsableMerchantName` drops names that would break `buildVendorChipId`.
48
+ draft.suggestedAllowMerchants = (action.payload.suggested_allow_merchants ?? []).filter(isUsableMerchantName);
49
+ draft.suggestedBlockMerchants = (action.payload.suggested_block_merchants ?? []).filter(isUsableMerchantName);
50
+ draft.suggestedAllowCategories = (action.payload.suggested_allow_catagories ?? []).map(toMccCategory);
51
+ draft.suggestedBlockCategories = (action.payload.suggested_block_catagories ?? []).map(toMccCategory);
52
+ draft.mccCategoriesFetchState = 'Completed';
53
+ draft.mccCategoriesError = undefined;
54
+ },
55
+ updateCardPolicyMccCategoriesFailure(draft, action) {
56
+ draft.mccCategoriesFetchState = 'Error';
57
+ draft.mccCategoriesError = action.payload;
58
+ },
59
+ updateCreatedCardPolicyTemplate(draft, action) {
60
+ const template = toCardPolicyTemplate(action.payload);
61
+ draft.cardPolicyTemplateById[template.templateId] = template;
62
+ },
63
+ // Full replace so server-side deletes evict locally too; the view slice owns the ordered ID list.
64
+ updateCardPolicyTemplates(draft, action) {
65
+ const byId = {};
66
+ for (const template of action.payload) {
67
+ byId[template.templateId] = template;
68
+ }
69
+ draft.cardPolicyTemplateById = byId;
70
+ },
71
+ removeCardPolicyTemplate(draft, action) {
72
+ delete draft.cardPolicyTemplateById[action.payload];
73
+ },
74
+ updateCardPolicyStats(draft, action) {
75
+ draft.cardPolicyStats = action.payload;
76
+ },
77
+ // Captures the first file name so the upload pill can render without callers retaining a File ref.
78
+ extractPolicyDocument: {
79
+ reducer(draft, action) {
80
+ draft.policyDocumentExtraction.fetchState = 'In-Progress';
81
+ draft.policyDocumentExtraction.error = undefined;
82
+ draft.policyDocumentExtraction.extractedRules = undefined;
83
+ draft.policyDocumentExtraction.uploadedFileName =
84
+ action.meta.uploadedFileName;
85
+ draft.policyDocumentExtraction.aiCfoAnswerId =
86
+ action.payload.aiCfoAnswerId;
87
+ draft.policyDocumentExtraction.aiCfoChatSessionId =
88
+ action.payload.aiCfoChatSessionId;
89
+ // Extraction + recommendation model one upload lifecycle; reset together so a re-upload doesn't read stale lifecycle from the prior chain.
90
+ draft.policyRecommendationFromUpload = {
91
+ ...initialPolicyRecommendationFromUploadState,
92
+ };
93
+ },
94
+ prepare(files, aiCfoAnswerId, aiCfoChatSessionId) {
95
+ return {
96
+ payload: { files, aiCfoAnswerId, aiCfoChatSessionId },
97
+ meta: { uploadedFileName: files[0]?.name },
98
+ };
99
+ },
100
+ },
101
+ updatePolicyDocumentExtractionSuccess(draft, action) {
102
+ draft.policyDocumentExtraction.fetchState = 'Completed';
103
+ draft.policyDocumentExtraction.error = undefined;
104
+ draft.policyDocumentExtraction.extractedRules =
105
+ toExtractedCardPolicyRules(action.payload);
106
+ },
107
+ updatePolicyDocumentExtractionFailure(draft, action) {
108
+ draft.policyDocumentExtraction.fetchState = 'Error';
109
+ draft.policyDocumentExtraction.error = action.payload;
110
+ draft.policyDocumentExtraction.extractedRules = undefined;
111
+ },
112
+ clearPolicyDocumentExtraction(draft) {
113
+ draft.policyDocumentExtraction = {
114
+ ...initialPolicyDocumentExtractionState,
115
+ };
116
+ // Pair with extractPolicyDocument: the two sub-slices reset and advance together.
117
+ draft.policyRecommendationFromUpload = {
118
+ ...initialPolicyRecommendationFromUploadState,
119
+ };
120
+ },
121
+ // Chained after extractPolicyDocument; epic merges the returned wizard plan into the AI CFO answer identified by answerId + chatSessionId.
122
+ fetchCardPolicyRecommendationFromUpload: {
123
+ reducer(draft, action) {
124
+ draft.policyRecommendationFromUpload.fetchState = 'In-Progress';
125
+ draft.policyRecommendationFromUpload.answerId = action.payload.answerId;
126
+ draft.policyRecommendationFromUpload.chatSessionId =
127
+ action.payload.chatSessionId;
128
+ draft.policyRecommendationFromUpload.error = undefined;
129
+ },
130
+ prepare(answerId, chatSessionId, extractedRules) {
131
+ return { payload: { answerId, chatSessionId, extractedRules } };
132
+ },
133
+ },
134
+ updatePolicyRecommendationFromUploadSuccess(draft) {
135
+ draft.policyRecommendationFromUpload.fetchState = 'Completed';
136
+ draft.policyRecommendationFromUpload.error = undefined;
137
+ },
138
+ updatePolicyRecommendationFromUploadFailure(draft, action) {
139
+ draft.policyRecommendationFromUpload.fetchState = 'Error';
140
+ draft.policyRecommendationFromUpload.error = action.payload;
141
+ },
142
+ // Empty searchString = top vendors by YTD spend; non-empty filters server-side.
143
+ fetchCardPolicyVendorOptions: {
144
+ reducer(draft, action) {
145
+ draft.vendorSearch.fetchState = 'In-Progress';
146
+ draft.vendorSearch.searchString = action.payload.searchString;
147
+ draft.vendorSearch.error = undefined;
148
+ },
149
+ prepare(searchString) {
150
+ return { payload: { searchString: searchString ?? '' } };
151
+ },
152
+ },
153
+ updateCardPolicyVendorOptions(draft, action) {
154
+ // Same `buildVendorChipId` guard as the suggested-merchants seeds above.
155
+ draft.vendorSearch.vendors = (action.payload.vendors ?? [])
156
+ .map(toCardPolicyVendorSearchOption)
157
+ .filter((vendor) => isUsableMerchantName(vendor.name));
158
+ draft.vendorSearch.fetchState = 'Completed';
159
+ draft.vendorSearch.error = undefined;
160
+ },
161
+ updateCardPolicyVendorOptionsFailure(draft, action) {
162
+ draft.vendorSearch.fetchState = 'Error';
163
+ draft.vendorSearch.error = action.payload;
164
+ },
165
+ clearCardPolicy(draft) {
166
+ Object.assign(draft, initialState);
167
+ },
168
+ },
169
+ });
170
+ export const { fetchCardPolicyMccCategories, fetchCardPolicyVendorOptions, updateCardPolicyMccCategories, updateCardPolicyMccCategoriesFailure, updateCardPolicyVendorOptions, updateCardPolicyVendorOptionsFailure, updateCreatedCardPolicyTemplate, updateCardPolicyTemplates, removeCardPolicyTemplate, updateCardPolicyStats, extractPolicyDocument, updatePolicyDocumentExtractionSuccess, updatePolicyDocumentExtractionFailure, clearPolicyDocumentExtraction, fetchCardPolicyRecommendationFromUpload, updatePolicyRecommendationFromUploadSuccess, updatePolicyRecommendationFromUploadFailure, clearCardPolicy, } = cardPolicy.actions;
171
+ export default cardPolicy.reducer;
@@ -0,0 +1,75 @@
1
+ export function getCardPolicyMccCategories(state) {
2
+ return state.mccCategories;
3
+ }
4
+ export function getCardPolicyMccCategoriesFetchState(state) {
5
+ return state.mccCategoriesFetchState;
6
+ }
7
+ export function getCardPolicyMccCategoriesError(state) {
8
+ return state.mccCategoriesError;
9
+ }
10
+ export function getCardPolicyTemplateById(state, templateId) {
11
+ return state.cardPolicyTemplateById[templateId];
12
+ }
13
+ export function getAllCardPolicyTemplates(state) {
14
+ return Object.values(state.cardPolicyTemplateById);
15
+ }
16
+ /**
17
+ * Resolve an ordered list of `templateId`s against the entity store and
18
+ * return the corresponding `CardPolicyTemplate[]` in the same order.
19
+ * Missing IDs (e.g. stale local state during a refetch) are silently
20
+ * dropped. Pair with `getCardPolicyTemplateIds` from the view slice to
21
+ * render the Policy List page in server order.
22
+ */
23
+ export function getCardPolicyTemplatesByIds(state, templateIds) {
24
+ return templateIds
25
+ .map((id) => state.cardPolicyTemplateById[id])
26
+ .filter((template) => template != null);
27
+ }
28
+ export function getCardPolicyStats(state) {
29
+ return state.cardPolicyStats;
30
+ }
31
+ export function getPolicyDocumentExtractionFetchState(state) {
32
+ return state.policyDocumentExtraction.fetchState;
33
+ }
34
+ export function getPolicyDocumentExtractionError(state) {
35
+ return state.policyDocumentExtraction.error;
36
+ }
37
+ export function getExtractedCardPolicyRules(state) {
38
+ return state.policyDocumentExtraction.extractedRules;
39
+ }
40
+ export function getUploadedPolicyDocumentFileName(state) {
41
+ return state.policyDocumentExtraction.uploadedFileName;
42
+ }
43
+ export function getPolicyRecommendationFromUploadFetchState(state) {
44
+ return state.policyRecommendationFromUpload.fetchState;
45
+ }
46
+ export function getPolicyRecommendationFromUploadError(state) {
47
+ return state.policyRecommendationFromUpload.error;
48
+ }
49
+ export function getPolicyRecommendationFromUploadAnswerId(state) {
50
+ return state.policyRecommendationFromUpload.answerId;
51
+ }
52
+ export function getPolicyRecommendationFromUploadChatSessionId(state) {
53
+ return state.policyRecommendationFromUpload.chatSessionId;
54
+ }
55
+ export function getCardPolicySuggestedAllowMerchants(state) {
56
+ return state.suggestedAllowMerchants;
57
+ }
58
+ export function getCardPolicySuggestedBlockMerchants(state) {
59
+ return state.suggestedBlockMerchants;
60
+ }
61
+ export function getCardPolicySuggestedAllowCategories(state) {
62
+ return state.suggestedAllowCategories;
63
+ }
64
+ export function getCardPolicySuggestedBlockCategories(state) {
65
+ return state.suggestedBlockCategories;
66
+ }
67
+ export function getCardPolicyVendorSearchOptions(state) {
68
+ return state.vendorSearch.vendors;
69
+ }
70
+ export function getCardPolicyVendorSearchFetchState(state) {
71
+ return state.vendorSearch.fetchState;
72
+ }
73
+ export function getCardPolicyVendorSearchString(state) {
74
+ return state.vendorSearch.searchString;
75
+ }
@@ -0,0 +1,9 @@
1
+ import { stringToUnion } from '../../commonStateTypes/stringToUnion';
2
+ export const ALL_CARD_POLICY_TEMPLATE_MODES = ['strict', 'flexible'];
3
+ export const toCardPolicyTemplateMode = (v) => stringToUnion(v, ALL_CARD_POLICY_TEMPLATE_MODES);
4
+ export const ALL_CARD_POLICY_TEMPLATE_STATUSES = [
5
+ 'active',
6
+ 'inactive',
7
+ 'archived',
8
+ ];
9
+ export const toCardPolicyTemplateStatus = (v) => stringToUnion(v, ALL_CARD_POLICY_TEMPLATE_STATUSES);
@@ -0,0 +1,64 @@
1
+ import { of } from 'rxjs';
2
+ import { catchError, filter, mergeMap, switchMap, takeUntil } from 'rxjs/operators';
3
+ import { createZeniAPIStatus, isSuccessStatus } from '../../responsePayload';
4
+ import { clearPolicyDocumentExtraction, extractPolicyDocument, updatePolicyDocumentExtractionFailure, updatePolicyDocumentExtractionSuccess, } from './cardPolicyReducer';
5
+ /**
6
+ * Build a multipart `FormData` body for `POST /cards/1.0/policy-documents/extract`.
7
+ *
8
+ * Uses the same `attachment_file_<i>` / `attachment_json_<i>` field-naming
9
+ * convention as the charge-card receipt upload (`uploadReceipts.ts` in
10
+ * `web-components`) so backends that already support that wire shape
11
+ * accept this endpoint without bespoke parsing.
12
+ */
13
+ const buildPolicyDocumentFormData = (files) => {
14
+ const data = new FormData();
15
+ files.forEach((file, index) => {
16
+ data.append(`attachment_file_${index}`, file);
17
+ const attachmentJson = JSON.stringify({
18
+ file_name: file.name,
19
+ content_type: file.type,
20
+ size: file.size,
21
+ });
22
+ data.append(`attachment_json_${index}`, attachmentJson);
23
+ });
24
+ return data;
25
+ };
26
+ /**
27
+ * Listens for `extractPolicyDocument`, POSTs the file(s) as multipart
28
+ * form-data to the cards micro-service's policy-document extract endpoint,
29
+ * and dispatches success / failure into the entity slice.
30
+ *
31
+ * Consumed by:
32
+ * - Manual `CardPolicyCreatePage` (read result via
33
+ * `getExtractedCardPolicyRules` then pre-fill the RHF form via
34
+ * `applyExtractedPolicyRulesToFormValues` from `@zeniai/web-components`).
35
+ * - (Future) AI CFO upload surface — same action + selector contract.
36
+ */
37
+ export const extractPolicyDocumentEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(extractPolicyDocument.match),
38
+ // `switchMap` (vs `mergeMap`) cancels any in-flight extract whenever a
39
+ // new upload is dispatched. With `mergeMap` an older, slower response
40
+ // could win the race: `updatePolicyDocumentExtractionSuccess` would
41
+ // fire with stale `extractedRules` and the chained bridge epic would
42
+ // pair them with whatever `aiCfoAnswerId` / `aiCfoChatSessionId` are
43
+ // currently in state — recommending the old file's rules against the
44
+ // wrong AI CFO answer.
45
+ switchMap((action) => {
46
+ const formData = buildPolicyDocumentFormData(action.payload.files);
47
+ return zeniAPI
48
+ .postFormData(`${zeniAPI.apiEndPoints.cardMicroServiceBaseUrl}/1.0/policy-documents/extract`, formData)
49
+ .pipe(mergeMap((response) => {
50
+ if (isSuccessStatus(response) &&
51
+ response.data != null &&
52
+ response.data.extracted_rules != null) {
53
+ return of(updatePolicyDocumentExtractionSuccess(response.data.extracted_rules));
54
+ }
55
+ return of(updatePolicyDocumentExtractionFailure(response.status));
56
+ }), catchError((error) => of(updatePolicyDocumentExtractionFailure(createZeniAPIStatus('Unexpected Error', 'Extract card-policy document REST API call errored out' +
57
+ JSON.stringify(error))))),
58
+ // `clearPolicyDocumentExtraction` (e.g. user clicks the "× Policy.pdf"
59
+ // pill) tears down the in-flight extract subscription, so a late
60
+ // response can't re-flip `policyDocumentExtraction.fetchState` back
61
+ // to `Completed` or repopulate `extractedRules` after the user
62
+ // already dismissed the upload.
63
+ takeUntil(actions$.pipe(filter(clearPolicyDocumentExtraction.match))));
64
+ }));
@@ -0,0 +1,43 @@
1
+ import { of } from 'rxjs';
2
+ import { catchError, filter, switchMap } from 'rxjs/operators';
3
+ import { createZeniAPIStatus, isSuccessStatus } from '../../responsePayload';
4
+ import { fetchCardPolicyVendorOptions, updateCardPolicyVendorOptions, updateCardPolicyVendorOptionsFailure, } from './cardPolicyReducer';
5
+ const buildQuery = (searchString) => ({
6
+ view: 'vendor_list',
7
+ page_token: null,
8
+ sort_by: 'year_to_date_spend',
9
+ sort_order: 'desc',
10
+ search_text: searchString,
11
+ vendor_name: searchString,
12
+ });
13
+ /**
14
+ * Card-policy vendor search.
15
+ *
16
+ * Listens for `fetchCardPolicyVendorOptions` and hits the same
17
+ * `/accounting/1.0/vendors` endpoint the Vendors-tab uses, but writes
18
+ * results onto the dedicated `cardPolicyState.vendorSearch` slice — no
19
+ * fan-out to the global `vendor` / `account` / `class` / `vendorList`
20
+ * entities. That isolation is important: the user may be configuring a
21
+ * card policy in parallel with browsing the Vendors tab, and we don't
22
+ * want either flow to clobber the other's list state.
23
+ *
24
+ * Uses `switchMap` so the latest typed search wins — earlier in-flight
25
+ * requests are abandoned, which is the right semantics for a
26
+ * search-as-you-type UX.
27
+ *
28
+ * Consumers:
29
+ * - Manual `CardPolicyCreate / EditScreen`
30
+ * - AI CFO `CardPolicyInteractiveForm` (vendor step)
31
+ */
32
+ export const fetchCardPolicyVendorOptionsEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(fetchCardPolicyVendorOptions.match), switchMap((action) => {
33
+ const query = buildQuery(action.payload.searchString);
34
+ const apiUrl = `${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/vendors` +
35
+ `?query=${encodeURIComponent(JSON.stringify(query))}`;
36
+ return zeniAPI.getJSON(apiUrl).pipe(switchMap((response) => {
37
+ if (isSuccessStatus(response) && response.data != null) {
38
+ return of(updateCardPolicyVendorOptions(response.data));
39
+ }
40
+ return of(updateCardPolicyVendorOptionsFailure(response.status));
41
+ }), catchError((error) => of(updateCardPolicyVendorOptionsFailure(createZeniAPIStatus('Unexpected Error', 'Fetch card policy vendor options REST API call errored out' +
42
+ JSON.stringify(error))))));
43
+ }));
@@ -0,0 +1,35 @@
1
+ import { EMPTY, of } from 'rxjs';
2
+ import { filter, mergeMap } from 'rxjs/operators';
3
+ import { fetchCardPolicyRecommendationFromUpload, updatePolicyDocumentExtractionSuccess, } from './cardPolicyReducer';
4
+ /**
5
+ * Bridge epic — chains the AI CFO `upload`-mode flow's two API hops.
6
+ *
7
+ * The first hop (`extractPolicyDocument` → multipart POST to
8
+ * `policy-documents/extract`) lives on the cardPolicy slice and is
9
+ * shared with the manual `CardPolicyCreatePage`. The second hop
10
+ * (`fetchCardPolicyRecommendationFromUpload` → JSON POST to
11
+ * `ai-cfo/policy-recommendation-from-upload`) is AI-CFO only.
12
+ *
13
+ * The chain is gated on `policyDocumentExtraction.aiCfoAnswerId` being
14
+ * populated — manual callers leave it undefined, so the bridge is a
15
+ * silent no-op there.
16
+ *
17
+ * Splitting this off from `policyRecommendationFromUploadEpic` keeps
18
+ * the wizard component a pure renderer: it dispatches
19
+ * `extractPolicyDocument(files, answerId, chatSessionId)` once, then
20
+ * subscribes to `cardPolicyState` lifecycle flags to drive its
21
+ * "Extracting…" / "Recommending…" pill.
22
+ */
23
+ export const policyDocumentExtractionToRecommendationBridgeEpic = (actions$, state$) => actions$.pipe(filter(updatePolicyDocumentExtractionSuccess.match), mergeMap((action) => {
24
+ const extraction = state$.value.cardPolicyState.policyDocumentExtraction;
25
+ const aiCfoAnswerId = extraction.aiCfoAnswerId;
26
+ const aiCfoChatSessionId = extraction.aiCfoChatSessionId;
27
+ const extractedRules = extraction.extractedRules;
28
+ if (aiCfoAnswerId == null ||
29
+ aiCfoChatSessionId == null ||
30
+ extractedRules == null) {
31
+ return EMPTY;
32
+ }
33
+ void action;
34
+ return of(fetchCardPolicyRecommendationFromUpload(aiCfoAnswerId, aiCfoChatSessionId, extractedRules));
35
+ }));
@@ -0,0 +1,100 @@
1
+ import { of } from 'rxjs';
2
+ import { catchError, filter, mergeMap, switchMap, takeUntil } from 'rxjs/operators';
3
+ import { updateAiCfoAnswerCardPolicyWizardPlan } from '../aiCfo/aiCfoReducer';
4
+ import { createZeniAPIStatus, isSuccessStatus } from '../../responsePayload';
5
+ import { clearPolicyDocumentExtraction, fetchCardPolicyRecommendationFromUpload, updatePolicyRecommendationFromUploadFailure, updatePolicyRecommendationFromUploadSuccess, } from './cardPolicyReducer';
6
+ /**
7
+ * Listens for `fetchCardPolicyRecommendationFromUpload` and POSTs the
8
+ * just-extracted policy rules to the AI-CFO recommendation endpoint.
9
+ *
10
+ * On success — dispatches BOTH:
11
+ * - `updatePolicyRecommendationFromUploadSuccess` (flips the
12
+ * cardPolicy slice's recommendation lifecycle to `Completed`), and
13
+ * - `updateAiCfoAnswerCardPolicyWizardPlan` (patches the in-flight AI
14
+ * CFO answer's `CardPolicyInitialData` so the wizard can advance from
15
+ * Step 1 → Step 2 in the upload variant).
16
+ *
17
+ * The reducer payload originally captured at kickoff (`answerId` +
18
+ * `chatSessionId`) re-enters via the action so the patch can find the
19
+ * right answer to merge into.
20
+ */
21
+ export const policyRecommendationFromUploadEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(fetchCardPolicyRecommendationFromUpload.match),
22
+ // `switchMap` (vs `mergeMap`) cancels any in-flight recommendation
23
+ // whenever a new upload kicks off another one. Without this an older,
24
+ // slower recommendation response could still resolve after a fresh
25
+ // extract has started — that late response would dispatch
26
+ // `updateAiCfoAnswerCardPolicyWizardPlan` against the *current*
27
+ // `answerId`/`chatSessionId` (the ones captured at its kickoff) and
28
+ // overwrite the wizard plan with stale draft policies from the prior
29
+ // document. Pairs with the matching `switchMap` in
30
+ // `extractPolicyDocumentEpic`.
31
+ switchMap((action) => {
32
+ const { answerId, chatSessionId, extractedRules } = action.payload;
33
+ const body = {
34
+ extracted_rules: {
35
+ allowed_entity: {
36
+ category_codes: extractedRules.allowedEntity.categoryCodes,
37
+ merchant_names: extractedRules.allowedEntity.merchantNames,
38
+ },
39
+ blocked_entity: {
40
+ category_codes: extractedRules.blockedEntity.categoryCodes,
41
+ merchant_names: extractedRules.blockedEntity.merchantNames,
42
+ },
43
+ confidence_score: extractedRules.confidenceScore,
44
+ policy_name: extractedRules.policyName,
45
+ required_receipt_threshold: extractedRules.requiredReceiptThreshold,
46
+ transaction_limit: extractedRules.transactionLimit,
47
+ },
48
+ };
49
+ return zeniAPI
50
+ .postAndGetJSON(`${zeniAPI.apiEndPoints.cardMicroServiceBaseUrl}/1.0/ai-cfo/policy-recommendation-from-upload`, body)
51
+ .pipe(mergeMap((response) => {
52
+ if (!isSuccessStatus(response) ||
53
+ response.data?.wizard_plan?.step_5_review == null) {
54
+ return of(updatePolicyRecommendationFromUploadFailure(response.status));
55
+ }
56
+ const data = response.data;
57
+ const review = data.wizard_plan.step_5_review;
58
+ const wizardPlan = {
59
+ step5Review: {
60
+ draftPolicies: (review.draft_policies ?? []).map((draft, index) => ({
61
+ id: `draft-${index}`,
62
+ name: draft.name,
63
+ description: draft.description ?? '',
64
+ mode: draft.mode,
65
+ allowedEntity: {
66
+ categoryCodes: draft.allowed_entity?.category_codes ?? [],
67
+ merchantNames: draft.allowed_entity?.merchant_names ?? [],
68
+ },
69
+ blockedEntity: {
70
+ categoryCodes: draft.blocked_entity?.category_codes ?? [],
71
+ merchantNames: draft.blocked_entity?.merchant_names ?? [],
72
+ },
73
+ applyToCards: draft.apply_to_cards ?? [],
74
+ requiredReceiptThreshold: draft.required_receipt_threshold ?? 0,
75
+ spendLimits: {
76
+ transaction: draft.spend_limits?.transaction ?? 0,
77
+ },
78
+ })),
79
+ groupingSource: review.grouping_source ?? 'none',
80
+ prompt: review.prompt ?? '',
81
+ },
82
+ };
83
+ const source = data.source != null
84
+ ? {
85
+ confidenceScore: data.source.confidence_score,
86
+ fileName: data.source.file_name,
87
+ lowConfidenceFields: data.source.low_confidence_fields ?? [],
88
+ }
89
+ : undefined;
90
+ return of(updatePolicyRecommendationFromUploadSuccess(), updateAiCfoAnswerCardPolicyWizardPlan({
91
+ answerId,
92
+ chatSessionId,
93
+ wizardPlan,
94
+ source,
95
+ }));
96
+ }), catchError((error) => of(updatePolicyRecommendationFromUploadFailure(createZeniAPIStatus('Unexpected Error', 'Policy recommendation from upload REST API call errored out' +
97
+ JSON.stringify(error))))),
98
+ // Guards the user-dismissed case that switchMap doesn't cover: a late response would patch a wizard plan the user already cleared.
99
+ takeUntil(actions$.pipe(filter(clearPolicyDocumentExtraction.match))));
100
+ }));
@@ -95,6 +95,9 @@ const ALL_SNACKBAR_MESSAGE_SECTIONS = [
95
95
  'charge_card_receipt_upload',
96
96
  'charge_card_resend_invite',
97
97
  'charge_card_revoke_invite',
98
+ 'card_policy_created',
99
+ 'card_policy_updated',
100
+ 'card_policy_deleted',
98
101
  'charge_card_update_limit',
99
102
  'charge_cards_update_limit',
100
103
  'close_charge_card',
@@ -97,6 +97,9 @@ import { clearInternationalWire } from '../../view/spendManagement/billPay/inter
97
97
  import { clearInternationalVerificationView } from '../../view/spendManagement/billPay/internationalWireVerification/internationalWireVerificationReducer';
98
98
  import { clearPreviousBills } from '../../view/spendManagement/billPay/previousBills/previousBillsReducer';
99
99
  import { clearWiseRedirectStatus } from '../../view/spendManagement/billPay/wiseRedirectView/wiseRedirectReducer';
100
+ import { clearCardPolicyDetail } from '../../view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailReducer';
101
+ import { clearCardPolicyList } from '../../view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListReducer';
102
+ import { clearCreateCardPolicy } from '../../view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyReducer';
100
103
  import { clearCardUserOnboarding } from '../../view/spendManagement/chargeCards/cardUserOnboarding/cardUserOnboardingReducer';
101
104
  import { clearCashbackDetail } from '../../view/spendManagement/chargeCards/cashbackDetail/cashbackDetailReducer';
102
105
  import { clearChargeCardConfig } from '../../view/spendManagement/chargeCards/chargeCardConfig/chargeCardConfigReducer';
@@ -168,6 +171,7 @@ import { clearAllBillTransactions } from '../billPay/billTransaction/billTransac
168
171
  import { clearContacts } from '../billPay/contact/contactReducer';
169
172
  import { clearAllRecurringBills } from '../billPay/recurringBills/recurringBillsReducer';
170
173
  import { clearAllCardPayments } from '../cardPayment/cardPaymentReducer';
174
+ import { clearCardPolicy } from '../cardPolicy/cardPolicyReducer';
171
175
  import { clearAllChargeCards } from '../chargeCard/chargeCardReducer';
172
176
  import { clearAllChargeCardRepayments } from '../chargeCardRepayment/chargeCardRepaymentReducer';
173
177
  import { clearAllChargeCardTransactions } from '../chargeCardTransaction/chargeCardTransactionReducer';
@@ -244,6 +248,8 @@ export const clearAllEpic = (actions$) => actions$.pipe(filter(clearAll.match),
244
248
  clearBillPaySetupView(),
245
249
  clearCardBalance(),
246
250
  clearCardPaymentView(),
251
+ clearCardPolicyDetail(),
252
+ clearCardPolicyList(),
247
253
  clearCardUserOnboarding(),
248
254
  clearCashbackDetail(),
249
255
  clearCashBalance(),
@@ -263,6 +269,7 @@ export const clearAllEpic = (actions$) => actions$.pipe(filter(clearAll.match),
263
269
  clearCompanyMonthEndReportView(),
264
270
  clearCompanyTaskManagerView(),
265
271
  clearCompanyView(),
272
+ clearCreateCardPolicy(),
266
273
  clearCreateTransferEntry(),
267
274
  clearAllCreditAgent(),
268
275
  clearCreditAgentView(),
@@ -424,6 +431,7 @@ export const clearAllEpic = (actions$) => actions$.pipe(filter(clearAll.match),
424
431
  clearAllVendorExpenseTrends(),
425
432
  clearAllVendors(),
426
433
  clearCannedResponses(),
434
+ clearCardPolicy(),
427
435
  clearClassList(),
428
436
  clearContacts(),
429
437
  clearCountryList(),