@zeniai/client-epic-state 5.0.83-betaRR5 → 5.0.83

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 (97) hide show
  1. package/lib/entity/aiCfo/aiCfoPayload.d.ts +4 -1
  2. package/lib/entity/aiCfo/aiCfoReducer.js +17 -4
  3. package/lib/entity/aiCfo/aiCfoState.d.ts +19 -0
  4. package/lib/entity/aiCfo/aiCfoState.js +8 -1
  5. package/lib/entity/cardPolicy/cardPolicyReducer.js +99 -9
  6. package/lib/entity/cardPolicy/cardPolicySelector.js +4 -0
  7. package/lib/entity/cardPolicy/policyRecommendationFromUploadEpic.d.ts +2 -3
  8. package/lib/entity/cardPolicy/policyRecommendationFromUploadEpic.js +10 -4
  9. package/lib/epic.d.ts +12 -15
  10. package/lib/epic.js +12 -15
  11. package/lib/esm/entity/aiCfo/aiCfoReducer.js +18 -5
  12. package/lib/esm/entity/aiCfo/aiCfoState.js +7 -0
  13. package/lib/esm/entity/cardPolicy/cardPolicyReducer.js +99 -9
  14. package/lib/esm/entity/cardPolicy/cardPolicySelector.js +4 -0
  15. package/lib/esm/entity/cardPolicy/policyRecommendationFromUploadEpic.js +11 -5
  16. package/lib/esm/epic.js +12 -15
  17. package/lib/esm/index.js +6 -21
  18. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyReducer.js +19 -138
  19. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicySelector.js +0 -18
  20. package/lib/esm/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardReducer.js +5 -38
  21. package/lib/esm/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardSelector.js +0 -23
  22. package/lib/index.d.ts +7 -28
  23. package/lib/index.js +14 -68
  24. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyReducer.d.ts +1 -40
  25. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyReducer.js +20 -139
  26. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicySelector.d.ts +0 -15
  27. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicySelector.js +0 -20
  28. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/createCardPolicyState.d.ts +0 -28
  29. package/lib/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardReducer.d.ts +1 -7
  30. package/lib/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardReducer.js +6 -39
  31. package/lib/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardSelector.d.ts +0 -15
  32. package/lib/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardSelector.js +1 -26
  33. package/lib/view/spendManagement/chargeCards/issueChargeCard/issueChargeCardState.d.ts +0 -16
  34. package/package.json +1 -1
  35. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/applyAiCardPolicyFormDraftUpdate.js +0 -328
  36. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/applyExtractedPolicyToAiCardPolicyDraft.js +0 -120
  37. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/applyExtractedPolicyToDraftEpic.js +0 -60
  38. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/applyExtractedPolicyToManualCardPolicyDraft.js +0 -118
  39. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/applyUploadPlanToAiCardPolicyDraft.js +0 -33
  40. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/buildAiCardPolicyFormDraftSeed.js +0 -385
  41. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/buildManualCardPolicyFormDraftSeed.js +0 -34
  42. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/cardPolicyChipIds.js +0 -33
  43. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/cardPolicyFormDraftTypes.js +0 -17
  44. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/cardPolicyRequestParts.js +0 -144
  45. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/deriveAiPolicyReviewRowsFromInputs.js +0 -148
  46. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/seedAiCardPolicyFormDraftEpic.js +0 -112
  47. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/toBulkCardPolicyTemplateRequestsFromDraft.js +0 -101
  48. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/toCardPolicyTemplateRequestFromDraft.js +0 -71
  49. package/lib/esm/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/toManualCardPolicyTemplateRequestFromDraft.js +0 -34
  50. package/lib/esm/view/spendManagement/chargeCards/issueChargeCard/aiCardCreationFormDraftTypes.js +0 -1
  51. package/lib/esm/view/spendManagement/chargeCards/issueChargeCard/applyAiCardCreationFormDraftUpdate.js +0 -42
  52. package/lib/esm/view/spendManagement/chargeCards/issueChargeCard/buildAiCardCreationFormDraftSeed.js +0 -69
  53. package/lib/esm/view/spendManagement/chargeCards/issueChargeCard/deriveAiCardRowsFromTeams.js +0 -45
  54. package/lib/esm/view/spendManagement/chargeCards/issueChargeCard/seedAiCardCreationFormDraftEpic.js +0 -65
  55. package/lib/esm/view/spendManagement/chargeCards/issueChargeCard/toIssueChargeCardLocalDataFromDraft.js +0 -64
  56. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/applyAiCardPolicyFormDraftUpdate.d.ts +0 -38
  57. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/applyAiCardPolicyFormDraftUpdate.js +0 -333
  58. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/applyExtractedPolicyToAiCardPolicyDraft.d.ts +0 -25
  59. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/applyExtractedPolicyToAiCardPolicyDraft.js +0 -124
  60. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/applyExtractedPolicyToDraftEpic.d.ts +0 -28
  61. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/applyExtractedPolicyToDraftEpic.js +0 -64
  62. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/applyExtractedPolicyToManualCardPolicyDraft.d.ts +0 -17
  63. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/applyExtractedPolicyToManualCardPolicyDraft.js +0 -122
  64. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/applyUploadPlanToAiCardPolicyDraft.d.ts +0 -23
  65. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/applyUploadPlanToAiCardPolicyDraft.js +0 -37
  66. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/buildAiCardPolicyFormDraftSeed.d.ts +0 -38
  67. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/buildAiCardPolicyFormDraftSeed.js +0 -391
  68. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/buildManualCardPolicyFormDraftSeed.d.ts +0 -11
  69. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/buildManualCardPolicyFormDraftSeed.js +0 -38
  70. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/cardPolicyChipIds.d.ts +0 -24
  71. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/cardPolicyChipIds.js +0 -40
  72. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/cardPolicyFormDraftTypes.d.ts +0 -253
  73. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/cardPolicyFormDraftTypes.js +0 -21
  74. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/cardPolicyRequestParts.d.ts +0 -66
  75. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/cardPolicyRequestParts.js +0 -151
  76. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/deriveAiPolicyReviewRowsFromInputs.d.ts +0 -30
  77. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/deriveAiPolicyReviewRowsFromInputs.js +0 -152
  78. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/seedAiCardPolicyFormDraftEpic.d.ts +0 -26
  79. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/seedAiCardPolicyFormDraftEpic.js +0 -116
  80. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/toBulkCardPolicyTemplateRequestsFromDraft.d.ts +0 -35
  81. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/toBulkCardPolicyTemplateRequestsFromDraft.js +0 -105
  82. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/toCardPolicyTemplateRequestFromDraft.d.ts +0 -23
  83. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/toCardPolicyTemplateRequestFromDraft.js +0 -75
  84. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/toManualCardPolicyTemplateRequestFromDraft.d.ts +0 -15
  85. package/lib/view/spendManagement/chargeCards/cardPolicy/createCardPolicy/toManualCardPolicyTemplateRequestFromDraft.js +0 -38
  86. package/lib/view/spendManagement/chargeCards/issueChargeCard/aiCardCreationFormDraftTypes.d.ts +0 -76
  87. package/lib/view/spendManagement/chargeCards/issueChargeCard/aiCardCreationFormDraftTypes.js +0 -2
  88. package/lib/view/spendManagement/chargeCards/issueChargeCard/applyAiCardCreationFormDraftUpdate.d.ts +0 -7
  89. package/lib/view/spendManagement/chargeCards/issueChargeCard/applyAiCardCreationFormDraftUpdate.js +0 -46
  90. package/lib/view/spendManagement/chargeCards/issueChargeCard/buildAiCardCreationFormDraftSeed.d.ts +0 -28
  91. package/lib/view/spendManagement/chargeCards/issueChargeCard/buildAiCardCreationFormDraftSeed.js +0 -73
  92. package/lib/view/spendManagement/chargeCards/issueChargeCard/deriveAiCardRowsFromTeams.d.ts +0 -23
  93. package/lib/view/spendManagement/chargeCards/issueChargeCard/deriveAiCardRowsFromTeams.js +0 -49
  94. package/lib/view/spendManagement/chargeCards/issueChargeCard/seedAiCardCreationFormDraftEpic.d.ts +0 -11
  95. package/lib/view/spendManagement/chargeCards/issueChargeCard/seedAiCardCreationFormDraftEpic.js +0 -69
  96. package/lib/view/spendManagement/chargeCards/issueChargeCard/toIssueChargeCardLocalDataFromDraft.d.ts +0 -11
  97. package/lib/view/spendManagement/chargeCards/issueChargeCard/toIssueChargeCardLocalDataFromDraft.js +0 -68
