@adyen/kyc-components
Version:
This guide assumes that you have already an account with Adyen. A legalEntity needs to be created, and you need to have a `legalEntityId` to instatiate a Component.
71 lines (70 loc) • 4.66 kB
JavaScript
try {
let e = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof globalThis ? globalThis : "undefined" != typeof self ? self : {}, n = new e.Error().stack;
n && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[n] = "5872e590-f6d1-4824-8b48-f78776ac177c", e._sentryDebugIdIdentifier = "sentry-dbid-5872e590-f6d1-4824-8b48-f78776ac177c");
} catch (e) {}
import { r as useLegalEntity, t as ROOT_LE } from "./useLegalEntity-yxi9XhLi.js";
import { t as LegalEntityTypes } from "./legal-entity-type-VIfNYnJP.js";
import { s as getOwnEntityAssociations } from "./entityAssociationUtil-BEzUdPbm.js";
import { t as useAssociatedLegalEntity } from "./useAssociatedLegalEntity-zrU8J6iw.js";
import { n as getLegalEntityNameBasedOnType } from "./getName-Bdwp_hkV.js";
import { t as UnincorporatedPartnershipMemberTypes } from "./unincorporated-partnership-5MvG_ts4.js";
import { useMemo } from "preact/hooks";
//#region src/components/UnincorporatedPartnership/utils/unincorporatedPartnershipMembers.ts
var getMemberOwnerId = (memberId, entityAssociations) => entityAssociations.find((association) => association.associatorId === memberId)?.legalEntityId;
var convertEntityAssociationIntoUnincorporatedPartnershipMember = (association) => {
if (association.entityType === LegalEntityTypes.INDIVIDUAL || association.entityType === LegalEntityTypes.ORGANIZATION) return {
memberType: association.type,
roles: [],
legalEntityType: association.entityType,
legalEntityId: association.legalEntityId || "",
name: association.name || ""
};
throw new Error(`Not a valid member: ${JSON.stringify(association)}`);
};
/**
* In the API response, there are multiple {@link LegalEntityAssociation}s for the same associated entity;
* one for each role e.g. 'secondaryPartner', 'uboThroughControl', 'uboThroughOwnersghip'...
*
* Therefore we need to combine these into one {@link UnincorporatedPartnershipMember} with multiple roles.
*/
var mapEntityAssociationsToUnincorporatedPartnershipMembers = (entityId, entityAssociations, rootLegalEntity) => {
const mappedUnincorporatedPartnershipMembers = entityAssociations.reduce((acc, entityAssociation) => {
if (!Object.values(UnincorporatedPartnershipMemberTypes).includes(entityAssociation.type) || entityAssociation.associatorId !== entityId || !entityAssociation.legalEntityId) return acc;
const unincorporatedPartnershipMember = acc[entityAssociation.legalEntityId] ?? convertEntityAssociationIntoUnincorporatedPartnershipMember(entityAssociation);
const unincorporatedPartnershipMemberType = entityAssociation.type;
const memberOwnerId = getMemberOwnerId(entityAssociation.legalEntityId, entityAssociations);
if (memberOwnerId) unincorporatedPartnershipMember.ownerId = memberOwnerId;
acc[entityAssociation.legalEntityId] = {
...unincorporatedPartnershipMember,
roles: [...new Set([...unincorporatedPartnershipMember.roles, unincorporatedPartnershipMemberType])]
};
return acc;
}, {});
if (rootLegalEntity) mappedUnincorporatedPartnershipMembers[rootLegalEntity.id] = {
legalEntityId: rootLegalEntity.id,
legalEntityType: rootLegalEntity.type,
name: getLegalEntityNameBasedOnType(rootLegalEntity),
memberType: UnincorporatedPartnershipMemberTypes.SECONDARY_PARTNER,
roles: ["primaryPartner"]
};
return Object.values(mappedUnincorporatedPartnershipMembers)?.sort((member) => member?.legalEntityId !== rootLegalEntity?.id ? 1 : -1);
};
var deleteUnincorporatedPartnershipMember = async ({ associatedMember, unincorporatedPartnership, updateLegalEntity }) => {
const ownEntityAssociations = getOwnEntityAssociations(unincorporatedPartnership);
await updateLegalEntity({
id: unincorporatedPartnership.id,
entityAssociations: ownEntityAssociations.filter((entityAssociation) => entityAssociation.legalEntityId !== associatedMember.legalEntityId)
});
};
//#endregion
//#region src/hooks/useUnincorporatedPartnershipMembers.ts
function useUnincorporatedPartnershipMembers() {
const { data: rootLegalEntity } = useLegalEntity(ROOT_LE);
const { data: unincorporatedPartnership } = useAssociatedLegalEntity(rootLegalEntity, LegalEntityTypes.UNINCORPORATED_PARTNERSHIP);
return useMemo(() => {
if (!rootLegalEntity || !unincorporatedPartnership?.unincorporatedPartnership) return [];
return mapEntityAssociationsToUnincorporatedPartnershipMembers(unincorporatedPartnership.id, unincorporatedPartnership.entityAssociations ?? [], rootLegalEntity);
}, [rootLegalEntity, unincorporatedPartnership]);
}
//#endregion
export { deleteUnincorporatedPartnershipMember as n, useUnincorporatedPartnershipMembers as t };