@zeniai/client-epic-state 5.1.4 → 5.1.5-betaJK1

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 (103) hide show
  1. package/lib/entity/company/companyPayload.d.ts +4 -0
  2. package/lib/entity/company/companyPayload.js +6 -0
  3. package/lib/entity/company/companyStateTypes.d.ts +7 -0
  4. package/lib/entity/paymentAccount/paymentAccountSelector.d.ts +1 -0
  5. package/lib/entity/paymentAccount/paymentAccountSelector.js +9 -0
  6. package/lib/entity/snackbar/snackbarTypes.d.ts +1 -1
  7. package/lib/entity/snackbar/snackbarTypes.js +1 -0
  8. package/lib/entity/task/taskPayload.d.ts +1 -0
  9. package/lib/entity/task/taskPayload.js +1 -0
  10. package/lib/entity/task/taskReducer.d.ts +5 -1
  11. package/lib/entity/task/taskReducer.js +8 -2
  12. package/lib/entity/task/taskState.d.ts +1 -0
  13. package/lib/entity/tenant/epic/deleteConnectionEpic.d.ts +1 -1
  14. package/lib/entity/tenant/epic/initEmailConnectOAuthEpic.d.ts +21 -0
  15. package/lib/entity/tenant/epic/initEmailConnectOAuthEpic.js +59 -0
  16. package/lib/entity/tenant/epic/saveAPIKeyConnectionEpic.d.ts +1 -1
  17. package/lib/entity/tenant/epic/saveConnectorCredentialsEpic.d.ts +3 -3
  18. package/lib/entity/tenant/epic/saveOAuthConnectionEpic.d.ts +1 -1
  19. package/lib/entity/tenant/tenantPayload.d.ts +1 -0
  20. package/lib/entity/tenant/tenantReducer.d.ts +38 -25
  21. package/lib/entity/tenant/tenantReducer.js +65 -5
  22. package/lib/entity/tenant/tenantState.d.ts +1 -0
  23. package/lib/epic.d.ts +8 -1
  24. package/lib/epic.js +9 -1
  25. package/lib/esm/entity/company/companyPayload.js +6 -0
  26. package/lib/esm/entity/paymentAccount/paymentAccountSelector.js +8 -0
  27. package/lib/esm/entity/snackbar/snackbarTypes.js +1 -0
  28. package/lib/esm/entity/task/taskPayload.js +1 -0
  29. package/lib/esm/entity/task/taskReducer.js +7 -1
  30. package/lib/esm/entity/tenant/epic/initEmailConnectOAuthEpic.js +55 -0
  31. package/lib/esm/entity/tenant/tenantReducer.js +63 -3
  32. package/lib/esm/epic.js +9 -1
  33. package/lib/esm/index.js +13 -9
  34. package/lib/esm/view/fileView/epic/deleteFileEpic.js +2 -2
  35. package/lib/esm/view/fileView/epic/deleteFileListEpic.js +2 -2
  36. package/lib/esm/view/onboardingView/customerView/epic/aiAgentsActivation/fetchAiAgentsActivationStatusEpic.js +40 -0
  37. package/lib/esm/view/onboardingView/customerView/epic/customerDetails/acknowledgeOnboardingAiActivationViewedEpic.js +29 -0
  38. package/lib/esm/view/onboardingView/customerView/epic/customerDetails/acknowledgeOnboardingAiFinanceTeamEpic.js +40 -0
  39. package/lib/esm/view/onboardingView/customerView/epic/customerDetails/updateOnboardingCustomerViewEpic.js +24 -18
  40. package/lib/esm/view/onboardingView/customerView/epic/customerDetails/updateOnboardingCustomerViewLocalStoreDataEpic.js +29 -17
  41. package/lib/esm/view/onboardingView/customerView/onboardingCustomerViewReducer.js +223 -51
  42. package/lib/esm/view/onboardingView/customerView/onboardingCustomerViewSelector.js +24 -12
  43. package/lib/esm/view/onboardingView/customerView/onboardingCustomerViewState.js +37 -6
  44. package/lib/esm/view/spendManagement/commonSetup/epic/setup/parseUploadedKybDocumentEpic.js +58 -0
  45. package/lib/esm/view/spendManagement/commonSetup/epic/setup/parseUploadedKycDocumentEpic.js +77 -0
  46. package/lib/esm/view/spendManagement/commonSetup/kycKybAutofillActions.js +14 -0
  47. package/lib/esm/view/spendManagement/commonSetup/kycKybParseMapper.js +207 -0
  48. package/lib/esm/view/spendManagement/commonSetup/setupViewReducer.js +106 -52
  49. package/lib/esm/view/spendManagement/commonSetup/setupViewSelector.js +6 -1
  50. package/lib/esm/view/spendManagement/commonSetup/types/kycKybAutofill.js +41 -0
  51. package/lib/esm/view/taskManager/taskDetailView/epics/createSubTaskEpic.js +80 -0
  52. package/lib/esm/view/taskManager/taskDetailView/epics/fetchSubTasksEpic.js +36 -0
  53. package/lib/esm/view/taskManager/taskDetailView/epics/fetchTaskDetailEpic.js +13 -0
  54. package/lib/esm/view/taskManager/taskDetailView/taskDetailReducer.js +56 -2
  55. package/lib/esm/view/taskManager/taskDetailView/taskDetailSelector.js +19 -8
  56. package/lib/index.d.ts +17 -13
  57. package/lib/index.js +67 -35
  58. package/lib/view/expenseAutomationView/helpers/transactionCategorizationLocalDataHelper.d.ts +1 -1
  59. package/lib/view/fileView/epic/deleteFileEpic.js +1 -1
  60. package/lib/view/fileView/epic/deleteFileListEpic.js +1 -1
  61. package/lib/view/onboardingView/customerView/epic/aiAgentsActivation/fetchAiAgentsActivationStatusEpic.d.ts +7 -0
  62. package/lib/view/onboardingView/customerView/epic/aiAgentsActivation/fetchAiAgentsActivationStatusEpic.js +44 -0
  63. package/lib/view/onboardingView/customerView/epic/customerDetails/acknowledgeOnboardingAiActivationViewedEpic.d.ts +8 -0
  64. package/lib/view/onboardingView/customerView/epic/customerDetails/acknowledgeOnboardingAiActivationViewedEpic.js +33 -0
  65. package/lib/view/onboardingView/customerView/epic/customerDetails/acknowledgeOnboardingAiFinanceTeamEpic.d.ts +9 -0
  66. package/lib/view/onboardingView/customerView/epic/customerDetails/acknowledgeOnboardingAiFinanceTeamEpic.js +44 -0
  67. package/lib/view/onboardingView/customerView/epic/customerDetails/updateOnboardingCustomerViewEpic.js +24 -18
  68. package/lib/view/onboardingView/customerView/epic/customerDetails/updateOnboardingCustomerViewLocalStoreDataEpic.d.ts +2 -2
  69. package/lib/view/onboardingView/customerView/epic/customerDetails/updateOnboardingCustomerViewLocalStoreDataEpic.js +27 -15
  70. package/lib/view/onboardingView/customerView/onboardingCustomerViewPayload.d.ts +3 -0
  71. package/lib/view/onboardingView/customerView/onboardingCustomerViewReducer.d.ts +44 -5
  72. package/lib/view/onboardingView/customerView/onboardingCustomerViewReducer.js +225 -52
  73. package/lib/view/onboardingView/customerView/onboardingCustomerViewSelector.d.ts +6 -1
  74. package/lib/view/onboardingView/customerView/onboardingCustomerViewSelector.js +27 -12
  75. package/lib/view/onboardingView/customerView/onboardingCustomerViewState.d.ts +52 -8
  76. package/lib/view/onboardingView/customerView/onboardingCustomerViewState.js +39 -7
  77. package/lib/view/spendManagement/commonSetup/epic/setup/parseUploadedKybDocumentEpic.d.ts +28 -0
  78. package/lib/view/spendManagement/commonSetup/epic/setup/parseUploadedKybDocumentEpic.js +62 -0
  79. package/lib/view/spendManagement/commonSetup/epic/setup/parseUploadedKycDocumentEpic.d.ts +9 -0
  80. package/lib/view/spendManagement/commonSetup/epic/setup/parseUploadedKycDocumentEpic.js +81 -0
  81. package/lib/view/spendManagement/commonSetup/kycKybAutofillActions.d.ts +24 -0
  82. package/lib/view/spendManagement/commonSetup/kycKybAutofillActions.js +17 -0
  83. package/lib/view/spendManagement/commonSetup/kycKybParseMapper.d.ts +29 -0
  84. package/lib/view/spendManagement/commonSetup/kycKybParseMapper.js +215 -0
  85. package/lib/view/spendManagement/commonSetup/setupViewReducer.d.ts +28 -2
  86. package/lib/view/spendManagement/commonSetup/setupViewReducer.js +107 -53
  87. package/lib/view/spendManagement/commonSetup/setupViewSelector.d.ts +7 -2
  88. package/lib/view/spendManagement/commonSetup/setupViewSelector.js +6 -1
  89. package/lib/view/spendManagement/commonSetup/setupViewState.d.ts +19 -0
  90. package/lib/view/spendManagement/commonSetup/types/kycKybAutofill.d.ts +154 -0
  91. package/lib/view/spendManagement/commonSetup/types/kycKybAutofill.js +46 -0
  92. package/lib/view/taskManager/taskDetailView/epics/createSubTaskEpic.d.ts +9 -0
  93. package/lib/view/taskManager/taskDetailView/epics/createSubTaskEpic.js +84 -0
  94. package/lib/view/taskManager/taskDetailView/epics/fetchSubTasksEpic.d.ts +8 -0
  95. package/lib/view/taskManager/taskDetailView/epics/fetchSubTasksEpic.js +40 -0
  96. package/lib/view/taskManager/taskDetailView/epics/fetchTaskDetailEpic.d.ts +2 -1
  97. package/lib/view/taskManager/taskDetailView/epics/fetchTaskDetailEpic.js +13 -0
  98. package/lib/view/taskManager/taskDetailView/taskDetail.d.ts +13 -0
  99. package/lib/view/taskManager/taskDetailView/taskDetailReducer.d.ts +14 -2
  100. package/lib/view/taskManager/taskDetailView/taskDetailReducer.js +57 -3
  101. package/lib/view/taskManager/taskDetailView/taskDetailSelector.d.ts +2 -1
  102. package/lib/view/taskManager/taskDetailView/taskDetailSelector.js +17 -6
  103. package/package.json +1 -1
