@zeniai/client-epic-state 5.0.64-beta1ND → 5.0.64-beta3ND

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 (34) hide show
  1. package/lib/epic.d.ts +3 -1
  2. package/lib/epic.js +3 -1
  3. package/lib/esm/epic.js +3 -1
  4. package/lib/esm/index.js +6 -4
  5. package/lib/esm/view/onboardingView/customerView/onboardingCustomerViewReducer.js +61 -50
  6. package/lib/esm/view/spendManagement/commonSetup/epic/setup/parseUploadedKybDocumentEpic.js +49 -0
  7. package/lib/esm/view/spendManagement/commonSetup/epic/setup/parseUploadedKycDocumentEpic.js +58 -0
  8. package/lib/esm/view/spendManagement/commonSetup/kycKybAutofillActions.js +12 -0
  9. package/lib/esm/view/spendManagement/commonSetup/kycKybParseMapper.js +205 -0
  10. package/lib/esm/view/spendManagement/commonSetup/setupViewReducer.js +71 -52
  11. package/lib/esm/view/spendManagement/commonSetup/setupViewSelector.js +2 -0
  12. package/lib/esm/view/spendManagement/commonSetup/types/kycKybAutofill.js +28 -0
  13. package/lib/index.d.ts +7 -4
  14. package/lib/index.js +28 -17
  15. package/lib/tsconfig.typecheck.tsbuildinfo +1 -0
  16. package/lib/view/onboardingView/customerView/onboardingCustomerViewReducer.d.ts +25 -2
  17. package/lib/view/onboardingView/customerView/onboardingCustomerViewReducer.js +62 -51
  18. package/lib/view/onboardingView/customerView/onboardingCustomerViewState.d.ts +10 -0
  19. package/lib/view/spendManagement/commonSetup/epic/setup/parseUploadedKybDocumentEpic.d.ts +8 -0
  20. package/lib/view/spendManagement/commonSetup/epic/setup/parseUploadedKybDocumentEpic.js +53 -0
  21. package/lib/view/spendManagement/commonSetup/epic/setup/parseUploadedKycDocumentEpic.d.ts +8 -0
  22. package/lib/view/spendManagement/commonSetup/epic/setup/parseUploadedKycDocumentEpic.js +62 -0
  23. package/lib/view/spendManagement/commonSetup/kycKybAutofillActions.d.ts +27 -0
  24. package/lib/view/spendManagement/commonSetup/kycKybAutofillActions.js +15 -0
  25. package/lib/view/spendManagement/commonSetup/kycKybParseMapper.d.ts +24 -0
  26. package/lib/view/spendManagement/commonSetup/kycKybParseMapper.js +213 -0
  27. package/lib/view/spendManagement/commonSetup/setupViewReducer.d.ts +24 -2
  28. package/lib/view/spendManagement/commonSetup/setupViewReducer.js +72 -53
  29. package/lib/view/spendManagement/commonSetup/setupViewSelector.d.ts +4 -0
  30. package/lib/view/spendManagement/commonSetup/setupViewSelector.js +2 -0
  31. package/lib/view/spendManagement/commonSetup/setupViewState.d.ts +12 -0
  32. package/lib/view/spendManagement/commonSetup/types/kycKybAutofill.d.ts +125 -0
  33. package/lib/view/spendManagement/commonSetup/types/kycKybAutofill.js +32 -0
  34. package/package.json +2 -3
