@zeniai/client-epic-state 5.1.6 → 5.1.8-betaAS1

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 (40) hide show
  1. package/lib/commonPayloadTypes/commonPayload.d.ts +25 -4
  2. package/lib/esm/index.js +6 -1
  3. package/lib/esm/view/onboardingView/customerView/onboardingCustomerViewSelector.js +13 -7
  4. package/lib/esm/view/onboardingView/customerView/onboardingCustomerViewState.js +8 -0
  5. package/lib/esm/view/spendManagement/billPay/internationalWireVerification/epics/fetchIntlVerificationFormEpic.js +7 -3
  6. package/lib/esm/view/spendManagement/billPay/internationalWireVerification/epics/initializeIntlVerificationFormEpic.js +33 -34
  7. package/lib/esm/view/spendManagement/billPay/internationalWireVerification/epics/submitIntlVerificationEpic.js +2 -7
  8. package/lib/esm/view/spendManagement/billPay/internationalWireVerification/internationalWireOnboardingDetailsToLocalData.js +146 -0
  9. package/lib/esm/view/spendManagement/billPay/internationalWireVerification/internationalWireVerificationFieldConstants.js +40 -0
  10. package/lib/esm/view/spendManagement/billPay/internationalWireVerification/internationalWireVerificationLocalDataHelpers.js +86 -0
  11. package/lib/esm/view/spendManagement/billPay/internationalWireVerification/internationalWireVerificationPayload.js +55 -8
  12. package/lib/esm/view/spendManagement/billPay/internationalWireVerification/internationalWireVerificationReducer.js +5 -6
  13. package/lib/esm/view/spendManagement/billPay/internationalWireVerification/internationalWireVerificationSelector.js +39 -15
  14. package/lib/esm/view/spendManagement/billPay/internationalWireVerification/internationalWireVerificationSubmitPayload.js +154 -0
  15. package/lib/esm/view/spendManagement/commonSetup/kycKybParseMapper.js +15 -1
  16. package/lib/index.d.ts +8 -2
  17. package/lib/index.js +24 -6
  18. package/lib/view/onboardingView/customerView/onboardingCustomerViewSelector.js +12 -6
  19. package/lib/view/onboardingView/customerView/onboardingCustomerViewState.d.ts +1 -0
  20. package/lib/view/onboardingView/customerView/onboardingCustomerViewState.js +9 -1
  21. package/lib/view/spendManagement/billPay/internationalWireVerification/epics/fetchIntlVerificationFormEpic.d.ts +3 -3
  22. package/lib/view/spendManagement/billPay/internationalWireVerification/epics/fetchIntlVerificationFormEpic.js +6 -2
  23. package/lib/view/spendManagement/billPay/internationalWireVerification/epics/initializeIntlVerificationFormEpic.d.ts +2 -1
  24. package/lib/view/spendManagement/billPay/internationalWireVerification/epics/initializeIntlVerificationFormEpic.js +32 -33
  25. package/lib/view/spendManagement/billPay/internationalWireVerification/epics/submitIntlVerificationEpic.js +2 -7
  26. package/lib/view/spendManagement/billPay/internationalWireVerification/internationalWireOnboardingDetailsToLocalData.d.ts +4 -0
  27. package/lib/view/spendManagement/billPay/internationalWireVerification/internationalWireOnboardingDetailsToLocalData.js +150 -0
  28. package/lib/view/spendManagement/billPay/internationalWireVerification/internationalWireVerificationFieldConstants.d.ts +38 -0
  29. package/lib/view/spendManagement/billPay/internationalWireVerification/internationalWireVerificationFieldConstants.js +43 -0
  30. package/lib/view/spendManagement/billPay/internationalWireVerification/internationalWireVerificationLocalDataHelpers.d.ts +27 -0
  31. package/lib/view/spendManagement/billPay/internationalWireVerification/internationalWireVerificationLocalDataHelpers.js +96 -0
  32. package/lib/view/spendManagement/billPay/internationalWireVerification/internationalWireVerificationPayload.d.ts +24 -1
  33. package/lib/view/spendManagement/billPay/internationalWireVerification/internationalWireVerificationPayload.js +59 -9
  34. package/lib/view/spendManagement/billPay/internationalWireVerification/internationalWireVerificationReducer.js +4 -5
  35. package/lib/view/spendManagement/billPay/internationalWireVerification/internationalWireVerificationSelector.js +39 -15
  36. package/lib/view/spendManagement/billPay/internationalWireVerification/internationalWireVerificationState.d.ts +20 -1
  37. package/lib/view/spendManagement/billPay/internationalWireVerification/internationalWireVerificationSubmitPayload.d.ts +32 -0
  38. package/lib/view/spendManagement/billPay/internationalWireVerification/internationalWireVerificationSubmitPayload.js +159 -0
  39. package/lib/view/spendManagement/commonSetup/kycKybParseMapper.js +15 -1
  40. package/package.json +6 -4
