@zeniai/client-epic-state 5.0.65-betaRR7 → 5.0.65

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 (117) hide show
  1. package/lib/common/aiCfo/aiCfoSuggestedQuestionsPageContext.d.ts +1 -1
  2. package/lib/entity/aiCfo/aiCfoPayload.d.ts +1 -171
  3. package/lib/entity/aiCfo/aiCfoReducer.d.ts +1 -7
  4. package/lib/entity/aiCfo/aiCfoReducer.js +4 -219
  5. package/lib/entity/aiCfo/aiCfoState.d.ts +4 -163
  6. package/lib/entity/aiCfo/aiCfoState.js +1 -10
  7. package/lib/entity/jeSchedules/jeSchedulesTypes.d.ts +1 -1
  8. package/lib/entity/monthEndCloseChecks/monthEndCloseChecksState.d.ts +1 -1
  9. package/lib/entity/snackbar/snackbarTypes.d.ts +1 -1
  10. package/lib/entity/snackbar/snackbarTypes.js +0 -2
  11. package/lib/entity/tenant/clearAllEpic.d.ts +2 -6
  12. package/lib/entity/tenant/clearAllEpic.js +0 -8
  13. package/lib/epic.d.ts +1 -11
  14. package/lib/epic.js +1 -11
  15. package/lib/esm/entity/aiCfo/aiCfoReducer.js +4 -219
  16. package/lib/esm/entity/aiCfo/aiCfoState.js +0 -7
  17. package/lib/esm/entity/snackbar/snackbarTypes.js +0 -2
  18. package/lib/esm/entity/tenant/clearAllEpic.js +0 -8
  19. package/lib/esm/epic.js +1 -11
  20. package/lib/esm/index.js +4 -19
  21. package/lib/esm/reducer.js +0 -12
  22. package/lib/esm/view/aiCfoView/aiCfoViewReducer.js +3 -6
  23. package/lib/esm/view/aiCfoView/epics/createSessionAndSubmitEpic.js +2 -5
  24. package/lib/esm/view/aiCfoView/epics/createSessionEpic.js +1 -2
  25. package/lib/esm/view/aiCfoView/epics/fetchSuggestedQuestionsEpic.js +2 -12
  26. package/lib/esm/view/spendManagement/chargeCards/chargeCardList/chargeCardListSelector.js +0 -25
  27. package/lib/index.d.ts +4 -17
  28. package/lib/index.js +11 -112
  29. package/lib/reducer.d.ts +0 -12
  30. package/lib/reducer.js +0 -12
  31. package/lib/tsconfig.typecheck.tsbuildinfo +1 -0
  32. package/lib/view/aiCfoView/aiCfoViewReducer.d.ts +2 -11
  33. package/lib/view/aiCfoView/aiCfoViewReducer.js +3 -6
  34. package/lib/view/aiCfoView/epics/createSessionAndSubmitEpic.js +2 -5
  35. package/lib/view/aiCfoView/epics/createSessionEpic.js +1 -2
  36. package/lib/view/aiCfoView/epics/fetchSuggestedQuestionsEpic.d.ts +1 -8
  37. package/lib/view/aiCfoView/epics/fetchSuggestedQuestionsEpic.js +2 -12
  38. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
  39. package/lib/view/expenseAutomationView/types/jeSchedulesViewState.d.ts +1 -1
  40. package/lib/view/expenseAutomationView/types/missingReceiptsViewState.d.ts +2 -2
  41. package/lib/view/expenseAutomationView/types/transactionsViewState.d.ts +1 -1
  42. package/lib/view/people/peopleTypes.d.ts +1 -1
  43. package/lib/view/scheduleView/scheduleListView/scheduleListTypes.d.ts +1 -1
  44. package/lib/view/spendManagement/chargeCards/chargeCardList/chargeCardList.d.ts +1 -1
  45. package/lib/view/spendManagement/chargeCards/chargeCardList/chargeCardListSelector.d.ts +0 -14
  46. package/lib/view/spendManagement/chargeCards/chargeCardList/chargeCardListSelector.js +1 -27
  47. package/lib/view/taskManager/taskListView/taskListReducer.d.ts +1 -1
  48. package/package.json +1 -1
  49. package/lib/entity/cardPolicy/cardPolicyPayload.d.ts +0 -277
  50. package/lib/entity/cardPolicy/cardPolicyPayload.js +0 -143
  51. package/lib/entity/cardPolicy/cardPolicyReducer.d.ts +0 -19
  52. package/lib/entity/cardPolicy/cardPolicyReducer.js +0 -256
  53. package/lib/entity/cardPolicy/cardPolicySelector.d.ts +0 -32
  54. package/lib/entity/cardPolicy/cardPolicySelector.js +0 -103
  55. package/lib/entity/cardPolicy/cardPolicyState.d.ts +0 -205
  56. package/lib/entity/cardPolicy/cardPolicyState.js +0 -14
  57. package/lib/entity/cardPolicy/extractPolicyDocumentEpic.d.ts +0 -18
  58. package/lib/entity/cardPolicy/extractPolicyDocumentEpic.js +0 -54
  59. package/lib/entity/cardPolicy/fetchCardPolicyVendorOptionsEpic.d.ts +0 -26
  60. package/lib/entity/cardPolicy/fetchCardPolicyVendorOptionsEpic.js +0 -47
  61. package/lib/entity/cardPolicy/policyDocumentExtractionToRecommendationBridgeEpic.d.ts +0 -25
  62. package/lib/entity/cardPolicy/policyDocumentExtractionToRecommendationBridgeEpic.js +0 -39
  63. package/lib/entity/cardPolicy/policyRecommendationFromUploadEpic.d.ts +0 -23
  64. package/lib/entity/cardPolicy/policyRecommendationFromUploadEpic.js +0 -92
  65. package/lib/esm/entity/cardPolicy/cardPolicyPayload.js +0 -130
  66. package/lib/esm/entity/cardPolicy/cardPolicyReducer.js +0 -252
  67. package/lib/esm/entity/cardPolicy/cardPolicySelector.js +0 -79
  68. package/lib/esm/entity/cardPolicy/cardPolicyState.js +0 -9
  69. package/lib/esm/entity/cardPolicy/extractPolicyDocumentEpic.js +0 -50
  70. package/lib/esm/entity/cardPolicy/fetchCardPolicyVendorOptionsEpic.js +0 -43
  71. package/lib/esm/entity/cardPolicy/policyDocumentExtractionToRecommendationBridgeEpic.js +0 -35
  72. package/lib/esm/entity/cardPolicy/policyRecommendationFromUploadEpic.js +0 -88
  73. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailReducer.js +0 -70
  74. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailSelector.js +0 -22
  75. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailState.js +0 -1
  76. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/fetchCardPolicyDetailEpic.js +0 -56
  77. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/updateCardPolicyEpic.js +0 -49
  78. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/archiveCardPolicyEpic.js +0 -42
  79. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListReducer.js +0 -72
  80. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListSelector.js +0 -21
  81. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListState.js +0 -1
  82. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/fetchCardPolicyListEpic.js +0 -56
  83. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyReducer.js +0 -59
  84. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicySelector.js +0 -31
  85. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyState.js +0 -1
  86. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyTemplateEpic.js +0 -53
  87. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/fetchCardPolicyMccCategoriesEpic.js +0 -25
  88. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailReducer.d.ts +0 -14
  89. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailReducer.js +0 -74
  90. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailSelector.d.ts +0 -21
  91. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailSelector.js +0 -28
  92. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailState.d.ts +0 -25
  93. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/cardPolicyDetailState.js +0 -2
  94. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/fetchCardPolicyDetailEpic.d.ts +0 -19
  95. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/fetchCardPolicyDetailEpic.js +0 -60
  96. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/updateCardPolicyEpic.d.ts +0 -18
  97. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyDetail/updateCardPolicyEpic.js +0 -53
  98. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/archiveCardPolicyEpic.d.ts +0 -16
  99. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/archiveCardPolicyEpic.js +0 -46
  100. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListReducer.d.ts +0 -15
  101. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListReducer.js +0 -76
  102. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListSelector.d.ts +0 -21
  103. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListSelector.js +0 -27
  104. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListState.d.ts +0 -19
  105. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/cardPolicyListState.js +0 -2
  106. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/fetchCardPolicyListEpic.d.ts +0 -19
  107. package/lib/view/spendManagement/chargeCards/cardPolicy/cardPolicyList/fetchCardPolicyListEpic.js +0 -60
  108. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyReducer.d.ts +0 -13
  109. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyReducer.js +0 -63
  110. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicySelector.d.ts +0 -26
  111. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicySelector.js +0 -37
  112. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyState.d.ts +0 -36
  113. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyState.js +0 -2
  114. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyTemplateEpic.d.ts +0 -25
  115. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyTemplateEpic.js +0 -57
  116. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/fetchCardPolicyMccCategoriesEpic.d.ts +0 -15
  117. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/fetchCardPolicyMccCategoriesEpic.js +0 -29