@@ -0,0 +1,49 @@
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 } 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
+ return zeniAPI
19
+ .postAndGetJSON(url, requestPayload)
20
+ .pipe(mergeMap((response) => {
21
+ if (!isSuccessResponse(response) || response.data == null) {
22
+ return of();
23
+ }
24
+ let result;
25
+ switch (documentType) {
26
+ case 'certificate_of_incorporation':
27
+ result = mapCoiToCompanyDetails(response.data);
28
+ break;
29
+ case 'tax_ein':
30
+ result = mapTaxEinToCompanyDetails(response.data);
31
+ break;
32
+ }
33
+ if (result.autoFilledFieldNames.length === 0) {
34
+ return of();
35
+ }
36
+ const applyAction = target === 'setup'
37
+ ? applyKybDocumentAutofillForSetup({
38
+ companyId,
39
+ values: result.values,
40
+ autoFilledFieldNames: result.autoFilledFieldNames,
41
+ })
42
+ : applyKybDocumentAutofillForOnboarding({
43
+ companyId,
44
+ values: result.values,
45
+ autoFilledFieldNames: result.autoFilledFieldNames,
46
+ });
47
+ return of(applyAction);
48
+ }), catchError(() => of()));
49
+ }));
@@ -0,0 +1,58 @@
1
+ import { of } from 'rxjs';
2
+ import { catchError, filter, mergeMap } from 'rxjs/operators';
3
+ import { getCountryList } from '../../../../../entity/countryList/countryListSelector';
4
+ import { isSuccessResponse } from '../../../../../responsePayload';
5
+ import { applyKycDocumentAutofillForOnboarding } from '../../../../onboardingView/customerView/onboardingCustomerViewReducer';
6
+ import { parseUploadedKycDocument } 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
+ return zeniAPI
20
+ .postAndGetJSON(url, requestPayload)
21
+ .pipe(mergeMap((response) => {
22
+ if (!isSuccessResponse(response) || response.data == null) {
23
+ return of();
24
+ }
25
+ const allCountries = getCountryList(state$.value.countryListState, 'nationalityCountryList').countries;
26
+ let result;
27
+ switch (documentType) {
28
+ case 'passport':
29
+ result = mapPassportToOfficer(response.data, allCountries);
30
+ break;
31
+ case 'driving_license':
32
+ result = mapDrivingLicenseToOfficer(response.data);
33
+ break;
34
+ case 'social_security_card':
35
+ result = mapSsnCardToOfficer(response.data);
36
+ break;
37
+ }
38
+ if (result.autoFilledFieldNames.length === 0) {
39
+ return of();
40
+ }
41
+ const applyAction = target === 'setup'
42
+ ? applyKycDocumentAutofillForSetup({
43
+ companyId,
44
+ officerType,
45
+ values: result.values,
46
+ autoFilledFieldNames: result.autoFilledFieldNames,
47
+ })
48
+ : applyKycDocumentAutofillForOnboarding({
49
+ companyId,
50
+ officerType,
51
+ values: result.values,
52
+ autoFilledFieldNames: result.autoFilledFieldNames,
53
+ });
54
+ return of(applyAction);
55
+ }), catchError(() =>
56
+ // Autofill is best-effort; swallow errors silently so the user can keep typing.
57
+ of()));
58
+ }));
@@ -0,0 +1,12 @@
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');
@@ -0,0 +1,205 @@
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
+ const emptyResult = () => ({
12
+ values: {},
13
+ autoFilledFieldNames: [],
14
+ });
15
+ const isConfident = (field) => {
16
+ if (field == null) {
17
+ return false;
18
+ }
19
+ if (field.value == null) {
20
+ return false;
21
+ }
22
+ return field.confidence >= KYC_KYB_AUTOFILL_MIN_CONFIDENCE;
23
+ };
24
+ const assignAutofilledValue = (result, key, value) => {
25
+ if (value == null) {
26
+ return;
27
+ }
28
+ if (typeof value === 'string' && value.trim() === '') {
29
+ return;
30
+ }
31
+ result.values[key] = value;
32
+ result.autoFilledFieldNames.push(key);
33
+ };
34
+ const tryParseDate = (rawDate) => {
35
+ const parsedDate = date(rawDate);
36
+ if (parsedDate.isValid()) {
37
+ return parsedDate;
38
+ }
39
+ return undefined;
40
+ };
41
+ const normalizeNationality = (rawNationality, countries) => {
42
+ const needle = rawNationality.trim().toLowerCase();
43
+ if (needle === '') {
44
+ return undefined;
45
+ }
46
+ // Exact ISO-2 / ISO-3 match.
47
+ const isoMatch = countries.find((country) => country.countryCode.toLowerCase() === needle);
48
+ if (isoMatch != null) {
49
+ return isoMatch.countryCode;
50
+ }
51
+ // Common nationality adjectives map to country names (e.g. "American" → "United States").
52
+ const adjectiveToCountry = {
53
+ american: 'united states',
54
+ british: 'united kingdom',
55
+ indian: 'india',
56
+ canadian: 'canada',
57
+ australian: 'australia',
58
+ german: 'germany',
59
+ french: 'france',
60
+ chinese: 'china',
61
+ japanese: 'japan',
62
+ mexican: 'mexico',
63
+ brazilian: 'brazil',
64
+ };
65
+ const resolvedName = adjectiveToCountry[needle] ?? needle;
66
+ const nameMatch = countries.find((country) => country.countryName.toLowerCase() === resolvedName);
67
+ return nameMatch?.countryCode;
68
+ };
69
+ const splitFullName = (fullName) => {
70
+ const parts = fullName.trim().split(/\s+/);
71
+ if (parts.length === 1) {
72
+ return { firstName: parts[0], lastName: '' };
73
+ }
74
+ const lastName = parts[parts.length - 1];
75
+ const firstName = parts.slice(0, -1).join(' ');
76
+ return { firstName, lastName };
77
+ };
78
+ /** Passport → Company Officer. */
79
+ export const mapPassportToOfficer = (parsed, allNationalityCountries) => {
80
+ const result = emptyResult();
81
+ if (isConfident(parsed.first_name)) {
82
+ assignAutofilledValue(result, 'firstName', parsed.first_name.value);
83
+ }
84
+ if (isConfident(parsed.last_name)) {
85
+ assignAutofilledValue(result, 'lastName', parsed.last_name.value);
86
+ }
87
+ if (isConfident(parsed.date_of_birth)) {
88
+ const parsedDate = tryParseDate(parsed.date_of_birth.value);
89
+ if (parsedDate != null) {
90
+ assignAutofilledValue(result, 'birthday', parsedDate);
91
+ }
92
+ }
93
+ if (isConfident(parsed.nationality)) {
94
+ const isoCode = normalizeNationality(parsed.nationality.value, allNationalityCountries);
95
+ if (isoCode != null) {
96
+ assignAutofilledValue(result, 'nationalityCountryCode', isoCode);
97
+ }
98
+ }
99
+ return result;
100
+ };
101
+ /** Driving License → Company Officer. */
102
+ export const mapDrivingLicenseToOfficer = (parsed) => {
103
+ const result = emptyResult();
104
+ if (isConfident(parsed.first_name)) {
105
+ assignAutofilledValue(result, 'firstName', parsed.first_name.value);
106
+ }
107
+ if (isConfident(parsed.last_name)) {
108
+ assignAutofilledValue(result, 'lastName', parsed.last_name.value);
109
+ }
110
+ if (isConfident(parsed.date_of_birth)) {
111
+ const parsedDate = tryParseDate(parsed.date_of_birth.value);
112
+ if (parsedDate != null) {
113
+ assignAutofilledValue(result, 'birthday', parsedDate);
114
+ }
115
+ }
116
+ // address_* fields are mapped at a higher layer (addressView reducer) — kept here as values
117
+ // only, the consuming epic dispatches the address payload separately.
118
+ return result;
119
+ };
120
+ /** SSN Card → Company Officer (name only — SSN value not yet returned by parser). */
121
+ export const mapSsnCardToOfficer = (parsed) => {
122
+ const result = emptyResult();
123
+ if (isConfident(parsed.full_name)) {
124
+ const { firstName, lastName } = splitFullName(parsed.full_name.value);
125
+ if (firstName !== '') {
126
+ assignAutofilledValue(result, 'firstName', firstName);
127
+ }
128
+ if (lastName !== '') {
129
+ assignAutofilledValue(result, 'lastName', lastName);
130
+ }
131
+ }
132
+ return result;
133
+ };
134
+ /** Certificate of Incorporation → Company Details. */
135
+ export const mapCoiToCompanyDetails = (parsed) => {
136
+ const result = emptyResult();
137
+ if (isConfident(parsed.company_legal_name)) {
138
+ assignAutofilledValue(result, 'companyLegalName', parsed.company_legal_name.value);
139
+ }
140
+ if (isConfident(parsed.ein)) {
141
+ assignAutofilledValue(result, 'taxIdOrEIN', parsed.ein.value);
142
+ }
143
+ if (isConfident(parsed.phone_number)) {
144
+ assignAutofilledValue(result, 'phone', parsed.phone_number.value);
145
+ }
146
+ if (isConfident(parsed.product_description)) {
147
+ assignAutofilledValue(result, 'companyDescription', parsed.product_description.value);
148
+ }
149
+ if (isConfident(parsed.website)) {
150
+ try {
151
+ assignAutofilledValue(result, 'website', toZeniUrl(parsed.website.value));
152
+ }
153
+ catch {
154
+ // ignore — malformed URL string from OCR
155
+ }
156
+ }
157
+ if (isConfident(parsed.industry)) {
158
+ assignAutofilledValue(result, 'companyIndustryType', parsed.industry.value);
159
+ }
160
+ if (isConfident(parsed.sub_industry)) {
161
+ assignAutofilledValue(result, 'companySubIndustry', parsed.sub_industry.value);
162
+ }
163
+ if (isConfident(parsed.type_of_incorporation)) {
164
+ assignAutofilledValue(result, 'typeOfIncorporation', parsed.type_of_incorporation.value);
165
+ }
166
+ if (isConfident(parsed.date_of_incorporation)) {
167
+ const parsedDate = tryParseDate(parsed.date_of_incorporation.value);
168
+ if (parsedDate != null) {
169
+ assignAutofilledValue(result, 'incDate', parsedDate);
170
+ }
171
+ }
172
+ if (isConfident(parsed.state_of_incorporation)) {
173
+ assignAutofilledValue(result, 'stateOfIncorporation', parsed.state_of_incorporation.value);
174
+ }
175
+ if (isConfident(parsed.countries_of_operations)) {
176
+ assignAutofilledValue(result, 'countriesOfOperations', parsed.countries_of_operations.value);
177
+ }
178
+ if (isConfident(parsed.source_of_funds)) {
179
+ assignAutofilledValue(result, 'sourceOfFunds', parsed.source_of_funds.value);
180
+ }
181
+ if (isConfident(parsed.transaction_volume_expectations)) {
182
+ assignAutofilledValue(result, 'transactionVolume', parsed.transaction_volume_expectations.value);
183
+ }
184
+ if (isConfident(parsed.purpose_of_account)) {
185
+ assignAutofilledValue(result, 'purposeOfAccount', parsed.purpose_of_account.value);
186
+ }
187
+ if (isConfident(parsed.regulated_status)) {
188
+ assignAutofilledValue(result, 'regulatedStatus', parsed.regulated_status.value);
189
+ }
190
+ if (isConfident(parsed.us_nexus)) {
191
+ assignAutofilledValue(result, 'usNexus', parsed.us_nexus.value);
192
+ }
193
+ return result;
194
+ };
195
+ /** Tax EIN letter → Company Details. */
196
+ export const mapTaxEinToCompanyDetails = (parsed) => {
197
+ const result = emptyResult();
198
+ if (isConfident(parsed.legal_business_name)) {
199
+ assignAutofilledValue(result, 'companyLegalName', parsed.legal_business_name.value);
200
+ }
201
+ if (isConfident(parsed.ein)) {
202
+ assignAutofilledValue(result, 'taxIdOrEIN', parsed.ein.value);
203
+ }
204
+ return result;
205
+ };
@@ -3,60 +3,26 @@ const initialFetchStatus = {
3
3
  fetchState: 'Not-Started',
4
4
  error: undefined,
5
5
  };
