@zeniai/client-epic-state 5.0.83 → 5.0.84-beta24RJ

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 (131) hide show
  1. package/lib/common/aiCfo/aiCfoSuggestedQuestionsPageContext.d.ts +1 -1
  2. package/lib/entity/aiCfo/aiCfoPayload.d.ts +1 -140
  3. package/lib/entity/aiCfo/aiCfoReducer.d.ts +2 -23
  4. package/lib/entity/aiCfo/aiCfoReducer.js +4 -332
  5. package/lib/entity/aiCfo/aiCfoSelector.d.ts +1 -13
  6. package/lib/entity/aiCfo/aiCfoSelector.js +1 -28
  7. package/lib/entity/aiCfo/aiCfoState.d.ts +4 -225
  8. package/lib/entity/aiCfo/aiCfoState.js +1 -30
  9. package/lib/entity/jeSchedules/jeSchedulesPayload.d.ts +1 -0
  10. package/lib/entity/jeSchedules/jeSchedulesPayload.js +7 -0
  11. package/lib/entity/jeSchedules/jeSchedulesState.d.ts +1 -0
  12. package/lib/entity/jeSchedules/jeSchedulesTypes.d.ts +1 -1
  13. package/lib/entity/monthEndCloseChecks/monthEndCloseChecksState.d.ts +1 -1
  14. package/lib/entity/snackbar/snackbarTypes.d.ts +1 -1
  15. package/lib/entity/snackbar/snackbarTypes.js +0 -3
  16. package/lib/entity/tenant/clearAllEpic.d.ts +2 -6
  17. package/lib/entity/tenant/clearAllEpic.js +0 -8
  18. package/lib/epic.d.ts +1 -11
  19. package/lib/epic.js +1 -11
  20. package/lib/esm/entity/aiCfo/aiCfoReducer.js +4 -332
  21. package/lib/esm/entity/aiCfo/aiCfoSelector.js +1 -26
  22. package/lib/esm/entity/aiCfo/aiCfoState.js +0 -27
  23. package/lib/esm/entity/jeSchedules/jeSchedulesPayload.js +7 -0
  24. package/lib/esm/entity/snackbar/snackbarTypes.js +0 -3
  25. package/lib/esm/entity/tenant/clearAllEpic.js +0 -8
  26. package/lib/esm/epic.js +1 -11
  27. package/lib/esm/index.js +7 -22
  28. package/lib/esm/reducer.js +0 -12
  29. package/lib/esm/view/aiCfoView/aiCfoViewReducer.js +3 -6
  30. package/lib/esm/view/aiCfoView/epics/createSessionAndSubmitEpic.js +2 -5
  31. package/lib/esm/view/aiCfoView/epics/createSessionEpic.js +1 -2
  32. package/lib/esm/view/aiCfoView/epics/fetchSuggestedQuestionsEpic.js +2 -12
  33. package/lib/esm/view/spendManagement/chargeCards/chargeCardList/chargeCardListSelector.js +0 -25
  34. package/lib/esm/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardEpic.js +2 -2
  35. package/lib/esm/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardReducer.js +4 -16
  36. package/lib/esm/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardSelector.js +0 -38
  37. package/lib/index.d.ts +7 -20
  38. package/lib/index.js +10 -125
  39. package/lib/reducer.d.ts +0 -12
  40. package/lib/reducer.js +0 -12
  41. package/lib/view/aiCfoView/aiCfoViewReducer.d.ts +2 -11
  42. package/lib/view/aiCfoView/aiCfoViewReducer.js +3 -6
  43. package/lib/view/aiCfoView/epics/createSessionAndSubmitEpic.js +2 -5
  44. package/lib/view/aiCfoView/epics/createSessionEpic.js +1 -2
  45. package/lib/view/aiCfoView/epics/fetchSuggestedQuestionsEpic.d.ts +1 -8
  46. package/lib/view/aiCfoView/epics/fetchSuggestedQuestionsEpic.js +2 -12
  47. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
  48. package/lib/view/expenseAutomationView/types/reconciliationViewState.d.ts +1 -1
  49. package/lib/view/people/peopleTypes.d.ts +1 -1
  50. package/lib/view/scheduleView/scheduleListView/scheduleListTypes.d.ts +1 -1
  51. package/lib/view/spendManagement/chargeCards/chargeCardList/chargeCardList.d.ts +1 -1
  52. package/lib/view/spendManagement/chargeCards/chargeCardList/chargeCardListSelector.d.ts +0 -14
  53. package/lib/view/spendManagement/chargeCards/chargeCardList/chargeCardListSelector.js +1 -27
  54. package/lib/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardEpic.d.ts +2 -2
  55. package/lib/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardEpic.js +1 -1
  56. package/lib/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardReducer.d.ts +1 -5
  57. package/lib/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardReducer.js +5 -17
  58. package/lib/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardSelector.d.ts +0 -27
  59. package/lib/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardSelector.js +1 -43
  60. package/lib/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardState.d.ts +0 -2
  61. package/lib/view/taskManager/taskListView/taskListReducer.d.ts +1 -1
  62. package/package.json +1 -1
  63. package/lib/entity/cardPolicy/cardPolicyPayload.d.ts +0 -277
  64. package/lib/entity/cardPolicy/cardPolicyPayload.js +0 -143
  65. package/lib/entity/cardPolicy/cardPolicyReducer.d.ts +0 -19
  66. package/lib/entity/cardPolicy/cardPolicyReducer.js +0 -265
  67. package/lib/entity/cardPolicy/cardPolicySelector.d.ts +0 -32
  68. package/lib/entity/cardPolicy/cardPolicySelector.js +0 -103
  69. package/lib/entity/cardPolicy/cardPolicyState.d.ts +0 -205
  70. package/lib/entity/cardPolicy/cardPolicyState.js +0 -14
  71. package/lib/entity/cardPolicy/extractPolicyDocumentEpic.d.ts +0 -18
  72. package/lib/entity/cardPolicy/extractPolicyDocumentEpic.js +0 -68
  73. package/lib/entity/cardPolicy/fetchCardPolicyVendorOptionsEpic.d.ts +0 -26
  74. package/lib/entity/cardPolicy/fetchCardPolicyVendorOptionsEpic.js +0 -47
  75. package/lib/entity/cardPolicy/policyDocumentExtractionToRecommendationBridgeEpic.d.ts +0 -25
  76. package/lib/entity/cardPolicy/policyDocumentExtractionToRecommendationBridgeEpic.js +0 -39
  77. package/lib/entity/cardPolicy/policyRecommendationFromUploadEpic.d.ts +0 -23
  78. package/lib/entity/cardPolicy/policyRecommendationFromUploadEpic.js +0 -111
  79. package/lib/esm/entity/cardPolicy/cardPolicyPayload.js +0 -130
  80. package/lib/esm/entity/cardPolicy/cardPolicyReducer.js +0 -261
  81. package/lib/esm/entity/cardPolicy/cardPolicySelector.js +0 -79
  82. package/lib/esm/entity/cardPolicy/cardPolicyState.js +0 -9
  83. package/lib/esm/entity/cardPolicy/extractPolicyDocumentEpic.js +0 -64
  84. package/lib/esm/entity/cardPolicy/fetchCardPolicyVendorOptionsEpic.js +0 -43
  85. package/lib/esm/entity/cardPolicy/policyDocumentExtractionToRecommendationBridgeEpic.js +0 -35
  86. package/lib/esm/entity/cardPolicy/policyRecommendationFromUploadEpic.js +0 -107
  87. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailReducer.js +0 -70
  88. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailSelector.js +0 -22
  89. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailState.js +0 -1
  90. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/fetchCardPolicyDetailEpic.js +0 -56
  91. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/updateCardPolicyEpic.js +0 -49
  92. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/archiveCardPolicyEpic.js +0 -42
  93. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListReducer.js +0 -72
  94. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListSelector.js +0 -21
  95. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListState.js +0 -1
  96. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/fetchCardPolicyListEpic.js +0 -56
  97. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyReducer.js +0 -62
  98. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicySelector.js +0 -39
  99. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyState.js +0 -1
  100. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyTemplateEpic.js +0 -53
  101. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/fetchCardPolicyMccCategoriesEpic.js +0 -25
  102. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailReducer.d.ts +0 -14
  103. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailReducer.js +0 -74
  104. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailSelector.d.ts +0 -21
  105. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailSelector.js +0 -28
  106. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailState.d.ts +0 -25
  107. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailState.js +0 -2
  108. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/fetchCardPolicyDetailEpic.d.ts +0 -19
  109. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/fetchCardPolicyDetailEpic.js +0 -60
  110. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/updateCardPolicyEpic.d.ts +0 -18
  111. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/updateCardPolicyEpic.js +0 -53
  112. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/archiveCardPolicyEpic.d.ts +0 -16
  113. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/archiveCardPolicyEpic.js +0 -46
  114. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListReducer.d.ts +0 -15
  115. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListReducer.js +0 -76
  116. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListSelector.d.ts +0 -21
  117. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListSelector.js +0 -27
  118. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListState.d.ts +0 -19
  119. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListState.js +0 -2
  120. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/fetchCardPolicyListEpic.d.ts +0 -19
  121. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/fetchCardPolicyListEpic.js +0 -60
  122. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyReducer.d.ts +0 -13
  123. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyReducer.js +0 -66
  124. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicySelector.d.ts +0 -32
  125. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicySelector.js +0 -46
  126. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyState.d.ts +0 -45
  127. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyState.js +0 -2
  128. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyTemplateEpic.d.ts +0 -25
  129. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyTemplateEpic.js +0 -57
  130. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/fetchCardPolicyMccCategoriesEpic.d.ts +0 -15
  131. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/fetchCardPolicyMccCategoriesEpic.js +0 -29