@@ -0,0 +1,58 @@
1
+ import { of } from 'rxjs';
2
+ import { catchError, filter, mergeMap } from 'rxjs/operators';
3
+ import { isSuccessResponse } from '../../../../../responsePayload';
4
+ import { applyKybDocumentAutofillForOnboarding } from '../../../../onboardingView/customerView/onboardingCustomerViewReducer';
5
+ import { parseUploadedKybDocument, parseUploadedKybDocumentFailure, } from '../../kycKybAutofillActions';
6
+ import { mapCoiToCompanyDetails, mapTaxEinToCompanyDetails, } from '../../kycKybParseMapper';
7
+ import { applyKybDocumentAutofillForSetup } from '../../setupViewReducer';
8
+ const PROCESS_DOCUMENT_SYNC_PATH = '/1.0/documents/process/sync';
9
+ export const parseUploadedKybDocumentEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(parseUploadedKybDocument.match), mergeMap((action) => {
10
+ const { target, companyId, fileId, documentType } = action.payload;
11
+ const url = `${zeniAPI.apiEndPoints.communicationAgentMicroServiceBaseUrl}${PROCESS_DOCUMENT_SYNC_PATH}`;
12
+ const requestPayload = {
13
+ provided_document_type: documentType,
14
+ files: [{ file_id: fileId }],
15
+ processing_priority: 10,
16
+ metadata: { source: 'kyc_kyb_autofill' },
17
+ };
18
+ const failureAction = parseUploadedKybDocumentFailure({ target, fileId });
19
+ return zeniAPI
20
+ .postAndGetJSON(url, requestPayload)
21
+ .pipe(mergeMap((response) => {
22
+ if (!isSuccessResponse(response) || response.data == null) {
23
+ return of(failureAction);
24
+ }
25
+ // Sync API returns a batch envelope: `data.files[0].extracted_data`
26
+ // is the parser payload; `data` itself is the request-level wrapper.
27
+ const extracted = response.data.files?.[0]?.extracted_data;
28
+ if (extracted == null) {
29
+ return of(failureAction);
30
+ }
31
+ let result;
32
+ switch (documentType) {
33
+ case 'certificate_of_incorporation':
34
+ result = mapCoiToCompanyDetails(extracted);
35
+ break;
36
+ case 'tax_ein':
37
+ result = mapTaxEinToCompanyDetails(extracted);
38
+ break;
39
+ }
40
+ if (result.autoFilledFieldNames.length === 0) {
41
+ return of(failureAction);
42
+ }
43
+ const applyAction = target === 'setup'
44
+ ? applyKybDocumentAutofillForSetup({
45
+ companyId,
46
+ fileId,
47
+ values: result.values,
48
+ autoFilledFieldNames: result.autoFilledFieldNames,
49
+ })
50
+ : applyKybDocumentAutofillForOnboarding({
51
+ companyId,
52
+ fileId,
53
+ values: result.values,
54
+ autoFilledFieldNames: result.autoFilledFieldNames,
55
+ });
56
+ return of(applyAction);
57
+ }), catchError(() => of(failureAction)));
58
+ }));
@@ -0,0 +1,77 @@
1
+ import { from, of } from 'rxjs';
2
+ import { catchError, filter, mergeMap } from 'rxjs/operators';
3
+ import { isSuccessResponse } from '../../../../../responsePayload';
4
+ import { newAddressInLocalStore } from '../../../../addressView/addressViewReducer';
5
+ import { applyKycDocumentAutofillForOnboarding } from '../../../../onboardingView/customerView/onboardingCustomerViewReducer';
6
+ import { parseUploadedKycDocument, parseUploadedKycDocumentFailure, } from '../../kycKybAutofillActions';
7
+ import { mapDrivingLicenseToOfficer, mapPassportToOfficer, mapSsnCardToOfficer, } from '../../kycKybParseMapper';
8
+ import { applyKycDocumentAutofillForSetup } from '../../setupViewReducer';
9
+ const PROCESS_DOCUMENT_SYNC_PATH = '/1.0/documents/process/sync';
10
+ export const parseUploadedKycDocumentEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(parseUploadedKycDocument.match), mergeMap((action) => {
11
+ const { target, companyId, officerType, fileId, documentType } = action.payload;
12
+ const url = `${zeniAPI.apiEndPoints.communicationAgentMicroServiceBaseUrl}${PROCESS_DOCUMENT_SYNC_PATH}`;
13
+ const requestPayload = {
14
+ provided_document_type: documentType,
15
+ files: [{ file_id: fileId }],
16
+ processing_priority: 10,
17
+ metadata: { source: 'kyc_kyb_autofill' },
18
+ };
19
+ const failureAction = parseUploadedKycDocumentFailure({ target, fileId });
20
+ return zeniAPI
21
+ .postAndGetJSON(url, requestPayload)
22
+ .pipe(mergeMap((response) => {
23
+ if (!isSuccessResponse(response) || response.data == null) {
24
+ return of(failureAction);
25
+ }
26
+ // Sync API returns a batch envelope: `data.files[0].extracted_data`
27
+ // is the parser payload; `data` itself is the request-level wrapper
28
+ // ({request_id, status, files, metadata, ...}). Drill in before
29
+ // dispatching to the mapper.
30
+ const extracted = response.data.files?.[0]?.extracted_data;
31
+ if (extracted == null) {
32
+ return of(failureAction);
33
+ }
34
+ let result;
35
+ switch (documentType) {
36
+ case 'passport':
37
+ result = mapPassportToOfficer(extracted);
38
+ break;
39
+ case 'driving_license':
40
+ result = mapDrivingLicenseToOfficer(extracted);
41
+ break;
42
+ case 'social_security_card':
43
+ result = mapSsnCardToOfficer(extracted);
44
+ break;
45
+ }
46
+ if (result.autoFilledFieldNames.length === 0) {
47
+ return of(failureAction);
48
+ }
49
+ const applyAction = target === 'setup'
50
+ ? applyKycDocumentAutofillForSetup({
51
+ companyId,
52
+ officerType,
53
+ fileId,
54
+ values: result.values,
55
+ autoFilledFieldNames: result.autoFilledFieldNames,
56
+ })
57
+ : applyKycDocumentAutofillForOnboarding({
58
+ companyId,
59
+ officerType,
60
+ fileId,
61
+ values: result.values,
62
+ autoFilledFieldNames: result.autoFilledFieldNames,
63
+ });
64
+ const actions = [applyAction];
65
+ // Driving licenses also carry the home address, which lives in the
66
+ // addressView slice (keyed `officer_<n>_address`). Seed it so the
67
+ // section's address field + ✦ badge pick it up.
68
+ if (result.address != null) {
69
+ const addressType = `${officerType.toLowerCase()}_address`;
70
+ actions.push(newAddressInLocalStore({
71
+ addressType,
72
+ addressToCreate: result.address,
73
+ }));
74
+ }
75
+ return from(actions);
76
+ }), catchError(() => of(failureAction)));
77
+ }));
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Trigger actions for the KYC / KYB autofill epics.
3
+ *
4
+ * These actions don't mutate state — the epic listens for them, calls
5
+ * document-communication-agent's sync endpoint, and dispatches the appropriate
6
+ * `applyKyc/KybDocumentAutofillFor{Setup,Onboarding}` against the matching
7
+ * slice. Co-located with the rest of the commonSetup module because the entire
8
+ * autofill flow is auxiliary to the setup view; there is no separate state.
9
+ */
10
+ import { createAction } from '@reduxjs/toolkit';
11
+ export const parseUploadedKycDocument = createAction('commonSetup/parseUploadedKycDocument');
12
+ export const parseUploadedKybDocument = createAction('commonSetup/parseUploadedKybDocument');
13
+ export const parseUploadedKycDocumentFailure = createAction('commonSetup/parseUploadedKycDocumentFailure');
14
+ export const parseUploadedKybDocumentFailure = createAction('commonSetup/parseUploadedKybDocumentFailure');
@@ -0,0 +1,207 @@
1
+ /**
2
+ * Pure mappers from ExtendAI parser payloads to our form-side local-data shapes.
3
+ *
4
+ * Each mapper filters out fields below KYC_KYB_AUTOFILL_MIN_CONFIDENCE and returns
5
+ * both the merged values and the list of field names that were autofilled so the
6
+ * UI can show the ✦ AI badge next to each.
7
+ */
8
+ import { date } from '../../../zeniDayJS';
9
+ import { toZeniUrl } from '../../../zeniUrl';
10
+ import { KYC_KYB_AUTOFILL_MIN_CONFIDENCE, } from './types/kycKybAutofill';
11
+ export const OFFICER_ADDRESS_AUTOFILL_FIELD = 'officerAddress';
12
+ // US driving licenses carry a US state in `address_state` but no country field;
13
+ // default the composed address to the US.
14
+ const DRIVING_LICENSE_DEFAULT_COUNTRY = 'United States';
15
+ const DRIVING_LICENSE_DEFAULT_COUNTRY_CODE = 'US';
16
+ const emptyResult = () => ({
17
+ values: {},
18
+ autoFilledFieldNames: [],
19
+ });
20
+ const isConfident = (field) => {
21
+ if (field == null) {
22
+ return false;
23
+ }
24
+ if (field.value == null) {
25
+ return false;
26
+ }
27
+ return field.confidence >= KYC_KYB_AUTOFILL_MIN_CONFIDENCE;
28
+ };
29
+ const assignAutofilledValue = (result, key, value) => {
30
+ if (value == null) {
31
+ return;
32
+ }
33
+ if (typeof value === 'string' && value.trim() === '') {
34
+ return;
35
+ }
36
+ result.values[key] = value;
37
+ result.autoFilledFieldNames.push(key);
38
+ };
39
+ const tryParseDate = (rawDate) => {
40
+ const parsedDate = date(rawDate);
41
+ if (parsedDate.isValid()) {
42
+ return parsedDate;
43
+ }
44
+ return undefined;
45
+ };
46
+ const splitFullName = (fullName) => {
47
+ const parts = fullName.trim().split(/\s+/);
48
+ if (parts.length === 1) {
49
+ return { firstName: parts[0], lastName: '' };
50
+ }
51
+ const lastName = parts[parts.length - 1];
52
+ const firstName = parts.slice(0, -1).join(' ');
53
+ return { firstName, lastName };
54
+ };
55
+ /** Passport → Company Officer. */
56
+ export const mapPassportToOfficer = (parsed) => {
57
+ const result = emptyResult();
58
+ if (isConfident(parsed.first_name)) {
59
+ assignAutofilledValue(result, 'firstName', parsed.first_name.value);
60
+ }
61
+ if (isConfident(parsed.last_name)) {
62
+ assignAutofilledValue(result, 'lastName', parsed.last_name.value);
63
+ }
64
+ if (isConfident(parsed.date_of_birth)) {
65
+ const parsedDate = tryParseDate(parsed.date_of_birth.value);
66
+ if (parsedDate != null) {
67
+ assignAutofilledValue(result, 'birthday', parsedDate);
68
+ }
69
+ }
70
+ // The raw nationality string (e.g. "USA", "UNITED STATES OF AMERICA") is
71
+ // passed through unresolved; the consuming form section normalizes it to an
72
+ // ISO-2 code via the `countries-list` dataset before `setValue`. The form
73
+ // value (not this localData seed) is what gets submitted.
74
+ if (isConfident(parsed.nationality)) {
75
+ assignAutofilledValue(result, 'nationalityCountryCode', parsed.nationality.value);
76
+ }
77
+ return result;
78
+ };
79
+ /** Driving License → Company Officer (name, DOB, and home address). */
80
+ export const mapDrivingLicenseToOfficer = (parsed) => {
81
+ const result = emptyResult();
82
+ if (isConfident(parsed.first_name)) {
83
+ assignAutofilledValue(result, 'firstName', parsed.first_name.value);
84
+ }
85
+ if (isConfident(parsed.last_name)) {
86
+ assignAutofilledValue(result, 'lastName', parsed.last_name.value);
87
+ }
88
+ if (isConfident(parsed.date_of_birth)) {
89
+ const parsedDate = tryParseDate(parsed.date_of_birth.value);
90
+ if (parsedDate != null) {
91
+ assignAutofilledValue(result, 'birthday', parsedDate);
92
+ }
93
+ }
94
+ // The officer address lives in the addressView slice rather than
95
+ // CompanyOfficerLocalData, so it's returned separately for the epic to
96
+ // dispatch via newAddressInLocalStore.
97
+ const street = isConfident(parsed.address_street)
98
+ ? parsed.address_street.value.trim()
99
+ : undefined;
100
+ const city = isConfident(parsed.address_city)
101
+ ? parsed.address_city.value.trim()
102
+ : undefined;
103
+ const state = isConfident(parsed.address_state)
104
+ ? parsed.address_state.value.trim()
105
+ : undefined;
106
+ const postalCode = isConfident(parsed.address_zip)
107
+ ? parsed.address_zip.value.trim()
108
+ : undefined;
109
+ if (street != null || city != null || state != null || postalCode != null) {
110
+ result.address = {
111
+ street: street != null ? [street] : [],
112
+ city: city ?? '',
113
+ state: state ?? '',
114
+ postalCode: postalCode ?? '',
115
+ country: DRIVING_LICENSE_DEFAULT_COUNTRY,
116
+ countryCode: DRIVING_LICENSE_DEFAULT_COUNTRY_CODE,
117
+ };
118
+ result.autoFilledFieldNames.push(OFFICER_ADDRESS_AUTOFILL_FIELD);
119
+ }
120
+ return result;
121
+ };
122
+ /** SSN Card → Company Officer (name only — SSN value not yet returned by parser). */
123
+ export const mapSsnCardToOfficer = (parsed) => {
124
+ const result = emptyResult();
125
+ if (isConfident(parsed.full_name)) {
126
+ const { firstName, lastName } = splitFullName(parsed.full_name.value);
127
+ if (firstName !== '') {
128
+ assignAutofilledValue(result, 'firstName', firstName);
129
+ }
130
+ if (lastName !== '') {
131
+ assignAutofilledValue(result, 'lastName', lastName);
132
+ }
133
+ }
134
+ return result;
135
+ };
136
+ /** Certificate of Incorporation → Company Details. */
137
+ export const mapCoiToCompanyDetails = (parsed) => {
138
+ const result = emptyResult();
139
+ if (isConfident(parsed.company_legal_name)) {
140
+ assignAutofilledValue(result, 'companyLegalName', parsed.company_legal_name.value);
141
+ }
142
+ if (isConfident(parsed.ein)) {
143
+ assignAutofilledValue(result, 'taxIdOrEIN', parsed.ein.value);
144
+ }
145
+ if (isConfident(parsed.phone_number)) {
146
+ assignAutofilledValue(result, 'phone', parsed.phone_number.value);
147
+ }
148
+ if (isConfident(parsed.product_description)) {
149
+ assignAutofilledValue(result, 'companyDescription', parsed.product_description.value);
150
+ }
151
+ if (isConfident(parsed.website)) {
152
+ try {
153
+ assignAutofilledValue(result, 'website', toZeniUrl(parsed.website.value));
154
+ }
155
+ catch {
156
+ // ignore — malformed URL string from OCR
157
+ }
158
+ }
159
+ if (isConfident(parsed.industry)) {
160
+ assignAutofilledValue(result, 'companyIndustryType', parsed.industry.value);
161
+ }
162
+ if (isConfident(parsed.sub_industry)) {
163
+ assignAutofilledValue(result, 'companySubIndustry', parsed.sub_industry.value);
164
+ }
165
+ if (isConfident(parsed.type_of_incorporation)) {
166
+ assignAutofilledValue(result, 'typeOfIncorporation', parsed.type_of_incorporation.value);
167
+ }
168
+ if (isConfident(parsed.date_of_incorporation)) {
169
+ const parsedDate = tryParseDate(parsed.date_of_incorporation.value);
170
+ if (parsedDate != null) {
171
+ assignAutofilledValue(result, 'incDate', parsedDate);
172
+ }
173
+ }
174
+ if (isConfident(parsed.state_of_incorporation)) {
175
+ assignAutofilledValue(result, 'stateOfIncorporation', parsed.state_of_incorporation.value);
176
+ }
177
+ if (isConfident(parsed.countries_of_operations)) {
178
+ assignAutofilledValue(result, 'countriesOfOperations', parsed.countries_of_operations.value);
179
+ }
180
+ if (isConfident(parsed.source_of_funds)) {
181
+ assignAutofilledValue(result, 'sourceOfFunds', parsed.source_of_funds.value);
182
+ }
183
+ if (isConfident(parsed.transaction_volume_expectations)) {
184
+ assignAutofilledValue(result, 'transactionVolume', parsed.transaction_volume_expectations.value);
185
+ }
186
+ if (isConfident(parsed.purpose_of_account)) {
187
+ assignAutofilledValue(result, 'purposeOfAccount', parsed.purpose_of_account.value);
188
+ }
189
+ if (isConfident(parsed.regulated_status)) {
190
+ assignAutofilledValue(result, 'regulatedStatus', parsed.regulated_status.value);
191
+ }
192
+ if (isConfident(parsed.us_nexus)) {
193
+ assignAutofilledValue(result, 'usNexus', parsed.us_nexus.value);
194
+ }
195
+ return result;
196
+ };
197
+ /** Tax EIN letter → Company Details. */
198
+ export const mapTaxEinToCompanyDetails = (parsed) => {
199
+ const result = emptyResult();
200
+ if (isConfident(parsed.legal_business_name)) {
201
+ assignAutofilledValue(result, 'companyLegalName', parsed.legal_business_name.value);
202
+ }
203
+ if (isConfident(parsed.ein)) {
204
+ assignAutofilledValue(result, 'taxIdOrEIN', parsed.ein.value);
205
+ }
206
+ return result;
207
+ };
@@ -1,62 +1,30 @@
1
1
  import { createSlice } from '@reduxjs/toolkit';