@@ -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
- });
@@ -1,252 +0,0 @@
1
- import { createSlice } from '@reduxjs/toolkit';
2
- import { toCardPolicyTemplate, toCardPolicyVendorSearchOption, toExtractedCardPolicyRules, toMccCategory, } from './cardPolicyPayload';
3
- /**
4
- * Defensive predicate for vendor / merchant names that flow into
5
- * `buildVendorChipId(name)` (in `@zeniai/web-components`). That helper
6
- * calls `name.trim().toLowerCase()`, so a null / undefined / whitespace-
7
- * only value would throw at render time, and an empty string would
8
- * collapse every nameless row into a single colliding `vendor-` chip-id.
9
- * Used at the redux ingestion boundary for both the vendor-search results
10
- * and the BE-suggested merchant seed arrays.
11
- */
12
- const isUsableMerchantName = (name) => typeof name === 'string' && name.trim() !== '';
13
- const initialPolicyDocumentExtractionState = {
14
- fetchState: 'Not-Started',
15
- error: undefined,
16
- extractedRules: undefined,
17
- uploadedFileName: undefined,
18
- };
19
- const initialPolicyRecommendationFromUploadState = {
20
- fetchState: 'Not-Started',
21
- answerId: undefined,
22
- chatSessionId: undefined,
23
- error: undefined,
24
- };
25
- const initialVendorSearchState = {
26
- fetchState: 'Not-Started',
27
- searchString: '',
28
- vendors: [],
29
- error: undefined,
30
- };
31
- export const initialState = {
32
- cardPolicyTemplateById: {},
33
- mccCategories: [],
34
- mccCategoriesError: undefined,
35
- mccCategoriesFetchState: 'Not-Started',
36
- policyDocumentExtraction: initialPolicyDocumentExtractionState,
37
- policyRecommendationFromUpload: initialPolicyRecommendationFromUploadState,
38
- suggestedAllowCategories: [],
39
- suggestedAllowMerchants: [],
40
- suggestedBlockCategories: [],
41
- suggestedBlockMerchants: [],
42
- vendorSearch: initialVendorSearchState,
43
- cardPolicyStats: undefined,
44
- };
45
- const cardPolicy = createSlice({
46
- name: 'cardPolicy',
47
- initialState,
48
- reducers: {
49
- fetchCardPolicyMccCategories(draft) {
50
- draft.mccCategoriesFetchState = 'In-Progress';
51
- draft.mccCategoriesError = undefined;
52
- },
53
- updateCardPolicyMccCategories(draft, action) {
54
- draft.mccCategories = (action.payload.categories ?? []).map(toMccCategory);
55
- // Persist BE-suggested allow / block seeds alongside the universe.
56
- // Both flows (manual create page + AI CFO interactive form) read
57
- // these to pre-populate the chip cloud body before the user edits.
58
- // Drop empty / nullish merchant names defensively — they feed
59
- // `buildVendorChipId(name)` (in @zeniai/web-components) which calls
60
- // `.trim().toLowerCase()` and would crash the chip-picker render
61
- // path if any entry slipped through as undefined / "".
62
- draft.suggestedAllowMerchants = (action.payload.suggested_allow_merchants ?? []).filter(isUsableMerchantName);
63
- draft.suggestedBlockMerchants = (action.payload.suggested_block_merchants ?? []).filter(isUsableMerchantName);
64
- draft.suggestedAllowCategories = (action.payload.suggested_allow_catagories ?? []).map(toMccCategory);
65
- draft.suggestedBlockCategories = (action.payload.suggested_block_catagories ?? []).map(toMccCategory);
66
- draft.mccCategoriesFetchState = 'Completed';
67
- draft.mccCategoriesError = undefined;
68
- },
69
- updateCardPolicyMccCategoriesFailure(draft, action) {
70
- draft.mccCategoriesFetchState = 'Error';
71
- draft.mccCategoriesError = action.payload;
72
- },
73
- /**
74
- * Store a newly-created (or refreshed) card-policy template keyed by
75
- * `templateId`. Dispatched by the create / list / get epics; consumed
76
- * by both manual and AI-CFO policy flows via `getCardPolicyTemplateById`.
77
- */
78
- updateCreatedCardPolicyTemplate(draft, action) {
79
- const template = toCardPolicyTemplate(action.payload);
80
- draft.cardPolicyTemplateById[template.templateId] = template;
81
- },
82
- /**
83
- * Replace the entity store's `cardPolicyTemplateById` map with the
84
- * full list returned by the templates-list endpoint. Full replace is
85
- * intentional — templates that no longer exist on the server should be
86
- * dropped from local state too. The view slice keeps the server-order
87
- * ID list separately for stable list rendering.
88
- */
89
- updateCardPolicyTemplates(draft, action) {
90
- const byId = {};
91
- for (const template of action.payload) {
92
- byId[template.templateId] = template;
93
- }
94
- draft.cardPolicyTemplateById = byId;
95
- },
96
- /**
97
- * Drop a single template from the entity map. Dispatched by the
98
- * archive (DELETE) epic on success; also usable by any future flow
99
- * that needs to evict a template (e.g. AI-CFO rejection).
100
- */
101
- removeCardPolicyTemplate(draft, action) {
102
- delete draft.cardPolicyTemplateById[action.payload];
103
- },
104
- /**
105
- * Replace the tenant-wide policy stats. Dispatched alongside
106
- * `updateCardPolicyTemplates` from the list epic, but lives on the
107
- * entity slice so any consumer can read it without re-fetching the
108
- * list.
109
- */
110
- updateCardPolicyStats(draft, action) {
111
- draft.cardPolicyStats = action.payload;
112
- },
113
- /**
114
- * Kick off the `POST /cards/1.0/policy-documents/extract` request.
115
- *
116
- * Synchronously flips the sub-slice to `In-Progress` and captures the
117
- * first uploaded file's name (used by the manual `CardPolicyCreatePage`
118
- * to render the "Policy.pdf ×" pill once the request completes) so
119
- * downstream callers don't have to keep their own file refs.
120
- *
121
- * The accompanying `extractPolicyDocumentEpic` listens for this action,
122
- * POSTs multipart form-data to the cards micro-service, and dispatches
123
- * either `updatePolicyDocumentExtractionSuccess` or
124
- * `updatePolicyDocumentExtractionFailure`.
125
- *
126
- * Designed to be dispatched from both the manual create page and a
127
- * future AI CFO composer/upload surface — selectors return a single
128
- * source of truth.
129
- */
130
- extractPolicyDocument: {
131
- reducer(draft, action) {
132
- draft.policyDocumentExtraction.fetchState = 'In-Progress';
133
- draft.policyDocumentExtraction.error = undefined;
134
- draft.policyDocumentExtraction.extractedRules = undefined;
135
- draft.policyDocumentExtraction.uploadedFileName =
136
- action.meta.uploadedFileName;
137
- draft.policyDocumentExtraction.aiCfoAnswerId =
138
- action.payload.aiCfoAnswerId;
139
- draft.policyDocumentExtraction.aiCfoChatSessionId =
140
- action.payload.aiCfoChatSessionId;
141
- },
142
- prepare(files, aiCfoAnswerId, aiCfoChatSessionId) {
143
- return {
144
- payload: { files, aiCfoAnswerId, aiCfoChatSessionId },
145
- meta: { uploadedFileName: files[0]?.name },
146
- };
147
- },
148
- },
149
- updatePolicyDocumentExtractionSuccess(draft, action) {
150
- draft.policyDocumentExtraction.fetchState = 'Completed';
151
- draft.policyDocumentExtraction.error = undefined;
152
- draft.policyDocumentExtraction.extractedRules =
153
- toExtractedCardPolicyRules(action.payload);
154
- },
155
- updatePolicyDocumentExtractionFailure(draft, action) {
156
- draft.policyDocumentExtraction.fetchState = 'Error';
157
- draft.policyDocumentExtraction.error = action.payload;
158
- draft.policyDocumentExtraction.extractedRules = undefined;
159
- },
160
- clearPolicyDocumentExtraction(draft) {
161
- draft.policyDocumentExtraction = {
162
- ...initialPolicyDocumentExtractionState,
163
- };
164
- // Clear the chained recommendation slice too — the two together
165
- // model the upload lifecycle and either both reset (× pill,
166
- // unmount) or both advance (drop file → extract → recommend).
167
- draft.policyRecommendationFromUpload = {
168
- ...initialPolicyRecommendationFromUploadState,
169
- };
170
- },
171
- /**
172
- * Kick off `POST /cards/1.0/ai-cfo/policy-recommendation-from-upload`.
173
- *
174
- * Chained after `extractPolicyDocument` succeeds in the AI CFO
175
- * `upload`-mode flow. The accompanying epic forwards the
176
- * just-returned `extracted_rules` to the BE and dispatches success /
177
- * failure into this slice; on success, a sibling action
178
- * (`updateAiCfoAnswerCardPolicyWizardPlan` on the aiCfo slice) is
179
- * dispatched by the epic to merge the returned `wizard_plan` + `source`
180
- * into the in-flight AI CFO answer's `CardPolicyInitialData`.
181
- *
182
- * `answerId` + `chatSessionId` identify which AI CFO answer should
183
- * receive the patch. Both are required so the wizard reads a single
184
- * source of truth for its lifecycle pill (`fetchState`) and the
185
- * bridge epic can correlate against the originating answer.
186
- */
187
- fetchCardPolicyRecommendationFromUpload: {
188
- reducer(draft, action) {
189
- draft.policyRecommendationFromUpload.fetchState = 'In-Progress';
190
- draft.policyRecommendationFromUpload.answerId = action.payload.answerId;
191
- draft.policyRecommendationFromUpload.chatSessionId =
192
- action.payload.chatSessionId;
193
- draft.policyRecommendationFromUpload.error = undefined;
194
- },
195
- prepare(answerId, chatSessionId, extractedRules) {
196
- return { payload: { answerId, chatSessionId, extractedRules } };
197
- },
198
- },
199
- updatePolicyRecommendationFromUploadSuccess(draft) {
200
- draft.policyRecommendationFromUpload.fetchState = 'Completed';
201
- draft.policyRecommendationFromUpload.error = undefined;
202
- },
203
- updatePolicyRecommendationFromUploadFailure(draft, action) {
204
- draft.policyRecommendationFromUpload.fetchState = 'Error';
205
- draft.policyRecommendationFromUpload.error = action.payload;
206
- },
207
- /**
208
- * Kick off `GET /accounting/1.0/vendors` (card-policy mode). When
209
- * `searchString` is empty the BE returns the top vendors sorted by
210
- * year-to-date spend; with a non-empty value it filters server-side.
211
- *
212
- * The accompanying `fetchCardPolicyVendorOptionsEpic` listens for
213
- * this action, builds the `query` JSON (matching `fetchVendorsList`'s
214
- * `view: "vendor_list"` shape) and dispatches success / failure.
215
- *
216
- * Designed to be dispatched from both the manual `CardPolicyCreate /
217
- * EditScreen` (on mount + on every chip-picker keystroke, debounced)
218
- * and the AI CFO interactive form's vendor step.
219
- */
220
- fetchCardPolicyVendorOptions: {
221
- reducer(draft, action) {
222
- draft.vendorSearch.fetchState = 'In-Progress';
223
- draft.vendorSearch.searchString = action.payload.searchString;
224
- draft.vendorSearch.error = undefined;
225
- },
226
- prepare(searchString) {
227
- return { payload: { searchString: searchString ?? '' } };
228
- },
229
- },
230
- updateCardPolicyVendorOptions(draft, action) {
231
- // Drop rows with no usable name. The chip-picker keys vendors by
232
- // `buildVendorChipId(name)` (in @zeniai/web-components), which calls
233
- // `name.trim().toLowerCase()`. A null / undefined / whitespace-only
234
- // name would either throw at render time or collapse every nameless
235
- // row into a single colliding `vendor-` chip-id.
236
- draft.vendorSearch.vendors = (action.payload.vendors ?? [])
237
- .map(toCardPolicyVendorSearchOption)
238
- .filter((vendor) => isUsableMerchantName(vendor.name));
239
- draft.vendorSearch.fetchState = 'Completed';
240
- draft.vendorSearch.error = undefined;
241
- },
242
- updateCardPolicyVendorOptionsFailure(draft, action) {
243
- draft.vendorSearch.fetchState = 'Error';
244
- draft.vendorSearch.error = action.payload;
245
- },
246
- clearCardPolicy(draft) {
247
- Object.assign(draft, initialState);
248
- },
249
- },
250
- });
251
- export const { fetchCardPolicyMccCategories, fetchCardPolicyVendorOptions, updateCardPolicyMccCategories, updateCardPolicyMccCategoriesFailure, updateCardPolicyVendorOptions, updateCardPolicyVendorOptionsFailure, updateCreatedCardPolicyTemplate, updateCardPolicyTemplates, removeCardPolicyTemplate, updateCardPolicyStats, extractPolicyDocument, updatePolicyDocumentExtractionSuccess, updatePolicyDocumentExtractionFailure, clearPolicyDocumentExtraction, fetchCardPolicyRecommendationFromUpload, updatePolicyRecommendationFromUploadSuccess, updatePolicyRecommendationFromUploadFailure, clearCardPolicy, } = cardPolicy.actions;
252
- export default cardPolicy.reducer;
@@ -1,79 +0,0 @@
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
- // ── Policy document extraction ───────────────────────────────────────
32
- export function getPolicyDocumentExtractionFetchState(state) {
33
- return state.policyDocumentExtraction.fetchState;
34
- }
35
- export function getPolicyDocumentExtractionError(state) {
36
- return state.policyDocumentExtraction.error;
37
- }
38
- export function getExtractedCardPolicyRules(state) {
39
- return state.policyDocumentExtraction.extractedRules;
40
- }
41
- export function getUploadedPolicyDocumentFileName(state) {
42
- return state.policyDocumentExtraction.uploadedFileName;
43
- }
44
- // ── Policy recommendation from upload (AI CFO upload mode) ───────────
45
- export function getPolicyRecommendationFromUploadFetchState(state) {
46
- return state.policyRecommendationFromUpload.fetchState;
47
- }
48
- export function getPolicyRecommendationFromUploadError(state) {
49
- return state.policyRecommendationFromUpload.error;
50
- }
51
- export function getPolicyRecommendationFromUploadAnswerId(state) {
52
- return state.policyRecommendationFromUpload.answerId;
53
- }
54
- export function getPolicyRecommendationFromUploadChatSessionId(state) {
55
- return state.policyRecommendationFromUpload.chatSessionId;
56
- }
57
- // ── Suggested allow / block seeds (shipped alongside MCC categories) ─
58
- export function getCardPolicySuggestedAllowMerchants(state) {
59
- return state.suggestedAllowMerchants;
60
- }
61
- export function getCardPolicySuggestedBlockMerchants(state) {
62
- return state.suggestedBlockMerchants;
63
- }
64
- export function getCardPolicySuggestedAllowCategories(state) {
65
- return state.suggestedAllowCategories;
66
- }
67
- export function getCardPolicySuggestedBlockCategories(state) {
68
- return state.suggestedBlockCategories;
69
- }
70
- // ── Vendor search dropdown ───────────────────────────────────────────
71
- export function getCardPolicyVendorSearchOptions(state) {
72
- return state.vendorSearch.vendors;
73
- }
74
- export function getCardPolicyVendorSearchFetchState(state) {
75
- return state.vendorSearch.fetchState;
76
- }
77
- export function getCardPolicyVendorSearchString(state) {
78
- return state.vendorSearch.searchString;
79
- }
@@ -1,9 +0,0 @@
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);
@@ -1,50 +0,0 @@
1
- import { of } from 'rxjs';
2
- import { catchError, filter, mergeMap } from 'rxjs/operators';
3
- import { createZeniAPIStatus, isSuccessStatus } from '../../responsePayload';
4
- import { 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), mergeMap((action) => {
38
- const formData = buildPolicyDocumentFormData(action.payload.files);
39
- return zeniAPI
40
- .postFormData(`${zeniAPI.apiEndPoints.cardMicroServiceBaseUrl}/1.0/policy-documents/extract`, formData)
41
- .pipe(mergeMap((response) => {
42
- if (isSuccessStatus(response) &&
43
- response.data != null &&
44
- response.data.extracted_rules != null) {
45
- return of(updatePolicyDocumentExtractionSuccess(response.data.extracted_rules));
46
- }
47
- return of(updatePolicyDocumentExtractionFailure(response.status));
48
- }), catchError((error) => of(updatePolicyDocumentExtractionFailure(createZeniAPIStatus('Unexpected Error', 'Extract card-policy document REST API call errored out' +
49
- JSON.stringify(error))))));
50
- }));
@@ -1,43 +0,0 @@
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
- }));
@@ -1,35 +0,0 @@
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
- }));