6
+ const emptyOfficerSlot = {
7
+ autoFilledFields: [],
8
+ localData: undefined,
9
+ sendOtpStatus: initialFetchStatus,
10
+ otpverificationStatus: initialFetchStatus,
11
+ };
6
12
  export const initialState = {
7
13
  updateStatus: { fetchState: 'Not-Started', error: undefined },
8
- companyDetails: {},
14
+ companyDetails: { autoFilledFields: [] },
9
15
  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
- },
16
+ Officer_1: { ...emptyOfficerSlot },
17
+ Officer_2: { ...emptyOfficerSlot },
18
+ Officer_3: { ...emptyOfficerSlot },
19
+ Officer_4: { ...emptyOfficerSlot },
20
+ Officer_5: { ...emptyOfficerSlot },
21
+ Officer_6: { ...emptyOfficerSlot },
22
+ Officer_7: { ...emptyOfficerSlot },
23
+ Officer_8: { ...emptyOfficerSlot },
24
+ Officer_9: { ...emptyOfficerSlot },
25
+ Officer_10: { ...emptyOfficerSlot },
60
26
  },
61
27
  primaryContactDetails: {},
62
28
  };
@@ -297,7 +263,60 @@ const setupView = createSlice({
297
263
  clearSetupView(draft) {
298
264
  Object.assign(draft, initialState);
299
265
  },
266
+ /**
267
+ * Merge AI-parsed officer fields into the selected officer's localData and
268
+ * track which field names were autofilled so the form can show the ✦ badge.
269
+ */
270
+ applyKycDocumentAutofillForSetup: {
271
+ reducer(draft, action) {
272
+ const { officerType, values, autoFilledFieldNames } = action.payload;
273
+ const slot = draft.companyOfficerUpdateStatus[officerType];
274
+ slot.localData = Object.assign({}, slot.localData, values);
275
+ slot.autoFilledFields = Array.from(new Set([...slot.autoFilledFields, ...autoFilledFieldNames]));
276
+ },
277
+ prepare(payload) {
278
+ return { payload };
279
+ },
280
+ },
281
+ /**
282
+ * Merge AI-parsed company fields into companyDetails.localData and track
283
+ * which field names were autofilled.
284
+ */
285
+ applyKybDocumentAutofillForSetup: {
286
+ reducer(draft, action) {
287
+ const { values, autoFilledFieldNames } = action.payload;
288
+ draft.companyDetails.localData = Object.assign({}, draft.companyDetails.localData, values);
289
+ draft.companyDetails.autoFilledFields = Array.from(new Set([
290
+ ...draft.companyDetails.autoFilledFields,
291
+ ...autoFilledFieldNames,
292
+ ]));
293
+ },
294
+ prepare(payload) {
295
+ return { payload };
296
+ },
297
+ },
298
+ /**
299
+ * Wipe AI-autofill badges. If `officerType` is provided, clears only that
300
+ * officer; otherwise clears company details too.
301
+ */
302
+ clearKycKybAutofillForSetup: {
303
+ reducer(draft, action) {
304
+ const { officerType } = action.payload;
305
+ if (officerType != null) {
306
+ draft.companyOfficerUpdateStatus[officerType].autoFilledFields = [];
307
+ }
308
+ else {
309
+ draft.companyDetails.autoFilledFields = [];
310
+ Object.keys(draft.companyOfficerUpdateStatus).forEach((key) => {
311
+ draft.companyOfficerUpdateStatus[key].autoFilledFields = [];
312
+ });
313
+ }
314
+ },
315
+ prepare(payload = {}) {
316
+ return { payload };
317
+ },
318
+ },
300
319
  },
301
320
  });
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;
321
+ 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
322
  export default setupView.reducer;