2
+ import { parseUploadedKybDocument, parseUploadedKybDocumentFailure, parseUploadedKycDocument, parseUploadedKycDocumentFailure, } from './kycKybAutofillActions';
2
3
  const initialFetchStatus = {
3
4
  fetchState: 'Not-Started',
4
5
  error: undefined,
5
6
  };
7
+ const emptyOfficerSlot = {
8
+ autoFilledFields: [],
9
+ localData: undefined,
10
+ sendOtpStatus: initialFetchStatus,
11
+ otpverificationStatus: initialFetchStatus,
12
+ };
6
13
  export const initialState = {
7
14
  updateStatus: { fetchState: 'Not-Started', error: undefined },
8
- companyDetails: {},
15
+ parsingDocumentFileIds: [],
16
+ companyDetails: { autoFilledFields: [] },
9
17
  companyOfficerUpdateStatus: {
10
- Officer_1: {
11
- localData: undefined,
12
- sendOtpStatus: initialFetchStatus,
13
- otpverificationStatus: initialFetchStatus,
14
- },
15
- Officer_2: {
16
- localData: undefined,
17
- sendOtpStatus: initialFetchStatus,
18
- otpverificationStatus: initialFetchStatus,
19
- },
20
- Officer_3: {
21
- localData: undefined,
22
- sendOtpStatus: initialFetchStatus,
23
- otpverificationStatus: initialFetchStatus,
24
- },
25
- Officer_4: {
26
- localData: undefined,
27
- sendOtpStatus: initialFetchStatus,
28
- otpverificationStatus: initialFetchStatus,
29
- },
30
- Officer_5: {
31
- localData: undefined,
32
- sendOtpStatus: initialFetchStatus,
33
- otpverificationStatus: initialFetchStatus,
34
- },
35
- Officer_6: {
36
- localData: undefined,
37
- sendOtpStatus: initialFetchStatus,
38
- otpverificationStatus: initialFetchStatus,
39
- },
40
- Officer_7: {
41
- localData: undefined,
42
- sendOtpStatus: initialFetchStatus,
43
- otpverificationStatus: initialFetchStatus,
44
- },
45
- Officer_8: {
46
- localData: undefined,
47
- sendOtpStatus: initialFetchStatus,
48
- otpverificationStatus: initialFetchStatus,
49
- },
50
- Officer_9: {
51
- localData: undefined,
52
- sendOtpStatus: initialFetchStatus,
53
- otpverificationStatus: initialFetchStatus,
54
- },
55
- Officer_10: {
56
- localData: undefined,
57
- sendOtpStatus: initialFetchStatus,
58
- otpverificationStatus: initialFetchStatus,
59
- },
18
+ Officer_1: { ...emptyOfficerSlot },
19
+ Officer_2: { ...emptyOfficerSlot },
20
+ Officer_3: { ...emptyOfficerSlot },
21
+ Officer_4: { ...emptyOfficerSlot },
22
+ Officer_5: { ...emptyOfficerSlot },
23
+ Officer_6: { ...emptyOfficerSlot },
24
+ Officer_7: { ...emptyOfficerSlot },
25
+ Officer_8: { ...emptyOfficerSlot },
26
+ Officer_9: { ...emptyOfficerSlot },
27
+ Officer_10: { ...emptyOfficerSlot },
60
28
  },
61
29
  primaryContactDetails: {},
62
30
  };