@@ -1,68 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extractPolicyDocumentEpic = void 0;
4
- const rxjs_1 = require("rxjs");
5
- const operators_1 = require("rxjs/operators");
6
- const responsePayload_1 = require("../../responsePayload");
7
- const cardPolicyReducer_1 = require("./cardPolicyReducer");
8
- /**
9
- * Build a multipart `FormData` body for `POST /cards/1.0/policy-documents/extract`.
10
- *
11
- * Uses the same `attachment_file_<i>` / `attachment_json_<i>` field-naming
12
- * convention as the charge-card receipt upload (`uploadReceipts.ts` in
13
- * `web-components`) so backends that already support that wire shape
14
- * accept this endpoint without bespoke parsing.
15
- */
16
- const buildPolicyDocumentFormData = (files) => {
17
- const data = new FormData();
18
- files.forEach((file, index) => {
19
- data.append(`attachment_file_${index}`, file);
20
- const attachmentJson = JSON.stringify({
21
- file_name: file.name,
22
- content_type: file.type,
23
- size: file.size,
24
- });
25
- data.append(`attachment_json_${index}`, attachmentJson);
26
- });
27
- return data;
28
- };
29
- /**
30
- * Listens for `extractPolicyDocument`, POSTs the file(s) as multipart
31
- * form-data to the cards micro-service's policy-document extract endpoint,
32
- * and dispatches success / failure into the entity slice.
33
- *
34
- * Consumed by:
35
- * - Manual `CardPolicyCreatePage` (read result via
36
- * `getExtractedCardPolicyRules` then pre-fill the RHF form via
37
- * `applyExtractedPolicyRulesToFormValues` from `@zeniai/web-components`).
38
- * - (Future) AI CFO upload surface — same action + selector contract.
39
- */
40
- const extractPolicyDocumentEpic = (actions$, _state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(cardPolicyReducer_1.extractPolicyDocument.match),
41
- // `switchMap` (vs `mergeMap`) cancels any in-flight extract whenever a
42
- // new upload is dispatched. With `mergeMap` an older, slower response
43
- // could win the race: `updatePolicyDocumentExtractionSuccess` would
44
- // fire with stale `extractedRules` and the chained bridge epic would
45
- // pair them with whatever `aiCfoAnswerId` / `aiCfoChatSessionId` are
46
- // currently in state — recommending the old file's rules against the
47
- // wrong AI CFO answer.
48
- (0, operators_1.switchMap)((action) => {
49
- const formData = buildPolicyDocumentFormData(action.payload.files);
50
- return zeniAPI
51
- .postFormData(`${zeniAPI.apiEndPoints.cardMicroServiceBaseUrl}/1.0/policy-documents/extract`, formData)
52
- .pipe((0, operators_1.mergeMap)((response) => {
53
- if ((0, responsePayload_1.isSuccessStatus)(response) &&
54
- response.data != null &&
55
- response.data.extracted_rules != null) {
56
- return (0, rxjs_1.of)((0, cardPolicyReducer_1.updatePolicyDocumentExtractionSuccess)(response.data.extracted_rules));
57
- }
58
- return (0, rxjs_1.of)((0, cardPolicyReducer_1.updatePolicyDocumentExtractionFailure)(response.status));
59
- }), (0, operators_1.catchError)((error) => (0, rxjs_1.of)((0, cardPolicyReducer_1.updatePolicyDocumentExtractionFailure)((0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', 'Extract card-policy document REST API call errored out' +
60
- JSON.stringify(error))))),
61
- // `clearPolicyDocumentExtraction` (e.g. user clicks the "× Policy.pdf"
62
- // pill) tears down the in-flight extract subscription, so a late
63
- // response can't re-flip `policyDocumentExtraction.fetchState` back
64
- // to `Completed` or repopulate `extractedRules` after the user
65
- // already dismissed the upload.
66
- (0, operators_1.takeUntil)(actions$.pipe((0, operators_1.filter)(cardPolicyReducer_1.clearPolicyDocumentExtraction.match))));
67
- }));
68
- exports.extractPolicyDocumentEpic = extractPolicyDocumentEpic;
@@ -1,26 +0,0 @@
1
- import { ActionsObservable, StateObservable } from 'redux-observable';
2
- import { Observable } from 'rxjs';
3
- import { RootState } from '../../reducer';
4
- import { ZeniAPI } from '../../zeniAPI';
5
- import { fetchCardPolicyVendorOptions, updateCardPolicyVendorOptions, updateCardPolicyVendorOptionsFailure } from './cardPolicyReducer';
6
- export type ActionType = ReturnType<typeof fetchCardPolicyVendorOptions> | ReturnType<typeof updateCardPolicyVendorOptions> | ReturnType<typeof updateCardPolicyVendorOptionsFailure>;
7
- /**
8
- * Card-policy vendor search.
9
- *
10
- * Listens for `fetchCardPolicyVendorOptions` and hits the same
11
- * `/accounting/1.0/vendors` endpoint the Vendors-tab uses, but writes
12
- * results onto the dedicated `cardPolicyState.vendorSearch` slice — no
13
- * fan-out to the global `vendor` / `account` / `class` / `vendorList`
14
- * entities. That isolation is important: the user may be configuring a
15
- * card policy in parallel with browsing the Vendors tab, and we don't
16
- * want either flow to clobber the other's list state.
17
- *
18
- * Uses `switchMap` so the latest typed search wins — earlier in-flight
19
- * requests are abandoned, which is the right semantics for a
20
- * search-as-you-type UX.
21
- *
22
- * Consumers:
23
- * - Manual `CardPolicyCreate / EditScreen`
24
- * - AI CFO `CardPolicyInteractiveForm` (vendor step)
25
- */
26
- export declare const fetchCardPolicyVendorOptionsEpic: (actions$: ActionsObservable<ActionType>, _state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => Observable<ActionType>;
@@ -1,47 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fetchCardPolicyVendorOptionsEpic = void 0;
4
- const rxjs_1 = require("rxjs");
5
- const operators_1 = require("rxjs/operators");
6
- const responsePayload_1 = require("../../responsePayload");
7
- const cardPolicyReducer_1 = require("./cardPolicyReducer");
8
- const buildQuery = (searchString) => ({
9
- view: 'vendor_list',
10
- page_token: null,
11
- sort_by: 'year_to_date_spend',
12
- sort_order: 'desc',
13
- search_text: searchString,
14
- vendor_name: searchString,
15
- });
16
- /**
17
- * Card-policy vendor search.
18
- *
19
- * Listens for `fetchCardPolicyVendorOptions` and hits the same
20
- * `/accounting/1.0/vendors` endpoint the Vendors-tab uses, but writes
21
- * results onto the dedicated `cardPolicyState.vendorSearch` slice — no
22
- * fan-out to the global `vendor` / `account` / `class` / `vendorList`
23
- * entities. That isolation is important: the user may be configuring a
24
- * card policy in parallel with browsing the Vendors tab, and we don't
25
- * want either flow to clobber the other's list state.
26
- *
27
- * Uses `switchMap` so the latest typed search wins — earlier in-flight
28
- * requests are abandoned, which is the right semantics for a
29
- * search-as-you-type UX.
30
- *
31
- * Consumers:
32
- * - Manual `CardPolicyCreate / EditScreen`
33
- * - AI CFO `CardPolicyInteractiveForm` (vendor step)
34
- */
35
- const fetchCardPolicyVendorOptionsEpic = (actions$, _state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(cardPolicyReducer_1.fetchCardPolicyVendorOptions.match), (0, operators_1.switchMap)((action) => {
36
- const query = buildQuery(action.payload.searchString);
37
- const apiUrl = `${zeniAPI.apiEndPoints.accountMicroServiceBaseUrl}/1.0/vendors` +
38
- `?query=${encodeURIComponent(JSON.stringify(query))}`;
39
- return zeniAPI.getJSON(apiUrl).pipe((0, operators_1.switchMap)((response) => {
40
- if ((0, responsePayload_1.isSuccessStatus)(response) && response.data != null) {
41
- return (0, rxjs_1.of)((0, cardPolicyReducer_1.updateCardPolicyVendorOptions)(response.data));
42
- }
43
- return (0, rxjs_1.of)((0, cardPolicyReducer_1.updateCardPolicyVendorOptionsFailure)(response.status));
44
- }), (0, operators_1.catchError)((error) => (0, rxjs_1.of)((0, cardPolicyReducer_1.updateCardPolicyVendorOptionsFailure)((0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', 'Fetch card policy vendor options REST API call errored out' +
45
- JSON.stringify(error))))));
46
- }));
47
- exports.fetchCardPolicyVendorOptionsEpic = fetchCardPolicyVendorOptionsEpic;
@@ -1,25 +0,0 @@
1
- import { ActionsObservable, StateObservable } from 'redux-observable';
2
- import { Observable } from 'rxjs';
3
- import { RootState } from '../../reducer';
4
- import { fetchCardPolicyRecommendationFromUpload, updatePolicyDocumentExtractionSuccess } from './cardPolicyReducer';
5
- export type ActionType = ReturnType<typeof updatePolicyDocumentExtractionSuccess> | ReturnType<typeof fetchCardPolicyRecommendationFromUpload>;
6
- /**
7
- * Bridge epic — chains the AI CFO `upload`-mode flow's two API hops.
8
- *
9
- * The first hop (`extractPolicyDocument` → multipart POST to
10
- * `policy-documents/extract`) lives on the cardPolicy slice and is
11
- * shared with the manual `CardPolicyCreatePage`. The second hop
12
- * (`fetchCardPolicyRecommendationFromUpload` → JSON POST to
13
- * `ai-cfo/policy-recommendation-from-upload`) is AI-CFO only.
14
- *
15
- * The chain is gated on `policyDocumentExtraction.aiCfoAnswerId` being
16
- * populated — manual callers leave it undefined, so the bridge is a
17
- * silent no-op there.
18
- *
19
- * Splitting this off from `policyRecommendationFromUploadEpic` keeps
20
- * the wizard component a pure renderer: it dispatches
21
- * `extractPolicyDocument(files, answerId, chatSessionId)` once, then
22
- * subscribes to `cardPolicyState` lifecycle flags to drive its
23
- * "Extracting…" / "Recommending…" pill.
24
- */
25
- export declare const policyDocumentExtractionToRecommendationBridgeEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>) => Observable<ActionType>;
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.policyDocumentExtractionToRecommendationBridgeEpic = void 0;
4
- const rxjs_1 = require("rxjs");
5
- const operators_1 = require("rxjs/operators");
6
- const cardPolicyReducer_1 = require("./cardPolicyReducer");
7
- /**
8
- * Bridge epic — chains the AI CFO `upload`-mode flow's two API hops.
9
- *
10
- * The first hop (`extractPolicyDocument` → multipart POST to
11
- * `policy-documents/extract`) lives on the cardPolicy slice and is
12
- * shared with the manual `CardPolicyCreatePage`. The second hop
13
- * (`fetchCardPolicyRecommendationFromUpload` → JSON POST to
14
- * `ai-cfo/policy-recommendation-from-upload`) is AI-CFO only.
15
- *
16
- * The chain is gated on `policyDocumentExtraction.aiCfoAnswerId` being
17
- * populated — manual callers leave it undefined, so the bridge is a
18
- * silent no-op there.
19
- *
20
- * Splitting this off from `policyRecommendationFromUploadEpic` keeps
21
- * the wizard component a pure renderer: it dispatches
22
- * `extractPolicyDocument(files, answerId, chatSessionId)` once, then
23
- * subscribes to `cardPolicyState` lifecycle flags to drive its
24
- * "Extracting…" / "Recommending…" pill.
25
- */
26
- const policyDocumentExtractionToRecommendationBridgeEpic = (actions$, state$) => actions$.pipe((0, operators_1.filter)(cardPolicyReducer_1.updatePolicyDocumentExtractionSuccess.match), (0, operators_1.mergeMap)((action) => {
27
- const extraction = state$.value.cardPolicyState.policyDocumentExtraction;
28
- const aiCfoAnswerId = extraction.aiCfoAnswerId;
29
- const aiCfoChatSessionId = extraction.aiCfoChatSessionId;
30
- const extractedRules = extraction.extractedRules;
31
- if (aiCfoAnswerId == null ||
32
- aiCfoChatSessionId == null ||
33
- extractedRules == null) {
34
- return rxjs_1.EMPTY;
35
- }
36
- void action;
37
- return (0, rxjs_1.of)((0, cardPolicyReducer_1.fetchCardPolicyRecommendationFromUpload)(aiCfoAnswerId, aiCfoChatSessionId, extractedRules));
38
- }));
39
- exports.policyDocumentExtractionToRecommendationBridgeEpic = policyDocumentExtractionToRecommendationBridgeEpic;
@@ -1,23 +0,0 @@
1
- import { ActionsObservable, StateObservable } from 'redux-observable';
2
- import { Observable } from 'rxjs';
3
- import { updateAiCfoAnswerCardPolicyWizardPlan } from '../aiCfo/aiCfoReducer';
4
- import { RootState } from '../../reducer';
5
- import { ZeniAPI } from '../../zeniAPI';
6
- import { clearPolicyDocumentExtraction, fetchCardPolicyRecommendationFromUpload, updatePolicyRecommendationFromUploadFailure, updatePolicyRecommendationFromUploadSuccess } from './cardPolicyReducer';
7
- export type ActionType = ReturnType<typeof fetchCardPolicyRecommendationFromUpload> | ReturnType<typeof updatePolicyRecommendationFromUploadSuccess> | ReturnType<typeof updatePolicyRecommendationFromUploadFailure> | ReturnType<typeof updateAiCfoAnswerCardPolicyWizardPlan> | ReturnType<typeof clearPolicyDocumentExtraction>;
8
- /**
9
- * Listens for `fetchCardPolicyRecommendationFromUpload` and POSTs the
10
- * just-extracted policy rules to the AI-CFO recommendation endpoint.
11
- *
12
- * On success — dispatches BOTH:
13
- * - `updatePolicyRecommendationFromUploadSuccess` (flips the
14
- * cardPolicy slice's recommendation lifecycle to `Completed`), and
15
- * - `updateAiCfoAnswerCardPolicyWizardPlan` (patches the in-flight AI
16
- * CFO answer's `CardPolicyInitialData` so the wizard can advance from
17
- * Step 1 → Step 2 in the upload variant).
18
- *
19
- * The reducer payload originally captured at kickoff (`answerId` +
20
- * `chatSessionId`) re-enters via the action so the patch can find the
21
- * right answer to merge into.
22
- */
23
- export declare const policyRecommendationFromUploadEpic: (actions$: ActionsObservable<ActionType>, _state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => Observable<ActionType>;
@@ -1,111 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.policyRecommendationFromUploadEpic = void 0;
4
- const rxjs_1 = require("rxjs");
5
- const operators_1 = require("rxjs/operators");
6
- const aiCfoReducer_1 = require("../aiCfo/aiCfoReducer");
7
- const responsePayload_1 = require("../../responsePayload");
8
- const cardPolicyReducer_1 = require("./cardPolicyReducer");
9
- /**
10
- * Listens for `fetchCardPolicyRecommendationFromUpload` and POSTs the
11
- * just-extracted policy rules to the AI-CFO recommendation endpoint.
12
- *
13
- * On success — dispatches BOTH:
14
- * - `updatePolicyRecommendationFromUploadSuccess` (flips the
15
- * cardPolicy slice's recommendation lifecycle to `Completed`), and
16
- * - `updateAiCfoAnswerCardPolicyWizardPlan` (patches the in-flight AI
17
- * CFO answer's `CardPolicyInitialData` so the wizard can advance from
18
- * Step 1 → Step 2 in the upload variant).
19
- *
20
- * The reducer payload originally captured at kickoff (`answerId` +
21
- * `chatSessionId`) re-enters via the action so the patch can find the
22
- * right answer to merge into.
23
- */
24
- const policyRecommendationFromUploadEpic = (actions$, _state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(cardPolicyReducer_1.fetchCardPolicyRecommendationFromUpload.match),
25
- // `switchMap` (vs `mergeMap`) cancels any in-flight recommendation
26
- // whenever a new upload kicks off another one. Without this an older,
27
- // slower recommendation response could still resolve after a fresh
28
- // extract has started — that late response would dispatch
29
- // `updateAiCfoAnswerCardPolicyWizardPlan` against the *current*
30
- // `answerId`/`chatSessionId` (the ones captured at its kickoff) and
31
- // overwrite the wizard plan with stale draft policies from the prior
32
- // document. Pairs with the matching `switchMap` in
33
- // `extractPolicyDocumentEpic`.
34
- (0, operators_1.switchMap)((action) => {
35
- const { answerId, chatSessionId, extractedRules } = action.payload;
36
- const body = {
37
- extracted_rules: {
38
- allowed_entity: {
39
- category_codes: extractedRules.allowedEntity.categoryCodes,
40
- merchant_names: extractedRules.allowedEntity.merchantNames,
41
- },
42
- blocked_entity: {
43
- category_codes: extractedRules.blockedEntity.categoryCodes,
44
- merchant_names: extractedRules.blockedEntity.merchantNames,
45
- },
46
- confidence_score: extractedRules.confidenceScore,
47
- policy_name: extractedRules.policyName,
48
- required_receipt_threshold: extractedRules.requiredReceiptThreshold,
49
- transaction_limit: extractedRules.transactionLimit,
50
- },
51
- };
52
- return zeniAPI
53
- .postAndGetJSON(`${zeniAPI.apiEndPoints.cardMicroServiceBaseUrl}/1.0/ai-cfo/policy-recommendation-from-upload`, body)
54
- .pipe((0, operators_1.mergeMap)((response) => {
55
- if (!(0, responsePayload_1.isSuccessStatus)(response) ||
56
- response.data?.wizard_plan?.step_5_review == null) {
57
- return (0, rxjs_1.of)((0, cardPolicyReducer_1.updatePolicyRecommendationFromUploadFailure)(response.status));
58
- }
59
- const data = response.data;
60
- const review = data.wizard_plan.step_5_review;
61
- const wizardPlan = {
62
- step5Review: {
63
- draftPolicies: (review.draft_policies ?? []).map((draft, index) => ({
64
- id: `draft-${index}`,
65
- name: draft.name,
66
- description: draft.description ?? '',
67
- mode: draft.mode,
68
- allowedEntity: {
69
- categoryCodes: draft.allowed_entity?.category_codes ?? [],
70
- merchantNames: draft.allowed_entity?.merchant_names ?? [],
71
- },
72
- blockedEntity: {
73
- categoryCodes: draft.blocked_entity?.category_codes ?? [],
74
- merchantNames: draft.blocked_entity?.merchant_names ?? [],
75
- },
76
- applyToCards: draft.apply_to_cards ?? [],
77
- requiredReceiptThreshold: draft.required_receipt_threshold ?? 0,
78
- spendLimits: {
79
- transaction: draft.spend_limits?.transaction ?? 0,
80
- },
81
- })),
82
- groupingSource: review.grouping_source ?? 'none',
83
- prompt: review.prompt ?? '',
84
- },
85
- };
86
- const source = data.source != null
87
- ? {
88
- confidenceScore: data.source.confidence_score,
89
- fileName: data.source.file_name,
90
- lowConfidenceFields: data.source.low_confidence_fields ?? [],
91
- }
92
- : undefined;
93
- return (0, rxjs_1.of)((0, cardPolicyReducer_1.updatePolicyRecommendationFromUploadSuccess)(), (0, aiCfoReducer_1.updateAiCfoAnswerCardPolicyWizardPlan)({
94
- answerId,
95
- chatSessionId,
96
- wizardPlan,
97
- source,
98
- }));
99
- }), (0, operators_1.catchError)((error) => (0, rxjs_1.of)((0, cardPolicyReducer_1.updatePolicyRecommendationFromUploadFailure)((0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', 'Policy recommendation from upload REST API call errored out' +
100
- JSON.stringify(error))))),
101
- // `clearPolicyDocumentExtraction` (× pill) tears down the in-flight
102
- // recommendation subscription so a late response can't dispatch
103
- // `updateAiCfoAnswerCardPolicyWizardPlan` against the captured-at-
104
- // kickoff `answerId`/`chatSessionId` and patch the AI CFO answer
105
- // with a wizard plan the user already dismissed. The outer
106
- // `switchMap` only handles the "another upload kicks off another
107
- // recommendation" race; this guards the orthogonal "user cleared
108
- // mid-flight" case.
109
- (0, operators_1.takeUntil)(actions$.pipe((0, operators_1.filter)(cardPolicyReducer_1.clearPolicyDocumentExtraction.match))));
110
- }));
111
- exports.policyRecommendationFromUploadEpic = policyRecommendationFromUploadEpic;
@@ -1,130 +0,0 @@
1
- import { date } from '../../zeniDayJS';
2
- import { toCardPolicyTemplateMode, toCardPolicyTemplateStatus, } from './cardPolicyState';
3
- export const toMccCategory = (payload) => ({
4
- count: payload.count,
5
- mccCodes: payload.mcc_codes ?? [],
6
- name: payload.name,
7
- });
8
- export const toCardPolicyVendorSearchOption = (payload) => ({
9
- vendorId: payload.vendor_id,
10
- name: payload.vendor_name,
11
- });
12
- export const toCardPolicyStats = (payload) => ({
13
- activePolicies: payload.active_policies,
14
- totalCards: payload.total_cards,
15
- totalTemplates: payload.total_templates,
16
- });
17
- export const toCardPolicyTemplateList = (data) => (data.templates ?? []).map((row) => toCardPolicyTemplate(row.data.template));
18
- const toCardPolicyTemplateEntityList = (payload) => ({
19
- categoryCodes: payload.category_codes ?? [],
20
- merchantNames: payload.merchant_names ?? [],
21
- });
22
- export const toCardPolicyTemplate = (payload) => ({
23
- allowedEntity: toCardPolicyTemplateEntityList(payload.allowed_entity),
24
- appliedCards: payload.applied_cards ?? [],
25
- blockedEntity: toCardPolicyTemplateEntityList(payload.blocked_entity),
26
- cardsCount: payload.cards_count,
27
- categoryRestrictions: payload.category_restrictions ?? [],
28
- createdAt: date(payload.created_at),
29
- createdBy: payload.created_by,
30
- description: payload.description,
31
- mode: toCardPolicyTemplateMode(payload.mode),
32
- name: payload.name,
33
- requiredReceiptThreshold: payload.required_receipt_threshold,
34
- spendLimits: {
35
- transaction: payload.spend_limits.transaction,
36
- },
37
- status: toCardPolicyTemplateStatus(payload.status),
38
- templateId: payload.template_id,
39
- tenantId: payload.tenant_id,
40
- updatedAt: date(payload.updated_at),
41
- });
42
- /**
43
- * Re-shape a single camelCase create request into the snake_case wire
44
- * body. Used by the bulk-create mapper to build each entry of the
45
- * `templates` array, and directly by the update epic (PUT) since the
46
- * update endpoint still consumes a single object.
47
- */
48
- export const toCreateCardPolicyTemplateRequestBody = (request) => ({
49
- allowed_entity: {
50
- category_codes: request.allowedEntity.categoryCodes,
51
- merchant_names: request.allowedEntity.merchantNames,
52
- },
53
- apply_to_cards: request.applyToCards,
54
- blocked_entity: {
55
- category_codes: request.blockedEntity.categoryCodes,
56
- merchant_names: request.blockedEntity.merchantNames,
57
- },
58
- description: request.description,
59
- mode: request.mode ?? 'strict',
60
- name: request.name,
61
- required_receipt_threshold: request.requiredReceiptThreshold,
62
- spend_limits: {
63
- transaction: request.spendLimits.transaction,
64
- },
65
- });
66
- /**
67
- * Re-shape a bulk create request into the snake_case wire body for
68
- * `POST /cards/1.0/policy-templates`. Maps each entry through
69
- * `toCreateCardPolicyTemplateRequestBody` and only emits
70
- * `source_chat_session_id` when the camelCase counterpart is defined,
71
- * so manual-create callers don't ship a stray `undefined` over the wire.
72
- */
73
- export const toCreateCardPolicyTemplatesRequestBody = (request) => {
74
- const body = {
75
- templates: request.templates.map(toCreateCardPolicyTemplateRequestBody),
76
- };
77
- if (request.sourceChatSessionId != null) {
78
- body.source_chat_session_id = request.sourceChatSessionId;
79
- }
80
- return body;
81
- };
82
- /**
83
- * Map a single bulk-response error payload to its camelCased view shape.
84
- * Defensive against missing optional fields (see `BulkCreateCardPolicyTemplateErrorPayload`
85
- * docstring — the BE contract isn't fully locked yet).
86
- */
87
- export const toBulkCreateCardPolicyTemplateError = (payload) => ({
88
- message: payload.message,
89
- code: payload.code,
90
- index: payload.index,
91
- name: payload.name,
92
- });
93
- // Update body uses the exact same wire shape as create — the PUT
94
- // endpoint is a full replace and was not affected by the bulk migration.
95
- export const toUpdateCardPolicyTemplateRequestBody = toCreateCardPolicyTemplateRequestBody;
96
- /**
97
- * Seed an edit-form draft (`CreateCardPolicyTemplateRequest`) from an
98
- * existing camelCased `CardPolicyTemplate`. Used by the detail-fetch
99
- * epic so the edit page can render with the saved values pre-populated.
100
- */
101
- export const toCardPolicyEditFormDraft = (template) => ({
102
- allowedEntity: {
103
- categoryCodes: [...template.allowedEntity.categoryCodes],
104
- merchantNames: [...template.allowedEntity.merchantNames],
105
- },
106
- applyToCards: [...template.appliedCards],
107
- blockedEntity: {
108
- categoryCodes: [...template.blockedEntity.categoryCodes],
109
- merchantNames: [...template.blockedEntity.merchantNames],
110
- },
111
- description: template.description,
112
- mode: template.mode,
113
- name: template.name,
114
- requiredReceiptThreshold: template.requiredReceiptThreshold,
115
- spendLimits: { transaction: template.spendLimits.transaction },
116
- });
117
- export const toExtractedCardPolicyRules = (payload) => ({
118
- allowedEntity: {
119
- categoryCodes: payload.allowed_entity?.category_codes ?? [],
120
- merchantNames: payload.allowed_entity?.merchant_names ?? [],
121
- },
122
- blockedEntity: {
123
- categoryCodes: payload.blocked_entity?.category_codes ?? [],
124
- merchantNames: payload.blocked_entity?.merchant_names ?? [],
125
- },
126
- confidenceScore: payload.confidence_score,
127
- policyName: payload.policy_name,
128
- requiredReceiptThreshold: payload.required_receipt_threshold,
129
- transactionLimit: payload.transaction_limit,
130
- });