@@ -119,6 +119,7 @@ export const getCompanyAndIdentityDetails = (state, companyId, companyAndIdentit
119
119
  const companyAddress = addressViewState.newAddressState?.company_address;
120
120
  const registeredCompanyAddress = addressViewState.newAddressState?.company_registered_address;
121
121
  companyDetailsLocalData = {
122
+ autoFilledFields: companyDetails.autoFilledFields,
122
123
  companyId,
123
124
  companyDescription,
124
125
  companyLegalName,
@@ -191,6 +192,7 @@ export const getCompanyAndIdentityDetails = (state, companyId, companyAndIdentit
191
192
  const companyOfficerAddress = addressViewState.newAddressState?.[addressType];
192
193
  companyOfficerLocalData[officerType] = {
193
194
  ...companyOfficer.localData,
195
+ autoFilledFields: companyOfficer.autoFilledFields,
194
196
  userFiles: getFilesByFileIds(fileState, fileIds),
195
197
  additionalFiles: getFilesByFileIds(fileState, additionalSubmittedDocumentsForVerificationFileIds),
196
198
  deleteFileStatusById,
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Shared types for the KYC / KYB document autofill flow that lives inside the
3
+ * commonSetup feature (Setup pages + Onboarding both consume it via the same
4
+ * selector view; there is no separate state slice).
5
+ *
6
+ * Backed by document-communication-agent `POST /1.0/documents/process/sync`,
7
+ * which proxies document-service ExtendAI parsers and returns one of the
8
+ * parser payloads below — each value shaped as `{value, confidence}` per field.
9
+ */
10
+ /** Confidence floor below which we drop an autofill candidate. */
11
+ export const KYC_KYB_AUTOFILL_MIN_CONFIDENCE = 0.5;
12
+ /**
13
+ * Maps the form-side {@link KycSelectDocumentType} (camelCase) to the
14
+ * parser-side {@link KycProvidedDocumentType} (snake_case). Returns `null` for
15
+ * `stateId`, which has no parser today.
16
+ */
17
+ export const toKycProvidedDocumentType = (selectType) => {
18
+ switch (selectType) {
19
+ case 'driverLicense':
20
+ return 'driving_license';
21
+ case 'passport':
22
+ return 'passport';
23
+ case 'ssnCard':
24
+ return 'social_security_card';
25
+ case 'stateId':
26
+ return null;
27
+ }
28
+ };
package/lib/index.d.ts CHANGED
@@ -333,7 +333,7 @@ import { clearOnboardingCustomerViewUpdateData, fetchCompanyOnboardingView, fetc
333
333
  import { NewOnboardingCustomerLocalData, NewOnboardingCustomerView, OnboardingCockpitView, ProductInfo, getNewOnboardingCustomerView, getOnboardingCockpitView } from './view/onboardingView/cockpitView/onboardingCockpitViewSelector';
334
334
  import { OnboardingCustomerListUIState, QBOConnectionPool } from './view/onboardingView/cockpitView/onboardingCockpitViewState';
335
335
  import { CustomerCreationStatus, NewOnboardingCustomer, OnboardingCompanyDetails, OnboardingCustomer, OnboardingCustomerCompletedStatus, ProductGroupType, ProductType, toProductType, toProductTypeStrict } from './view/onboardingView/cockpitView/types/onboardingCockpitViewTypes';
336
- import { clearOnboardingCustomerView, clearOnboardingCustomerViewDataInLocalStore, establishOnboardingPlaidConnection, fetchOnboardingCustomerSetupView, fetchOnboardingCustomerView, getOnboardingPlaidLinkToken, saveOnboardingCompnayOfficerPhoneInLocalStore, saveOnboardingCustomerViewDataInLocalStore, updateCurrentStep, updateOnboardingCustomerView, updateOnboardingCustomerViewAccountDetails, updateOnboardingCustomerViewCompleteStatus, updateOnboardingCustomerViewDashboardLoaded, updateOnboardingCustomerViewLocalStoreData, updateOnboardingCustomerViewUIState, updateOnboardingPaymentAccountLoginStatus, updateOnboardingPaymentAccountStatus } from './view/onboardingView/customerView/onboardingCustomerViewReducer';
336
+ import { applyKycDocumentAutofillForOnboarding, applyKybDocumentAutofillForOnboarding, clearKycKybAutofillForOnboarding, clearOnboardingCustomerView, clearOnboardingCustomerViewDataInLocalStore, establishOnboardingPlaidConnection, fetchOnboardingCustomerSetupView, fetchOnboardingCustomerView, getOnboardingPlaidLinkToken, saveOnboardingCompnayOfficerPhoneInLocalStore, saveOnboardingCustomerViewDataInLocalStore, updateCurrentStep, updateOnboardingCustomerView, updateOnboardingCustomerViewAccountDetails, updateOnboardingCustomerViewCompleteStatus, updateOnboardingCustomerViewDashboardLoaded, updateOnboardingCustomerViewLocalStoreData, updateOnboardingCustomerViewUIState, updateOnboardingPaymentAccountLoginStatus, updateOnboardingPaymentAccountStatus } from './view/onboardingView/customerView/onboardingCustomerViewReducer';
337
337
  import { OnboardingCustomerView, getOnboardingCustomerView, getProductSettingsString } from './view/onboardingView/customerView/onboardingCustomerViewSelector';
338
338
  import { OnboardingCustomerViewLocalData, OnboardingCustomerViewUIState, OnboardingStep } from './view/onboardingView/customerView/onboardingCustomerViewState';
339
339
  import { fetchOpEx, fetchOpExWithForecast, updateOpExCOABalancesRange, updateOpExDownloadState, updateOpExUIState } from './view/opEx/opExReducer';
@@ -472,7 +472,8 @@ import { IssueChargeCardSelectorView, getIssueChargeCardView } from './view/spen
472
472
  import { ActiveChargeCardCount, ActiveDebitCardCount, ActiveDebitCardCountByUserId, IssueChargeCardLocalData, IssueChargeCardState, PhysicalCreditCardData, PhysicalDebitCardData, VirtualCreditCardData, VirtualDebitCardData } from './view/spendManagement/chargeCards/issueChargeCard/issueChargeCardState';
473
473
  import { CommonHistoryView, HistoricEvent, HistoricEventUpdate } from './view/spendManagement/commonHistoryView/commonHistory';
474
474
  import { ActivityHistorySelectorView } from './view/spendManagement/commonHistoryView/commonHistorySelector';
475
- import { clearSetupViewDataInLocalStore, enableSetup, saveCompnayOfficerAdditionalDocumentsInLocalStore, saveCompnayOfficerPhoneInLocalStore, saveIndustryAndIncDateInLocalStore, saveSetupViewDataInLocalStore, saveTreasuryAdditionalDocumentsInLocalStore, updateBusinessVerificationDetails, updateSelectedCompanyOfficer, updateSetupViewLocalStoreData } from './view/spendManagement/commonSetup/setupViewReducer';
475
+ import { clearSetupViewDataInLocalStore, enableSetup, saveCompnayOfficerAdditionalDocumentsInLocalStore, saveCompnayOfficerPhoneInLocalStore, saveIndustryAndIncDateInLocalStore, saveSetupViewDataInLocalStore, saveTreasuryAdditionalDocumentsInLocalStore, updateBusinessVerificationDetails, updateSelectedCompanyOfficer, updateSetupViewLocalStoreData, applyKycDocumentAutofillForSetup, applyKybDocumentAutofillForSetup, clearKycKybAutofillForSetup } from './view/spendManagement/commonSetup/setupViewReducer';
476
+ import { parseUploadedKycDocument, parseUploadedKybDocument } from './view/spendManagement/commonSetup/kycKybAutofillActions';
476
477
  import { BusinessVerificationDetails, CompanyDetails, CompanyOfficersDetails, FundingAccount, SetupView, getBusinessVerificationDetails, getCommonSetupViewDetails } from './view/spendManagement/commonSetup/setupViewSelector';
477
478
  import { SetupViewLocalData, SetupViewState } from './view/spendManagement/commonSetup/setupViewState';
478
479
  import { COMPANY_ONBOARDING_INDUSTRY_TYPE_CODES, COMPANY_ONBOARDING_SUB_INDUSTRY_CODES_BY_INDUSTRY, COMPANY_PURPOSE_OF_ACCOUNT_CODES, COMPANY_SOURCE_OF_FUNDS_CODES, COMPANY_TRANSACTION_VOLUME_CODES, COMPANY_US_NEXUS_TYPE_CODES, CompanyOnboardingIndustryTypeCode, CompanyOnboardingSubIndustryTypeCode, CompanyPurposeOfAccountCode, CompanySourceOfFundsCode, CompanyTransactionVolumeCode, CompanyUsNexusTypeCode, getCompanyOnboardingSubIndustryCodesForIndustry } from './view/spendManagement/commonSetup/types/businessVerification';
@@ -794,7 +795,7 @@ export { MilageReimbursementLine, OutofPocketReimbursementLine, ReimbursementLin
794
795
  export { AccountListSelectorView, ClassListSelectorView, getClassList, fetchClassList, ProjectListSelectorView, getProjectList, fetchProjectList, };
795
796
  export { BillTab, BillsSubTabType, SaveBillStageCode, BillPayReviewSelectorView, DuplicateBillsSelectorView, EditBillDetailSelectorView, LineItemRecommendationsLocalData, EditBillInitialDetails, BillableStatus, PaymentDetailsSection, BillListReport, BillListDownloadReport, WhatForSection, fetchBillList, fetchBillListPerTab, updateTab, updateSubTab, updateSelectedBillId, updateBillDetailSaveBillCode, fetchVendorByNameAndParseInvoice, saveBillUpdatesToLocalStore, discardBillUpdatesInLocalStore, saveBillDetail, approveOrRejectBill, updateApprovalStatusOnSuccess, deleteBill, cancelAndDeleteBill, retryOrRefundBill, getBillList, getBillDownloadList, BillDetailViewSelector, ActorActivityWithUser, BillActivity, StepWithStatus, getBillDetailView, checkApproveRejectBtnShowForBill, BillDetailView, getBillTransactionDetailKey, fetchBillDetail, fetchEditBillDetailPage, fetchAndUpdateVendorRecommendations, fetchDuplicateBill, clearBillPayReview, EditBillDetail, EditBillDetailViewState, getEditBillDetail, getReviewPageBillDetail, BillDetailLocalData, PaymentDetailsSectionView, fetchBillAndInitializeLocalStore, updateShowAutofill, saveVendorSuccessOrFailure, BillPaymentStatus, BillPaymentStatusCodeType, BillPaymentRefundStatus, BillPaymentRefundStatusCodeType, BillStatus, BillStatusCodeType, BillApprovalType, updateBillListUIState, BillListUIState, BillPayViewSortKey, BillPayFilters, BillPayFilterCategory, BillListViewFilterCategoryField, BILL_PAY_FILTER_CATEGORIES, updateVendorDetailLocalData, resetVendorDetailLocalData, resetVendorSaveStatus, updateContactsInVendorDetailLocalData, updateVendorTabDetailUIState, updateContactsInVendorTabDetailLocalData, updateBillUploadFetchState, updateBillListSearchResult, fetchUserDetails, verifyUser, updateVendorContact, PaymentToOption, toPaymentToOption, convertAmountToHomeCurrency, RecurringBillInstance, RecurringBillConfigLocalData, EditRecurringBillType, fetchVendorAndUpdateBillLocalData, markBillForRetry, updateWithdrawFromAccountId, removeBillFileFromLocalStore, replaceBillFileInLocalStore, updateShouldReplaceBillData, };
796
797
  export { SpendManagementFiltersType, SpendManagementFilterEntityType, FilterCategoryType, BillPayFilterCategoryDropdownOption, ReimbursementFilterCategoryDropdownOption, TaskFilterCategoryDropdownOption, SpendManagementFilterCategoryDropdownOption, MatchingOperatorDropdownOption, CategoryCombinationOperator, hideCreatedByFilter, };
797
- export { BillPaySetupViewState, ZeniAccountSetupViewState, BillPaySetupViewLocalData, ZeniAccountSetupViewLocalData, PlaidAccountState, fetchBillPaySetupView, fetchZeniAccountSetupView, enableSetup, getPaymentAccounts, getPlaidLinkToken, updateSelectedCompanyOfficer, updateSetupViewLocalStoreData, updateBusinessVerificationDetails, updatePaymentAccount, updatePaymentAccountLoginStatus, updatePaymentAccountStatus, establishPlaidConnection, updateMappedCashAccount, updatePrimaryFundingAccount, acceptBillPayTerms, acceptZeniAccountTerms, acceptBillPayUpdatedTerms, saveSetupViewDataInLocalStore, saveCompnayOfficerPhoneInLocalStore, saveCompnayOfficerAdditionalDocumentsInLocalStore, saveTreasuryAdditionalDocumentsInLocalStore, saveIndustryAndIncDateInLocalStore, clearSetupViewDataInLocalStore, clearBillPaySetupView, clearZeniAccountSetupView, sendOtp, resendOtp, verifyOtp, CompanyDetails, CompanyOfficersDetails, BillPaySetupView, ZeniAccountSetupView, BillPayBusinessVerificationDetails, ZeniAccountBusinessVerificationDetails, TreasuryBusinessVerificationDetails, SetupViewState, SetupViewLocalData, SetupView, BusinessVerificationDetails, getBillPaySetupViewDetails, getPlaidAccountDetails, getZeniAccountSetupViewDetails, getBusinessVerificationDetails, getBillPayBusinessVerificationDetails, getZeniAccountBusinessVerificationDetails, getTreasuryBusinessVerificationDetails, getCommonSetupViewDetails, PlaidConnectionDetails, PlaidLinkTokenType, PlaidAccountKeyType, Token, FundingAccount, getTwoFactorAuthenticationView, getTwoFactorAuthenticationViewForCardUserOnboarding, getTwoFactorAuthenticationViewForChargeCardHolder, TwoFactorAuthenticationView, };
798
+ export { BillPaySetupViewState, ZeniAccountSetupViewState, BillPaySetupViewLocalData, ZeniAccountSetupViewLocalData, PlaidAccountState, fetchBillPaySetupView, fetchZeniAccountSetupView, enableSetup, getPaymentAccounts, getPlaidLinkToken, updateSelectedCompanyOfficer, updateSetupViewLocalStoreData, updateBusinessVerificationDetails, updatePaymentAccount, updatePaymentAccountLoginStatus, updatePaymentAccountStatus, establishPlaidConnection, updateMappedCashAccount, updatePrimaryFundingAccount, acceptBillPayTerms, acceptZeniAccountTerms, acceptBillPayUpdatedTerms, saveSetupViewDataInLocalStore, saveCompnayOfficerPhoneInLocalStore, saveCompnayOfficerAdditionalDocumentsInLocalStore, saveTreasuryAdditionalDocumentsInLocalStore, saveIndustryAndIncDateInLocalStore, clearSetupViewDataInLocalStore, clearBillPaySetupView, clearZeniAccountSetupView, applyKycDocumentAutofillForSetup, applyKybDocumentAutofillForSetup, clearKycKybAutofillForSetup, parseUploadedKycDocument, parseUploadedKybDocument, sendOtp, resendOtp, verifyOtp, CompanyDetails, CompanyOfficersDetails, BillPaySetupView, ZeniAccountSetupView, BillPayBusinessVerificationDetails, ZeniAccountBusinessVerificationDetails, TreasuryBusinessVerificationDetails, SetupViewState, SetupViewLocalData, SetupView, BusinessVerificationDetails, getBillPaySetupViewDetails, getPlaidAccountDetails, getZeniAccountSetupViewDetails, getBusinessVerificationDetails, getBillPayBusinessVerificationDetails, getZeniAccountBusinessVerificationDetails, getTreasuryBusinessVerificationDetails, getCommonSetupViewDetails, PlaidConnectionDetails, PlaidLinkTokenType, PlaidAccountKeyType, Token, FundingAccount, getTwoFactorAuthenticationView, getTwoFactorAuthenticationViewForCardUserOnboarding, getTwoFactorAuthenticationViewForChargeCardHolder, TwoFactorAuthenticationView, };
798
799
  export { BankConnectionsSetupView, IntegrationsView, getApprovalRuleViewDetails, getBankConnectionsSetupViewDetails, getIntegrationsView, };
799
800
  export { fetchUserFinancialAccount };
800
801
  export { getUserFinancialAccount, UserFinancialAccountSelectorView };
@@ -845,7 +846,7 @@ export { CountryWithCurrency };
845
846
  export { fetchCompanyConfig };
846
847
  export { getCompanyConfig };
847
848
  export { isZeniClearingAccountReport, ZENI_CLEARING_ACCOUNT, isZeniClearingAccount, };
848
- export { fetchOnboardingCustomerView, fetchOnboardingCustomerSetupView, getOnboardingPlaidLinkToken, establishOnboardingPlaidConnection, updateOnboardingCustomerViewAccountDetails, updateOnboardingCustomerViewCompleteStatus, updateOnboardingCustomerViewDashboardLoaded, updateOnboardingPaymentAccountLoginStatus, updateOnboardingPaymentAccountStatus, updateOnboardingCustomerView, updateOnboardingCustomerViewLocalStoreData, updateCurrentStep, updateOnboardingCustomerViewUIState, saveOnboardingCompnayOfficerPhoneInLocalStore, saveOnboardingCustomerViewDataInLocalStore, clearOnboardingCustomerView, clearOnboardingCustomerViewDataInLocalStore, getOnboardingCustomerView, getProductSettingsString, OnboardingCustomerView, OnboardingStep, OnboardingCustomerViewUIState, OnboardingCustomerViewLocalData, };
849
+ export { fetchOnboardingCustomerView, fetchOnboardingCustomerSetupView, getOnboardingPlaidLinkToken, establishOnboardingPlaidConnection, updateOnboardingCustomerViewAccountDetails, updateOnboardingCustomerViewCompleteStatus, updateOnboardingCustomerViewDashboardLoaded, updateOnboardingPaymentAccountLoginStatus, updateOnboardingPaymentAccountStatus, updateOnboardingCustomerView, updateOnboardingCustomerViewLocalStoreData, updateCurrentStep, updateOnboardingCustomerViewUIState, saveOnboardingCompnayOfficerPhoneInLocalStore, saveOnboardingCustomerViewDataInLocalStore, clearOnboardingCustomerView, clearOnboardingCustomerViewDataInLocalStore, applyKycDocumentAutofillForOnboarding, applyKybDocumentAutofillForOnboarding, clearKycKybAutofillForOnboarding, getOnboardingCustomerView, getProductSettingsString, OnboardingCustomerView, OnboardingStep, OnboardingCustomerViewUIState, OnboardingCustomerViewLocalData, };
849
850
  export { saveAccountMapping, saveAccountMappingLocalData, clearAccountMappingLocalData, AccountMappingLocalData, AccountMappingView, VendorAccountMappingView, getAccountMappingView, initializeAccountMappingView, ExpenseCategory1099Filing, };
850
851
  export { MagicLinkView, getMagicLinkView, getMagicLinkBankAccountView, getMagicLinkCurrentAddressState, };
851
852
  export { fetchMagicLinkTenant, fetchBillAttachment, saveBankAccount, updateMagicLinkBankAccountLocalStoreData, updateMagicLinkInternationalBankAccountLocalStoreData, fetchMagicLinkBankNameByRouting, fetchMagicLinkBankNameBySwift, saveMagicLinkAddressInLocalStore, };
@@ -929,3 +930,5 @@ export { UserGroup } from './entity/userGroups/userGroupsState';
929
930
  export { SessionManager } from './entity/tenant/SessionManager';
930
931
  export type { SessionCallbacks, SessionConfig, } from './entity/tenant/sessionTypes';
931
932
  export { DEFAULT_SESSION_CONFIG } from './entity/tenant/sessionTypes';
933
+ export type { KybProvidedDocumentType, KycKybAutofillTarget, KycKybProvidedDocumentType, KycProvidedDocumentType, KycSelectDocumentType, } from './view/spendManagement/commonSetup/types/kycKybAutofill';
934
+ export { toKycProvidedDocumentType } from './view/spendManagement/commonSetup/types/kycKybAutofill';