@@ -297,7 +265,93 @@ const setupView = createSlice({
297
265
  clearSetupView(draft) {
298
266
  Object.assign(draft, initialState);
299
267
  },
268
+ /**
269
+ * Merge AI-parsed officer fields into the selected officer's localData and
270
+ * track which field names were autofilled so the form can show the ✦ badge.
271
+ */
272
+ applyKycDocumentAutofillForSetup: {
273
+ reducer(draft, action) {
274
+ const { officerType, values, autoFilledFieldNames, fileId } = action.payload;
275
+ const slot = draft.companyOfficerUpdateStatus[officerType];
276
+ slot.localData = Object.assign({}, slot.localData, values);
277
+ slot.autoFilledFields = Array.from(new Set([...(slot.autoFilledFields ?? []), ...autoFilledFieldNames]));
278
+ draft.parsingDocumentFileIds = (draft.parsingDocumentFileIds ?? []).filter((id) => id !== fileId);
279
+ },
280
+ prepare(payload) {
281
+ return { payload };
282
+ },
283
+ },
284
+ /**
285
+ * Merge AI-parsed company fields into companyDetails.localData and track
286
+ * which field names were autofilled.
287
+ */
288
+ applyKybDocumentAutofillForSetup: {
289
+ reducer(draft, action) {
290
+ const { values, autoFilledFieldNames, fileId } = action.payload;
291
+ draft.companyDetails.localData = Object.assign({}, draft.companyDetails.localData, values);
292
+ draft.companyDetails.autoFilledFields = Array.from(new Set([
293
+ ...(draft.companyDetails.autoFilledFields ?? []),
294
+ ...autoFilledFieldNames,
295
+ ]));
296
+ draft.parsingDocumentFileIds = (draft.parsingDocumentFileIds ?? []).filter((id) => id !== fileId);
297
+ },
298
+ prepare(payload) {
299
+ return { payload };
300
+ },
301
+ },
302
+ /**
303
+ * Wipe AI-autofill badges. If `officerType` is provided, clears only that
304
+ * officer; otherwise clears company details too.
305
+ */
306
+ clearKycKybAutofillForSetup: {
307
+ reducer(draft, action) {
308
+ const { officerType } = action.payload;
309
+ if (officerType != null) {
310
+ draft.companyOfficerUpdateStatus[officerType].autoFilledFields = [];
311
+ }
312
+ else {
313
+ draft.companyDetails.autoFilledFields = [];
314
+ Object.keys(draft.companyOfficerUpdateStatus).forEach((key) => {
315
+ draft.companyOfficerUpdateStatus[key].autoFilledFields = [];
316
+ });
317
+ }
318
+ },
319
+ prepare(payload = {}) {
320
+ return { payload };
321
+ },
322
+ },
323
+ },
324
+ extraReducers: (builder) => {
325
+ const addParsingFileId = (draft, fileId) => {
326
+ draft.parsingDocumentFileIds = draft.parsingDocumentFileIds ?? [];
327
+ if (!draft.parsingDocumentFileIds.includes(fileId)) {
328
+ draft.parsingDocumentFileIds.push(fileId);
329
+ }
330
+ };
331
+ const removeParsingFileId = (draft, fileId) => {
332
+ draft.parsingDocumentFileIds = (draft.parsingDocumentFileIds ?? []).filter((id) => id !== fileId);
333
+ };
334
+ builder.addCase(parseUploadedKycDocument, (draft, action) => {
335
+ if (action.payload.target === 'setup') {
336
+ addParsingFileId(draft, action.payload.fileId);
337
+ }
338
+ });
339
+ builder.addCase(parseUploadedKybDocument, (draft, action) => {
340
+ if (action.payload.target === 'setup') {
341
+ addParsingFileId(draft, action.payload.fileId);
342
+ }
343
+ });
344
+ builder.addCase(parseUploadedKycDocumentFailure, (draft, action) => {
345
+ if (action.payload.target === 'setup') {
346
+ removeParsingFileId(draft, action.payload.fileId);
347
+ }
348
+ });
349
+ builder.addCase(parseUploadedKybDocumentFailure, (draft, action) => {
350
+ if (action.payload.target === 'setup') {
351
+ removeParsingFileId(draft, action.payload.fileId);
352
+ }
353
+ });
300
354
  },
301
355
  });