@@ -10,10 +10,31 @@ export interface AllowedValueWithCodeOptionalPayload {
10
10
  export declare function isAllowedValueWithCodePayload(allowedValueWithCodePayload: any): allowedValueWithCodePayload is AllowedValueWithCodePayload;
11
11
  export declare function isAllowedValueWithCodeOptionalPayload(allowedValueWithCodePayload: any): allowedValueWithCodePayload is AllowedValueWithCodeOptionalPayload;
12
12
  export declare function toAllowedValueWithCode(allowedValueWithCodePayload: AllowedValueWithCodePayload): AllowedValueWithCode;
13
+ export interface LabelValueCodeDescriptionPayload {
14
+ code: string;
15
+ description: string;
16
+ }
17
+ export interface LabelValueFileOptionPayload {
18
+ file_id: string;
19
+ option?: string;
20
+ }
21
+ export interface LabelValuePersonNamePayload {
22
+ first_name?: string;
23
+ last_name?: string;
24
+ }
25
+ export interface LabelValuePersonPayload {
26
+ company_role?: string;
27
+ date_of_birth?: string;
28
+ email?: string;
29
+ name?: LabelValuePersonNamePayload;
30
+ nationality?: string;
31
+ ownership_percentage?: number;
32
+ proof_of_address?: LabelValueFileOptionPayload[];
33
+ proof_of_identity?: LabelValueFileOptionPayload[];
34
+ ssn?: string;
35
+ }
36
+ export type LabelValueCodesValuesPayload = string | string[] | LabelValueCodeDescriptionPayload | LabelValueCodeDescriptionPayload[] | LabelValueFileOptionPayload | LabelValueFileOptionPayload[] | LabelValuePersonPayload | LabelValuePersonPayload[];
13
37
  export interface LabelValueCodesPayload {
14
38
  label: string;
15
- values: {
16
- code: string;
17
- description: string;
18
- }[] | string[];
39
+ values: LabelValueCodesValuesPayload;
19
40
  }
package/lib/esm/index.js CHANGED
@@ -292,6 +292,7 @@ import { convertAmountToHomeCurrency, discardBillUpdatesInLocalStore, discardOut
292
292
  import { checkIfCreatorIsApprover, getEditBillDetail, toPaymentToOption, } from './view/spendManagement/billPay/editBillView/editBillViewSelector';
293
293
  import { clearInternationalWire, createPaymentInstrument, createPaymentInstrumentUpdateStatus, deletePaymentInstrument, fetchInternationalWireDynamicForm, initializeDynamicForm, initializeInternationalWireLocalData, updateInternationalWireLocalStoreData, } from './view/spendManagement/billPay/internationalWire/internationalWireReducer';
294
294
  import { getInternationalWireView, } from './view/spendManagement/billPay/internationalWire/internationalWireSelector';
295
+ import { InternationalWireVerificationFormOrder, sortVerificationFormFields, } from './view/spendManagement/billPay/internationalWireVerification/internationalWireVerificationPayload';
295
296
  import { fetchInternationalVerificationForm, submitInternationalVerificationForm, updateVerificationFormLocalData, } from './view/spendManagement/billPay/internationalWireVerification/internationalWireVerificationReducer';
296
297
  import { getIntlWireVerificationView, } from './view/spendManagement/billPay/internationalWireVerification/internationalWireVerificationSelector';
297
298
  import { fetchBillAttachment, fetchMagicLinkBankNameByRouting, fetchMagicLinkBankNameBySwift, fetchMagicLinkTenant, saveBankAccount, saveMagicLinkAddressInLocalStore, updateMagicLinkBankAccountLocalStoreData, updateMagicLinkInternationalBankAccountLocalStoreData, } from './view/spendManagement/billPay/magicLinkView/magicLinkViewReducer';
@@ -644,7 +645,11 @@ export { pushToastNotification, getLastNotificationTime, getNotifications, };
644
645
  export { getReferralListView, getInviteFormView, toReferralListViewSortKeyType, StatusTypes, AmountStatusTypes, fetchReferrals, sendReferralInvite, clearReferrals, saveReferralFormDataInLocalStore, updateReferralListSortUiState, resendReferralInvite, fetchRewardsPlan, getRewardsPlanCard, updateReferViewed, };
645
646
  export { ALL_WEEK_DAYS, SEMI_WEEKLY_REQUIRED_DAYS_COUNT, getMinAllowedEndDate, getRecurringEndDateFromCount, toDayOfWeek, toRecurringFrequency, };
646
647
  export { fetchCockpitContext, fetchCompanyTaskManagerView, fetchTaskManagerMetrics, getCompanyTaskManagerView, createTaskFromTaskGroupTemplate, };
647
- export { fetchInternationalVerificationForm, submitInternationalVerificationForm, updateVerificationFormLocalData, getIntlWireVerificationView, };
648
+ export { InternationalWireVerificationFormOrder, sortVerificationFormFields, fetchInternationalVerificationForm, submitInternationalVerificationForm, updateVerificationFormLocalData, getIntlWireVerificationView, };
649
+ export { InternationalWireVerificationBooleanWithSubfieldsFieldNameList, InternationalWireVerificationBooleanWithSubfieldsFieldNames, InternationalWireVerificationControllingPersonFieldName, InternationalWireVerificationFormFieldNames, InternationalWireVerificationStakeHolderFieldName, InternationalWireVerificationSubfieldNames, } from './view/spendManagement/billPay/internationalWireVerification/internationalWireVerificationFieldConstants';
650
+ export { IntlWireVerificationLocalDataSuffix, toIntlWireVerificationFormDetails, toIntlWireVerificationSubmitPayload, } from './view/spendManagement/billPay/internationalWireVerification/internationalWireVerificationSubmitPayload';
651
+ export { getStakeHolderOwnerIndicesFromLocalData, } from './view/spendManagement/billPay/internationalWireVerification/internationalWireVerificationLocalDataHelpers';
652
+ export { toVerificationFormLocalDataFromOnboardingDetails, } from './view/spendManagement/billPay/internationalWireVerification/internationalWireOnboardingDetailsToLocalData';
648
653
  export { fetchExpressPayInitialDetails, updateExpressPayFormLocalData, submitExpressPay, resetExpressPayLocalData, getExpressPayView, };
649
654
  export { acceptTreasuryTerms, fetchTreasurySetupView, clearTreasurySetupView, fetchTreasuryFunds, updatePortfolioAllocation, fetchPortfolioAllocation, updateFundAllocationLocalData, updateTreasuryPromoIntroClosedByOutsideClick, updateTreasuryPromoRemindMeLaterClicked, updateTreasuryVideoViewed, getTreasurySetupViewDetails, getTreasuryFundsMaximumYield, };
650
655
  // ── AI Accountant Entity ──
@@ -8,7 +8,7 @@ import { getUserRoleByUserIds } from '../../../entity/userRole/userRoleSelector'
8
8
  import { getCompanyConfig } from '../../companyConfigView/companyConfigSelector';
9
9
  import { getCompanyView } from '../../companyView/selectorHelpers/getCompanyView';
10
10
  import { getCompanyAndIdentityDetails, } from '../../spendManagement/commonSetup/setupViewSelector';
11
- import { ALL_ONBOARDING_STEPS, ALL_ZENI_USER_ONBOARDING_STEPS, REQUIRED_ONBOARDING_STEPS, ZENI_USER_REQUIRED_ONBOARDING_STEPS, emptyAiAgentsActivationSubview, toOnboardingStepType, } from './onboardingCustomerViewState';
11
+ import { ALL_ONBOARDING_STEPS, ALL_ZENI_USER_BOOKKEEPING_ONBOARDING_STEPS, ALL_ZENI_USER_ONBOARDING_STEPS, REQUIRED_ONBOARDING_STEPS, ZENI_USER_REQUIRED_ONBOARDING_STEPS, emptyAiAgentsActivationSubview, toOnboardingStepType, } from './onboardingCustomerViewState';
12
12
  export function getOnboardingCustomerView(state, companyId) {
13
13
  const { fileState, paymentAccountState, onboardingCustomerViewState, userState, userRoleState, subscriptionPaymentAccountState, companyConfigState, cardPaymentViewState, countryListState, addressViewState, } = state;
14
14
  const { companyDetails, companyOfficerUpdateStatus, primaryContactDetails, subscriptionPaymentAccountIds, paymentAccountDetails, plaidConnectionDetails, parsingDocumentFileIds, updateStatus, saveStatus, currentStep, currentSubStep, uiState, fetchState, error, } = onboardingCustomerViewState;
@@ -207,14 +207,20 @@ export function isOfficerDetailsCompleted(companyOfficers, companyOfficerRoles,
207
207
  isPhoneVerified === true);
208
208
  }
209
209
  export const onboardingStepsData = (isValidConnection, productSettings, accountingConnectionCreationMode) => {
210
- const allStepsData = accountingConnectionCreationMode === 'zeni_user' ||
211
- ((productSettings.isBankingEnabled || productSettings.isCardsEnabled) &&
212
- !productSettings.isBookkeepingEnabled)
210
+ // 3 cohorts:
211
+ // - Core-only (banking/cards, no bookkeeping): no ledger, no integrations.
212
+ // - Zeni-team-connects-QBO bookkeeping: skip ledger but keep integrations
213
+ // so the customer can still wire up Plaid / Stripe / HubSpot / email.
214
+ // - Customer-connects-QBO bookkeeping: full 4-step flow.
215
+ const isCoreOnlyTenant = (productSettings.isBankingEnabled || productSettings.isCardsEnabled) &&
216
+ !productSettings.isBookkeepingEnabled;
217
+ const allStepsData = isCoreOnlyTenant
213
218
  ? ALL_ZENI_USER_ONBOARDING_STEPS
214
- : ALL_ONBOARDING_STEPS;
219
+ : accountingConnectionCreationMode === 'zeni_user'
220
+ ? ALL_ZENI_USER_BOOKKEEPING_ONBOARDING_STEPS
221
+ : ALL_ONBOARDING_STEPS;
215
222
  const requiredStepsData = (accountingConnectionCreationMode === 'zeni_user' && isValidConnection) ||
216
- ((productSettings.isBankingEnabled || productSettings.isCardsEnabled) &&
217
- !productSettings.isBookkeepingEnabled)
223
+ isCoreOnlyTenant
218
224
  ? ZENI_USER_REQUIRED_ONBOARDING_STEPS
219
225
  : REQUIRED_ONBOARDING_STEPS;
220
226
  return {
@@ -18,6 +18,14 @@ export const ALL_ZENI_USER_ONBOARDING_STEPS = [
18
18
  ...ZENI_USER_REQUIRED_ONBOARDING_STEPS,
19
19
  ...ALL_ZENI_USER_ONBOARDING_STEPS_WITHOUT_ACCOUNT,
20
20
  ];
21
+ // Zeni-team-connects-QBO bookkeeping tenants: skip the `connect_ledger` step
22
+ // (Zeni already did it) but keep `connect_data_source` so the customer can
23
+ // still wire up non-QBO integrations (Plaid, Stripe, HubSpot, email, etc.).
24
+ export const ALL_ZENI_USER_BOOKKEEPING_ONBOARDING_STEPS = [
25
+ ...ZENI_USER_REQUIRED_ONBOARDING_STEPS,
26
+ 'connect_data_source',
27
+ ...ALL_ZENI_USER_ONBOARDING_STEPS_WITHOUT_ACCOUNT,
28
+ ];
21
29
  export const ALL_CUSTOMER_ONBOARDING_STEPS_WITH_QBO = [
22
30
  ...CUSTOMER_REQUIRED_ONBOARDING_STEPS_WITH_QBO,
23
31
  'connect_data_source',
@@ -1,8 +1,9 @@
1
1
  import { from, of } from 'rxjs';
2
2
  import { catchError, filter, mergeMap, switchMap } from 'rxjs/operators';
3
3
  import { createZeniAPIStatus, isSuccessResponse, } from '../../../../../responsePayload';
4
- import { fetchInternationalVerificationForm, initializeIntlVerificationForm, updateInternationalVerificationForm, updateVerificationFormFailure, } from '../internationalWireVerificationReducer';
5
- export const fetchIntlVerificationFormEpic = (actions$, _state$, zeniAPI) => actions$.pipe(filter(fetchInternationalVerificationForm.match), switchMap((action) => {
4
+ import { toVerificationFormLocalDataFromOnboardingDetails } from '../internationalWireOnboardingDetailsToLocalData';
5
+ import { fetchInternationalVerificationForm, updateInternationalVerificationForm, updateVerificationFormFailure, updateVerificationFormLocalData, } from '../internationalWireVerificationReducer';
6
+ export const fetchIntlVerificationFormEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(fetchInternationalVerificationForm.match), switchMap((action) => {
6
7
  const query = {
7
8
  region: 'US',
8
9
  legal_type: 'BUSINESS',
@@ -11,11 +12,14 @@ export const fetchIntlVerificationFormEpic = (actions$, _state$, zeniAPI) => act
11
12
  .getJSON(`${zeniAPI.apiEndPoints.payMicroServiceBaseUrl}/1.0/international-wire/onboarding-fields?query=${encodeURIComponent(JSON.stringify(query))}`)
12
13
  .pipe(mergeMap((response) => {
13
14
  if (isSuccessResponse(response) && response.data != null) {
15
+ const onboardingDataFromCompanyInfo = state$.value.companyState.companiesById[action.payload.companyId]
16
+ ?.companyBillPayInfo?.internationalWireOnboardingDetails;
17
+ const localData = toVerificationFormLocalDataFromOnboardingDetails(onboardingDataFromCompanyInfo, response.data.labels);
14
18
  return from([
15
19
  updateInternationalVerificationForm({
16
20
  internationalWireFormPayload: response.data.labels,
17
21
  }),
18
- initializeIntlVerificationForm(action.payload.companyId, response.data.labels),
22
+ updateVerificationFormLocalData(localData),
19
23
  ]);
20
24
  }
21
25
  else {
@@ -1,39 +1,38 @@
1
- import { from } from 'rxjs';
1
+ import { empty, from } from 'rxjs';
2
2
  import { filter, mergeMap } from 'rxjs/operators';
3
+ import { getCurrentTenant } from '../../../../../entity/tenant/tenantSelector';
4
+ import { fetchBillPaySetupViewSuccess } from '../../billPaySetupView/billPaySetupViewReducer';
5
+ import { toVerificationFormLocalDataFromOnboardingDetails } from '../internationalWireOnboardingDetailsToLocalData';
3
6
  import { initializeIntlVerificationForm, updateVerificationFormLocalData, } from '../internationalWireVerificationReducer';
4
- export const initializeIntlVerificationFormEpic = (actions$, state$) => actions$.pipe(filter(initializeIntlVerificationForm.match), mergeMap((action) => {
5
- const { companyId, internationalWireFormPayload } = action.payload;
6
- const actions = [];
7
+ const hasSavedPersonSubfieldData = (localData) => Object.keys(localData).some((key) => /^stake_holder_\d+_/.test(key) ||
8
+ (key.startsWith('controlling_person_') && key !== 'controlling_person'));
9
+ export const initializeIntlVerificationFormEpic = (actions$, state$) => actions$.pipe(filter((action) => initializeIntlVerificationForm.match(action) ||
10
+ fetchBillPaySetupViewSuccess.match(action)), mergeMap((action) => {
7
11
  const state = state$.value;
8
- const onboardingDataFromCompanyInfo = state.companyState.companiesById[companyId].companyBillPayInfo
9
- .internationalWireOnboardingDetails;
10
- const localData = {};
11
- Object.keys(internationalWireFormPayload).forEach((formFieldKey) => {
12
- const values = onboardingDataFromCompanyInfo != null
13
- ? onboardingDataFromCompanyInfo[formFieldKey]?.values
14
- : undefined;
15
- if (values != null) {
16
- localData[formFieldKey] =
17
- internationalWireFormPayload[formFieldKey].type === 'enum'
18
- ? internationalWireFormPayload[formFieldKey]
19
- .is_multiple_values_allowed === false
20
- ? typeof values[0] === 'object' && 'code' in values[0]
21
- ? values[0].code
22
- : ''
23
- : values.map((value) => typeof value === 'object' && 'code' in value
24
- ? value.code
25
- : '')
26
- : values[0];
12
+ const formFieldLabels = state.internationalWireVerificationState.verificationFormFieldLabels;
13
+ if (Object.keys(formFieldLabels).length === 0) {
14
+ return empty();
15
+ }
16
+ const companyId = initializeIntlVerificationForm.match(action) ?
17
+ action.payload.companyId
18
+ : getCurrentTenant(state)?.companyId;
19
+ if (companyId == null) {
20
+ return empty();
21
+ }
22
+ const onboardingDataFromCompanyInfo = state.companyState.companiesById[companyId]?.companyBillPayInfo
23
+ ?.internationalWireOnboardingDetails;
24
+ const localDataFromCompany = toVerificationFormLocalDataFromOnboardingDetails(onboardingDataFromCompanyInfo, formFieldLabels);
25
+ const existingLocalData = state.internationalWireVerificationState.verificationFormLocalData;
26
+ if (fetchBillPaySetupViewSuccess.match(action)) {
27
+ if (!hasSavedPersonSubfieldData(localDataFromCompany) ||
28
+ hasSavedPersonSubfieldData(existingLocalData)) {
29
+ return empty();
27
30
  }
28
- else {
29
- localData[formFieldKey] =
30
- internationalWireFormPayload[formFieldKey].type === 'enum' &&
31
- internationalWireFormPayload[formFieldKey]
32
- .is_multiple_values_allowed === true
33
- ? []
34
- : '';
35
- }
36
- });
37
- actions.push(updateVerificationFormLocalData(localData));
38
- return from(actions);
31
+ }
32
+ return from([
33
+ updateVerificationFormLocalData({
34
+ ...existingLocalData,
35
+ ...localDataFromCompany,
36
+ }),
37
+ ]);
39
38
  }));
@@ -3,6 +3,7 @@ import { catchError, filter, mergeMap, switchMap } from 'rxjs/operators';
3
3
  import { updateInternationalWireOnboardingStatus } from '../../../../../entity/company/companyReducer';
4
4
  import { openSnackbar } from '../../../../../entity/snackbar/snackbarReducer';
5
5
  import { createZeniAPIStatus, isSuccessResponse, } from '../../../../../responsePayload';
6
+ import { toIntlWireVerificationSubmitPayload } from '../internationalWireVerificationSubmitPayload';
6
7
  import { submitInternationalVerificationForm, updateVerificationFormSubmissionStatus, } from '../internationalWireVerificationReducer';
7
8
  export const submitIntlVerificationEpic = (actions$, state$, zeniAPI) => actions$.pipe(filter(submitInternationalVerificationForm.match), switchMap((action) => {
8
9
  const { internationalWireVerificationState } = state$.value;
@@ -10,7 +11,7 @@ export const submitIntlVerificationEpic = (actions$, state$, zeniAPI) => actions
10
11
  const localData = internationalWireVerificationState.verificationFormLocalData;
11
12
  if (localData != null) {
12
13
  return zeniAPI
13
- .postAndGetJSON(`${zeniAPI.apiEndPoints.payMicroServiceBaseUrl}/1.0/international-wire/onboarding`, toIntlWireVerificationPayload(localData))
14
+ .postAndGetJSON(`${zeniAPI.apiEndPoints.payMicroServiceBaseUrl}/1.0/international-wire/onboarding`, toIntlWireVerificationSubmitPayload(localData))
14
15
  .pipe(mergeMap((response) => {
15
16
  const actions = [];
16
17
  if (isSuccessResponse(response) && response.data != null) {
@@ -54,9 +55,3 @@ export const submitIntlVerificationEpic = (actions$, state$, zeniAPI) => actions
54
55
  return from([]);
55
56
  }
56
57
  }));
57
- const toIntlWireVerificationPayload = (localData) => {
58
- return {
59
- is_applicant_declaration: true,
60
- form_details: localData,
61
- };
62
- };
@@ -0,0 +1,146 @@
1
+ import { InternationalWireVerificationBooleanWithSubfieldsFieldNames, InternationalWireVerificationFormFieldNames, } from './internationalWireVerificationFieldConstants';
2
+ import { appendIntlWireFileOptionsToLocalData, appendIntlWirePersonToLocalData, isIntlWireFileOptionLike, isIntlWirePersonLike, toIntlWireFileOptionArray, } from './internationalWireVerificationLocalDataHelpers';
3
+ const MULTI_OPTION_FILE_FIELD_NAMES = new Set([
4
+ InternationalWireVerificationFormFieldNames.businessOwnership,
5
+ InternationalWireVerificationFormFieldNames.companyProofOfAddress,
6
+ InternationalWireVerificationFormFieldNames.companyOfficerProofOfAddress,
7
+ ]);
8
+ const toValuesArray = (values) => {
9
+ if (values == null) {
10
+ return [];
11
+ }
12
+ if (Array.isArray(values)) {
13
+ return values;
14
+ }
15
+ return [values];
16
+ };
17
+ const getCodeFromValue = (value) => {
18
+ if (typeof value === 'string') {
19
+ return value;
20
+ }
21
+ if (typeof value === 'object' &&
22
+ value != null &&
23
+ 'code' in value &&
24
+ typeof value.code === 'string') {
25
+ return value.code;
26
+ }
27
+ return '';
28
+ };
29
+ const setEmptyFieldDefault = (localData, fieldKey, fieldPayload) => {
30
+ if (fieldPayload.type === 'enum') {
31
+ localData[fieldKey] =
32
+ fieldPayload.is_multiple_values_allowed === true ? [] : '';
33
+ return;
34
+ }
35
+ if (fieldPayload.type === 'boolean_with_subfields') {
36
+ if (fieldKey ===
37
+ InternationalWireVerificationBooleanWithSubfieldsFieldNames.stakeHolder) {
38
+ localData[fieldKey] = 'false';
39
+ return;
40
+ }
41
+ if (fieldKey ===
42
+ InternationalWireVerificationBooleanWithSubfieldsFieldNames.controllingPerson) {
43
+ localData[fieldKey] = fieldPayload.default === true ? 'true' : 'false';
44
+ }
45
+ }
46
+ };
47
+ const parseEnumValues = (localData, fieldKey, fieldPayload, values) => {
48
+ if (fieldPayload.is_multiple_values_allowed === true) {
49
+ localData[fieldKey] = values
50
+ .map(getCodeFromValue)
51
+ .filter((code) => code.length > 0);
52
+ return;
53
+ }
54
+ localData[fieldKey] = getCodeFromValue(values[0]);
55
+ };
56
+ const parseFileValues = (localData, fieldKey, fieldPayload, values) => {
57
+ if (values.length > 0 &&
58
+ (isIntlWireFileOptionLike(values[0]) ||
59
+ MULTI_OPTION_FILE_FIELD_NAMES.has(fieldKey))) {
60
+ const fileOptions = toIntlWireFileOptionArray(values);
61
+ if (fileOptions.length > 0) {
62
+ appendIntlWireFileOptionsToLocalData(localData, fieldKey, fileOptions);
63
+ }
64
+ return;
65
+ }
66
+ const fileIds = values.filter((value) => typeof value === 'string' && value.length > 0);
67
+ if (fieldPayload.is_multiple_values_allowed === true) {
68
+ localData[fieldKey] = fileIds;
69
+ return;
70
+ }
71
+ localData[fieldKey] = fileIds[0] ?? '';
72
+ };
73
+ const parseBooleanWithSubfieldsValues = (localData, fieldKey, fieldPayload, rawValues) => {
74
+ if (fieldKey ===
75
+ InternationalWireVerificationBooleanWithSubfieldsFieldNames.controllingPerson) {
76
+ if (isIntlWirePersonLike(rawValues)) {
77
+ localData[fieldKey] = 'false';
78
+ appendIntlWirePersonToLocalData(localData, fieldKey, rawValues);
79
+ return;
80
+ }
81
+ const values = toValuesArray(rawValues);
82
+ if (values.length > 0 && isIntlWirePersonLike(values[0])) {
83
+ localData[fieldKey] = 'false';
84
+ appendIntlWirePersonToLocalData(localData, fieldKey, values[0]);
85
+ return;
86
+ }
87
+ const selection = getCodeFromValue(values[0]);
88
+ localData[fieldKey] =
89
+ selection.length > 0
90
+ ? selection
91
+ : fieldPayload.default === true
92
+ ? 'true'
93
+ : 'false';
94
+ return;
95
+ }
96
+ if (fieldKey ===
97
+ InternationalWireVerificationBooleanWithSubfieldsFieldNames.stakeHolder) {
98
+ const values = toValuesArray(rawValues);
99
+ if (values.length > 0 && isIntlWirePersonLike(values[0])) {
100
+ localData[fieldKey] = 'true';
101
+ values.forEach((person, ownerIndex) => {
102
+ if (isIntlWirePersonLike(person)) {
103
+ appendIntlWirePersonToLocalData(localData, `${fieldKey}_${ownerIndex}`, person);
104
+ }
105
+ });
106
+ return;
107
+ }
108
+ const selection = getCodeFromValue(values[0]);
109
+ localData[fieldKey] = selection.length > 0 ? selection : 'false';
110
+ }
111
+ };
112
+ export const toVerificationFormLocalDataFromOnboardingDetails = (onboardingDetails, internationalWireFormPayload) => {
113
+ const localData = {};
114
+ Object.keys(internationalWireFormPayload).forEach((fieldKey) => {
115
+ const fieldPayload = internationalWireFormPayload[fieldKey];
116
+ const rawValues = onboardingDetails?.[fieldKey]?.values;
117
+ if (rawValues == null) {
118
+ setEmptyFieldDefault(localData, fieldKey, fieldPayload);
119
+ return;
120
+ }
121
+ if (fieldPayload.type === 'boolean_with_subfields') {
122
+ parseBooleanWithSubfieldsValues(localData, fieldKey, fieldPayload, rawValues);
123
+ return;
124
+ }
125
+ const values = toValuesArray(rawValues);
126
+ if (values.length === 0) {
127
+ setEmptyFieldDefault(localData, fieldKey, fieldPayload);
128
+ return;
129
+ }
130
+ switch (fieldPayload.type) {
131
+ case 'enum':
132
+ parseEnumValues(localData, fieldKey, fieldPayload, values);
133
+ break;
134
+ case 'file':
135
+ parseFileValues(localData, fieldKey, fieldPayload, values);
136
+ break;
137
+ case 'date':
138
+ localData[fieldKey] = getCodeFromValue(values[0]);
139
+ break;
140
+ default:
141
+ localData[fieldKey] = getCodeFromValue(values[0]);
142
+ break;
143
+ }
144
+ });
145
+ return localData;
146
+ };
@@ -0,0 +1,40 @@
1
+ export const InternationalWireVerificationFormFieldNames = {
2
+ certificateOfGoodStanding: 'certificate_of_good_standing',
3
+ businessOwnership: 'business_ownership',
4
+ companyProofOfAddress: 'company_proof_of_address',
5
+ companyOfficerProofOfAddress: 'company_officer_proof_of_address',
6
+ companyRegistrationDate: 'company_registration_date',
7
+ annualTurnover: 'annual_turnover',
8
+ expectedTransactionVolume: 'expected_transaction_volume',
9
+ employeeCount: 'employee_count',
10
+ intendedUseOfAccount: 'intended_use_of_account',
11
+ transactionCountries: 'transaction_countries',
12
+ stakeHolder: 'stake_holder',
13
+ controllingPerson: 'controlling_person',
14
+ };
15
+ export const InternationalWireVerificationStakeHolderFieldName = InternationalWireVerificationFormFieldNames.stakeHolder;
16
+ export const InternationalWireVerificationControllingPersonFieldName = InternationalWireVerificationFormFieldNames.controllingPerson;
17
+ export const InternationalWireVerificationBooleanWithSubfieldsFieldNames = {
18
+ stakeHolder: InternationalWireVerificationStakeHolderFieldName,
19
+ controllingPerson: InternationalWireVerificationControllingPersonFieldName,
20
+ };
21
+ export const InternationalWireVerificationBooleanWithSubfieldsFieldNameList = Object.values(InternationalWireVerificationBooleanWithSubfieldsFieldNames);
22
+ export const InternationalWireVerificationSubfieldNames = {
23
+ companyRole: 'company_role',
24
+ dateOfBirth: 'date_of_birth',
25
+ name: 'name',
26
+ email: 'email',
27
+ nationality: 'nationality',
28
+ ownershipPercentage: 'ownership_percentage',
29
+ proofOfIdentity: 'proof_of_identity',
30
+ proofOfAddress: 'proof_of_address',
31
+ ssn: 'ssn',
32
+ };
33
+ export const InternationalWireVerificationReadonlyHideableFieldNames = [
34
+ InternationalWireVerificationFormFieldNames.stakeHolder,
35
+ InternationalWireVerificationFormFieldNames.controllingPerson,
36
+ InternationalWireVerificationFormFieldNames.businessOwnership,
37
+ InternationalWireVerificationFormFieldNames.companyProofOfAddress,
38
+ InternationalWireVerificationFormFieldNames.companyOfficerProofOfAddress,
39
+ ];
40
+ export const InternationalWireVerificationReadonlyVisibilityGateFieldName = InternationalWireVerificationFormFieldNames.businessOwnership;
@@ -0,0 +1,86 @@
1
+ import { InternationalWireVerificationFormFieldNames, InternationalWireVerificationSubfieldNames, } from './internationalWireVerificationFieldConstants';
2
+ import { IntlWireVerificationLocalDataSuffix } from './internationalWireVerificationSubmitPayload';
3
+ export const isIntlWireFileOptionLike = (value) => typeof value === 'object' &&
4
+ value != null &&
5
+ 'file_id' in value &&
6
+ typeof value.file_id === 'string';
7
+ export const isIntlWirePersonLike = (value) => {
8
+ if (typeof value !== 'object' || value == null || Array.isArray(value)) {
9
+ return false;
10
+ }
11
+ const person = value;
12
+ return (person.name != null ||
13
+ person.email != null ||
14
+ person.nationality != null ||
15
+ person.company_role != null ||
16
+ person.ssn != null ||
17
+ person.date_of_birth != null ||
18
+ person.ownership_percentage != null ||
19
+ person.proof_of_identity != null ||
20
+ person.proof_of_address != null);
21
+ };
22
+ export const toIntlWireFileOptionArray = (items) => items.filter(isIntlWireFileOptionLike);
23
+ export const appendIntlWireFileOptionsToLocalData = (localData, baseKey, fileOptions) => {
24
+ const [front, back] = fileOptions;
25
+ if (front?.file_id != null && front.file_id !== '') {
26
+ localData[baseKey] = front.file_id;
27
+ if (front.option != null && front.option !== '') {
28
+ localData[`${baseKey}${IntlWireVerificationLocalDataSuffix.documentOption}`] = front.option;
29
+ }
30
+ }
31
+ if (back?.file_id != null && back.file_id !== '') {
32
+ localData[`${baseKey}${IntlWireVerificationLocalDataSuffix.documentBack}`] =
33
+ back.file_id;
34
+ }
35
+ };
36
+ export const appendIntlWirePersonToLocalData = (localData, keyPrefix, person) => {
37
+ const nameBaseKey = `${keyPrefix}_${InternationalWireVerificationSubfieldNames.name}`;
38
+ if (person.name?.first_name != null) {
39
+ localData[`${nameBaseKey}${IntlWireVerificationLocalDataSuffix.nameFirst}`] = person.name.first_name;
40
+ }
41
+ if (person.name?.last_name != null) {
42
+ localData[`${nameBaseKey}${IntlWireVerificationLocalDataSuffix.nameLast}`] = person.name.last_name;
43
+ }
44
+ const assignStringField = (subfieldName, fieldValue) => {
45
+ if (fieldValue != null && fieldValue !== '') {
46
+ localData[`${keyPrefix}_${subfieldName}`] = fieldValue;
47
+ }
48
+ };
49
+ assignStringField(InternationalWireVerificationSubfieldNames.nationality, person.nationality);
50
+ assignStringField(InternationalWireVerificationSubfieldNames.email, person.email);
51
+ assignStringField(InternationalWireVerificationSubfieldNames.companyRole, person.company_role);
52
+ assignStringField(InternationalWireVerificationSubfieldNames.ssn, person.ssn);
53
+ assignStringField(InternationalWireVerificationSubfieldNames.dateOfBirth, person.date_of_birth);
54
+ if (person.ownership_percentage != null) {
55
+ localData[`${keyPrefix}_${InternationalWireVerificationSubfieldNames.ownershipPercentage}`] = person.ownership_percentage;
56
+ }
57
+ if (person.proof_of_identity != null) {
58
+ appendIntlWireFileOptionsToLocalData(localData, `${keyPrefix}_${InternationalWireVerificationSubfieldNames.proofOfIdentity}`, toIntlWireFileOptionArray(person.proof_of_identity));
59
+ }
60
+ if (person.proof_of_address != null) {
61
+ appendIntlWireFileOptionsToLocalData(localData, `${keyPrefix}_${InternationalWireVerificationSubfieldNames.proofOfAddress}`, toIntlWireFileOptionArray(person.proof_of_address));
62
+ }
63
+ };
64
+ export const getStakeHolderOwnerIndicesFromLocalData = (localData) => {
65
+ const indices = new Set();
66
+ Object.keys(localData).forEach((key) => {
67
+ const match = key.match(/^stake_holder_(\d+)_/);
68
+ if (match != null) {
69
+ indices.add(Number.parseInt(match[1], 10));
70
+ }
71
+ });
72
+ return Array.from(indices).sort((a, b) => a - b);
73
+ };
74
+ export const hasBusinessOwnershipValueInLocalData = (localData) => {
75
+ const baseKey = InternationalWireVerificationFormFieldNames.businessOwnership;
76
+ const frontFileId = localData[baseKey];
77
+ if (typeof frontFileId === 'string' && frontFileId !== '') {
78
+ return true;
79
+ }
80
+ const backFileId = localData[`${baseKey}${IntlWireVerificationLocalDataSuffix.documentBack}`];
81
+ if (typeof backFileId === 'string' && backFileId !== '') {
82
+ return true;
83
+ }
84
+ const documentOption = localData[`${baseKey}${IntlWireVerificationLocalDataSuffix.documentOption}`];
85
+ return typeof documentOption === 'string' && documentOption !== '';
86
+ };
@@ -1,15 +1,62 @@
1
+ import { InternationalWireVerificationReadonlyHideableFieldNames, InternationalWireVerificationFormFieldNames, } from './internationalWireVerificationFieldConstants';
2
+ import { hasBusinessOwnershipValueInLocalData } from './internationalWireVerificationLocalDataHelpers';
3
+ export const InternationalWireVerificationFormOrder = [
4
+ InternationalWireVerificationFormFieldNames.certificateOfGoodStanding,
5
+ InternationalWireVerificationFormFieldNames.businessOwnership,
6
+ InternationalWireVerificationFormFieldNames.companyProofOfAddress,
7
+ InternationalWireVerificationFormFieldNames.companyOfficerProofOfAddress,
8
+ InternationalWireVerificationFormFieldNames.companyRegistrationDate,
9
+ InternationalWireVerificationFormFieldNames.annualTurnover,
10
+ InternationalWireVerificationFormFieldNames.expectedTransactionVolume,
11
+ InternationalWireVerificationFormFieldNames.employeeCount,
12
+ InternationalWireVerificationFormFieldNames.intendedUseOfAccount,
13
+ InternationalWireVerificationFormFieldNames.transactionCountries,
14
+ InternationalWireVerificationFormFieldNames.stakeHolder,
15
+ InternationalWireVerificationFormFieldNames.controllingPerson,
16
+ ];
17
+ const toFieldValues = (fieldValues) => fieldValues?.map(({ code, description }) => ({ code, description })) ?? [];
18
+ const toSubField = (subfield) => ({
19
+ label: subfield.label,
20
+ placeholder: subfield.field_hint_text ?? '',
21
+ type: subfield.type,
22
+ fieldValues: toFieldValues(subfield.field_values),
23
+ isMultipleOptionsSupported: subfield.is_multiple_options_supported,
24
+ options: subfield.options,
25
+ });
1
26
  export const toDynamicFormField = (key, payload) => ({
2
27
  name: key,
3
28
  label: payload.label,
4
29
  placeholder: payload.field_hint_text ?? '',
5
30
  isMultipleValuesAllowed: payload.is_multiple_values_allowed ?? false,
6
31
  type: payload.type,
7
- fieldValues: payload.field_values != null && payload.field_values.length > 0
8
- ? payload.field_values.map((fieldValue) => {
9
- return {
10
- code: fieldValue.code,
11
- description: fieldValue.description,
12
- };
13
- })
14
- : [],
32
+ fieldValues: toFieldValues(payload.field_values),
33
+ isMultipleOptionsSupported: payload.is_multiple_options_supported,
34
+ options: payload.options,
35
+ requirements: payload.requirements,
36
+ default: payload.default,
37
+ subfields: payload.subfields != null
38
+ ? Object.fromEntries(Object.entries(payload.subfields).map(([subfieldKey, subfield]) => [
39
+ subfieldKey,
40
+ toSubField(subfield),
41
+ ]))
42
+ : undefined,
15
43
  });
44
+ const readonlyHideableVerificationFormFieldNames = new Set(InternationalWireVerificationReadonlyHideableFieldNames);
45
+ export const filterVerificationFormFieldsForReadonlyView = (fields, localData, isReadonly) => {
46
+ if (!isReadonly || hasBusinessOwnershipValueInLocalData(localData)) {
47
+ return fields;
48
+ }
49
+ return fields.filter((field) => !readonlyHideableVerificationFormFieldNames.has(field.name));
50
+ };
51
+ export const sortVerificationFormFields = (fields) => {
52
+ const orderIndex = new Map(InternationalWireVerificationFormOrder.map((name, index) => [name, index]));
53
+ return fields.slice().sort((a, b) => {
54
+ const aIndex = orderIndex.get(a.name) ?? InternationalWireVerificationFormOrder.length;
55
+ const bIndex = orderIndex.get(b.name) ?? InternationalWireVerificationFormOrder.length;
56
+ if (aIndex !== bIndex) {
57
+ return aIndex - bIndex;
58
+ }
59
+ return a.name.localeCompare(b.name);
60
+ });
61
+ };
62
+ export const toVerificationFormFields = (internationalWireFormPayload) => sortVerificationFormFields(Object.keys(internationalWireFormPayload).map((key) => toDynamicFormField(key, internationalWireFormPayload[key])));
@@ -1,9 +1,10 @@
1
1
  import { createSlice } from '@reduxjs/toolkit';
2
- import { toDynamicFormField, } from './internationalWireVerificationPayload';
2
+ import { toVerificationFormFields, } from './internationalWireVerificationPayload';
3
3
  export const initialState = {
4
4
  verificationFormFetchState: {
5
5
  fetchState: 'Not-Started',
6
6
  },
7
+ verificationFormFieldLabels: {},
7
8
  verificationFormFields: [],
8
9
  verificationFormLocalData: {},
9
10
  verificationFormSubmitState: {
@@ -31,11 +32,8 @@ const internationalWireVerification = createSlice({
31
32
  },
32
33
  updateInternationalVerificationForm(draft, action) {
33
34
  const { internationalWireFormPayload } = action.payload;
34
- const verificationFormFields = [];
35
- Object.keys(internationalWireFormPayload).forEach((key) => {
36
- verificationFormFields.push(toDynamicFormField(key, internationalWireFormPayload[key]));
37
- });
38
- draft.verificationFormFields = verificationFormFields;
35
+ draft.verificationFormFieldLabels = internationalWireFormPayload;
36
+ draft.verificationFormFields = toVerificationFormFields(internationalWireFormPayload);
39
37
  draft.verificationFormFetchState.fetchState = 'Completed';
40
38
  },
41
39
  updateVerificationFormFailure(draft, action) {
@@ -45,6 +43,7 @@ const internationalWireVerification = createSlice({
45
43
  },
46
44
  updateVerificationFormLocalData(draft, action) {
47
45
  draft.verificationFormLocalData = {
46
+ ...draft.verificationFormLocalData,
48
47
  ...action.payload,
49
48
  };
50
49
  },