@open-mercato/core 0.5.1-develop.2912.8d7b1fef24 → 0.5.1-develop.2924.d13908516e
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.
- package/dist/modules/customers/api/companies/[id]/people/route.js +12 -7
- package/dist/modules/customers/api/companies/[id]/people/route.js.map +2 -2
- package/dist/modules/customers/backend/customers/companies-v2/[id]/page.js +2 -1
- package/dist/modules/customers/backend/customers/companies-v2/[id]/page.js.map +2 -2
- package/dist/modules/customers/backend/customers/people-v2/[id]/page.js +7 -2
- package/dist/modules/customers/backend/customers/people-v2/[id]/page.js.map +2 -2
- package/dist/modules/customers/commands/companies.js +93 -19
- package/dist/modules/customers/commands/companies.js.map +2 -2
- package/dist/modules/customers/commands/people.js +9 -1
- package/dist/modules/customers/commands/people.js.map +2 -2
- package/dist/modules/customers/commands/personCompanyLinks.js +2 -2
- package/dist/modules/customers/commands/personCompanyLinks.js.map +2 -2
- package/dist/modules/customers/components/detail/CompanyCard.js +32 -3
- package/dist/modules/customers/components/detail/CompanyCard.js.map +2 -2
- package/dist/modules/customers/components/detail/CompanyDetailTabs.js +37 -19
- package/dist/modules/customers/components/detail/CompanyDetailTabs.js.map +2 -2
- package/dist/modules/customers/components/detail/CompanyPeopleSection.js +7 -4
- package/dist/modules/customers/components/detail/CompanyPeopleSection.js.map +2 -2
- package/dist/modules/customers/components/detail/PersonCompaniesSection.js +63 -2
- package/dist/modules/customers/components/detail/PersonCompaniesSection.js.map +2 -2
- package/dist/modules/customers/components/detail/PersonDetailTabs.js +37 -19
- package/dist/modules/customers/components/detail/PersonDetailTabs.js.map +2 -2
- package/dist/modules/customers/components/detail/TasksSection.js +1 -11
- package/dist/modules/customers/components/detail/TasksSection.js.map +2 -2
- package/dist/modules/customers/components/formConfig.js +50 -39
- package/dist/modules/customers/components/formConfig.js.map +2 -2
- package/dist/modules/customers/events.js +3 -3
- package/dist/modules/customers/events.js.map +2 -2
- package/dist/modules/customers/lib/displayName.js +13 -1
- package/dist/modules/customers/lib/displayName.js.map +2 -2
- package/dist/modules/customers/lib/personCompanies.js +12 -7
- package/dist/modules/customers/lib/personCompanies.js.map +2 -2
- package/dist/modules/customers/lib/personCompanyLinkTable.js +5 -0
- package/dist/modules/customers/lib/personCompanyLinkTable.js.map +2 -2
- package/dist/modules/workflows/lib/activity-executor.js +21 -17
- package/dist/modules/workflows/lib/activity-executor.js.map +2 -2
- package/package.json +3 -3
- package/src/modules/customers/api/companies/[id]/people/route.ts +12 -7
- package/src/modules/customers/backend/customers/companies-v2/[id]/page.tsx +2 -1
- package/src/modules/customers/backend/customers/people-v2/[id]/page.tsx +12 -2
- package/src/modules/customers/commands/companies.ts +107 -19
- package/src/modules/customers/commands/people.ts +16 -1
- package/src/modules/customers/commands/personCompanyLinks.ts +3 -2
- package/src/modules/customers/components/detail/CompanyCard.tsx +28 -4
- package/src/modules/customers/components/detail/CompanyDetailTabs.tsx +18 -2
- package/src/modules/customers/components/detail/CompanyPeopleSection.tsx +8 -4
- package/src/modules/customers/components/detail/PersonCompaniesSection.tsx +66 -0
- package/src/modules/customers/components/detail/PersonDetailTabs.tsx +18 -2
- package/src/modules/customers/components/detail/TasksSection.tsx +1 -8
- package/src/modules/customers/components/formConfig.tsx +59 -40
- package/src/modules/customers/events.ts +3 -3
- package/src/modules/customers/i18n/de.json +10 -0
- package/src/modules/customers/i18n/en.json +10 -0
- package/src/modules/customers/i18n/es.json +10 -0
- package/src/modules/customers/i18n/pl.json +10 -0
- package/src/modules/customers/lib/displayName.ts +19 -0
- package/src/modules/customers/lib/personCompanies.ts +12 -7
- package/src/modules/customers/lib/personCompanyLinkTable.ts +14 -0
- package/src/modules/workflows/lib/activity-executor.ts +21 -18
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/modules/customers/commands/people.ts"],
|
|
4
|
-
"sourcesContent": ["import { registerCommand } from '@open-mercato/shared/lib/commands'\nimport type { CommandHandler } from '@open-mercato/shared/lib/commands'\nimport {\n parseWithCustomFields,\n setCustomFieldsIfAny,\n emitCrudSideEffects,\n emitCrudUndoSideEffects,\n requireId,\n snapshotsEqual,\n} from '@open-mercato/shared/lib/commands/helpers'\nimport type { DataEngine } from '@open-mercato/shared/lib/data/engine'\nimport type { CommandRuntimeContext } from '@open-mercato/shared/lib/commands'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport {\n CustomerAddress,\n CustomerComment,\n CustomerActivity,\n CustomerInteraction,\n CustomerDeal,\n CustomerDealPersonLink,\n CustomerPersonCompanyLink,\n CustomerTodoLink,\n CustomerEntity,\n CustomerPersonProfile,\n CustomerTagAssignment,\n} from '../data/entities'\nimport { resolvePersonCustomFieldRouting, CUSTOMER_ENTITY_ID, PERSON_ENTITY_ID } from '../lib/customFieldRouting'\nimport { CustomFieldValue } from '@open-mercato/core/modules/entities/data/entities'\nimport {\n personCreateSchema,\n personUpdateSchema,\n type PersonCreateInput,\n type PersonUpdateInput,\n} from '../data/validators'\nimport {\n ensureOrganizationScope,\n ensureTenantScope,\n extractUndoPayload,\n assertFound,\n syncEntityTags,\n loadEntityTagIds,\n ensureDictionaryEntry,\n emitQueryIndexDeleteEvents,\n emitQueryIndexUpsertEvents,\n type QueryIndexEventEntry,\n} from './shared'\nimport { withAtomicFlush } from '@open-mercato/shared/lib/commands/flush'\nimport { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'\nimport { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'\nimport {\n loadCustomFieldSnapshot,\n buildCustomFieldResetMap,\n} from '@open-mercato/shared/lib/commands/customFieldSnapshots'\nimport type { CrudIndexerConfig, CrudEventsConfig } from '@open-mercato/shared/lib/crud/types'\nimport { E } from '#generated/entities.ids.generated'\nimport { findWithDecryption, findOneWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport {\n loadPersonCompanyLinks,\n summarizePersonCompanies,\n syncLegacyPrimaryCompanyLink,\n} from '../lib/personCompanies'\n\nconst INTERACTION_ENTITY_ID = 'customers:customer_interaction'\n\ntype PersonAddressSnapshot = {\n id: string\n name: string | null\n purpose: string | null\n addressLine1: string\n addressLine2: string | null\n city: string | null\n region: string | null\n postalCode: string | null\n country: string | null\n latitude: number | null\n longitude: number | null\n isPrimary: boolean\n}\n\ntype PersonCommentSnapshot = {\n id: string\n body: string\n authorUserId: string | null\n dealId: string | null\n createdAt: Date\n updatedAt: Date\n deletedAt: Date | null\n appearanceIcon: string | null\n appearanceColor: string | null\n}\n\ntype PersonActivitySnapshot = {\n id: string\n activityType: string\n subject: string | null\n body: string | null\n occurredAt: Date | null\n authorUserId: string | null\n appearanceIcon: string | null\n appearanceColor: string | null\n dealId: string | null\n createdAt: Date\n updatedAt: Date\n}\n\ntype PersonTodoSnapshot = {\n id: string\n todoId: string\n todoSource: string\n createdAt: Date\n createdByUserId: string | null\n}\n\ntype PersonInteractionSnapshot = {\n id: string\n interactionType: string\n title: string | null\n body: string | null\n status: string\n scheduledAt: Date | null\n occurredAt: Date | null\n priority: number | null\n authorUserId: string | null\n ownerUserId: string | null\n appearanceIcon: string | null\n appearanceColor: string | null\n source: string | null\n dealId: string | null\n createdAt: Date\n updatedAt: Date\n deletedAt: Date | null\n custom?: Record<string, unknown>\n}\n\ntype PersonSnapshot = {\n entity: {\n id: string\n organizationId: string\n tenantId: string\n displayName: string\n description: string | null\n ownerUserId: string | null\n primaryEmail: string | null\n primaryPhone: string | null\n status: string | null\n lifecycleStage: string | null\n source: string | null\n nextInteractionAt: Date | null\n nextInteractionName: string | null\n nextInteractionRefId: string | null\n nextInteractionIcon: string | null\n nextInteractionColor: string | null\n isActive: boolean\n }\n profile: {\n id: string\n firstName: string | null\n lastName: string | null\n preferredName: string | null\n jobTitle: string | null\n department: string | null\n seniority: string | null\n timezone: string | null\n linkedInUrl: string | null\n twitterUrl: string | null\n companyEntityId: string | null\n }\n companies: Array<{\n linkId: string | null\n companyId: string\n displayName: string\n isPrimary: boolean\n }>\n tagIds: string[]\n addresses: PersonAddressSnapshot[]\n comments: PersonCommentSnapshot[]\n custom?: Record<string, unknown>\n deals: Array<{\n id: string\n dealId: string\n participantRole: string | null\n createdAt: Date\n }>\n activities: PersonActivitySnapshot[]\n todos: PersonTodoSnapshot[]\n interactions: PersonInteractionSnapshot[]\n}\n\ntype PersonUndoPayload = {\n before?: PersonSnapshot | null\n after?: PersonSnapshot | null\n}\n\nconst personCrudIndexer: CrudIndexerConfig<CustomerEntity> = {\n entityType: E.customers.customer_person_profile,\n}\n\nconst personCrudEvents: CrudEventsConfig<CustomerEntity> = {\n module: 'customers',\n entity: 'person',\n persistent: true,\n buildPayload: (ctx) => ({\n id: ctx.identifiers.id,\n entityId: ctx.entity?.id ?? ctx.identifiers.id,\n organizationId: ctx.identifiers.organizationId,\n tenantId: ctx.identifiers.tenantId,\n }),\n}\n\nfunction personEntityIndexEntry(entity: CustomerEntity): QueryIndexEventEntry {\n return {\n entityType: E.customers.customer_entity,\n recordId: entity.id,\n tenantId: entity.tenantId,\n organizationId: entity.organizationId,\n }\n}\n\nfunction normalizeOptionalString(value: string | null | undefined): string | null {\n if (typeof value !== 'string') return null\n const trimmed = value.trim()\n return trimmed.length ? trimmed : null\n}\n\nfunction normalizeHexColor(value: string | null | undefined): string | null {\n if (typeof value !== 'string') return null\n const trimmed = value.trim().toLowerCase()\n return /^#([0-9a-f]{6})$/.test(trimmed) ? trimmed : null\n}\n\nfunction normalizeEmail(value: string | null | undefined): string | null {\n const normalized = normalizeOptionalString(value)\n return normalized ? normalized.toLowerCase() : null\n}\n\nfunction serializePersonSnapshot(\n entity: CustomerEntity,\n profile: CustomerPersonProfile,\n tagIds: string[],\n addresses: CustomerAddress[],\n comments: CustomerComment[],\n deals: CustomerDealPersonLink[],\n activities: CustomerActivity[],\n todoLinks: CustomerTodoLink[],\n interactions: Array<PersonInteractionSnapshot>,\n custom?: Record<string, unknown>\n): PersonSnapshot {\n const companies = summarizePersonCompanies(profile, [])\n return {\n entity: {\n id: entity.id,\n organizationId: entity.organizationId,\n tenantId: entity.tenantId,\n displayName: entity.displayName,\n description: entity.description ?? null,\n ownerUserId: entity.ownerUserId ?? null,\n primaryEmail: entity.primaryEmail ?? null,\n primaryPhone: entity.primaryPhone ?? null,\n status: entity.status ?? null,\n lifecycleStage: entity.lifecycleStage ?? null,\n source: entity.source ?? null,\n nextInteractionAt: entity.nextInteractionAt ?? null,\n nextInteractionName: entity.nextInteractionName ?? null,\n nextInteractionRefId: entity.nextInteractionRefId ?? null,\n nextInteractionIcon: entity.nextInteractionIcon ?? null,\n nextInteractionColor: entity.nextInteractionColor ?? null,\n isActive: entity.isActive,\n },\n profile: {\n id: profile.id,\n firstName: profile.firstName ?? null,\n lastName: profile.lastName ?? null,\n preferredName: profile.preferredName ?? null,\n jobTitle: profile.jobTitle ?? null,\n department: profile.department ?? null,\n seniority: profile.seniority ?? null,\n timezone: profile.timezone ?? null,\n linkedInUrl: profile.linkedInUrl ?? null,\n twitterUrl: profile.twitterUrl ?? null,\n companyEntityId: profile.company\n ? typeof profile.company === 'string'\n ? profile.company\n : profile.company.id\n : null,\n },\n companies,\n tagIds,\n addresses: addresses.map((address) => ({\n id: address.id,\n name: address.name ?? null,\n purpose: address.purpose ?? null,\n addressLine1: address.addressLine1,\n addressLine2: address.addressLine2 ?? null,\n city: address.city ?? null,\n region: address.region ?? null,\n postalCode: address.postalCode ?? null,\n country: address.country ?? null,\n latitude: address.latitude ?? null,\n longitude: address.longitude ?? null,\n isPrimary: address.isPrimary,\n })),\n comments: comments.map((comment) => ({\n id: comment.id,\n body: comment.body,\n authorUserId: comment.authorUserId ?? null,\n dealId: comment.deal\n ? typeof comment.deal === 'string'\n ? comment.deal\n : comment.deal.id\n : null,\n createdAt: comment.createdAt,\n updatedAt: comment.updatedAt,\n deletedAt: comment.deletedAt ?? null,\n appearanceIcon: comment.appearanceIcon ?? null,\n appearanceColor: comment.appearanceColor ?? null,\n })),\n deals: deals\n .filter((link) => link.deal)\n .map((link) => ({\n id: link.id,\n dealId: link.deal.id,\n participantRole: link.participantRole ?? null,\n createdAt: link.createdAt,\n })),\n activities: activities.map((activity) => ({\n id: activity.id,\n activityType: activity.activityType,\n subject: activity.subject ?? null,\n body: activity.body ?? null,\n occurredAt: activity.occurredAt ?? null,\n authorUserId: activity.authorUserId ?? null,\n appearanceIcon: activity.appearanceIcon ?? null,\n appearanceColor: activity.appearanceColor ?? null,\n dealId: activity.deal\n ? typeof activity.deal === 'string'\n ? activity.deal\n : activity.deal.id\n : null,\n createdAt: activity.createdAt,\n updatedAt: activity.updatedAt,\n })),\n todos: todoLinks.map((todo) => ({\n id: todo.id,\n todoId: todo.todoId,\n todoSource: todo.todoSource,\n createdAt: todo.createdAt,\n createdByUserId: todo.createdByUserId ?? null,\n })),\n interactions,\n custom,\n }\n}\n\nasync function loadPersonSnapshot(em: EntityManager, entityId: string): Promise<PersonSnapshot | null> {\n const entity = await em.findOne(CustomerEntity, { id: entityId, deletedAt: null })\n if (!entity || entity.kind !== 'person') return null\n const profile = await findOneWithDecryption(\n em,\n CustomerPersonProfile,\n { entity: entity },\n { populate: ['company'] },\n { tenantId: entity.tenantId, organizationId: entity.organizationId },\n )\n if (!profile) return null\n const companyLinks = await loadPersonCompanyLinks(em, entity)\n const tagIds = await loadEntityTagIds(em, entity)\n const addresses = await em.find(CustomerAddress, { entity }, { orderBy: { createdAt: 'asc' } })\n const comments = await findWithDecryption(\n em,\n CustomerComment,\n { entity },\n { orderBy: { createdAt: 'asc' }, populate: ['deal'] },\n { tenantId: entity.tenantId, organizationId: entity.organizationId },\n )\n const deals = await findWithDecryption(\n em,\n CustomerDealPersonLink,\n { person: entity },\n { orderBy: { createdAt: 'asc' }, populate: ['deal'] },\n { tenantId: entity.tenantId, organizationId: entity.organizationId },\n )\n const activities = await findWithDecryption(\n em,\n CustomerActivity,\n { entity },\n { orderBy: { createdAt: 'asc' }, populate: ['deal'] },\n { tenantId: entity.tenantId, organizationId: entity.organizationId },\n )\n const todoLinks = await em.find(CustomerTodoLink, { entity }, { orderBy: { createdAt: 'asc' } })\n const interactions = await em.find(CustomerInteraction, { entity }, { orderBy: { createdAt: 'asc' } })\n const entityCustom = await loadCustomFieldSnapshot(em, {\n entityId: CUSTOMER_ENTITY_ID,\n recordId: entity.id,\n tenantId: entity.tenantId,\n organizationId: entity.organizationId,\n })\n const profileCustom = await loadCustomFieldSnapshot(em, {\n entityId: PERSON_ENTITY_ID,\n recordId: profile.id,\n tenantId: entity.tenantId,\n organizationId: entity.organizationId,\n })\n const routing = await resolvePersonCustomFieldRouting(em, entity.tenantId, entity.organizationId)\n const custom: Record<string, unknown> = { ...entityCustom }\n for (const [key, value] of Object.entries(profileCustom)) {\n const target = routing.get(key)\n if (target === CUSTOMER_ENTITY_ID && Object.prototype.hasOwnProperty.call(custom, key)) continue\n custom[key] = value\n }\n const interactionSnapshots = await Promise.all(\n interactions.map(async (interaction) => ({\n id: interaction.id,\n interactionType: interaction.interactionType,\n title: interaction.title ?? null,\n body: interaction.body ?? null,\n status: interaction.status,\n scheduledAt: interaction.scheduledAt ?? null,\n occurredAt: interaction.occurredAt ?? null,\n priority: interaction.priority ?? null,\n authorUserId: interaction.authorUserId ?? null,\n ownerUserId: interaction.ownerUserId ?? null,\n appearanceIcon: interaction.appearanceIcon ?? null,\n appearanceColor: interaction.appearanceColor ?? null,\n source: interaction.source ?? null,\n dealId: interaction.dealId ?? null,\n createdAt: interaction.createdAt,\n updatedAt: interaction.updatedAt,\n deletedAt: interaction.deletedAt ?? null,\n custom: await loadCustomFieldSnapshot(em, {\n entityId: INTERACTION_ENTITY_ID,\n recordId: interaction.id,\n tenantId: entity.tenantId,\n organizationId: entity.organizationId,\n }),\n })),\n )\n const snapshot = serializePersonSnapshot(entity, profile, tagIds, addresses, comments, deals, activities, todoLinks, interactionSnapshots, custom)\n snapshot.companies = summarizePersonCompanies(profile, companyLinks)\n return snapshot\n}\n\nasync function resolveCompanyReference(\n em: EntityManager,\n companyId: string | null | undefined,\n organizationId: string,\n tenantId: string\n): Promise<CustomerEntity | null> {\n if (!companyId) return null\n const company = await em.findOne(CustomerEntity, { id: companyId, kind: 'company', deletedAt: null })\n if (!company) {\n throw new CrudHttpError(400, { error: 'Company not found' })\n }\n if (company.organizationId !== organizationId || company.tenantId !== tenantId) {\n throw new CrudHttpError(403, { error: 'Cannot link person to company outside current scope' })\n }\n return company\n}\n\nasync function setCustomFieldsForPerson(\n ctx: CommandRuntimeContext,\n entityId: string,\n profileId: string,\n organizationId: string,\n tenantId: string,\n values: Record<string, unknown>\n): Promise<void> {\n if (!values || !Object.keys(values).length) return\n const em = (ctx.container.resolve('em') as EntityManager)\n const routing = await resolvePersonCustomFieldRouting(em, tenantId, organizationId)\n const entityScoped: Record<string, unknown> = {}\n const profileScoped: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(values)) {\n const target = routing.get(key) ?? PERSON_ENTITY_ID\n if (target === CUSTOMER_ENTITY_ID) entityScoped[key] = value\n else profileScoped[key] = value\n }\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n if (Object.keys(entityScoped).length) {\n await setCustomFieldsIfAny({\n dataEngine: de,\n entityId: CUSTOMER_ENTITY_ID,\n recordId: entityId,\n organizationId,\n tenantId,\n values: entityScoped,\n notify: true,\n })\n }\n if (Object.keys(profileScoped).length) {\n await setCustomFieldsIfAny({\n dataEngine: de,\n entityId: PERSON_ENTITY_ID,\n recordId: profileId,\n organizationId,\n tenantId,\n values: profileScoped,\n notify: true,\n })\n }\n}\n\nconst createPersonCommand: CommandHandler<PersonCreateInput, { entityId: string; personId: string }> = {\n id: 'customers.people.create',\n async execute(rawInput, ctx) {\n const { parsed, custom } = parseWithCustomFields(personCreateSchema, rawInput)\n ensureTenantScope(ctx, parsed.tenantId)\n ensureOrganizationScope(ctx, parsed.organizationId)\n\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const firstName = parsed.firstName?.trim() ?? ''\n const lastName = parsed.lastName?.trim() ?? ''\n const description = normalizeOptionalString(parsed.description)\n const primaryEmail = normalizeEmail(parsed.primaryEmail)\n const primaryPhone = normalizeOptionalString(parsed.primaryPhone)\n const status = normalizeOptionalString(parsed.status)\n const lifecycleStage = normalizeOptionalString(parsed.lifecycleStage)\n const source = normalizeOptionalString(parsed.source)\n const preferredName = normalizeOptionalString(parsed.preferredName)\n const jobTitle = normalizeOptionalString(parsed.jobTitle)\n const department = normalizeOptionalString(parsed.department)\n const seniority = normalizeOptionalString(parsed.seniority)\n const timezone = normalizeOptionalString(parsed.timezone)\n const linkedInUrl = normalizeOptionalString(parsed.linkedInUrl)\n const twitterUrl = normalizeOptionalString(parsed.twitterUrl)\n const displayName = parsed.displayName?.trim() ?? ''\n const nextInteractionName = parsed.nextInteraction?.name ? parsed.nextInteraction.name.trim() : null\n const nextInteractionRefId = normalizeOptionalString(parsed.nextInteraction?.refId)\n const nextInteractionIcon = normalizeOptionalString(parsed.nextInteraction?.icon)\n const nextInteractionColor = normalizeHexColor(parsed.nextInteraction?.color)\n if (!firstName || !lastName) {\n throw new CrudHttpError(400, { error: 'First and last name are required' })\n }\n if (!displayName) {\n throw new CrudHttpError(400, { error: 'Display name is required' })\n }\n\n let entity!: CustomerEntity\n let profile!: CustomerPersonProfile\n await withAtomicFlush(em, [\n () => {\n entity = em.create(CustomerEntity, {\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n kind: 'person',\n displayName,\n description,\n ownerUserId: parsed.ownerUserId ?? null,\n primaryEmail,\n primaryPhone,\n status,\n lifecycleStage,\n source,\n nextInteractionAt: parsed.nextInteraction?.at ?? null,\n nextInteractionName,\n nextInteractionRefId,\n nextInteractionIcon,\n nextInteractionColor,\n isActive: parsed.isActive ?? true,\n })\n\n profile = em.create(CustomerPersonProfile, {\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n entity,\n firstName,\n lastName,\n preferredName,\n jobTitle,\n department,\n seniority,\n timezone,\n linkedInUrl,\n twitterUrl,\n company: null,\n })\n\n em.persist(entity)\n em.persist(profile)\n },\n async () => {\n if (status) {\n await ensureDictionaryEntry(em, {\n tenantId: parsed.tenantId,\n organizationId: parsed.organizationId,\n kind: 'status',\n value: status,\n })\n }\n if (jobTitle) {\n await ensureDictionaryEntry(em, {\n tenantId: parsed.tenantId,\n organizationId: parsed.organizationId,\n kind: 'job_title',\n value: jobTitle,\n })\n }\n if (source) {\n await ensureDictionaryEntry(em, {\n tenantId: parsed.tenantId,\n organizationId: parsed.organizationId,\n kind: 'source',\n value: source,\n })\n }\n },\n () => syncLegacyPrimaryCompanyLink(em, entity, profile, parsed.companyEntityId ?? null),\n () => syncEntityTags(em, entity, parsed.tags),\n ], { transaction: true })\n\n const tenantId = entity.tenantId\n const organizationId = entity.organizationId\n await setCustomFieldsForPerson(ctx, entity.id, profile.id, organizationId, tenantId, custom)\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudSideEffects({\n dataEngine: de,\n action: 'created',\n entity,\n identifiers: {\n id: profile.id ?? entity.id,\n tenantId,\n organizationId,\n },\n indexer: personCrudIndexer,\n events: personCrudEvents,\n })\n await emitQueryIndexUpsertEvents(ctx, [personEntityIndexEntry(entity)])\n\n return { entityId: entity.id, personId: profile.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return await loadPersonSnapshot(em, result.entityId)\n },\n buildLog: async ({ result, snapshots }) => {\n const { translate } = await resolveTranslations()\n const snapshot = snapshots.after as PersonSnapshot | undefined\n return {\n actionLabel: translate('customers.audit.people.create', 'Create person'),\n resourceKind: 'customers.person',\n resourceId: result.entityId,\n tenantId: snapshot?.entity.tenantId ?? null,\n organizationId: snapshot?.entity.organizationId ?? null,\n snapshotAfter: snapshot ?? null,\n payload: {\n undo: {\n after: snapshot,\n },\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<PersonUndoPayload>(logEntry) ?? null\n const entityId = logEntry?.resourceId ?? payload?.after?.entity.id ?? null\n if (!entityId) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const entity = await em.findOne(CustomerEntity, { id: entityId })\n if (!entity) return\n const profile = await findOneWithDecryption(\n em,\n CustomerPersonProfile,\n { entity },\n undefined,\n { tenantId: entity.tenantId, organizationId: entity.organizationId },\n )\n const identifiers = {\n id: payload?.after?.profile.id ?? profile?.id ?? entity.id,\n organizationId: entity.organizationId,\n tenantId: entity.tenantId,\n }\n await withAtomicFlush(em, [\n () => em.nativeDelete(CustomerTagAssignment, { entity, organizationId: entity.organizationId, tenantId: entity.tenantId }),\n () => {\n if (profile) em.remove(profile)\n },\n () => em.remove(entity),\n ], { transaction: true })\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudUndoSideEffects({\n dataEngine: de,\n action: 'deleted',\n entity,\n identifiers,\n indexer: personCrudIndexer,\n events: personCrudEvents,\n })\n await emitQueryIndexDeleteEvents(ctx, [personEntityIndexEntry(entity)])\n },\n}\n\nconst updatePersonCommand: CommandHandler<PersonUpdateInput, { entityId: string }> = {\n id: 'customers.people.update',\n async prepare(rawInput, ctx) {\n const { parsed } = parseWithCustomFields(personUpdateSchema, rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const snapshot = await loadPersonSnapshot(em, parsed.id)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(rawInput, ctx) {\n const { parsed, custom } = parseWithCustomFields(personUpdateSchema, rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const entity = await em.findOne(CustomerEntity, { id: parsed.id, deletedAt: null })\n const record = assertFound(entity, 'Person not found')\n ensureTenantScope(ctx, record.tenantId)\n ensureOrganizationScope(ctx, record.organizationId)\n const profile = await em.findOne(CustomerPersonProfile, { entity: record })\n if (!profile) throw new CrudHttpError(404, { error: 'Person profile not found' })\n\n if (parsed.displayName !== undefined) {\n const nextDisplayName = parsed.displayName.trim()\n if (!nextDisplayName) {\n throw new CrudHttpError(400, { error: 'Display name is required' })\n }\n }\n\n await withAtomicFlush(em, [\n () => {\n if (parsed.description !== undefined) record.description = normalizeOptionalString(parsed.description)\n if (parsed.ownerUserId !== undefined) record.ownerUserId = parsed.ownerUserId ?? null\n if (parsed.primaryEmail !== undefined) record.primaryEmail = normalizeEmail(parsed.primaryEmail)\n if (parsed.primaryPhone !== undefined) record.primaryPhone = normalizeOptionalString(parsed.primaryPhone)\n if (parsed.status !== undefined) {\n record.status = normalizeOptionalString(parsed.status)\n }\n if (parsed.lifecycleStage !== undefined) record.lifecycleStage = normalizeOptionalString(parsed.lifecycleStage)\n if (parsed.source !== undefined) {\n record.source = normalizeOptionalString(parsed.source)\n }\n if (parsed.isActive !== undefined) record.isActive = parsed.isActive\n if (parsed.nextInteraction) {\n record.nextInteractionAt = parsed.nextInteraction.at\n record.nextInteractionName = parsed.nextInteraction.name.trim()\n record.nextInteractionRefId = normalizeOptionalString(parsed.nextInteraction.refId) ?? null\n record.nextInteractionIcon = normalizeOptionalString(parsed.nextInteraction.icon)\n record.nextInteractionColor = normalizeHexColor(parsed.nextInteraction.color)\n } else if (parsed.nextInteraction === null) {\n record.nextInteractionAt = null\n record.nextInteractionName = null\n record.nextInteractionRefId = null\n record.nextInteractionIcon = null\n record.nextInteractionColor = null\n }\n\n if (parsed.firstName !== undefined) profile.firstName = normalizeOptionalString(parsed.firstName)\n if (parsed.lastName !== undefined) profile.lastName = normalizeOptionalString(parsed.lastName)\n if (parsed.preferredName !== undefined) profile.preferredName = normalizeOptionalString(parsed.preferredName)\n if (parsed.jobTitle !== undefined) {\n profile.jobTitle = normalizeOptionalString(parsed.jobTitle)\n }\n if (parsed.department !== undefined) profile.department = normalizeOptionalString(parsed.department)\n if (parsed.seniority !== undefined) profile.seniority = normalizeOptionalString(parsed.seniority)\n if (parsed.timezone !== undefined) profile.timezone = normalizeOptionalString(parsed.timezone)\n if (parsed.linkedInUrl !== undefined) profile.linkedInUrl = normalizeOptionalString(parsed.linkedInUrl)\n if (parsed.twitterUrl !== undefined) profile.twitterUrl = normalizeOptionalString(parsed.twitterUrl)\n\n const profileFieldsUpdated = [\n parsed.firstName, parsed.lastName, parsed.preferredName, parsed.jobTitle,\n parsed.department, parsed.seniority, parsed.timezone, parsed.linkedInUrl,\n parsed.twitterUrl, parsed.companyEntityId,\n ].some((v) => v !== undefined)\n if (profileFieldsUpdated) {\n record.updatedAt = new Date()\n }\n\n if (parsed.displayName !== undefined) {\n record.displayName = parsed.displayName.trim()\n }\n },\n async () => {\n if (parsed.status !== undefined) {\n const normalizedStatus = normalizeOptionalString(parsed.status)\n if (normalizedStatus) {\n await ensureDictionaryEntry(em, {\n tenantId: record.tenantId,\n organizationId: record.organizationId,\n kind: 'status',\n value: normalizedStatus,\n })\n }\n }\n if (parsed.source !== undefined) {\n const normalizedSource = normalizeOptionalString(parsed.source)\n if (normalizedSource) {\n await ensureDictionaryEntry(em, {\n tenantId: record.tenantId,\n organizationId: record.organizationId,\n kind: 'source',\n value: normalizedSource,\n })\n }\n }\n if (parsed.jobTitle !== undefined) {\n const normalizedJobTitle = normalizeOptionalString(parsed.jobTitle)\n if (normalizedJobTitle) {\n await ensureDictionaryEntry(em, {\n tenantId: record.tenantId,\n organizationId: record.organizationId,\n kind: 'job_title',\n value: normalizedJobTitle,\n })\n }\n }\n },\n async () => {\n if (parsed.companyEntityId !== undefined) {\n await syncLegacyPrimaryCompanyLink(em, record, profile, parsed.companyEntityId)\n }\n },\n () => syncEntityTags(em, record, parsed.tags),\n ], { transaction: true })\n\n await setCustomFieldsForPerson(ctx, record.id, profile.id, record.organizationId, record.tenantId, custom)\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: record,\n identifiers: {\n id: profile.id ?? record.id,\n tenantId: record.tenantId,\n organizationId: record.organizationId,\n },\n indexer: personCrudIndexer,\n events: personCrudEvents,\n })\n await emitQueryIndexUpsertEvents(ctx, [personEntityIndexEntry(record)])\n\n return { entityId: record.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return await loadPersonSnapshot(em, result.entityId)\n },\n buildLog: async ({ snapshots }) => {\n const { translate } = await resolveTranslations()\n const before = snapshots.before as PersonSnapshot | undefined\n if (!before) return null\n const afterSnapshot = snapshots.after as PersonSnapshot | undefined\n if (afterSnapshot && snapshotsEqual(before, afterSnapshot)) {\n return { skipLog: true }\n }\n return {\n actionLabel: translate('customers.audit.people.update', 'Update person'),\n resourceKind: 'customers.person',\n resourceId: before.entity.id,\n tenantId: before.entity.tenantId,\n organizationId: before.entity.organizationId,\n snapshotBefore: before,\n snapshotAfter: afterSnapshot ?? null,\n payload: {\n undo: {\n before,\n after: afterSnapshot ?? null,\n } satisfies PersonUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<PersonUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const entity = await em.findOne(CustomerEntity, { id: before.entity.id })\n if (!entity) {\n let newEntity!: CustomerEntity\n let newProfile!: CustomerPersonProfile\n await withAtomicFlush(em, [\n () => {\n newEntity = em.create(CustomerEntity, {\n id: before.entity.id,\n organizationId: before.entity.organizationId,\n tenantId: before.entity.tenantId,\n kind: 'person',\n displayName: before.entity.displayName,\n description: before.entity.description,\n ownerUserId: before.entity.ownerUserId,\n primaryEmail: before.entity.primaryEmail,\n primaryPhone: before.entity.primaryPhone,\n status: before.entity.status,\n lifecycleStage: before.entity.lifecycleStage,\n source: before.entity.source,\n nextInteractionAt: before.entity.nextInteractionAt,\n nextInteractionName: before.entity.nextInteractionName,\n nextInteractionRefId: before.entity.nextInteractionRefId,\n nextInteractionIcon: before.entity.nextInteractionIcon,\n nextInteractionColor: before.entity.nextInteractionColor,\n isActive: before.entity.isActive,\n })\n em.persist(newEntity)\n newProfile = em.create(CustomerPersonProfile, {\n id: before.profile.id,\n organizationId: before.entity.organizationId,\n tenantId: before.entity.tenantId,\n entity: newEntity,\n firstName: before.profile.firstName,\n lastName: before.profile.lastName,\n preferredName: before.profile.preferredName,\n jobTitle: before.profile.jobTitle,\n department: before.profile.department,\n seniority: before.profile.seniority,\n timezone: before.profile.timezone,\n linkedInUrl: before.profile.linkedInUrl,\n twitterUrl: before.profile.twitterUrl,\n })\n em.persist(newProfile)\n },\n () => syncLegacyPrimaryCompanyLink(em, newEntity, newProfile, before.profile.companyEntityId),\n () => syncEntityTags(em, newEntity, before.tagIds),\n ], { transaction: true })\n } else {\n await withAtomicFlush(em, [\n () => {\n entity.displayName = before.entity.displayName\n entity.description = before.entity.description\n entity.ownerUserId = before.entity.ownerUserId\n entity.primaryEmail = before.entity.primaryEmail\n entity.primaryPhone = before.entity.primaryPhone\n entity.status = before.entity.status\n entity.lifecycleStage = before.entity.lifecycleStage\n entity.source = before.entity.source\n entity.nextInteractionAt = before.entity.nextInteractionAt\n entity.nextInteractionName = before.entity.nextInteractionName\n entity.nextInteractionRefId = before.entity.nextInteractionRefId\n entity.nextInteractionIcon = before.entity.nextInteractionIcon\n entity.nextInteractionColor = before.entity.nextInteractionColor\n entity.isActive = before.entity.isActive\n },\n async () => {\n const profile = await findOneWithDecryption(\n em,\n CustomerPersonProfile,\n { entity },\n undefined,\n { tenantId: before.entity.tenantId, organizationId: before.entity.organizationId },\n )\n if (profile) {\n profile.firstName = before.profile.firstName\n profile.lastName = before.profile.lastName\n profile.preferredName = before.profile.preferredName\n profile.jobTitle = before.profile.jobTitle\n profile.department = before.profile.department\n profile.seniority = before.profile.seniority\n profile.timezone = before.profile.timezone\n profile.linkedInUrl = before.profile.linkedInUrl\n profile.twitterUrl = before.profile.twitterUrl\n await syncLegacyPrimaryCompanyLink(em, entity, profile, before.profile.companyEntityId)\n }\n },\n () => syncEntityTags(em, entity, before.tagIds),\n ], { transaction: true })\n }\n\n const indexedEntity = await em.findOne(CustomerEntity, { id: before.entity.id })\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudUndoSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: indexedEntity,\n identifiers: {\n id: before.profile.id ?? before.entity.id,\n organizationId: before.entity.organizationId,\n tenantId: before.entity.tenantId,\n },\n indexer: personCrudIndexer,\n events: personCrudEvents,\n })\n if (indexedEntity) {\n await emitQueryIndexUpsertEvents(ctx, [personEntityIndexEntry(indexedEntity)])\n }\n\n const resetValues = buildCustomFieldResetMap(before.custom, payload?.after?.custom)\n if (Object.keys(resetValues).length) {\n await setCustomFieldsForPerson(ctx, before.entity.id, before.profile.id, before.entity.organizationId, before.entity.tenantId, resetValues)\n }\n },\n}\n\nconst deletePersonCommand: CommandHandler<{ body?: Record<string, unknown>; query?: Record<string, unknown> }, { entityId: string }> =\n {\n id: 'customers.people.delete',\n async prepare(input, ctx) {\n const id = requireId(input, 'Person id required')\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const snapshot = await loadPersonSnapshot(em, id)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(input, ctx) {\n const id = requireId(input, 'Person id required')\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const snapshot = await loadPersonSnapshot(em, id)\n const entity = await em.findOne(CustomerEntity, { id, deletedAt: null })\n const record = assertFound(entity, 'Person not found')\n ensureTenantScope(ctx, record.tenantId)\n ensureOrganizationScope(ctx, record.organizationId)\n const profile = await em.findOne(CustomerPersonProfile, { entity: record })\n if (profile) em.remove(profile)\n await em.nativeDelete(CustomerAddress, { entity: record, organizationId: record.organizationId, tenantId: record.tenantId })\n await em.nativeDelete(CustomerComment, { entity: record, organizationId: record.organizationId, tenantId: record.tenantId })\n await em.nativeDelete(CustomerActivity, { entity: record, organizationId: record.organizationId, tenantId: record.tenantId })\n await em.nativeDelete(CustomerInteraction, { entity: record, organizationId: record.organizationId, tenantId: record.tenantId })\n await em.nativeDelete(CustomerTodoLink, { entity: record, organizationId: record.organizationId, tenantId: record.tenantId })\n await em.nativeDelete(CustomerTagAssignment, { entity: record, organizationId: record.organizationId, tenantId: record.tenantId })\n await em.nativeDelete(CustomerDealPersonLink, { person: record })\n await em.nativeDelete(CustomerPersonCompanyLink, { person: record })\n if (profile) {\n await em.nativeDelete(CustomFieldValue, { entityId: PERSON_ENTITY_ID, recordId: profile.id })\n }\n await em.nativeDelete(CustomFieldValue, { entityId: CUSTOMER_ENTITY_ID, recordId: record.id })\n em.remove(record)\n await em.flush()\n\n const indexDeletes: QueryIndexEventEntry[] = []\n const dealUpserts: QueryIndexEventEntry[] = []\n if (snapshot) {\n for (const activity of snapshot.activities ?? []) {\n indexDeletes.push({\n entityType: E.customers.customer_activity,\n recordId: activity.id,\n tenantId: record.tenantId,\n organizationId: record.organizationId,\n })\n }\n for (const comment of snapshot.comments ?? []) {\n indexDeletes.push({\n entityType: E.customers.customer_comment,\n recordId: comment.id,\n tenantId: record.tenantId,\n organizationId: record.organizationId,\n })\n }\n for (const address of snapshot.addresses ?? []) {\n indexDeletes.push({\n entityType: E.customers.customer_address,\n recordId: address.id,\n tenantId: record.tenantId,\n organizationId: record.organizationId,\n })\n }\n for (const todo of snapshot.todos ?? []) {\n indexDeletes.push({\n entityType: E.customers.customer_todo_link,\n recordId: todo.id,\n tenantId: record.tenantId,\n organizationId: record.organizationId,\n })\n }\n for (const interaction of snapshot.interactions ?? []) {\n indexDeletes.push({\n entityType: E.customers.customer_interaction,\n recordId: interaction.id,\n tenantId: record.tenantId,\n organizationId: record.organizationId,\n })\n }\n for (const deal of snapshot.deals ?? []) {\n if (deal.dealId) {\n dealUpserts.push({\n entityType: E.customers.customer_deal,\n recordId: deal.dealId,\n tenantId: record.tenantId,\n organizationId: record.organizationId,\n })\n }\n }\n }\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudSideEffects({\n dataEngine: de,\n action: 'deleted',\n entity: record,\n identifiers: {\n id: profile?.id ?? record.id,\n organizationId: record.organizationId,\n tenantId: record.tenantId,\n },\n indexer: personCrudIndexer,\n events: personCrudEvents,\n })\n\n await emitQueryIndexDeleteEvents(ctx, [personEntityIndexEntry(record)])\n await emitQueryIndexDeleteEvents(ctx, indexDeletes)\n await emitQueryIndexUpsertEvents(ctx, dealUpserts)\n return { entityId: record.id }\n },\n buildLog: async ({ snapshots }) => {\n const before = snapshots.before as PersonSnapshot | undefined\n if (!before) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('customers.audit.people.delete', 'Delete person'),\n resourceKind: 'customers.person',\n resourceId: before.entity.id,\n tenantId: before.entity.tenantId,\n organizationId: before.entity.organizationId,\n snapshotBefore: before,\n payload: {\n undo: {\n before,\n } satisfies PersonUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<PersonUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n\n const decryptionScope = {\n tenantId: before.entity.tenantId ?? null,\n organizationId: before.entity.organizationId ?? null,\n }\n // Bind the outer EntityManager to an explicit transaction so every\n // `em.flush()` below participates in the same unit of work. Using\n // `em.transactional(cb)` would pass a forked em into `cb` and the\n // surrounding closures would mutate the unwrapped em, escaping the\n // transaction (see SPEC-018 and H8 in the CRM details screens review).\n await em.begin()\n let txResult: {\n entity: CustomerEntity\n profile: CustomerPersonProfile\n beforeInteractions: PersonInteractionSnapshot[]\n beforeTodos: PersonTodoSnapshot[]\n }\n try {\n txResult = await (async () => {\n let entity = await findOneWithDecryption(\n em,\n CustomerEntity,\n {\n id: before.entity.id,\n tenantId: before.entity.tenantId,\n organizationId: before.entity.organizationId,\n },\n {},\n decryptionScope,\n )\n if (!entity) {\n entity = em.create(CustomerEntity, {\n id: before.entity.id,\n organizationId: before.entity.organizationId,\n tenantId: before.entity.tenantId,\n kind: 'person',\n displayName: before.entity.displayName,\n description: before.entity.description,\n ownerUserId: before.entity.ownerUserId,\n primaryEmail: before.entity.primaryEmail,\n primaryPhone: before.entity.primaryPhone,\n status: before.entity.status,\n lifecycleStage: before.entity.lifecycleStage,\n source: before.entity.source,\n nextInteractionAt: before.entity.nextInteractionAt,\n nextInteractionName: before.entity.nextInteractionName,\n nextInteractionRefId: before.entity.nextInteractionRefId,\n nextInteractionIcon: before.entity.nextInteractionIcon,\n nextInteractionColor: before.entity.nextInteractionColor,\n isActive: before.entity.isActive,\n })\n em.persist(entity)\n }\n\n entity.displayName = before.entity.displayName\n entity.description = before.entity.description\n entity.ownerUserId = before.entity.ownerUserId\n entity.primaryEmail = before.entity.primaryEmail\n entity.primaryPhone = before.entity.primaryPhone\n entity.status = before.entity.status\n entity.lifecycleStage = before.entity.lifecycleStage\n entity.source = before.entity.source\n entity.nextInteractionAt = before.entity.nextInteractionAt\n entity.nextInteractionName = before.entity.nextInteractionName\n entity.nextInteractionRefId = before.entity.nextInteractionRefId\n entity.nextInteractionIcon = before.entity.nextInteractionIcon\n entity.nextInteractionColor = before.entity.nextInteractionColor\n entity.isActive = before.entity.isActive\n entity.deletedAt = null\n\n let profile = await findOneWithDecryption(\n em,\n CustomerPersonProfile,\n {\n entity,\n tenantId: before.entity.tenantId,\n organizationId: before.entity.organizationId,\n },\n {},\n decryptionScope,\n )\n if (!profile) {\n profile = em.create(CustomerPersonProfile, {\n id: before.profile.id,\n organizationId: before.entity.organizationId,\n tenantId: before.entity.tenantId,\n entity,\n firstName: before.profile.firstName,\n lastName: before.profile.lastName,\n preferredName: before.profile.preferredName,\n jobTitle: before.profile.jobTitle,\n department: before.profile.department,\n seniority: before.profile.seniority,\n timezone: before.profile.timezone,\n linkedInUrl: before.profile.linkedInUrl,\n twitterUrl: before.profile.twitterUrl,\n })\n } else {\n profile.firstName = before.profile.firstName\n profile.lastName = before.profile.lastName\n profile.preferredName = before.profile.preferredName\n profile.jobTitle = before.profile.jobTitle\n profile.department = before.profile.department\n profile.seniority = before.profile.seniority\n profile.timezone = before.profile.timezone\n profile.linkedInUrl = before.profile.linkedInUrl\n profile.twitterUrl = before.profile.twitterUrl\n }\n\n await syncLegacyPrimaryCompanyLink(em, entity, profile, before.profile.companyEntityId)\n\n await em.flush()\n await em.nativeDelete(CustomerPersonCompanyLink, { person: entity })\n for (const companyLink of before.companies ?? []) {\n const company = await resolveCompanyReference(\n em,\n companyLink.companyId,\n before.entity.organizationId,\n before.entity.tenantId,\n )\n if (!company) continue\n const restoredLink = em.create(CustomerPersonCompanyLink, {\n id: companyLink.linkId ?? undefined,\n organizationId: before.entity.organizationId,\n tenantId: before.entity.tenantId,\n person: entity,\n company,\n isPrimary: companyLink.isPrimary,\n })\n em.persist(restoredLink)\n if (companyLink.isPrimary) {\n profile.company = company\n }\n }\n await withAtomicFlush(em, [\n () => syncEntityTags(em, entity, before.tagIds),\n ])\n\n const beforeActivities = (before as { activities?: PersonActivitySnapshot[] }).activities ?? []\n const beforeTodos = (before as { todos?: PersonTodoSnapshot[] }).todos ?? []\n const beforeInteractions = (before as { interactions?: PersonInteractionSnapshot[] }).interactions ?? []\n\n const relatedDealIds = new Set<string>()\n for (const link of before.deals) relatedDealIds.add(link.dealId)\n for (const activity of beforeActivities) {\n if (activity.dealId) relatedDealIds.add(activity.dealId)\n }\n for (const comment of before.comments) {\n if (comment.dealId) relatedDealIds.add(comment.dealId)\n }\n let dealMap = new Map<string, CustomerDeal>()\n if (relatedDealIds.size) {\n const deals = await em.find(CustomerDeal, {\n id: { $in: Array.from(relatedDealIds) },\n organizationId: entity.organizationId,\n tenantId: entity.tenantId,\n })\n dealMap = new Map(deals.map((deal) => [deal.id, deal]))\n }\n\n await em.nativeDelete(CustomerDealPersonLink, { person: entity })\n for (const link of before.deals) {\n const deal = dealMap.get(link.dealId)\n if (!deal) continue\n const restoredLink = em.create(CustomerDealPersonLink, {\n id: link.id,\n deal,\n person: entity,\n participantRole: link.participantRole,\n createdAt: link.createdAt,\n })\n em.persist(restoredLink)\n }\n await em.flush()\n\n await em.nativeDelete(CustomerActivity, { entity, organizationId: entity.organizationId, tenantId: entity.tenantId })\n for (const activity of beforeActivities) {\n const restoredActivity = em.create(CustomerActivity, {\n id: activity.id,\n organizationId: entity.organizationId,\n tenantId: entity.tenantId,\n entity,\n activityType: activity.activityType,\n subject: activity.subject,\n body: activity.body,\n occurredAt: activity.occurredAt,\n authorUserId: activity.authorUserId,\n appearanceIcon: activity.appearanceIcon,\n appearanceColor: activity.appearanceColor,\n deal: activity.dealId ? dealMap.get(activity.dealId) ?? null : null,\n createdAt: activity.createdAt,\n updatedAt: activity.updatedAt,\n })\n em.persist(restoredActivity)\n }\n await em.flush()\n\n await em.nativeDelete(CustomerComment, { entity, organizationId: entity.organizationId, tenantId: entity.tenantId })\n for (const comment of before.comments) {\n const restoredComment = em.create(CustomerComment, {\n id: comment.id,\n organizationId: entity.organizationId,\n tenantId: entity.tenantId,\n entity,\n body: comment.body,\n authorUserId: comment.authorUserId,\n appearanceIcon: comment.appearanceIcon,\n appearanceColor: comment.appearanceColor,\n deal: comment.dealId ? dealMap.get(comment.dealId) ?? null : null,\n createdAt: comment.createdAt,\n updatedAt: comment.updatedAt,\n deletedAt: comment.deletedAt,\n })\n em.persist(restoredComment)\n }\n await em.flush()\n\n await em.nativeDelete(CustomerAddress, { entity, organizationId: entity.organizationId, tenantId: entity.tenantId })\n for (const address of before.addresses) {\n const restoredAddress = em.create(CustomerAddress, {\n id: address.id,\n organizationId: entity.organizationId,\n tenantId: entity.tenantId,\n entity,\n name: address.name,\n purpose: address.purpose,\n addressLine1: address.addressLine1,\n addressLine2: address.addressLine2,\n city: address.city,\n region: address.region,\n postalCode: address.postalCode,\n country: address.country,\n latitude: address.latitude,\n longitude: address.longitude,\n isPrimary: address.isPrimary,\n })\n em.persist(restoredAddress)\n }\n await em.flush()\n\n await em.nativeDelete(CustomerTodoLink, { entity, organizationId: entity.organizationId, tenantId: entity.tenantId })\n for (const todo of beforeTodos) {\n const restoredTodo = em.create(CustomerTodoLink, {\n id: todo.id,\n organizationId: entity.organizationId,\n tenantId: entity.tenantId,\n entity,\n todoId: todo.todoId,\n todoSource: todo.todoSource,\n createdAt: todo.createdAt,\n createdByUserId: todo.createdByUserId,\n })\n em.persist(restoredTodo)\n }\n await em.flush()\n\n await em.nativeDelete(CustomerInteraction, { entity, organizationId: entity.organizationId, tenantId: entity.tenantId })\n for (const interaction of beforeInteractions) {\n const restoredInteraction = em.create(CustomerInteraction, {\n id: interaction.id,\n organizationId: entity.organizationId,\n tenantId: entity.tenantId,\n entity,\n interactionType: interaction.interactionType,\n title: interaction.title,\n body: interaction.body,\n status: interaction.status,\n scheduledAt: interaction.scheduledAt,\n occurredAt: interaction.occurredAt,\n priority: interaction.priority,\n authorUserId: interaction.authorUserId,\n ownerUserId: interaction.ownerUserId,\n dealId: interaction.dealId,\n source: interaction.source,\n appearanceIcon: interaction.appearanceIcon,\n appearanceColor: interaction.appearanceColor,\n createdAt: interaction.createdAt,\n updatedAt: interaction.updatedAt,\n deletedAt: interaction.deletedAt,\n })\n em.persist(restoredInteraction)\n }\n await em.flush()\n\n return { entity, profile, beforeInteractions, beforeTodos }\n })()\n await em.commit()\n } catch (err) {\n try {\n await em.rollback()\n } catch {\n // rollback failure should not mask the original error\n }\n throw err\n }\n\n for (const interaction of txResult.beforeInteractions) {\n if (!interaction.custom || !Object.keys(interaction.custom).length) continue\n await setCustomFieldsIfAny({\n dataEngine: de,\n entityId: INTERACTION_ENTITY_ID,\n recordId: interaction.id,\n organizationId: txResult.entity.organizationId,\n tenantId: txResult.entity.tenantId,\n values: interaction.custom,\n notify: false,\n })\n }\n\n const entity = txResult.entity\n const profile = txResult.profile\n\n await emitCrudUndoSideEffects({\n dataEngine: de,\n action: 'created',\n entity,\n identifiers: {\n id: profile.id ?? entity.id,\n organizationId: entity.organizationId,\n tenantId: entity.tenantId,\n },\n indexer: personCrudIndexer,\n events: personCrudEvents,\n })\n\n const upsertEntries: QueryIndexEventEntry[] = []\n for (const activity of before.activities ?? []) {\n upsertEntries.push({\n entityType: E.customers.customer_activity,\n recordId: activity.id,\n tenantId: entity.tenantId,\n organizationId: entity.organizationId,\n })\n }\n for (const comment of before.comments ?? []) {\n upsertEntries.push({\n entityType: E.customers.customer_comment,\n recordId: comment.id,\n tenantId: entity.tenantId,\n organizationId: entity.organizationId,\n })\n }\n for (const address of before.addresses ?? []) {\n upsertEntries.push({\n entityType: E.customers.customer_address,\n recordId: address.id,\n tenantId: entity.tenantId,\n organizationId: entity.organizationId,\n })\n }\n for (const todo of txResult.beforeTodos ?? []) {\n upsertEntries.push({\n entityType: E.customers.customer_todo_link,\n recordId: todo.id,\n tenantId: entity.tenantId,\n organizationId: entity.organizationId,\n })\n }\n for (const interaction of txResult.beforeInteractions ?? []) {\n upsertEntries.push({\n entityType: E.customers.customer_interaction,\n recordId: interaction.id,\n tenantId: entity.tenantId,\n organizationId: entity.organizationId,\n })\n }\n const dealUpserts: QueryIndexEventEntry[] = []\n for (const deal of before.deals ?? []) {\n if (deal.dealId) {\n dealUpserts.push({\n entityType: E.customers.customer_deal,\n recordId: deal.dealId,\n tenantId: entity.tenantId,\n organizationId: entity.organizationId,\n })\n }\n }\n const resetValues = buildCustomFieldResetMap(before.custom, undefined)\n if (Object.keys(resetValues).length) {\n await setCustomFieldsForPerson(ctx, entity.id, profile.id, entity.organizationId, entity.tenantId, resetValues)\n }\n await emitQueryIndexUpsertEvents(ctx, [personEntityIndexEntry(entity)])\n await emitQueryIndexUpsertEvents(ctx, upsertEntries)\n await emitQueryIndexUpsertEvents(ctx, dealUpserts)\n },\n }\n\nregisterCommand(createPersonCommand)\nregisterCommand(updatePersonCommand)\nregisterCommand(deletePersonCommand)\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,uBAAuB;AAEhC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAIP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,iCAAiC,oBAAoB,wBAAwB;AACtF,SAAS,wBAAw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O,QAAQ,MAAS;AACrE,QAAI,OAAO,KAAK,WAAW,EAAE,QAAQ;AACnC,YAAM,yBAAyB,KAAK,OAAO,IAAI,QAAQ,IAAI,OAAO,gBAAgB,OAAO,UAAU,WAAW;AAAA,IAChH;AACA,UAAM,2BAA2B,KAAK,CAAC,uBAAuB,MAAM,CAAC,CAAC;AACtE,UAAM,2BAA2B,KAAK,aAAa;AACnD,UAAM,2BAA2B,KAAK,WAAW;AAAA,EACnD;AACF;AAEF,gBAAgB,mBAAmB;AACnC,gBAAgB,mBAAmB;AACnC,gBAAgB,mBAAmB;",
|
|
4
|
+
"sourcesContent": ["import { registerCommand } from '@open-mercato/shared/lib/commands'\nimport type { CommandHandler } from '@open-mercato/shared/lib/commands'\nimport {\n parseWithCustomFields,\n setCustomFieldsIfAny,\n emitCrudSideEffects,\n emitCrudUndoSideEffects,\n requireId,\n snapshotsEqual,\n} from '@open-mercato/shared/lib/commands/helpers'\nimport type { DataEngine } from '@open-mercato/shared/lib/data/engine'\nimport type { CommandRuntimeContext } from '@open-mercato/shared/lib/commands'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport {\n CustomerAddress,\n CustomerComment,\n CustomerActivity,\n CustomerInteraction,\n CustomerDeal,\n CustomerDealPersonLink,\n CustomerPersonCompanyLink,\n CustomerTodoLink,\n CustomerEntity,\n CustomerPersonProfile,\n CustomerTagAssignment,\n} from '../data/entities'\nimport { resolvePersonCustomFieldRouting, CUSTOMER_ENTITY_ID, PERSON_ENTITY_ID } from '../lib/customFieldRouting'\nimport { CustomFieldValue } from '@open-mercato/core/modules/entities/data/entities'\nimport {\n personCreateSchema,\n personUpdateSchema,\n type PersonCreateInput,\n type PersonUpdateInput,\n} from '../data/validators'\nimport {\n ensureOrganizationScope,\n ensureTenantScope,\n extractUndoPayload,\n assertFound,\n syncEntityTags,\n loadEntityTagIds,\n ensureDictionaryEntry,\n emitQueryIndexDeleteEvents,\n emitQueryIndexUpsertEvents,\n type QueryIndexEventEntry,\n} from './shared'\nimport { withAtomicFlush } from '@open-mercato/shared/lib/commands/flush'\nimport { CrudHttpError } from '@open-mercato/shared/lib/crud/errors'\nimport { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'\nimport {\n loadCustomFieldSnapshot,\n buildCustomFieldResetMap,\n} from '@open-mercato/shared/lib/commands/customFieldSnapshots'\nimport type { CrudIndexerConfig, CrudEventsConfig } from '@open-mercato/shared/lib/crud/types'\nimport { E } from '#generated/entities.ids.generated'\nimport { findWithDecryption, findOneWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport { deriveDisplayName, isDerivedDisplayName } from '../lib/displayName'\nimport {\n loadPersonCompanyLinks,\n summarizePersonCompanies,\n syncLegacyPrimaryCompanyLink,\n} from '../lib/personCompanies'\n\nconst INTERACTION_ENTITY_ID = 'customers:customer_interaction'\n\ntype PersonAddressSnapshot = {\n id: string\n name: string | null\n purpose: string | null\n addressLine1: string\n addressLine2: string | null\n city: string | null\n region: string | null\n postalCode: string | null\n country: string | null\n latitude: number | null\n longitude: number | null\n isPrimary: boolean\n}\n\ntype PersonCommentSnapshot = {\n id: string\n body: string\n authorUserId: string | null\n dealId: string | null\n createdAt: Date\n updatedAt: Date\n deletedAt: Date | null\n appearanceIcon: string | null\n appearanceColor: string | null\n}\n\ntype PersonActivitySnapshot = {\n id: string\n activityType: string\n subject: string | null\n body: string | null\n occurredAt: Date | null\n authorUserId: string | null\n appearanceIcon: string | null\n appearanceColor: string | null\n dealId: string | null\n createdAt: Date\n updatedAt: Date\n}\n\ntype PersonTodoSnapshot = {\n id: string\n todoId: string\n todoSource: string\n createdAt: Date\n createdByUserId: string | null\n}\n\ntype PersonInteractionSnapshot = {\n id: string\n interactionType: string\n title: string | null\n body: string | null\n status: string\n scheduledAt: Date | null\n occurredAt: Date | null\n priority: number | null\n authorUserId: string | null\n ownerUserId: string | null\n appearanceIcon: string | null\n appearanceColor: string | null\n source: string | null\n dealId: string | null\n createdAt: Date\n updatedAt: Date\n deletedAt: Date | null\n custom?: Record<string, unknown>\n}\n\ntype PersonSnapshot = {\n entity: {\n id: string\n organizationId: string\n tenantId: string\n displayName: string\n description: string | null\n ownerUserId: string | null\n primaryEmail: string | null\n primaryPhone: string | null\n status: string | null\n lifecycleStage: string | null\n source: string | null\n nextInteractionAt: Date | null\n nextInteractionName: string | null\n nextInteractionRefId: string | null\n nextInteractionIcon: string | null\n nextInteractionColor: string | null\n isActive: boolean\n }\n profile: {\n id: string\n firstName: string | null\n lastName: string | null\n preferredName: string | null\n jobTitle: string | null\n department: string | null\n seniority: string | null\n timezone: string | null\n linkedInUrl: string | null\n twitterUrl: string | null\n companyEntityId: string | null\n }\n companies: Array<{\n linkId: string | null\n companyId: string\n displayName: string\n isPrimary: boolean\n }>\n tagIds: string[]\n addresses: PersonAddressSnapshot[]\n comments: PersonCommentSnapshot[]\n custom?: Record<string, unknown>\n deals: Array<{\n id: string\n dealId: string\n participantRole: string | null\n createdAt: Date\n }>\n activities: PersonActivitySnapshot[]\n todos: PersonTodoSnapshot[]\n interactions: PersonInteractionSnapshot[]\n}\n\ntype PersonUndoPayload = {\n before?: PersonSnapshot | null\n after?: PersonSnapshot | null\n}\n\nconst personCrudIndexer: CrudIndexerConfig<CustomerEntity> = {\n entityType: E.customers.customer_person_profile,\n}\n\nconst personCrudEvents: CrudEventsConfig<CustomerEntity> = {\n module: 'customers',\n entity: 'person',\n persistent: true,\n buildPayload: (ctx) => ({\n id: ctx.identifiers.id,\n entityId: ctx.entity?.id ?? ctx.identifiers.id,\n organizationId: ctx.identifiers.organizationId,\n tenantId: ctx.identifiers.tenantId,\n }),\n}\n\nfunction personEntityIndexEntry(entity: CustomerEntity): QueryIndexEventEntry {\n return {\n entityType: E.customers.customer_entity,\n recordId: entity.id,\n tenantId: entity.tenantId,\n organizationId: entity.organizationId,\n }\n}\n\nfunction normalizeOptionalString(value: string | null | undefined): string | null {\n if (typeof value !== 'string') return null\n const trimmed = value.trim()\n return trimmed.length ? trimmed : null\n}\n\nfunction normalizeHexColor(value: string | null | undefined): string | null {\n if (typeof value !== 'string') return null\n const trimmed = value.trim().toLowerCase()\n return /^#([0-9a-f]{6})$/.test(trimmed) ? trimmed : null\n}\n\nfunction normalizeEmail(value: string | null | undefined): string | null {\n const normalized = normalizeOptionalString(value)\n return normalized ? normalized.toLowerCase() : null\n}\n\nfunction serializePersonSnapshot(\n entity: CustomerEntity,\n profile: CustomerPersonProfile,\n tagIds: string[],\n addresses: CustomerAddress[],\n comments: CustomerComment[],\n deals: CustomerDealPersonLink[],\n activities: CustomerActivity[],\n todoLinks: CustomerTodoLink[],\n interactions: Array<PersonInteractionSnapshot>,\n custom?: Record<string, unknown>\n): PersonSnapshot {\n const companies = summarizePersonCompanies(profile, [])\n return {\n entity: {\n id: entity.id,\n organizationId: entity.organizationId,\n tenantId: entity.tenantId,\n displayName: entity.displayName,\n description: entity.description ?? null,\n ownerUserId: entity.ownerUserId ?? null,\n primaryEmail: entity.primaryEmail ?? null,\n primaryPhone: entity.primaryPhone ?? null,\n status: entity.status ?? null,\n lifecycleStage: entity.lifecycleStage ?? null,\n source: entity.source ?? null,\n nextInteractionAt: entity.nextInteractionAt ?? null,\n nextInteractionName: entity.nextInteractionName ?? null,\n nextInteractionRefId: entity.nextInteractionRefId ?? null,\n nextInteractionIcon: entity.nextInteractionIcon ?? null,\n nextInteractionColor: entity.nextInteractionColor ?? null,\n isActive: entity.isActive,\n },\n profile: {\n id: profile.id,\n firstName: profile.firstName ?? null,\n lastName: profile.lastName ?? null,\n preferredName: profile.preferredName ?? null,\n jobTitle: profile.jobTitle ?? null,\n department: profile.department ?? null,\n seniority: profile.seniority ?? null,\n timezone: profile.timezone ?? null,\n linkedInUrl: profile.linkedInUrl ?? null,\n twitterUrl: profile.twitterUrl ?? null,\n companyEntityId: profile.company\n ? typeof profile.company === 'string'\n ? profile.company\n : profile.company.id\n : null,\n },\n companies,\n tagIds,\n addresses: addresses.map((address) => ({\n id: address.id,\n name: address.name ?? null,\n purpose: address.purpose ?? null,\n addressLine1: address.addressLine1,\n addressLine2: address.addressLine2 ?? null,\n city: address.city ?? null,\n region: address.region ?? null,\n postalCode: address.postalCode ?? null,\n country: address.country ?? null,\n latitude: address.latitude ?? null,\n longitude: address.longitude ?? null,\n isPrimary: address.isPrimary,\n })),\n comments: comments.map((comment) => ({\n id: comment.id,\n body: comment.body,\n authorUserId: comment.authorUserId ?? null,\n dealId: comment.deal\n ? typeof comment.deal === 'string'\n ? comment.deal\n : comment.deal.id\n : null,\n createdAt: comment.createdAt,\n updatedAt: comment.updatedAt,\n deletedAt: comment.deletedAt ?? null,\n appearanceIcon: comment.appearanceIcon ?? null,\n appearanceColor: comment.appearanceColor ?? null,\n })),\n deals: deals\n .filter((link) => link.deal)\n .map((link) => ({\n id: link.id,\n dealId: link.deal.id,\n participantRole: link.participantRole ?? null,\n createdAt: link.createdAt,\n })),\n activities: activities.map((activity) => ({\n id: activity.id,\n activityType: activity.activityType,\n subject: activity.subject ?? null,\n body: activity.body ?? null,\n occurredAt: activity.occurredAt ?? null,\n authorUserId: activity.authorUserId ?? null,\n appearanceIcon: activity.appearanceIcon ?? null,\n appearanceColor: activity.appearanceColor ?? null,\n dealId: activity.deal\n ? typeof activity.deal === 'string'\n ? activity.deal\n : activity.deal.id\n : null,\n createdAt: activity.createdAt,\n updatedAt: activity.updatedAt,\n })),\n todos: todoLinks.map((todo) => ({\n id: todo.id,\n todoId: todo.todoId,\n todoSource: todo.todoSource,\n createdAt: todo.createdAt,\n createdByUserId: todo.createdByUserId ?? null,\n })),\n interactions,\n custom,\n }\n}\n\nasync function loadPersonSnapshot(em: EntityManager, entityId: string): Promise<PersonSnapshot | null> {\n const entity = await em.findOne(CustomerEntity, { id: entityId, deletedAt: null })\n if (!entity || entity.kind !== 'person') return null\n const profile = await findOneWithDecryption(\n em,\n CustomerPersonProfile,\n { entity: entity },\n { populate: ['company'] },\n { tenantId: entity.tenantId, organizationId: entity.organizationId },\n )\n if (!profile) return null\n const companyLinks = await loadPersonCompanyLinks(em, entity)\n const tagIds = await loadEntityTagIds(em, entity)\n const addresses = await em.find(CustomerAddress, { entity }, { orderBy: { createdAt: 'asc' } })\n const comments = await findWithDecryption(\n em,\n CustomerComment,\n { entity },\n { orderBy: { createdAt: 'asc' }, populate: ['deal'] },\n { tenantId: entity.tenantId, organizationId: entity.organizationId },\n )\n const deals = await findWithDecryption(\n em,\n CustomerDealPersonLink,\n { person: entity },\n { orderBy: { createdAt: 'asc' }, populate: ['deal'] },\n { tenantId: entity.tenantId, organizationId: entity.organizationId },\n )\n const activities = await findWithDecryption(\n em,\n CustomerActivity,\n { entity },\n { orderBy: { createdAt: 'asc' }, populate: ['deal'] },\n { tenantId: entity.tenantId, organizationId: entity.organizationId },\n )\n const todoLinks = await em.find(CustomerTodoLink, { entity }, { orderBy: { createdAt: 'asc' } })\n const interactions = await em.find(CustomerInteraction, { entity }, { orderBy: { createdAt: 'asc' } })\n const entityCustom = await loadCustomFieldSnapshot(em, {\n entityId: CUSTOMER_ENTITY_ID,\n recordId: entity.id,\n tenantId: entity.tenantId,\n organizationId: entity.organizationId,\n })\n const profileCustom = await loadCustomFieldSnapshot(em, {\n entityId: PERSON_ENTITY_ID,\n recordId: profile.id,\n tenantId: entity.tenantId,\n organizationId: entity.organizationId,\n })\n const routing = await resolvePersonCustomFieldRouting(em, entity.tenantId, entity.organizationId)\n const custom: Record<string, unknown> = { ...entityCustom }\n for (const [key, value] of Object.entries(profileCustom)) {\n const target = routing.get(key)\n if (target === CUSTOMER_ENTITY_ID && Object.prototype.hasOwnProperty.call(custom, key)) continue\n custom[key] = value\n }\n const interactionSnapshots = await Promise.all(\n interactions.map(async (interaction) => ({\n id: interaction.id,\n interactionType: interaction.interactionType,\n title: interaction.title ?? null,\n body: interaction.body ?? null,\n status: interaction.status,\n scheduledAt: interaction.scheduledAt ?? null,\n occurredAt: interaction.occurredAt ?? null,\n priority: interaction.priority ?? null,\n authorUserId: interaction.authorUserId ?? null,\n ownerUserId: interaction.ownerUserId ?? null,\n appearanceIcon: interaction.appearanceIcon ?? null,\n appearanceColor: interaction.appearanceColor ?? null,\n source: interaction.source ?? null,\n dealId: interaction.dealId ?? null,\n createdAt: interaction.createdAt,\n updatedAt: interaction.updatedAt,\n deletedAt: interaction.deletedAt ?? null,\n custom: await loadCustomFieldSnapshot(em, {\n entityId: INTERACTION_ENTITY_ID,\n recordId: interaction.id,\n tenantId: entity.tenantId,\n organizationId: entity.organizationId,\n }),\n })),\n )\n const snapshot = serializePersonSnapshot(entity, profile, tagIds, addresses, comments, deals, activities, todoLinks, interactionSnapshots, custom)\n snapshot.companies = summarizePersonCompanies(profile, companyLinks)\n return snapshot\n}\n\nasync function resolveCompanyReference(\n em: EntityManager,\n companyId: string | null | undefined,\n organizationId: string,\n tenantId: string\n): Promise<CustomerEntity | null> {\n if (!companyId) return null\n const company = await em.findOne(CustomerEntity, { id: companyId, kind: 'company', deletedAt: null })\n if (!company) {\n throw new CrudHttpError(400, { error: 'Company not found' })\n }\n if (company.organizationId !== organizationId || company.tenantId !== tenantId) {\n throw new CrudHttpError(403, { error: 'Cannot link person to company outside current scope' })\n }\n return company\n}\n\nasync function setCustomFieldsForPerson(\n ctx: CommandRuntimeContext,\n entityId: string,\n profileId: string,\n organizationId: string,\n tenantId: string,\n values: Record<string, unknown>\n): Promise<void> {\n if (!values || !Object.keys(values).length) return\n const em = (ctx.container.resolve('em') as EntityManager)\n const routing = await resolvePersonCustomFieldRouting(em, tenantId, organizationId)\n const entityScoped: Record<string, unknown> = {}\n const profileScoped: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(values)) {\n const target = routing.get(key) ?? PERSON_ENTITY_ID\n if (target === CUSTOMER_ENTITY_ID) entityScoped[key] = value\n else profileScoped[key] = value\n }\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n if (Object.keys(entityScoped).length) {\n await setCustomFieldsIfAny({\n dataEngine: de,\n entityId: CUSTOMER_ENTITY_ID,\n recordId: entityId,\n organizationId,\n tenantId,\n values: entityScoped,\n notify: true,\n })\n }\n if (Object.keys(profileScoped).length) {\n await setCustomFieldsIfAny({\n dataEngine: de,\n entityId: PERSON_ENTITY_ID,\n recordId: profileId,\n organizationId,\n tenantId,\n values: profileScoped,\n notify: true,\n })\n }\n}\n\nconst createPersonCommand: CommandHandler<PersonCreateInput, { entityId: string; personId: string }> = {\n id: 'customers.people.create',\n async execute(rawInput, ctx) {\n const { parsed, custom } = parseWithCustomFields(personCreateSchema, rawInput)\n ensureTenantScope(ctx, parsed.tenantId)\n ensureOrganizationScope(ctx, parsed.organizationId)\n\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const firstName = parsed.firstName?.trim() ?? ''\n const lastName = parsed.lastName?.trim() ?? ''\n const description = normalizeOptionalString(parsed.description)\n const primaryEmail = normalizeEmail(parsed.primaryEmail)\n const primaryPhone = normalizeOptionalString(parsed.primaryPhone)\n const status = normalizeOptionalString(parsed.status)\n const lifecycleStage = normalizeOptionalString(parsed.lifecycleStage)\n const source = normalizeOptionalString(parsed.source)\n const preferredName = normalizeOptionalString(parsed.preferredName)\n const jobTitle = normalizeOptionalString(parsed.jobTitle)\n const department = normalizeOptionalString(parsed.department)\n const seniority = normalizeOptionalString(parsed.seniority)\n const timezone = normalizeOptionalString(parsed.timezone)\n const linkedInUrl = normalizeOptionalString(parsed.linkedInUrl)\n const twitterUrl = normalizeOptionalString(parsed.twitterUrl)\n const displayNameInput = parsed.displayName?.trim() ?? ''\n const displayName = displayNameInput.length > 0\n ? displayNameInput\n : deriveDisplayName(firstName, lastName)\n const nextInteractionName = parsed.nextInteraction?.name ? parsed.nextInteraction.name.trim() : null\n const nextInteractionRefId = normalizeOptionalString(parsed.nextInteraction?.refId)\n const nextInteractionIcon = normalizeOptionalString(parsed.nextInteraction?.icon)\n const nextInteractionColor = normalizeHexColor(parsed.nextInteraction?.color)\n if (!firstName || !lastName) {\n throw new CrudHttpError(400, { error: 'First and last name are required' })\n }\n if (!displayName) {\n throw new CrudHttpError(400, { error: 'Display name is required' })\n }\n\n let entity!: CustomerEntity\n let profile!: CustomerPersonProfile\n await withAtomicFlush(em, [\n () => {\n entity = em.create(CustomerEntity, {\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n kind: 'person',\n displayName,\n description,\n ownerUserId: parsed.ownerUserId ?? null,\n primaryEmail,\n primaryPhone,\n status,\n lifecycleStage,\n source,\n nextInteractionAt: parsed.nextInteraction?.at ?? null,\n nextInteractionName,\n nextInteractionRefId,\n nextInteractionIcon,\n nextInteractionColor,\n isActive: parsed.isActive ?? true,\n })\n\n profile = em.create(CustomerPersonProfile, {\n organizationId: parsed.organizationId,\n tenantId: parsed.tenantId,\n entity,\n firstName,\n lastName,\n preferredName,\n jobTitle,\n department,\n seniority,\n timezone,\n linkedInUrl,\n twitterUrl,\n company: null,\n })\n\n em.persist(entity)\n em.persist(profile)\n },\n async () => {\n if (status) {\n await ensureDictionaryEntry(em, {\n tenantId: parsed.tenantId,\n organizationId: parsed.organizationId,\n kind: 'status',\n value: status,\n })\n }\n if (jobTitle) {\n await ensureDictionaryEntry(em, {\n tenantId: parsed.tenantId,\n organizationId: parsed.organizationId,\n kind: 'job_title',\n value: jobTitle,\n })\n }\n if (source) {\n await ensureDictionaryEntry(em, {\n tenantId: parsed.tenantId,\n organizationId: parsed.organizationId,\n kind: 'source',\n value: source,\n })\n }\n },\n () => syncLegacyPrimaryCompanyLink(em, entity, profile, parsed.companyEntityId ?? null),\n () => syncEntityTags(em, entity, parsed.tags),\n ], { transaction: true })\n\n const tenantId = entity.tenantId\n const organizationId = entity.organizationId\n await setCustomFieldsForPerson(ctx, entity.id, profile.id, organizationId, tenantId, custom)\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudSideEffects({\n dataEngine: de,\n action: 'created',\n entity,\n identifiers: {\n id: profile.id ?? entity.id,\n tenantId,\n organizationId,\n },\n indexer: personCrudIndexer,\n events: personCrudEvents,\n })\n await emitQueryIndexUpsertEvents(ctx, [personEntityIndexEntry(entity)])\n\n return { entityId: entity.id, personId: profile.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return await loadPersonSnapshot(em, result.entityId)\n },\n buildLog: async ({ result, snapshots }) => {\n const { translate } = await resolveTranslations()\n const snapshot = snapshots.after as PersonSnapshot | undefined\n return {\n actionLabel: translate('customers.audit.people.create', 'Create person'),\n resourceKind: 'customers.person',\n resourceId: result.entityId,\n tenantId: snapshot?.entity.tenantId ?? null,\n organizationId: snapshot?.entity.organizationId ?? null,\n snapshotAfter: snapshot ?? null,\n payload: {\n undo: {\n after: snapshot,\n },\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<PersonUndoPayload>(logEntry) ?? null\n const entityId = logEntry?.resourceId ?? payload?.after?.entity.id ?? null\n if (!entityId) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const entity = await em.findOne(CustomerEntity, { id: entityId })\n if (!entity) return\n const profile = await findOneWithDecryption(\n em,\n CustomerPersonProfile,\n { entity },\n undefined,\n { tenantId: entity.tenantId, organizationId: entity.organizationId },\n )\n const identifiers = {\n id: payload?.after?.profile.id ?? profile?.id ?? entity.id,\n organizationId: entity.organizationId,\n tenantId: entity.tenantId,\n }\n await withAtomicFlush(em, [\n () => em.nativeDelete(CustomerTagAssignment, { entity, organizationId: entity.organizationId, tenantId: entity.tenantId }),\n () => {\n if (profile) em.remove(profile)\n },\n () => em.remove(entity),\n ], { transaction: true })\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudUndoSideEffects({\n dataEngine: de,\n action: 'deleted',\n entity,\n identifiers,\n indexer: personCrudIndexer,\n events: personCrudEvents,\n })\n await emitQueryIndexDeleteEvents(ctx, [personEntityIndexEntry(entity)])\n },\n}\n\nconst updatePersonCommand: CommandHandler<PersonUpdateInput, { entityId: string }> = {\n id: 'customers.people.update',\n async prepare(rawInput, ctx) {\n const { parsed } = parseWithCustomFields(personUpdateSchema, rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const snapshot = await loadPersonSnapshot(em, parsed.id)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(rawInput, ctx) {\n const { parsed, custom } = parseWithCustomFields(personUpdateSchema, rawInput)\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const entity = await em.findOne(CustomerEntity, { id: parsed.id, deletedAt: null })\n const record = assertFound(entity, 'Person not found')\n ensureTenantScope(ctx, record.tenantId)\n ensureOrganizationScope(ctx, record.organizationId)\n const profile = await em.findOne(CustomerPersonProfile, { entity: record })\n if (!profile) throw new CrudHttpError(404, { error: 'Person profile not found' })\n\n if (parsed.displayName !== undefined) {\n const nextDisplayName = parsed.displayName.trim()\n if (!nextDisplayName) {\n throw new CrudHttpError(400, { error: 'Display name is required' })\n }\n }\n\n if (\n parsed.displayName === undefined\n && (parsed.firstName !== undefined || parsed.lastName !== undefined)\n && isDerivedDisplayName(record.displayName, profile.firstName, profile.lastName)\n ) {\n const nextFirst = parsed.firstName !== undefined ? parsed.firstName : profile.firstName\n const nextLast = parsed.lastName !== undefined ? parsed.lastName : profile.lastName\n const derived = deriveDisplayName(nextFirst, nextLast)\n if (derived.length > 0) parsed.displayName = derived\n }\n\n await withAtomicFlush(em, [\n () => {\n if (parsed.description !== undefined) record.description = normalizeOptionalString(parsed.description)\n if (parsed.ownerUserId !== undefined) record.ownerUserId = parsed.ownerUserId ?? null\n if (parsed.primaryEmail !== undefined) record.primaryEmail = normalizeEmail(parsed.primaryEmail)\n if (parsed.primaryPhone !== undefined) record.primaryPhone = normalizeOptionalString(parsed.primaryPhone)\n if (parsed.status !== undefined) {\n record.status = normalizeOptionalString(parsed.status)\n }\n if (parsed.lifecycleStage !== undefined) record.lifecycleStage = normalizeOptionalString(parsed.lifecycleStage)\n if (parsed.source !== undefined) {\n record.source = normalizeOptionalString(parsed.source)\n }\n if (parsed.isActive !== undefined) record.isActive = parsed.isActive\n if (parsed.nextInteraction) {\n record.nextInteractionAt = parsed.nextInteraction.at\n record.nextInteractionName = parsed.nextInteraction.name.trim()\n record.nextInteractionRefId = normalizeOptionalString(parsed.nextInteraction.refId) ?? null\n record.nextInteractionIcon = normalizeOptionalString(parsed.nextInteraction.icon)\n record.nextInteractionColor = normalizeHexColor(parsed.nextInteraction.color)\n } else if (parsed.nextInteraction === null) {\n record.nextInteractionAt = null\n record.nextInteractionName = null\n record.nextInteractionRefId = null\n record.nextInteractionIcon = null\n record.nextInteractionColor = null\n }\n\n if (parsed.firstName !== undefined) profile.firstName = normalizeOptionalString(parsed.firstName)\n if (parsed.lastName !== undefined) profile.lastName = normalizeOptionalString(parsed.lastName)\n if (parsed.preferredName !== undefined) profile.preferredName = normalizeOptionalString(parsed.preferredName)\n if (parsed.jobTitle !== undefined) {\n profile.jobTitle = normalizeOptionalString(parsed.jobTitle)\n }\n if (parsed.department !== undefined) profile.department = normalizeOptionalString(parsed.department)\n if (parsed.seniority !== undefined) profile.seniority = normalizeOptionalString(parsed.seniority)\n if (parsed.timezone !== undefined) profile.timezone = normalizeOptionalString(parsed.timezone)\n if (parsed.linkedInUrl !== undefined) profile.linkedInUrl = normalizeOptionalString(parsed.linkedInUrl)\n if (parsed.twitterUrl !== undefined) profile.twitterUrl = normalizeOptionalString(parsed.twitterUrl)\n\n const profileFieldsUpdated = [\n parsed.firstName, parsed.lastName, parsed.preferredName, parsed.jobTitle,\n parsed.department, parsed.seniority, parsed.timezone, parsed.linkedInUrl,\n parsed.twitterUrl, parsed.companyEntityId,\n ].some((v) => v !== undefined)\n if (profileFieldsUpdated) {\n record.updatedAt = new Date()\n }\n\n if (parsed.displayName !== undefined) {\n record.displayName = parsed.displayName.trim()\n }\n },\n async () => {\n if (parsed.status !== undefined) {\n const normalizedStatus = normalizeOptionalString(parsed.status)\n if (normalizedStatus) {\n await ensureDictionaryEntry(em, {\n tenantId: record.tenantId,\n organizationId: record.organizationId,\n kind: 'status',\n value: normalizedStatus,\n })\n }\n }\n if (parsed.source !== undefined) {\n const normalizedSource = normalizeOptionalString(parsed.source)\n if (normalizedSource) {\n await ensureDictionaryEntry(em, {\n tenantId: record.tenantId,\n organizationId: record.organizationId,\n kind: 'source',\n value: normalizedSource,\n })\n }\n }\n if (parsed.jobTitle !== undefined) {\n const normalizedJobTitle = normalizeOptionalString(parsed.jobTitle)\n if (normalizedJobTitle) {\n await ensureDictionaryEntry(em, {\n tenantId: record.tenantId,\n organizationId: record.organizationId,\n kind: 'job_title',\n value: normalizedJobTitle,\n })\n }\n }\n },\n async () => {\n if (parsed.companyEntityId !== undefined) {\n await syncLegacyPrimaryCompanyLink(em, record, profile, parsed.companyEntityId)\n }\n },\n () => syncEntityTags(em, record, parsed.tags),\n ], { transaction: true })\n\n await setCustomFieldsForPerson(ctx, record.id, profile.id, record.organizationId, record.tenantId, custom)\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: record,\n identifiers: {\n id: profile.id ?? record.id,\n tenantId: record.tenantId,\n organizationId: record.organizationId,\n },\n indexer: personCrudIndexer,\n events: personCrudEvents,\n })\n await emitQueryIndexUpsertEvents(ctx, [personEntityIndexEntry(record)])\n\n return { entityId: record.id }\n },\n captureAfter: async (_input, result, ctx) => {\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n return await loadPersonSnapshot(em, result.entityId)\n },\n buildLog: async ({ snapshots }) => {\n const { translate } = await resolveTranslations()\n const before = snapshots.before as PersonSnapshot | undefined\n if (!before) return null\n const afterSnapshot = snapshots.after as PersonSnapshot | undefined\n if (afterSnapshot && snapshotsEqual(before, afterSnapshot)) {\n return { skipLog: true }\n }\n return {\n actionLabel: translate('customers.audit.people.update', 'Update person'),\n resourceKind: 'customers.person',\n resourceId: before.entity.id,\n tenantId: before.entity.tenantId,\n organizationId: before.entity.organizationId,\n snapshotBefore: before,\n snapshotAfter: afterSnapshot ?? null,\n payload: {\n undo: {\n before,\n after: afterSnapshot ?? null,\n } satisfies PersonUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<PersonUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const entity = await em.findOne(CustomerEntity, { id: before.entity.id })\n if (!entity) {\n let newEntity!: CustomerEntity\n let newProfile!: CustomerPersonProfile\n await withAtomicFlush(em, [\n () => {\n newEntity = em.create(CustomerEntity, {\n id: before.entity.id,\n organizationId: before.entity.organizationId,\n tenantId: before.entity.tenantId,\n kind: 'person',\n displayName: before.entity.displayName,\n description: before.entity.description,\n ownerUserId: before.entity.ownerUserId,\n primaryEmail: before.entity.primaryEmail,\n primaryPhone: before.entity.primaryPhone,\n status: before.entity.status,\n lifecycleStage: before.entity.lifecycleStage,\n source: before.entity.source,\n nextInteractionAt: before.entity.nextInteractionAt,\n nextInteractionName: before.entity.nextInteractionName,\n nextInteractionRefId: before.entity.nextInteractionRefId,\n nextInteractionIcon: before.entity.nextInteractionIcon,\n nextInteractionColor: before.entity.nextInteractionColor,\n isActive: before.entity.isActive,\n })\n em.persist(newEntity)\n newProfile = em.create(CustomerPersonProfile, {\n id: before.profile.id,\n organizationId: before.entity.organizationId,\n tenantId: before.entity.tenantId,\n entity: newEntity,\n firstName: before.profile.firstName,\n lastName: before.profile.lastName,\n preferredName: before.profile.preferredName,\n jobTitle: before.profile.jobTitle,\n department: before.profile.department,\n seniority: before.profile.seniority,\n timezone: before.profile.timezone,\n linkedInUrl: before.profile.linkedInUrl,\n twitterUrl: before.profile.twitterUrl,\n })\n em.persist(newProfile)\n },\n () => syncLegacyPrimaryCompanyLink(em, newEntity, newProfile, before.profile.companyEntityId),\n () => syncEntityTags(em, newEntity, before.tagIds),\n ], { transaction: true })\n } else {\n await withAtomicFlush(em, [\n () => {\n entity.displayName = before.entity.displayName\n entity.description = before.entity.description\n entity.ownerUserId = before.entity.ownerUserId\n entity.primaryEmail = before.entity.primaryEmail\n entity.primaryPhone = before.entity.primaryPhone\n entity.status = before.entity.status\n entity.lifecycleStage = before.entity.lifecycleStage\n entity.source = before.entity.source\n entity.nextInteractionAt = before.entity.nextInteractionAt\n entity.nextInteractionName = before.entity.nextInteractionName\n entity.nextInteractionRefId = before.entity.nextInteractionRefId\n entity.nextInteractionIcon = before.entity.nextInteractionIcon\n entity.nextInteractionColor = before.entity.nextInteractionColor\n entity.isActive = before.entity.isActive\n },\n async () => {\n const profile = await findOneWithDecryption(\n em,\n CustomerPersonProfile,\n { entity },\n undefined,\n { tenantId: before.entity.tenantId, organizationId: before.entity.organizationId },\n )\n if (profile) {\n profile.firstName = before.profile.firstName\n profile.lastName = before.profile.lastName\n profile.preferredName = before.profile.preferredName\n profile.jobTitle = before.profile.jobTitle\n profile.department = before.profile.department\n profile.seniority = before.profile.seniority\n profile.timezone = before.profile.timezone\n profile.linkedInUrl = before.profile.linkedInUrl\n profile.twitterUrl = before.profile.twitterUrl\n await syncLegacyPrimaryCompanyLink(em, entity, profile, before.profile.companyEntityId)\n }\n },\n () => syncEntityTags(em, entity, before.tagIds),\n ], { transaction: true })\n }\n\n const indexedEntity = await em.findOne(CustomerEntity, { id: before.entity.id })\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudUndoSideEffects({\n dataEngine: de,\n action: 'updated',\n entity: indexedEntity,\n identifiers: {\n id: before.profile.id ?? before.entity.id,\n organizationId: before.entity.organizationId,\n tenantId: before.entity.tenantId,\n },\n indexer: personCrudIndexer,\n events: personCrudEvents,\n })\n if (indexedEntity) {\n await emitQueryIndexUpsertEvents(ctx, [personEntityIndexEntry(indexedEntity)])\n }\n\n const resetValues = buildCustomFieldResetMap(before.custom, payload?.after?.custom)\n if (Object.keys(resetValues).length) {\n await setCustomFieldsForPerson(ctx, before.entity.id, before.profile.id, before.entity.organizationId, before.entity.tenantId, resetValues)\n }\n },\n}\n\nconst deletePersonCommand: CommandHandler<{ body?: Record<string, unknown>; query?: Record<string, unknown> }, { entityId: string }> =\n {\n id: 'customers.people.delete',\n async prepare(input, ctx) {\n const id = requireId(input, 'Person id required')\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const snapshot = await loadPersonSnapshot(em, id)\n return snapshot ? { before: snapshot } : {}\n },\n async execute(input, ctx) {\n const id = requireId(input, 'Person id required')\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const snapshot = await loadPersonSnapshot(em, id)\n const entity = await em.findOne(CustomerEntity, { id, deletedAt: null })\n const record = assertFound(entity, 'Person not found')\n ensureTenantScope(ctx, record.tenantId)\n ensureOrganizationScope(ctx, record.organizationId)\n const profile = await em.findOne(CustomerPersonProfile, { entity: record })\n if (profile) em.remove(profile)\n await em.nativeDelete(CustomerAddress, { entity: record, organizationId: record.organizationId, tenantId: record.tenantId })\n await em.nativeDelete(CustomerComment, { entity: record, organizationId: record.organizationId, tenantId: record.tenantId })\n await em.nativeDelete(CustomerActivity, { entity: record, organizationId: record.organizationId, tenantId: record.tenantId })\n await em.nativeDelete(CustomerInteraction, { entity: record, organizationId: record.organizationId, tenantId: record.tenantId })\n await em.nativeDelete(CustomerTodoLink, { entity: record, organizationId: record.organizationId, tenantId: record.tenantId })\n await em.nativeDelete(CustomerTagAssignment, { entity: record, organizationId: record.organizationId, tenantId: record.tenantId })\n await em.nativeDelete(CustomerDealPersonLink, { person: record })\n await em.nativeDelete(CustomerPersonCompanyLink, { person: record })\n if (profile) {\n await em.nativeDelete(CustomFieldValue, { entityId: PERSON_ENTITY_ID, recordId: profile.id })\n }\n await em.nativeDelete(CustomFieldValue, { entityId: CUSTOMER_ENTITY_ID, recordId: record.id })\n em.remove(record)\n await em.flush()\n\n const indexDeletes: QueryIndexEventEntry[] = []\n const dealUpserts: QueryIndexEventEntry[] = []\n if (snapshot) {\n for (const activity of snapshot.activities ?? []) {\n indexDeletes.push({\n entityType: E.customers.customer_activity,\n recordId: activity.id,\n tenantId: record.tenantId,\n organizationId: record.organizationId,\n })\n }\n for (const comment of snapshot.comments ?? []) {\n indexDeletes.push({\n entityType: E.customers.customer_comment,\n recordId: comment.id,\n tenantId: record.tenantId,\n organizationId: record.organizationId,\n })\n }\n for (const address of snapshot.addresses ?? []) {\n indexDeletes.push({\n entityType: E.customers.customer_address,\n recordId: address.id,\n tenantId: record.tenantId,\n organizationId: record.organizationId,\n })\n }\n for (const todo of snapshot.todos ?? []) {\n indexDeletes.push({\n entityType: E.customers.customer_todo_link,\n recordId: todo.id,\n tenantId: record.tenantId,\n organizationId: record.organizationId,\n })\n }\n for (const interaction of snapshot.interactions ?? []) {\n indexDeletes.push({\n entityType: E.customers.customer_interaction,\n recordId: interaction.id,\n tenantId: record.tenantId,\n organizationId: record.organizationId,\n })\n }\n for (const deal of snapshot.deals ?? []) {\n if (deal.dealId) {\n dealUpserts.push({\n entityType: E.customers.customer_deal,\n recordId: deal.dealId,\n tenantId: record.tenantId,\n organizationId: record.organizationId,\n })\n }\n }\n }\n\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n await emitCrudSideEffects({\n dataEngine: de,\n action: 'deleted',\n entity: record,\n identifiers: {\n id: profile?.id ?? record.id,\n organizationId: record.organizationId,\n tenantId: record.tenantId,\n },\n indexer: personCrudIndexer,\n events: personCrudEvents,\n })\n\n await emitQueryIndexDeleteEvents(ctx, [personEntityIndexEntry(record)])\n await emitQueryIndexDeleteEvents(ctx, indexDeletes)\n await emitQueryIndexUpsertEvents(ctx, dealUpserts)\n return { entityId: record.id }\n },\n buildLog: async ({ snapshots }) => {\n const before = snapshots.before as PersonSnapshot | undefined\n if (!before) return null\n const { translate } = await resolveTranslations()\n return {\n actionLabel: translate('customers.audit.people.delete', 'Delete person'),\n resourceKind: 'customers.person',\n resourceId: before.entity.id,\n tenantId: before.entity.tenantId,\n organizationId: before.entity.organizationId,\n snapshotBefore: before,\n payload: {\n undo: {\n before,\n } satisfies PersonUndoPayload,\n },\n }\n },\n undo: async ({ logEntry, ctx }) => {\n const payload = extractUndoPayload<PersonUndoPayload>(logEntry)\n const before = payload?.before\n if (!before) return\n const em = (ctx.container.resolve('em') as EntityManager).fork()\n const de = (ctx.container.resolve('dataEngine') as DataEngine)\n\n const decryptionScope = {\n tenantId: before.entity.tenantId ?? null,\n organizationId: before.entity.organizationId ?? null,\n }\n // Bind the outer EntityManager to an explicit transaction so every\n // `em.flush()` below participates in the same unit of work. Using\n // `em.transactional(cb)` would pass a forked em into `cb` and the\n // surrounding closures would mutate the unwrapped em, escaping the\n // transaction (see SPEC-018 and H8 in the CRM details screens review).\n await em.begin()\n let txResult: {\n entity: CustomerEntity\n profile: CustomerPersonProfile\n beforeInteractions: PersonInteractionSnapshot[]\n beforeTodos: PersonTodoSnapshot[]\n }\n try {\n txResult = await (async () => {\n let entity = await findOneWithDecryption(\n em,\n CustomerEntity,\n {\n id: before.entity.id,\n tenantId: before.entity.tenantId,\n organizationId: before.entity.organizationId,\n },\n {},\n decryptionScope,\n )\n if (!entity) {\n entity = em.create(CustomerEntity, {\n id: before.entity.id,\n organizationId: before.entity.organizationId,\n tenantId: before.entity.tenantId,\n kind: 'person',\n displayName: before.entity.displayName,\n description: before.entity.description,\n ownerUserId: before.entity.ownerUserId,\n primaryEmail: before.entity.primaryEmail,\n primaryPhone: before.entity.primaryPhone,\n status: before.entity.status,\n lifecycleStage: before.entity.lifecycleStage,\n source: before.entity.source,\n nextInteractionAt: before.entity.nextInteractionAt,\n nextInteractionName: before.entity.nextInteractionName,\n nextInteractionRefId: before.entity.nextInteractionRefId,\n nextInteractionIcon: before.entity.nextInteractionIcon,\n nextInteractionColor: before.entity.nextInteractionColor,\n isActive: before.entity.isActive,\n })\n em.persist(entity)\n }\n\n entity.displayName = before.entity.displayName\n entity.description = before.entity.description\n entity.ownerUserId = before.entity.ownerUserId\n entity.primaryEmail = before.entity.primaryEmail\n entity.primaryPhone = before.entity.primaryPhone\n entity.status = before.entity.status\n entity.lifecycleStage = before.entity.lifecycleStage\n entity.source = before.entity.source\n entity.nextInteractionAt = before.entity.nextInteractionAt\n entity.nextInteractionName = before.entity.nextInteractionName\n entity.nextInteractionRefId = before.entity.nextInteractionRefId\n entity.nextInteractionIcon = before.entity.nextInteractionIcon\n entity.nextInteractionColor = before.entity.nextInteractionColor\n entity.isActive = before.entity.isActive\n entity.deletedAt = null\n\n let profile = await findOneWithDecryption(\n em,\n CustomerPersonProfile,\n {\n entity,\n tenantId: before.entity.tenantId,\n organizationId: before.entity.organizationId,\n },\n {},\n decryptionScope,\n )\n if (!profile) {\n profile = em.create(CustomerPersonProfile, {\n id: before.profile.id,\n organizationId: before.entity.organizationId,\n tenantId: before.entity.tenantId,\n entity,\n firstName: before.profile.firstName,\n lastName: before.profile.lastName,\n preferredName: before.profile.preferredName,\n jobTitle: before.profile.jobTitle,\n department: before.profile.department,\n seniority: before.profile.seniority,\n timezone: before.profile.timezone,\n linkedInUrl: before.profile.linkedInUrl,\n twitterUrl: before.profile.twitterUrl,\n })\n } else {\n profile.firstName = before.profile.firstName\n profile.lastName = before.profile.lastName\n profile.preferredName = before.profile.preferredName\n profile.jobTitle = before.profile.jobTitle\n profile.department = before.profile.department\n profile.seniority = before.profile.seniority\n profile.timezone = before.profile.timezone\n profile.linkedInUrl = before.profile.linkedInUrl\n profile.twitterUrl = before.profile.twitterUrl\n }\n\n await syncLegacyPrimaryCompanyLink(em, entity, profile, before.profile.companyEntityId)\n\n await em.flush()\n await em.nativeDelete(CustomerPersonCompanyLink, { person: entity })\n for (const companyLink of before.companies ?? []) {\n const company = await resolveCompanyReference(\n em,\n companyLink.companyId,\n before.entity.organizationId,\n before.entity.tenantId,\n )\n if (!company) continue\n const restoredLink = em.create(CustomerPersonCompanyLink, {\n id: companyLink.linkId ?? undefined,\n organizationId: before.entity.organizationId,\n tenantId: before.entity.tenantId,\n person: entity,\n company,\n isPrimary: companyLink.isPrimary,\n })\n em.persist(restoredLink)\n if (companyLink.isPrimary) {\n profile.company = company\n }\n }\n await withAtomicFlush(em, [\n () => syncEntityTags(em, entity, before.tagIds),\n ])\n\n const beforeActivities = (before as { activities?: PersonActivitySnapshot[] }).activities ?? []\n const beforeTodos = (before as { todos?: PersonTodoSnapshot[] }).todos ?? []\n const beforeInteractions = (before as { interactions?: PersonInteractionSnapshot[] }).interactions ?? []\n\n const relatedDealIds = new Set<string>()\n for (const link of before.deals) relatedDealIds.add(link.dealId)\n for (const activity of beforeActivities) {\n if (activity.dealId) relatedDealIds.add(activity.dealId)\n }\n for (const comment of before.comments) {\n if (comment.dealId) relatedDealIds.add(comment.dealId)\n }\n let dealMap = new Map<string, CustomerDeal>()\n if (relatedDealIds.size) {\n const deals = await em.find(CustomerDeal, {\n id: { $in: Array.from(relatedDealIds) },\n organizationId: entity.organizationId,\n tenantId: entity.tenantId,\n })\n dealMap = new Map(deals.map((deal) => [deal.id, deal]))\n }\n\n await em.nativeDelete(CustomerDealPersonLink, { person: entity })\n for (const link of before.deals) {\n const deal = dealMap.get(link.dealId)\n if (!deal) continue\n const restoredLink = em.create(CustomerDealPersonLink, {\n id: link.id,\n deal,\n person: entity,\n participantRole: link.participantRole,\n createdAt: link.createdAt,\n })\n em.persist(restoredLink)\n }\n await em.flush()\n\n await em.nativeDelete(CustomerActivity, { entity, organizationId: entity.organizationId, tenantId: entity.tenantId })\n for (const activity of beforeActivities) {\n const restoredActivity = em.create(CustomerActivity, {\n id: activity.id,\n organizationId: entity.organizationId,\n tenantId: entity.tenantId,\n entity,\n activityType: activity.activityType,\n subject: activity.subject,\n body: activity.body,\n occurredAt: activity.occurredAt,\n authorUserId: activity.authorUserId,\n appearanceIcon: activity.appearanceIcon,\n appearanceColor: activity.appearanceColor,\n deal: activity.dealId ? dealMap.get(activity.dealId) ?? null : null,\n createdAt: activity.createdAt,\n updatedAt: activity.updatedAt,\n })\n em.persist(restoredActivity)\n }\n await em.flush()\n\n await em.nativeDelete(CustomerComment, { entity, organizationId: entity.organizationId, tenantId: entity.tenantId })\n for (const comment of before.comments) {\n const restoredComment = em.create(CustomerComment, {\n id: comment.id,\n organizationId: entity.organizationId,\n tenantId: entity.tenantId,\n entity,\n body: comment.body,\n authorUserId: comment.authorUserId,\n appearanceIcon: comment.appearanceIcon,\n appearanceColor: comment.appearanceColor,\n deal: comment.dealId ? dealMap.get(comment.dealId) ?? null : null,\n createdAt: comment.createdAt,\n updatedAt: comment.updatedAt,\n deletedAt: comment.deletedAt,\n })\n em.persist(restoredComment)\n }\n await em.flush()\n\n await em.nativeDelete(CustomerAddress, { entity, organizationId: entity.organizationId, tenantId: entity.tenantId })\n for (const address of before.addresses) {\n const restoredAddress = em.create(CustomerAddress, {\n id: address.id,\n organizationId: entity.organizationId,\n tenantId: entity.tenantId,\n entity,\n name: address.name,\n purpose: address.purpose,\n addressLine1: address.addressLine1,\n addressLine2: address.addressLine2,\n city: address.city,\n region: address.region,\n postalCode: address.postalCode,\n country: address.country,\n latitude: address.latitude,\n longitude: address.longitude,\n isPrimary: address.isPrimary,\n })\n em.persist(restoredAddress)\n }\n await em.flush()\n\n await em.nativeDelete(CustomerTodoLink, { entity, organizationId: entity.organizationId, tenantId: entity.tenantId })\n for (const todo of beforeTodos) {\n const restoredTodo = em.create(CustomerTodoLink, {\n id: todo.id,\n organizationId: entity.organizationId,\n tenantId: entity.tenantId,\n entity,\n todoId: todo.todoId,\n todoSource: todo.todoSource,\n createdAt: todo.createdAt,\n createdByUserId: todo.createdByUserId,\n })\n em.persist(restoredTodo)\n }\n await em.flush()\n\n await em.nativeDelete(CustomerInteraction, { entity, organizationId: entity.organizationId, tenantId: entity.tenantId })\n for (const interaction of beforeInteractions) {\n const restoredInteraction = em.create(CustomerInteraction, {\n id: interaction.id,\n organizationId: entity.organizationId,\n tenantId: entity.tenantId,\n entity,\n interactionType: interaction.interactionType,\n title: interaction.title,\n body: interaction.body,\n status: interaction.status,\n scheduledAt: interaction.scheduledAt,\n occurredAt: interaction.occurredAt,\n priority: interaction.priority,\n authorUserId: interaction.authorUserId,\n ownerUserId: interaction.ownerUserId,\n dealId: interaction.dealId,\n source: interaction.source,\n appearanceIcon: interaction.appearanceIcon,\n appearanceColor: interaction.appearanceColor,\n createdAt: interaction.createdAt,\n updatedAt: interaction.updatedAt,\n deletedAt: interaction.deletedAt,\n })\n em.persist(restoredInteraction)\n }\n await em.flush()\n\n return { entity, profile, beforeInteractions, beforeTodos }\n })()\n await em.commit()\n } catch (err) {\n try {\n await em.rollback()\n } catch {\n // rollback failure should not mask the original error\n }\n throw err\n }\n\n for (const interaction of txResult.beforeInteractions) {\n if (!interaction.custom || !Object.keys(interaction.custom).length) continue\n await setCustomFieldsIfAny({\n dataEngine: de,\n entityId: INTERACTION_ENTITY_ID,\n recordId: interaction.id,\n organizationId: txResult.entity.organizationId,\n tenantId: txResult.entity.tenantId,\n values: interaction.custom,\n notify: false,\n })\n }\n\n const entity = txResult.entity\n const profile = txResult.profile\n\n await emitCrudUndoSideEffects({\n dataEngine: de,\n action: 'created',\n entity,\n identifiers: {\n id: profile.id ?? entity.id,\n organizationId: entity.organizationId,\n tenantId: entity.tenantId,\n },\n indexer: personCrudIndexer,\n events: personCrudEvents,\n })\n\n const upsertEntries: QueryIndexEventEntry[] = []\n for (const activity of before.activities ?? []) {\n upsertEntries.push({\n entityType: E.customers.customer_activity,\n recordId: activity.id,\n tenantId: entity.tenantId,\n organizationId: entity.organizationId,\n })\n }\n for (const comment of before.comments ?? []) {\n upsertEntries.push({\n entityType: E.customers.customer_comment,\n recordId: comment.id,\n tenantId: entity.tenantId,\n organizationId: entity.organizationId,\n })\n }\n for (const address of before.addresses ?? []) {\n upsertEntries.push({\n entityType: E.customers.customer_address,\n recordId: address.id,\n tenantId: entity.tenantId,\n organizationId: entity.organizationId,\n })\n }\n for (const todo of txResult.beforeTodos ?? []) {\n upsertEntries.push({\n entityType: E.customers.customer_todo_link,\n recordId: todo.id,\n tenantId: entity.tenantId,\n organizationId: entity.organizationId,\n })\n }\n for (const interaction of txResult.beforeInteractions ?? []) {\n upsertEntries.push({\n entityType: E.customers.customer_interaction,\n recordId: interaction.id,\n tenantId: entity.tenantId,\n organizationId: entity.organizationId,\n })\n }\n const dealUpserts: QueryIndexEventEntry[] = []\n for (const deal of before.deals ?? []) {\n if (deal.dealId) {\n dealUpserts.push({\n entityType: E.customers.customer_deal,\n recordId: deal.dealId,\n tenantId: entity.tenantId,\n organizationId: entity.organizationId,\n })\n }\n }\n const resetValues = buildCustomFieldResetMap(before.custom, undefined)\n if (Object.keys(resetValues).length) {\n await setCustomFieldsForPerson(ctx, entity.id, profile.id, entity.organizationId, entity.tenantId, resetValues)\n }\n await emitQueryIndexUpsertEvents(ctx, [personEntityIndexEntry(entity)])\n await emitQueryIndexUpsertEvents(ctx, upsertEntries)\n await emitQueryIndexUpsertEvents(ctx, dealUpserts)\n },\n }\n\nregisterCommand(createPersonCommand)\nregisterCommand(updatePersonCommand)\nregisterCommand(deletePersonCommand)\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,uBAAuB;AAEhC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAIP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,iCAAiC,oBAAoB,wBAAwB;AACtF,SAAS,wBAAwB;AACjC;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,uBAAuB;AAChC,SAAS,qBAAqB;AAC9B,SAAS,2BAA2B;AACpC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAEP,SAAS,SAAS;AAClB,SAAS,oBAAoB,6BAA6B;AAC1D,SAAS,mBAAmB,4BAA4B;AACxD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,MAAM,wBAAwB;AAmI9B,MAAM,oBAAuD;AAAA,EAC3D,YAAY,EAAE,UAA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I,OAAO,KAAK,WAAW,EAAE,QAAQ;AACnC,YAAM,yBAAyB,KAAK,OAAO,IAAI,QAAQ,IAAI,OAAO,gBAAgB,OAAO,UAAU,WAAW;AAAA,IAChH;AACA,UAAM,2BAA2B,KAAK,CAAC,uBAAuB,MAAM,CAAC,CAAC;AACtE,UAAM,2BAA2B,KAAK,aAAa;AACnD,UAAM,2BAA2B,KAAK,WAAW;AAAA,EACnD;AACF;AAEF,gBAAgB,mBAAmB;AACnC,gBAAgB,mBAAmB;AACnC,gBAAgB,mBAAmB;",
|
|
6
6
|
"names": ["entity", "profile"]
|
|
7
7
|
}
|
|
@@ -456,14 +456,14 @@ const deletePersonCompanyLinkCommand = {
|
|
|
456
456
|
const person = await requirePersonEntity(em, personId, parsed.tenantId, parsed.organizationId);
|
|
457
457
|
const profile = await requirePersonProfile(em, person);
|
|
458
458
|
const linkWasPrimary = link.isPrimary;
|
|
459
|
+
const existingLinks = await loadPersonCompanyLinks(em, person);
|
|
460
|
+
const remainingLinks = existingLinks.filter((entry) => entry.id !== link.id);
|
|
459
461
|
await withAtomicFlush(em, [
|
|
460
462
|
() => {
|
|
461
463
|
link.isPrimary = false;
|
|
462
464
|
link.deletedAt = /* @__PURE__ */ new Date();
|
|
463
465
|
},
|
|
464
466
|
async () => {
|
|
465
|
-
const existingLinks = await loadPersonCompanyLinks(em, person);
|
|
466
|
-
const remainingLinks = existingLinks.filter((entry) => entry.id !== link.id);
|
|
467
467
|
if (linkWasPrimary) {
|
|
468
468
|
await promoteFallbackPrimaryLink(em, person, profile, remainingLinks, companyId);
|
|
469
469
|
} else if (profile.company && typeof profile.company !== "string" && profile.company.id === companyId) {
|