302
- export const { enableSetup, enableSetupSuccess, enableSetupFailure, updateBusinessVerificationDetails, updateBusinessVerificationDetailsSuccess, updateBusinessVerificationDetailsFailure, updateSelectedCompanyOfficer, updateSetupViewLocalStoreData, saveSetupViewDataInLocalStore, saveCompnayOfficerPhoneInLocalStore, saveCompnayOfficerAdditionalDocumentsInLocalStore, saveTreasuryAdditionalDocumentsInLocalStore, sendOtp: sendOtpSpendManagementSetUp, resendOtp: resendOtpSpendManagementSetUp, sendOtpSuccess: sendOtpSuccessSpendManagementSetUp, sendOtpFailure: sendOtpFailureSpendManagementSetUp, verifyOtp: verifyOtpSpendManagementSetUp, verifyOtpSuccess: verifyOtpSuccessSpendManagementSetUp, verifyOtpFailure: verifyOtpFailureSpendManagementSetUp, saveIndustryAndIncDateInLocalStore, clearSetupViewDataInLocalStore, clearSetupView, } = setupView.actions;
356
+ export const { enableSetup, enableSetupSuccess, enableSetupFailure, updateBusinessVerificationDetails, updateBusinessVerificationDetailsSuccess, updateBusinessVerificationDetailsFailure, updateSelectedCompanyOfficer, updateSetupViewLocalStoreData, saveSetupViewDataInLocalStore, saveCompnayOfficerPhoneInLocalStore, saveCompnayOfficerAdditionalDocumentsInLocalStore, saveTreasuryAdditionalDocumentsInLocalStore, sendOtp: sendOtpSpendManagementSetUp, resendOtp: resendOtpSpendManagementSetUp, sendOtpSuccess: sendOtpSuccessSpendManagementSetUp, sendOtpFailure: sendOtpFailureSpendManagementSetUp, verifyOtp: verifyOtpSpendManagementSetUp, verifyOtpSuccess: verifyOtpSuccessSpendManagementSetUp, verifyOtpFailure: verifyOtpFailureSpendManagementSetUp, saveIndustryAndIncDateInLocalStore, clearSetupViewDataInLocalStore, clearSetupView, applyKycDocumentAutofillForSetup, applyKybDocumentAutofillForSetup, clearKycKybAutofillForSetup, } = setupView.actions;
303
357
  export default setupView.reducer;