@@ -1,26 +0,0 @@
1
- import { ActionsObservable, StateObservable } from 'redux-observable';
2
- import { Observable } from 'rxjs';
3
- import { upsertAnswerPayload, upsertOrAddQuestionAnswerPayload } from '../../../../../entity/aiCfo/aiCfoReducer';
4
- import { fetchCardPolicyMccCategories } from '../../../../../entity/cardPolicy/cardPolicyReducer';
5
- import { RootState } from '../../../../../reducer';
6
- import { clearAiCardPolicyFormDraft, createCardPolicyTemplates, seedAiCardPolicyFormDraft, updateCreateCardPolicyTemplateRequestState } from './createCardPolicyReducer';
7
- export type ActionType = ReturnType<typeof fetchCardPolicyMccCategories> | ReturnType<typeof seedAiCardPolicyFormDraft> | ReturnType<typeof clearAiCardPolicyFormDraft>;
8
- type SeedTriggerAction = ReturnType<typeof upsertAnswerPayload> | ReturnType<typeof upsertOrAddQuestionAnswerPayload>;
9
- type InboundAction = SeedTriggerAction | ReturnType<typeof createCardPolicyTemplates> | ReturnType<typeof updateCreateCardPolicyTemplateRequestState>;
10
- /**
11
- * Listens for AI CFO `interactive_form` answers with
12
- * `formType === "card_policy"` and seeds the AI card-policy form
13
- * draft + companion context onto `createCardPolicy` state. Mirrors
14
- * `seedAiCardCreationFormDraftEpic` for the cards form.
15
- *
16
- * Also clears the draft on a successful bulk create so a stale draft
17
- * doesn't leak into the next AI session.
18
- *
19
- * MCC categories drive category chip labels in the seed. When the
20
- * categories slice isn't loaded yet, the epic kicks off
21
- * `fetchCardPolicyMccCategories` and waits for `Completed` before
22
- * dispatching the seed (mirrors `fetchUserListByType` in the cards
23
- * variant).
24
- */
25
- export declare const seedAiCardPolicyFormDraftEpic: (actions$: ActionsObservable<InboundAction>, state$: StateObservable<RootState>) => Observable<ActionType>;
26
- export {};
@@ -1,116 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.seedAiCardPolicyFormDraftEpic = void 0;
4
- const rxjs_1 = require("rxjs");
5
- const operators_1 = require("rxjs/operators");
6
- const aiCfoReducer_1 = require("../../../../../entity/aiCfo/aiCfoReducer");
7
- const aiCfoSelector_1 = require("../../../../../entity/aiCfo/aiCfoSelector");
8
- const cardPolicyReducer_1 = require("../../../../../entity/cardPolicy/cardPolicyReducer");
9
- const chargeCardListSelector_1 = require("../../chargeCardList/chargeCardListSelector");
10
- const createCardPolicyReducer_1 = require("./createCardPolicyReducer");
11
- const isClosedChargeCardStatusCode = (code) => code === 'closed' || code === 'closed_by_customer';
12
- const toCardPolicyCardSelectionRow = (card) => {
13
- const user = card.cardHolderUser;
14
- const displayName = `${user.firstName ?? ''} ${user.lastName ?? ''}`.trim() ||
15
- user.email ||
16
- user.userId;
17
- return {
18
- id: card.id,
19
- isChecked: false,
20
- cardName: card.cardName,
21
- last4: card.accountLast4,
22
- limitAmount: card.limit?.amount ?? 0,
23
- limitCadence: card.creditLimitFrequency?.code,
24
- owner: {
25
- userId: user.userId,
26
- displayName,
27
- roleLabel: card.cardHolderRoles?.titleAtCompany,
28
- },
29
- utilizationAmount: (card.limit?.amount ?? 0) - (card.available?.amount ?? 0),
30
- };
31
- };
32
- const readCardsMasterList = (state) => {
33
- const view = (0, chargeCardListSelector_1.getAllChargeCardsWithUser)(state);
34
- return view.cards
35
- .filter((card) => !isClosedChargeCardStatusCode(card.status?.code))
36
- .map(toCardPolicyCardSelectionRow);
37
- };
38
- const readMccCategoriesAvailable = (state) => state.cardPolicyState.mccCategoriesFetchState === 'Completed';
39
- const readCardPolicyPayload = (state, chatSessionId, questionAnswerId) => {
40
- const qa = (0, aiCfoSelector_1.getQuestionAnswerByIdForChatSession)(state.aiCfoState, chatSessionId, questionAnswerId);
41
- const visualization = qa?.responses.answer?.content.visualization;
42
- if (visualization?.type !== 'interactive_form') {
43
- return undefined;
44
- }
45
- const data = visualization.data;
46
- if (!('formType' in data) || data.formType !== 'card_policy') {
47
- return undefined;
48
- }
49
- return data.payload;
50
- };
51
- const resolveQuestionAnswerId = (state, action) => {
52
- if (action.payload.questionAnswerId != null) {
53
- return action.payload.questionAnswerId;
54
- }
55
- const session = state.aiCfoState.aiCfoByChatSessionId[action.payload.chatSessionId];
56
- return session?.questionAnswers.slice(-1)[0]?.questionAnswerId;
57
- };
58
- const isSeedTrigger = (action) => aiCfoReducer_1.upsertAnswerPayload.match(action) ||
59
- aiCfoReducer_1.upsertOrAddQuestionAnswerPayload.match(action);
60
- const isCreateSuccess = (action) => createCardPolicyReducer_1.updateCreateCardPolicyTemplateRequestState.match(action) &&
61
- action.payload.fetchState === 'Completed';
62
- const buildSeedAction = (state, payload) => {
63
- const cardsMasterList = readCardsMasterList(state);
64
- const mccCategories = state.cardPolicyState.mccCategories;
65
- return (0, createCardPolicyReducer_1.seedAiCardPolicyFormDraft)({
66
- initialData: payload,
67
- cardsMasterList,
68
- mccCategories,
69
- suggestedAllowMerchants: state.cardPolicyState.suggestedAllowMerchants,
70
- suggestedBlockMerchants: state.cardPolicyState.suggestedBlockMerchants,
71
- suggestedAllowCategories: state.cardPolicyState.suggestedAllowCategories,
72
- suggestedBlockCategories: state.cardPolicyState.suggestedBlockCategories,
73
- });
74
- };
75
- /**
76
- * Listens for AI CFO `interactive_form` answers with
77
- * `formType === "card_policy"` and seeds the AI card-policy form
78
- * draft + companion context onto `createCardPolicy` state. Mirrors
79
- * `seedAiCardCreationFormDraftEpic` for the cards form.
80
- *
81
- * Also clears the draft on a successful bulk create so a stale draft
82
- * doesn't leak into the next AI session.
83
- *
84
- * MCC categories drive category chip labels in the seed. When the
85
- * categories slice isn't loaded yet, the epic kicks off
86
- * `fetchCardPolicyMccCategories` and waits for `Completed` before
87
- * dispatching the seed (mirrors `fetchUserListByType` in the cards
88
- * variant).
89
- */
90
- const seedAiCardPolicyFormDraftEpic = (actions$, state$) => actions$.pipe((0, operators_1.mergeMap)((action) => {
91
- if (isCreateSuccess(action)) {
92
- return (0, rxjs_1.of)((0, createCardPolicyReducer_1.clearAiCardPolicyFormDraft)());
93
- }
94
- if (!isSeedTrigger(action)) {
95
- return rxjs_1.EMPTY;
96
- }
97
- const state = state$.value;
98
- const questionAnswerId = resolveQuestionAnswerId(state, action);
99
- if (questionAnswerId == null) {
100
- return rxjs_1.EMPTY;
101
- }
102
- const payload = readCardPolicyPayload(state, action.payload.chatSessionId, questionAnswerId);
103
- if (payload == null) {
104
- return rxjs_1.EMPTY;
105
- }
106
- if (readMccCategoriesAvailable(state)) {
107
- return (0, rxjs_1.of)(buildSeedAction(state, payload));
108
- }
109
- const seedWhenMccLoaded$ = state$.pipe((0, operators_1.map)((rs) => readMccCategoriesAvailable(rs)), (0, operators_1.distinctUntilChanged)(), (0, operators_1.filter)((available) => available), (0, operators_1.take)(1), (0, operators_1.map)(() => buildSeedAction(state$.value, payload)));
110
- const mccFetchState = state.cardPolicyState.mccCategoriesFetchState;
111
- if (mccFetchState === 'In-Progress') {
112
- return seedWhenMccLoaded$;
113
- }
114
- return (0, rxjs_1.concat)((0, rxjs_1.of)((0, cardPolicyReducer_1.fetchCardPolicyMccCategories)()), seedWhenMccLoaded$);
115
- }));
116
- exports.seedAiCardPolicyFormDraftEpic = seedAiCardPolicyFormDraftEpic;
@@ -1,35 +0,0 @@
1
- import { ID } from '../../../../../commonStateTypes/common';
2
- import { CardPolicyTemplateEntityList } from '../../../../../entity/cardPolicy/cardPolicyState';
3
- import { CardPolicyFormDraft, CardPolicyModeValue } from './cardPolicyFormDraftTypes';
4
- export type CardPolicyBulkSubmitKind = 'auto' | 'guided' | 'upload';
5
- /**
6
- * Per-row wire entry produced by the bulk builder. Structural superset
7
- * of `CreateCardPolicyTemplateRequest` with `mode`, `spendLimits`, and
8
- * `requiredReceiptThreshold` widened to optional so the `auto` /
9
- * `upload` modes can drop them entirely.
10
- */
11
- export interface BulkCreateCardPolicyTemplateEntry {
12
- allowedEntity: CardPolicyTemplateEntityList;
13
- applyToCards: ID[];
14
- blockedEntity: CardPolicyTemplateEntityList;
15
- description: string;
16
- name: string;
17
- mode?: CardPolicyModeValue;
18
- requiredReceiptThreshold?: number | null;
19
- spendLimits?: {
20
- transaction: number | null;
21
- };
22
- }
23
- export interface ToBulkCardPolicyTemplateRequestsFromDraftArgs {
24
- draft: CardPolicyFormDraft;
25
- description?: string;
26
- /** Defaults to `"strict"`; only consumed by guided submit. */
27
- guidedMode?: CardPolicyModeValue;
28
- }
29
- /**
30
- * Build the array of per-row entries for the bulk
31
- * `createCardPolicyTemplates` action from the AI CFO form draft.
32
- * Iterates checked review rows and emits one entry per row, with the
33
- * per-mode key contract enforced internally.
34
- */
35
- export declare const toBulkCardPolicyTemplateRequestsFromDraft: ({ draft, description, guidedMode, }: ToBulkCardPolicyTemplateRequestsFromDraftArgs) => BulkCreateCardPolicyTemplateEntry[];
@@ -1,105 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toBulkCardPolicyTemplateRequestsFromDraft = void 0;
4
- const cardPolicyFormDraftTypes_1 = require("./cardPolicyFormDraftTypes");
5
- const cardPolicyRequestParts_1 = require("./cardPolicyRequestParts");
6
- const isSelectedChip = (chip) => chip.isSelected !== false;
7
- const chipsInGroup = (row, groupId) => {
8
- const group = row.chipGroups.find((g) => g.id === groupId);
9
- if (group == null) {
10
- return [];
11
- }
12
- return group.chips.filter(isSelectedChip);
13
- };
14
- const collectVendorLabelsFromReviewRow = (row, groupId) => chipsInGroup(row, groupId).map((chip) => chip.label);
15
- const collectCategoryCodesFromReviewRow = (row, groupId) => chipsInGroup(row, groupId).map((chip) => chip.optionalCode ?? chip.id);
16
- const collectCardIdsFromReviewRow = (row) => chipsInGroup(row, cardPolicyRequestParts_1.REVIEW_GROUP_IDS.appliedToCards).flatMap((chip) => chip.cardIds ?? []);
17
- const limitValueFromReviewRow = (row, chipId) => {
18
- const group = row.chipGroups.find((g) => g.id === cardPolicyRequestParts_1.REVIEW_GROUP_IDS.limits);
19
- if (group == null) {
20
- return null;
21
- }
22
- const chip = group.chips.find((c) => c.id === chipId && isSelectedChip(c));
23
- if (chip == null) {
24
- return null;
25
- }
26
- if (chip.optionalCode != null) {
27
- const parsed = Number(chip.optionalCode);
28
- return Number.isFinite(parsed) ? parsed : null;
29
- }
30
- const labelDigits = chip.label.match(/\d+(?:\.\d+)?/);
31
- if (labelDigits == null) {
32
- return null;
33
- }
34
- const parsed = Number(labelDigits[0]);
35
- return Number.isFinite(parsed) ? parsed : null;
36
- };
37
- const buildGuidedEntry = (row, draft, guidedMode, description) => ({
38
- allowedEntity: {
39
- categoryCodes: (0, cardPolicyRequestParts_1.collectCategoryCodes)(draft.categoryPolicy, 'allow'),
40
- merchantNames: (0, cardPolicyRequestParts_1.collectMerchantNames)(draft.vendorPolicy, 'allow'),
41
- },
42
- applyToCards: draft.cardSelections
43
- .filter((card) => card.isChecked)
44
- .map((card) => card.id),
45
- blockedEntity: {
46
- categoryCodes: (0, cardPolicyRequestParts_1.collectCategoryCodes)(draft.categoryPolicy, 'block'),
47
- merchantNames: (0, cardPolicyRequestParts_1.collectMerchantNames)(draft.vendorPolicy, 'block'),
48
- },
49
- description: description.trim(),
50
- mode: guidedMode,
51
- name: row.name.trim(),
52
- requiredReceiptThreshold: (0, cardPolicyRequestParts_1.amountFromLimitRow)(draft.limits, cardPolicyFormDraftTypes_1.CARD_POLICY_LIMIT_ROW_ID_REQUIRE_RECEIPT),
53
- spendLimits: {
54
- transaction: (0, cardPolicyRequestParts_1.amountFromLimitRow)(draft.limits, cardPolicyFormDraftTypes_1.CARD_POLICY_LIMIT_ROW_ID_TRANSACTION),
55
- },
56
- });
57
- const buildAutoEntry = (row, description) => ({
58
- allowedEntity: {
59
- categoryCodes: collectCategoryCodesFromReviewRow(row, cardPolicyRequestParts_1.REVIEW_GROUP_IDS.allowedCategories),
60
- merchantNames: collectVendorLabelsFromReviewRow(row, cardPolicyRequestParts_1.REVIEW_GROUP_IDS.allowedVendors),
61
- },
62
- applyToCards: collectCardIdsFromReviewRow(row),
63
- blockedEntity: {
64
- categoryCodes: collectCategoryCodesFromReviewRow(row, cardPolicyRequestParts_1.REVIEW_GROUP_IDS.restrictedCategories),
65
- merchantNames: collectVendorLabelsFromReviewRow(row, cardPolicyRequestParts_1.REVIEW_GROUP_IDS.blockedVendors),
66
- },
67
- description: description.trim(),
68
- name: row.name.trim(),
69
- });
70
- const buildUploadEntry = (row, draft, description) => ({
71
- allowedEntity: {
72
- categoryCodes: collectCategoryCodesFromReviewRow(row, cardPolicyRequestParts_1.REVIEW_GROUP_IDS.allowedCategories),
73
- merchantNames: collectVendorLabelsFromReviewRow(row, cardPolicyRequestParts_1.REVIEW_GROUP_IDS.allowedVendors),
74
- },
75
- applyToCards: draft.cardSelections
76
- .filter((card) => card.isChecked)
77
- .map((card) => card.id),
78
- blockedEntity: {
79
- categoryCodes: collectCategoryCodesFromReviewRow(row, cardPolicyRequestParts_1.REVIEW_GROUP_IDS.restrictedCategories),
80
- merchantNames: collectVendorLabelsFromReviewRow(row, cardPolicyRequestParts_1.REVIEW_GROUP_IDS.blockedVendors),
81
- },
82
- description: description.trim(),
83
- name: row.name.trim(),
84
- requiredReceiptThreshold: limitValueFromReviewRow(row, cardPolicyRequestParts_1.REVIEW_LIMIT_CHIP_IDS.receipt),
85
- spendLimits: {
86
- transaction: limitValueFromReviewRow(row, cardPolicyRequestParts_1.REVIEW_LIMIT_CHIP_IDS.transaction),
87
- },
88
- });
89
- /**
90
- * Build the array of per-row entries for the bulk
91
- * `createCardPolicyTemplates` action from the AI CFO form draft.
92
- * Iterates checked review rows and emits one entry per row, with the
93
- * per-mode key contract enforced internally.
94
- */
95
- const toBulkCardPolicyTemplateRequestsFromDraft = ({ draft, description = '', guidedMode = 'strict', }) => {
96
- const checkedRows = draft.policiesReview.filter((row) => row.isChecked);
97
- if (draft.policyKind === 'guided') {
98
- return checkedRows.map((row) => buildGuidedEntry(row, draft, guidedMode, description));
99
- }
100
- if (draft.policyKind === 'upload') {
101
- return checkedRows.map((row) => buildUploadEntry(row, draft, description));
102
- }
103
- return checkedRows.map((row) => buildAutoEntry(row, description));
104
- };
105
- exports.toBulkCardPolicyTemplateRequestsFromDraft = toBulkCardPolicyTemplateRequestsFromDraft;
@@ -1,23 +0,0 @@
1
- import { CreateCardPolicyTemplateRequest } from '../../../../../entity/cardPolicy/cardPolicyPayload';
2
- import { CardPolicyFormDraft, CardPolicyModeValue } from './cardPolicyFormDraftTypes';
3
- export interface ToCardPolicyTemplateRequestFromDraftArgs {
4
- draft: CardPolicyFormDraft;
5
- description?: string;
6
- /** Defaults to `"strict"`; only consumed by guided submit. */
7
- mode?: CardPolicyModeValue;
8
- }
9
- /**
10
- * Map the AI CFO `CardPolicyFormDraft` to the wire-ready
11
- * `CreateCardPolicyTemplateRequest`. Branches on `draft.policyKind`:
12
- *
13
- * - `auto` / `upload`: active review row's chip groups are canonical;
14
- * project via `projectAutoReviewRowToCardPolicyRequestParts`. Active
15
- * row = "first checked, fallback to first".
16
- * - `guided`: source slices are canonical (the
17
- * `applyAiCardPolicyFormDraftUpdate` reducer mirrors review-chip
18
- * edits back into them); read directly from the source slices.
19
- *
20
- * Name picking: first checked row of `policiesReview`, fallback to the
21
- * first row, fallback to empty.
22
- */
23
- export declare const toCardPolicyTemplateRequestFromDraft: ({ draft, description, mode, }: ToCardPolicyTemplateRequestFromDraftArgs) => CreateCardPolicyTemplateRequest;
@@ -1,75 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toCardPolicyTemplateRequestFromDraft = void 0;
4
- const cardPolicyFormDraftTypes_1 = require("./cardPolicyFormDraftTypes");
5
- const cardPolicyRequestParts_1 = require("./cardPolicyRequestParts");
6
- /**
7
- * Map the AI CFO `CardPolicyFormDraft` to the wire-ready
8
- * `CreateCardPolicyTemplateRequest`. Branches on `draft.policyKind`:
9
- *
10
- * - `auto` / `upload`: active review row's chip groups are canonical;
11
- * project via `projectAutoReviewRowToCardPolicyRequestParts`. Active
12
- * row = "first checked, fallback to first".
13
- * - `guided`: source slices are canonical (the
14
- * `applyAiCardPolicyFormDraftUpdate` reducer mirrors review-chip
15
- * edits back into them); read directly from the source slices.
16
- *
17
- * Name picking: first checked row of `policiesReview`, fallback to the
18
- * first row, fallback to empty.
19
- */
20
- const toCardPolicyTemplateRequestFromDraft = ({ draft, description = '', mode = 'strict', }) => {
21
- const name = pickPolicyName(draft);
22
- const base = {
23
- description: description.trim(),
24
- mode,
25
- name: name.trim(),
26
- };
27
- if (draft.policyKind === 'auto' || draft.policyKind === 'upload') {
28
- const activeRow = draft.policiesReview.find((row) => row.isChecked) ??
29
- draft.policiesReview[0];
30
- if (activeRow == null) {
31
- return {
32
- ...base,
33
- allowedEntity: { categoryCodes: [], merchantNames: [] },
34
- applyToCards: [],
35
- blockedEntity: { categoryCodes: [], merchantNames: [] },
36
- requiredReceiptThreshold: null,
37
- spendLimits: { transaction: null },
38
- };
39
- }
40
- return {
41
- ...base,
42
- ...(0, cardPolicyRequestParts_1.projectAutoReviewRowToCardPolicyRequestParts)(activeRow),
43
- };
44
- }
45
- // Guided
46
- return {
47
- ...base,
48
- allowedEntity: {
49
- categoryCodes: (0, cardPolicyRequestParts_1.collectCategoryCodes)(draft.categoryPolicy, 'allow'),
50
- merchantNames: (0, cardPolicyRequestParts_1.collectMerchantNames)(draft.vendorPolicy, 'allow'),
51
- },
52
- applyToCards: draft.cardSelections
53
- .filter((row) => row.isChecked)
54
- .map((row) => row.id),
55
- blockedEntity: {
56
- categoryCodes: (0, cardPolicyRequestParts_1.collectCategoryCodes)(draft.categoryPolicy, 'block'),
57
- merchantNames: (0, cardPolicyRequestParts_1.collectMerchantNames)(draft.vendorPolicy, 'block'),
58
- },
59
- requiredReceiptThreshold: (0, cardPolicyRequestParts_1.amountFromLimitRow)(draft.limits, cardPolicyFormDraftTypes_1.CARD_POLICY_LIMIT_ROW_ID_REQUIRE_RECEIPT),
60
- spendLimits: {
61
- transaction: (0, cardPolicyRequestParts_1.amountFromLimitRow)(draft.limits, cardPolicyFormDraftTypes_1.CARD_POLICY_LIMIT_ROW_ID_TRANSACTION),
62
- },
63
- };
64
- };
65
- exports.toCardPolicyTemplateRequestFromDraft = toCardPolicyTemplateRequestFromDraft;
66
- const pickPolicyName = (draft) => {
67
- const checked = draft.policiesReview.find((row) => row.isChecked);
68
- if (checked != null) {
69
- return checked.name;
70
- }
71
- if (draft.policiesReview.length > 0) {
72
- return draft.policiesReview[0].name;
73
- }
74
- return '';
75
- };
@@ -1,15 +0,0 @@
1
- import { CreateCardPolicyTemplateRequest } from '../../../../../entity/cardPolicy/cardPolicyPayload';
2
- import { CardPolicyCreateFormDraft } from './cardPolicyFormDraftTypes';
3
- /**
4
- * Map the manual `CardPolicyCreateFormDraft` onto the wire-ready
5
- * `CreateCardPolicyTemplateRequest` payload consumed by the
6
- * `createCardPolicyTemplates` epic.
7
- *
8
- * Mirrors the AI guided builder minus the `policiesReview` projection:
9
- * - `vendorPolicy` / `categoryPolicy` are read directly; `mode` is
10
- * forwarded from the form.
11
- * - `applyToCards` is the id list of checked rows in `cardSelections`.
12
- * - `spendLimits.transaction` / `requiredReceiptThreshold` are `null`
13
- * when their toggle is off (BE: "not configured").
14
- */
15
- export declare const toManualCardPolicyTemplateRequestFromDraft: (draft: CardPolicyCreateFormDraft) => CreateCardPolicyTemplateRequest;
@@ -1,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toManualCardPolicyTemplateRequestFromDraft = void 0;
4
- const cardPolicyFormDraftTypes_1 = require("./cardPolicyFormDraftTypes");
5
- const cardPolicyRequestParts_1 = require("./cardPolicyRequestParts");
6
- /**
7
- * Map the manual `CardPolicyCreateFormDraft` onto the wire-ready
8
- * `CreateCardPolicyTemplateRequest` payload consumed by the
9
- * `createCardPolicyTemplates` epic.
10
- *
11
- * Mirrors the AI guided builder minus the `policiesReview` projection:
12
- * - `vendorPolicy` / `categoryPolicy` are read directly; `mode` is
13
- * forwarded from the form.
14
- * - `applyToCards` is the id list of checked rows in `cardSelections`.
15
- * - `spendLimits.transaction` / `requiredReceiptThreshold` are `null`
16
- * when their toggle is off (BE: "not configured").
17
- */
18
- const toManualCardPolicyTemplateRequestFromDraft = (draft) => ({
19
- allowedEntity: {
20
- categoryCodes: (0, cardPolicyRequestParts_1.collectCategoryCodes)(draft.categoryPolicy, 'allow'),
21
- merchantNames: (0, cardPolicyRequestParts_1.collectMerchantNames)(draft.vendorPolicy, 'allow'),
22
- },
23
- applyToCards: draft.cardSelections
24
- .filter((row) => row.isChecked)
25
- .map((row) => row.id),
26
- blockedEntity: {
27
- categoryCodes: (0, cardPolicyRequestParts_1.collectCategoryCodes)(draft.categoryPolicy, 'block'),
28
- merchantNames: (0, cardPolicyRequestParts_1.collectMerchantNames)(draft.vendorPolicy, 'block'),
29
- },
30
- description: draft.description.trim(),
31
- mode: draft.mode,
32
- name: draft.name.trim(),
33
- requiredReceiptThreshold: (0, cardPolicyRequestParts_1.amountFromLimitRow)(draft.limits, cardPolicyFormDraftTypes_1.CARD_POLICY_LIMIT_ROW_ID_REQUIRE_RECEIPT),
34
- spendLimits: {
35
- transaction: (0, cardPolicyRequestParts_1.amountFromLimitRow)(draft.limits, cardPolicyFormDraftTypes_1.CARD_POLICY_LIMIT_ROW_ID_TRANSACTION),
36
- },
37
- });
38
- exports.toManualCardPolicyTemplateRequestFromDraft = toManualCardPolicyTemplateRequestFromDraft;
@@ -1,76 +0,0 @@
1
- import { ID } from '../../../../commonStateTypes/common';
2
- import { CardsCardKind, CardsCreationInitialData } from '../../../../entity/aiCfo/aiCfoState';
3
- import { User } from '../../../../entity/user/userState';
4
- /**
5
- * AI CFO card-creation form draft state — the canonical source of
6
- * truth for the `CardsCreationInteractiveForm` component (rule #4).
7
- *
8
- * The web-components form is a pure renderer that hydrates from
9
- * `IssueChargeCardState.aiCardCreationFormDraft` and emits every
10
- * change back via `onFormChange` → `updateAiCardCreationFormDraft`.
11
- *
12
- * The AI-payload-side types (`CardsCardKind`, `CardNameOption`,
13
- * `CardsCreationInitialData`, etc.) are defined on
14
- * `entity/aiCfo/aiCfoState.ts` and consumed directly from there — this
15
- * file only declares the FE-side form draft shapes and the companion
16
- * seed context the reducer keeps for re-derivation.
17
- */
18
- /**
19
- * Step-1 row: a single team the user can opt in/out of via a checkbox.
20
- *
21
- * Mirrors the AI's `teamRows[i]` payload field-for-field plus the
22
- * `isChecked` toggle, with FE display strings (`value`, `rightLabel`)
23
- * resolved from the AI's `avgMonthlySpend` / `recommendedLimit`.
24
- */
25
- export interface CardsTeamRow {
26
- cardKind: CardsCardKind;
27
- id: string;
28
- isChecked: boolean;
29
- label: string;
30
- /** Right column primary value, e.g. "$20,000". */
31
- rightLabel: string;
32
- /** Middle column primary value, e.g. "$18,400". */
33
- value: string;
34
- rightSubLabel?: string;
35
- subLabel?: string;
36
- subValue?: string;
37
- }
38
- /**
39
- * Owner field value held in the form state. Mirrors `UserSingleSelectField`
40
- * which wants both the universe of users and the currently selected user
41
- * collocated with the field value.
42
- */
43
- export interface CardsOwnerFieldValue {
44
- allUsers: User[];
45
- selectedUser?: User;
46
- }
47
- /**
48
- * Step-2 row: the configured card for one of the teams the user kept
49
- * in step 1.
50
- */
51
- export interface CardsCardRow {
52
- cardKind: CardsCardKind;
53
- id: string;
54
- label: string;
55
- owner: CardsOwnerFieldValue;
56
- recommendedLimit?: number;
57
- }
58
- /**
59
- * Canonical CES shape for the AI card-creation form. The web-components
60
- * `CardsCreationInteractiveForm` hydrates RHF from this object and emits
61
- * every change back through `onFormChange`.
62
- */
63
- export interface CardsFormDraft {
64
- cardRows: CardsCardRow[];
65
- teamRows: CardsTeamRow[];
66
- }
67
- /**
68
- * Seed context retained on the slice so subsequent `updateAiCardCreationFormDraft`
69
- * dispatches can re-derive step-2 rows from step-1 selections without the
70
- * component re-passing the full universe each time.
71
- */
72
- export interface AiCardCreationFormDraftSeedContext {
73
- allUsers: User[];
74
- mode: CardsCreationInitialData['mode'];
75
- suggestedOwnerUserIdByTeamId: Record<ID, string | undefined>;
76
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,7 +0,0 @@
1
- import { AiCardCreationFormDraftSeedContext, CardsFormDraft } from './aiCardCreationFormDraftTypes';
2
- export interface ApplyAiCardCreationFormDraftUpdateArgs {
3
- context: AiCardCreationFormDraftSeedContext | undefined;
4
- next: CardsFormDraft;
5
- prev: CardsFormDraft | undefined;
6
- }
7
- export declare const applyAiCardCreationFormDraftUpdate: ({ next, prev, context, }: ApplyAiCardCreationFormDraftUpdateArgs) => CardsFormDraft;
@@ -1,46 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.applyAiCardCreationFormDraftUpdate = void 0;
4
- const deriveAiCardRowsFromTeams_1 = require("./deriveAiCardRowsFromTeams");
5
- // Single source of truth for "what the next form draft should look like
6
- // after a watchHandler flush".
7
- //
8
- // `create` mode + missing context: keep the payload as-is.
9
- //
10
- // `review` mode: re-derive step-2 `cardRows` from the latest `teamRows`
11
- // ONLY when the step-1 selection changed (a team was toggled on/off).
12
- // Step-2-only edits (dropdown swap, owner change, limit edit) must skip
13
- // the re-derive because `deriveAiCardRowsFromTeams` matches previous rows
14
- // by `cardRow.id`, which the dropdown swap has just mutated — running it
15
- // on a step-2-only diff reverts the user's edit back to the source team's
16
- // original id/label.
17
- const applyAiCardCreationFormDraftUpdate = ({ next, prev, context, }) => {
18
- if (context == null || context.mode === 'create') {
19
- return next;
20
- }
21
- if (!haveCheckedTeamRowsChanged(prev?.teamRows, next.teamRows)) {
22
- return next;
23
- }
24
- return {
25
- teamRows: next.teamRows,
26
- cardRows: (0, deriveAiCardRowsFromTeams_1.deriveAiCardRowsFromTeams)({
27
- teamRows: next.teamRows,
28
- prevCardRows: next.cardRows,
29
- allUsers: context.allUsers,
30
- suggestedOwnerUserIdByTeamId: context.suggestedOwnerUserIdByTeamId,
31
- }),
32
- };
33
- };
34
- exports.applyAiCardCreationFormDraftUpdate = applyAiCardCreationFormDraftUpdate;
35
- const haveCheckedTeamRowsChanged = (prevTeamRows, nextTeamRows) => {
36
- const prevCheckedIds = (prevTeamRows ?? [])
37
- .filter((row) => row.isChecked)
38
- .map((row) => row.id);
39
- const nextCheckedIds = nextTeamRows
40
- .filter((row) => row.isChecked)
41
- .map((row) => row.id);
42
- if (prevCheckedIds.length !== nextCheckedIds.length) {
43
- return true;
44
- }
45
- return prevCheckedIds.some((id, idx) => id !== nextCheckedIds[idx]);
46
- };
@@ -1,28 +0,0 @@
1
- import { CardsCreationInitialData } from '../../../../entity/aiCfo/aiCfoState';
2
- import { User } from '../../../../entity/user/userState';
3
- import { AiCardCreationFormDraftSeedContext, CardsFormDraft } from './aiCardCreationFormDraftTypes';
4
- export interface BuildAiCardCreationFormDraftSeedArgs {
5
- allUsers: User[];
6
- initialData: CardsCreationInitialData;
7
- }
8
- export interface BuildAiCardCreationFormDraftSeedResult {
9
- context: AiCardCreationFormDraftSeedContext;
10
- draft: CardsFormDraft;
11
- }
12
- /**
13
- * Build the initial `CardsFormDraft` + companion seed context for a
14
- * fresh AI card-creation session. Used by the `seedAiCardCreationFormDraft`
15
- * reducer.
16
- *
17
- * Branches on `initialData.mode`:
18
- * - `review`: step-1 team rows start fully checked and step-2 `cardRows`
19
- * are seeded by `deriveAiCardRowsFromTeams` so the table is populated
20
- * on first render. `applyAiCardCreationFormDraftUpdate` only re-derives
21
- * when a team is toggled in step 1, so without this initial seed the
22
- * happy path (user proceeds to step 2 without un/re-checking) would
23
- * land on an empty table.
24
- * - `create`: no step-1 list — seed `cardRows` directly from the AI's
25
- * suggested cards (resolving owners via `allUsers`) and leave
26
- * `teamRows` empty.
27
- */
28
- export declare const buildAiCardCreationFormDraftSeed: ({ initialData, allUsers, }: BuildAiCardCreationFormDraftSeedArgs) => BuildAiCardCreationFormDraftSeedResult;