@@ -87,15 +87,17 @@ export function getBusinessVerificationDetails(state, companyId) {
87
87
  const { setupViewState, countryListState } = state;
88
88
  const { companyDetails, companyOfficerUpdateStatus, primaryContactDetails, updateStatus, } = setupViewState;
89
89
  const companyView = getCompanyView(state, companyId, []);
90
- const { companyDetailsLocalData, companyOfficerLocalData } = getCompanyAndIdentityDetails(state, companyId, {
90
+ const { companyDetailsLocalData, companyOfficerLocalData, parsingDocumentFileIds, } = getCompanyAndIdentityDetails(state, companyId, {
91
91
  companyDetails,
92
92
  companyOfficerUpdateStatus,
93
93
  primaryContactDetails,
94
+ parsingDocumentFileIds: setupViewState.parsingDocumentFileIds,
94
95
  });
95
96
  const allNationalityCountries = countryListState.byCountryListCode.nationalityCountryList.countries;
96
97
  return {
97
98
  companyDetailsLocalData,
98
99
  companyOfficerLocalData,
100
+ parsingDocumentFileIds,
99
101
  companyView,
100
102
  updateStatus,
101
103
  allNationalityCountries,
@@ -119,6 +121,7 @@ export const getCompanyAndIdentityDetails = (state, companyId, companyAndIdentit
119
121
  const companyAddress = addressViewState.newAddressState?.company_address;
120
122
  const registeredCompanyAddress = addressViewState.newAddressState?.company_registered_address;
121
123
  companyDetailsLocalData = {
124
+ autoFilledFields: companyDetails.autoFilledFields,
122
125
  companyId,
123
126
  companyDescription,
124
127
  companyLegalName,
@@ -191,6 +194,7 @@ export const getCompanyAndIdentityDetails = (state, companyId, companyAndIdentit
191
194
  const companyOfficerAddress = addressViewState.newAddressState?.[addressType];
192
195
  companyOfficerLocalData[officerType] = {
193
196
  ...companyOfficer.localData,
197
+ autoFilledFields: companyOfficer.autoFilledFields,
194
198
  userFiles: getFilesByFileIds(fileState, fileIds),
195
199
  additionalFiles: getFilesByFileIds(fileState, additionalSubmittedDocumentsForVerificationFileIds),
196
200
  deleteFileStatusById,
@@ -204,6 +208,7 @@ export const getCompanyAndIdentityDetails = (state, companyId, companyAndIdentit
204
208
  return {
205
209
  companyDetailsLocalData,
206
210
  companyOfficerLocalData,
211
+ parsingDocumentFileIds: companyAndIdentityDetails.parsingDocumentFileIds,
207
212
  };
208
213
  };
209
214
  /* This helper function takes deposit accounts and payment accounts
@@ -0,0 +1,41 @@
1
+ /** Confidence floor below which we drop an autofill candidate. */
2
+ export const KYC_KYB_AUTOFILL_MIN_CONFIDENCE = 0.5;
3
+ /**
4
+ * Maps the form-side {@link KycSelectDocumentType} (camelCase) to the
5
+ * parser-side {@link KycProvidedDocumentType} (snake_case). Returns `null` for
6
+ * `stateId`, which has no parser today.
7
+ */
8
+ export const toKycProvidedDocumentType = (selectType) => {
9
+ switch (selectType) {
10
+ case 'driverLicense':
11
+ return 'driving_license';
12
+ case 'passport':
13
+ return 'passport';
14
+ case 'ssnCard':
15
+ return 'social_security_card';
16
+ case 'stateId':
17
+ return null;
18
+ }
19
+ };
20
+ /**
21
+ * Maps a persisted {@link AllowedDocumentType} (snake_case — the value stored on
22
+ * an officer's `documentTypeSelectedForVerification`) to the parser-side
23
+ * {@link KycProvidedDocumentType}. Returns `null` for document types with no KYC
24
+ * parser today (e.g. `id_document` / state ID, and any non-identity doc).
25
+ *
26
+ * The officer's stored selection is an `AllowedDocumentType`, not a
27
+ * {@link KycSelectDocumentType}; use this — not {@link toKycProvidedDocumentType}
28
+ * — when triggering autofill off that field.
29
+ */
30
+ export const toKycProvidedDocumentTypeFromAllowed = (allowedType) => {
31
+ switch (allowedType) {
32
+ case 'passport':
33
+ return 'passport';
34
+ case 'driving_license':
35
+ return 'driving_license';
36
+ case 'social_security_card':
37
+ return 'social_security_card';
38
+ default:
39
+ return null;
40
+ }
41
+ };