{
  "version": 3,
  "sources": ["twenty-sdk-define-stub:__twenty-sdk-define-stub__", "../../../../src/logic-functions/on-email-interaction.ts", "../../../../src/constants/batch-handler-timeout-seconds.ts", "../../../../src/constants/universal-identifiers.ts", "../../../../src/utils/chunk.ts", "../../../../src/utils/execute-with-retry.ts", "../../../../src/utils/update-person-last-contact.ts", "../../../../src/utils/upsert-records-in-batches.ts", "../../../../src/utils/update-related-last-contact.ts", "../../../../src/utils/apply-person-interactions.ts", "../../../../src/utils/pick-contact-team-member.ts", "../../../../src/utils/collect-message-interactions.ts", "../../../../src/utils/apply-email-interactions.ts"],
  "sourcesContent": ["\n// Auto-generated stub for twenty-sdk/define injected by the SDK CLI build.\n// Real implementations would pull in zod, twenty-shared and ~1MB of code; at\n// runtime only `default.config.handler` is consumed, so tiny no-ops suffice.\nconst __defineFactoryStub = (config) => ({\n  success: true,\n  config,\n  errors: [],\n});\n\nconst __anyHandler = {\n  get(_target, prop) {\n    if (prop === '__esModule') return true;\n    if (prop === Symbol.toPrimitive) return () => '';\n    if (typeof prop === 'symbol') return undefined;\n    return new Proxy(() => undefined, __anyHandler);\n  },\n  apply() {\n    return new Proxy(() => undefined, __anyHandler);\n  },\n};\nconst __anyStub = new Proxy(() => undefined, __anyHandler);\n\nexport const createValidationResult = __defineFactoryStub;\nexport const defineAgent = __defineFactoryStub;\nexport const defineApplication = __defineFactoryStub;\nexport const defineApplicationRole = __defineFactoryStub;\nexport const defineCommandMenuItem = __defineFactoryStub;\nexport const defineConnectionProvider = __defineFactoryStub;\nexport const defineField = __defineFactoryStub;\nexport const defineFrontComponent = __defineFactoryStub;\nexport const defineIndex = __defineFactoryStub;\nexport const defineLogicFunction = __defineFactoryStub;\nexport const defineNavigationMenuItem = __defineFactoryStub;\nexport const defineObject = __defineFactoryStub;\nexport const definePageLayout = __defineFactoryStub;\nexport const definePageLayoutTab = __defineFactoryStub;\nexport const definePageLayoutWidget = __defineFactoryStub;\nexport const definePermissionFlag = __defineFactoryStub;\nexport const definePostInstallLogicFunction = __defineFactoryStub;\nexport const definePreInstallLogicFunction = __defineFactoryStub;\nexport const defineRole = __defineFactoryStub;\nexport const defineSettingsFrontComponent = __defineFactoryStub;\nexport const defineSkill = __defineFactoryStub;\nexport const defineTimelineActivityType = __defineFactoryStub;\nexport const defineUninstallLogicFunction = __defineFactoryStub;\nexport const defineView = __defineFactoryStub;\nexport const defineViewField = __defineFactoryStub;\nexport const AggregateOperations = __anyStub;\nexport const CommandMenuItemAvailabilityType = __anyStub;\nexport const DateDisplayFormat = __anyStub;\nexport const FieldMetadataSettingsOnClickAction = __anyStub;\nexport const FieldType = __anyStub;\nexport const HTTPMethod = __anyStub;\nexport const IndexType = __anyStub;\nexport const MetadataReadability = __anyStub;\nexport const MetadataWritability = __anyStub;\nexport const NavigationMenuItemType = __anyStub;\nexport const NumberDataType = __anyStub;\nexport const ObjectOpenRecordIn = __anyStub;\nexport const ObjectRecordGroupByDateGranularity = __anyStub;\nexport const OnDeleteAction = __anyStub;\nexport const PageLayoutTabLayoutMode = __anyStub;\nexport const PageLayoutType = __anyStub;\nexport const RelationType = __anyStub;\nexport const RowLevelPermissionPredicateGroupLogicalOperator = __anyStub;\nexport const RowLevelPermissionPredicateOperand = __anyStub;\nexport const STANDARD_OBJECT = __anyStub;\nexport const STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS = __anyStub;\nexport const STANDARD_PAGE_LAYOUT = __anyStub;\nexport const STANDARD_PAGE_LAYOUT_UNIVERSAL_IDENTIFIERS = __anyStub;\nexport const SYSTEM_VIEW_KEYS = __anyStub;\nexport const SystemPermissionFlag = __anyStub;\nexport const ViewCalendarLayout = __anyStub;\nexport const ViewFilterGroupLogicalOperator = __anyStub;\nexport const ViewFilterOperand = __anyStub;\nexport const ViewKey = __anyStub;\nexport const ViewOpenRecordIn = __anyStub;\nexport const ViewSortDirection = __anyStub;\nexport const ViewType = __anyStub;\nexport const ViewVisibility = __anyStub;\nexport const WidgetType = __anyStub;\nexport const canAccessFullAdminPanel = __anyStub;\nexport const canImpersonate = __anyStub;\nexport const every = __anyStub;\nexport const everyDefined = __anyStub;\nexport const everyEquals = __anyStub;\nexport const favoriteRecordIds = __anyStub;\nexport const featureFlags = __anyStub;\nexport const getFieldUniversalIdentifier = __anyStub;\nexport const getSystemPageLayoutTabUniversalIdentifier = __anyStub;\nexport const getSystemRecordPageLayoutUniversalIdentifier = __anyStub;\nexport const getSystemRelationFieldUniversalIdentifier = __anyStub;\nexport const getSystemViewFieldUniversalIdentifier = __anyStub;\nexport const getSystemViewUniversalIdentifier = __anyStub;\nexport const hasAnySoftDeleteFilterOnView = __anyStub;\nexport const includes = __anyStub;\nexport const includesEvery = __anyStub;\nexport const isDashboardPageLayoutInEditMode = __anyStub;\nexport const isDefined = __anyStub;\nexport const isInSidePanel = __anyStub;\nexport const isLayoutCustomizationModeEnabled = __anyStub;\nexport const isNonEmptyString = __anyStub;\nexport const isSelectAll = __anyStub;\nexport const none = __anyStub;\nexport const noneDefined = __anyStub;\nexport const noneEquals = __anyStub;\nexport const numberOfSelectedRecords = __anyStub;\nexport const objectMetadataItem = __anyStub;\nexport const objectMetadataLabel = __anyStub;\nexport const objectPermissions = __anyStub;\nexport const pageType = __anyStub;\nexport const selectedRecords = __anyStub;\nexport const some = __anyStub;\nexport const someDefined = __anyStub;\nexport const someEquals = __anyStub;\nexport const someNonEmptyString = __anyStub;\nexport const targetObjectReadPermissions = __anyStub;\nexport const targetObjectWritePermissions = __anyStub;\nexport const validateFields = __anyStub;\n", "import {\n  defineLogicFunction,\n  type ObjectRecordUpdateEvent,\n} from 'twenty-sdk/define';\nimport { type DatabaseEventBatchPayload } from 'twenty-sdk/logic-function';\nimport { CoreApiClient } from 'twenty-client-sdk/core';\n\nimport { BATCH_HANDLER_TIMEOUT_SECONDS } from 'src/constants/batch-handler-timeout-seconds';\nimport { EMAIL_INTERACTION_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER } from 'src/constants/universal-identifiers';\nimport {\n  applyEmailInteractions,\n  type MessageParticipantLink,\n} from 'src/utils/apply-email-interactions';\n\ntype MessageParticipantUpdate = {\n  personId?: string | null;\n  messageId?: string | null;\n};\n\nconst handler = async (\n  batch: DatabaseEventBatchPayload<\n    ObjectRecordUpdateEvent<MessageParticipantUpdate>\n  >,\n): Promise<void> => {\n  const linkByKey = new Map<string, MessageParticipantLink>();\n\n  for (const event of batch.events) {\n    const personId = event.properties.after.personId;\n    const messageId = event.properties.after.messageId;\n\n    if (personId && messageId) {\n      linkByKey.set(`${personId}:${messageId}`, { personId, messageId });\n    }\n  }\n\n  if (linkByKey.size === 0) {\n    return;\n  }\n\n  await applyEmailInteractions(new CoreApiClient(), [...linkByKey.values()]);\n};\n\nexport default defineLogicFunction({\n  universalIdentifier: EMAIL_INTERACTION_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER,\n  name: 'on-email-interaction',\n  description:\n    \"Updates a person's last-contacted fields, and the last contact on their company and opportunities, when a new email participant is created.\",\n  timeoutSeconds: BATCH_HANDLER_TIMEOUT_SECONDS,\n  databaseEventTriggerSettings: {\n    eventName: 'messageParticipant.updated',\n    updatedFields: ['personId'],\n    batchMode: true,\n  },\n  handler,\n});\n", "export const BATCH_HANDLER_TIMEOUT_SECONDS = 300;\n", "export const APP_DISPLAY_NAME = 'Last contact';\nexport const APP_DESCRIPTION =\n  'Know where every relationship stands. Adds Last contact, Last outbound, Last inbound, Last contact by, and the last email and meeting to People, plus Last contact on Companies and Opportunities, kept up to date automatically from your synced emails and meetings.';\nexport const APPLICATION_UNIVERSAL_IDENTIFIER = '66a504cc-0a75-410e-a43f-cdeae1db1522';\nexport const DEFAULT_ROLE_UNIVERSAL_IDENTIFIER = '34187abe-1b98-4153-85cd-4808e0aebf30';\nexport const LAST_CONTACT_AT_FIELD_UNIVERSAL_IDENTIFIER =\n  '4e0fd7ff-0bbc-47b2-baab-5fe2c0d12557';\nexport const EMAIL_INTERACTION_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER =\n  '87c8926b-15e3-43ed-a303-60f6d072f351';\nexport const CALENDAR_INTERACTION_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER =\n  'ff4e9fc0-a5d3-4a3d-87f9-81c23598589e';\nexport const BACKFILL_POST_INSTALL_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER =\n  'c94f671f-b3fa-47a2-8de6-dde94d13f8d1';\nexport const CALENDAR_EVENT_STARTED_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER =\n  'c56013d7-208b-46e2-a91f-27f481645591';\nexport const BACKFILL_PEOPLE_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER =\n  'a1e15917-86d6-49a4-90d5-6a2555abc6f5';\nexport const BACKFILL_COMPANIES_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER =\n  '086d247f-28da-41be-8edd-e6c58592d666';\nexport const BACKFILL_OPPORTUNITIES_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER =\n  'af176746-4334-47f8-a017-88a474a03fa3';\nexport const OPPORTUNITY_CREATED_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER =\n  '6659b54f-2f46-412b-aa7d-03aa9f1c5133';\nexport const OPPORTUNITY_UPDATED_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER =\n  '071a1c3e-b580-4312-806d-ff27287292ae';\nexport const COMPANY_CREATED_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER =\n  'd0631934-2f06-4799-9b33-6937f78e16ff';\nexport const PERSON_CREATED_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER =\n  'cf7460cc-4c48-4412-9a1a-0c30e4960fce';\nexport const PERSON_UPDATED_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER =\n  'a967064f-f440-43cd-bfbe-907c95d4563f';\n\nexport const LAST_CONTACT_BY_FIELD_UNIVERSAL_IDENTIFIER =\n  'cfdee7bd-8d41-41e6-a888-512705e75d7b';\nexport const LAST_CONTACT_FOR_PEOPLE_ON_WORKSPACE_MEMBER_FIELD_UNIVERSAL_IDENTIFIER =\n  'bec41e57-6b6f-4bb2-90cc-4030384dd8f6';\n\nexport const LAST_CONTACT_ITEM_MORPH_ID =\n  '97eafe97-0ee1-4857-b233-fec855f6bf1a';\nexport const LAST_CONTACT_ITEM_MESSAGE_FIELD_UNIVERSAL_IDENTIFIER =\n  'e4abd1da-32f4-4025-8908-e7834e85b8e2';\nexport const LAST_CONTACT_FOR_PEOPLE_ON_MESSAGE_FIELD_UNIVERSAL_IDENTIFIER =\n  '4dea9957-ff7d-46b8-988f-cc72f187d4b5';\nexport const LAST_CONTACT_ITEM_CALENDAR_EVENT_FIELD_UNIVERSAL_IDENTIFIER =\n  'cceb21fe-1422-40d4-bc8b-44c12c79c452';\nexport const LAST_CONTACT_FOR_PEOPLE_ON_CALENDAR_EVENT_FIELD_UNIVERSAL_IDENTIFIER =\n  'f49ce9ca-5aab-445d-9749-db256aaf74b7';\n\nexport const LAST_OUTBOUND_AT_FIELD_UNIVERSAL_IDENTIFIER =\n  'f4bbac22-8a3d-44c2-bbf2-7e28237252e1';\nexport const LAST_INBOUND_AT_FIELD_UNIVERSAL_IDENTIFIER =\n  '11ee7749-735d-4fcf-b127-fa6856de7ee0';\nexport const LAST_EMAIL_FIELD_UNIVERSAL_IDENTIFIER =\n  'fd705b81-c6c6-45d3-9777-818956b7627b';\nexport const LAST_EMAIL_FOR_PEOPLE_ON_MESSAGE_FIELD_UNIVERSAL_IDENTIFIER =\n  '7a3dcccb-d4fd-4839-971a-775ca7bd897f';\nexport const LAST_MEETING_FIELD_UNIVERSAL_IDENTIFIER =\n  'c8882287-f638-4a96-a235-1819e793e373';\nexport const LAST_MEETING_FOR_PEOPLE_ON_CALENDAR_EVENT_FIELD_UNIVERSAL_IDENTIFIER =\n  '257dd874-d834-403d-9cb8-f3db7e587d02';\n\nexport const COMPANY_LAST_CONTACT_AT_FIELD_UNIVERSAL_IDENTIFIER =\n  '4d84b45d-128d-460f-858a-f877bf6e58ac';\nexport const COMPANY_LAST_CONTACT_ITEM_MORPH_ID =\n  '64a265e9-c597-4ca4-a5f2-570d9661eea7';\nexport const COMPANY_LAST_CONTACT_ITEM_MESSAGE_FIELD_UNIVERSAL_IDENTIFIER =\n  'f43de098-74a9-491c-b718-2e132332c722';\nexport const COMPANY_LAST_CONTACT_ITEM_CALENDAR_EVENT_FIELD_UNIVERSAL_IDENTIFIER =\n  '4ef5546f-97e3-4eff-8090-91b5c6400ac9';\nexport const LAST_CONTACT_FOR_COMPANIES_ON_MESSAGE_FIELD_UNIVERSAL_IDENTIFIER =\n  '9f08c2e0-23ba-413c-94c8-04ba828586a3';\nexport const LAST_CONTACT_FOR_COMPANIES_ON_CALENDAR_EVENT_FIELD_UNIVERSAL_IDENTIFIER =\n  '79103905-cfdb-413a-b964-8f347332ef3c';\n\nexport const OPPORTUNITY_LAST_CONTACT_AT_FIELD_UNIVERSAL_IDENTIFIER =\n  '69225d61-0efb-4959-af6d-566caba58412';\nexport const OPPORTUNITY_LAST_CONTACT_ITEM_MORPH_ID =\n  '9199fef1-06e3-4024-8a4a-b4eee554418e';\nexport const OPPORTUNITY_LAST_CONTACT_ITEM_MESSAGE_FIELD_UNIVERSAL_IDENTIFIER =\n  '0b34dd29-35e7-4082-bfd1-551513132ba1';\nexport const OPPORTUNITY_LAST_CONTACT_ITEM_CALENDAR_EVENT_FIELD_UNIVERSAL_IDENTIFIER =\n  '1f1645d4-d141-413b-a07d-c428240eed2f';\nexport const LAST_CONTACT_FOR_OPPORTUNITIES_ON_MESSAGE_FIELD_UNIVERSAL_IDENTIFIER =\n  '1ccff5c2-44c3-4a7d-847f-c74440fe56a9';\nexport const LAST_CONTACT_FOR_OPPORTUNITIES_ON_CALENDAR_EVENT_FIELD_UNIVERSAL_IDENTIFIER =\n  'db36a44e-a6dc-4bec-a23e-3b27f63d1629';\n", "export const chunk = <TItem>(items: TItem[], size: number): TItem[][] => {\n  const chunks: TItem[][] = [];\n\n  for (let index = 0; index < items.length; index += size) {\n    chunks.push(items.slice(index, index + size));\n  }\n\n  return chunks;\n};\n", "const MAX_ATTEMPTS = 5;\nconst INITIAL_RETRY_DELAY_MS = 2_000;\nconst MAX_RETRY_DELAY_MS = 30_000;\nconst MAX_JITTER_MS = 1_000;\n\n// The client SDK surfaces HTTP failures as plain Error messages built from the\n// status text and raw response body, so retryability has to be detected from\n// the message text. Covers rate limiting (429, Cloudflare 1015), transient\n// gateway errors (502/503/504) and network-level failures.\nconst RETRYABLE_ERROR_PATTERN =\n  /\\b(429|1015|too many requests|rate ?limit\\w*|502|503|504|bad gateway|gateway time-?out|service unavailable|timed? ?out|fetch failed|econnreset|econnrefused|socket hang up)\\b/i;\n\nconst sleep = (durationMs: number): Promise<void> =>\n  new Promise((resolve) => setTimeout(resolve, durationMs));\n\nconst getErrorMessage = (error: unknown): string =>\n  error instanceof Error ? error.message : String(error);\n\nconst isRetryableError = (error: unknown): boolean =>\n  RETRYABLE_ERROR_PATTERN.test(getErrorMessage(error));\n\nconst parseRetryAfterMs = (error: unknown): number | undefined => {\n  const match = getErrorMessage(error).match(/\"retry_after\"\\s*:\\s*(\\d+)/);\n  return match ? Number(match[1]) * 1_000 : undefined;\n};\n\nexport const executeWithRetry = async <TResult>(\n  execute: () => TResult,\n): Promise<Awaited<TResult>> => {\n  for (let attempt = 1; ; attempt += 1) {\n    try {\n      return await execute();\n    } catch (error) {\n      if (attempt >= MAX_ATTEMPTS || !isRetryableError(error)) {\n        throw error;\n      }\n\n      const backoffMs = Math.min(\n        INITIAL_RETRY_DELAY_MS * 2 ** (attempt - 1),\n        MAX_RETRY_DELAY_MS,\n      );\n      const retryAfterMs = Math.min(\n        parseRetryAfterMs(error) ?? 0,\n        MAX_RETRY_DELAY_MS,\n      );\n      const jitterMs = Math.random() * MAX_JITTER_MS;\n\n      await sleep(Math.max(backoffMs, retryAfterMs) + jitterMs);\n    }\n  }\n};\n", "import { type CoreApiClient } from 'twenty-client-sdk/core';\n\nimport { chunk } from 'src/utils/chunk';\nimport { executeWithRetry } from 'src/utils/execute-with-retry';\nimport { type RecordUpsert } from 'src/utils/upsert-records-in-batches';\n\nconst PAGE_SIZE = 200;\n\nexport type InteractionKind = 'email' | 'meeting';\nexport type InteractionDirection = 'outbound' | 'inbound';\n\nexport type Interaction = {\n  occurredAt: string;\n  itemId: string;\n  workspaceMemberId: string | null;\n} & ({ kind: 'email'; direction: InteractionDirection } | { kind: 'meeting' });\n\nexport type PersonLastContactState = {\n  lastContactAt?: string | null;\n  lastOutboundAt?: string | null;\n  lastInboundAt?: string | null;\n  lastEmail?: { receivedAt: string | null } | null;\n  lastMeeting?: { startsAt: string | null } | null;\n};\n\nconst isNewer = (\n  candidate: string,\n  current: string | null | undefined,\n): boolean => !current || current < candidate;\n\nconst touchesOutbound = (interaction: Interaction): boolean =>\n  interaction.kind === 'meeting' || interaction.direction === 'outbound';\n\nconst touchesInbound = (interaction: Interaction): boolean =>\n  interaction.kind === 'meeting' || interaction.direction === 'inbound';\n\nconst pickLatest = (\n  interactions: Interaction[],\n  matches: (interaction: Interaction) => boolean = () => true,\n): Interaction | undefined =>\n  interactions.reduce<Interaction | undefined>(\n    (latest, interaction) =>\n      matches(interaction) &&\n      (!latest || interaction.occurredAt > latest.occurredAt)\n        ? interaction\n        : latest,\n    undefined,\n  );\n\nexport const pickLatestInteraction = (\n  interactions: Interaction[],\n): Interaction | undefined => pickLatest(interactions);\n\nexport const collectPersonLastContactState = async (\n  client: CoreApiClient,\n  personIds: string[],\n): Promise<Map<string, PersonLastContactState>> => {\n  const stateByPersonId = new Map<string, PersonLastContactState>();\n\n  for (const ids of chunk(personIds, PAGE_SIZE)) {\n    let after: string | undefined;\n\n    do {\n      const { people } = await executeWithRetry(() =>\n        client.query({\n          people: {\n            __args: { filter: { id: { in: ids } }, first: PAGE_SIZE, after },\n            edges: {\n              node: {\n                id: true,\n                lastContactAt: true,\n                lastOutboundAt: true,\n                lastInboundAt: true,\n                lastEmail: { receivedAt: true },\n                lastMeeting: { startsAt: true },\n              },\n            },\n            pageInfo: { hasNextPage: true, endCursor: true },\n          },\n        }),\n      );\n\n      for (const edge of people?.edges ?? []) {\n        const { id, ...state } = edge.node as PersonLastContactState & {\n          id?: string | null;\n        };\n\n        if (id) {\n          stateByPersonId.set(id, state);\n        }\n      }\n\n      after = people?.pageInfo.hasNextPage\n        ? (people.pageInfo.endCursor ?? undefined)\n        : undefined;\n    } while (after);\n  }\n\n  return stateByPersonId;\n};\n\nexport const buildPersonLastContactUpdate = (\n  personId: string,\n  current: PersonLastContactState,\n  interactions: Interaction[],\n): RecordUpsert | undefined => {\n  const latestContact = pickLatest(interactions);\n\n  if (!latestContact) {\n    return undefined;\n  }\n\n  const data: Record<string, string | null> = {};\n  const occurredAt = latestContact.occurredAt;\n\n  if (isNewer(occurredAt, current.lastContactAt)) {\n    data.lastContactAt = occurredAt;\n    data.lastContactById = latestContact.workspaceMemberId ?? null;\n    if (latestContact.kind === 'email') {\n      data.lastContactItemMessageId = latestContact.itemId;\n      data.lastContactItemCalendarEventId = null;\n    } else {\n      data.lastContactItemCalendarEventId = latestContact.itemId;\n      data.lastContactItemMessageId = null;\n    }\n  }\n\n  const latestOutbound = pickLatest(interactions, touchesOutbound);\n  const latestInbound = pickLatest(interactions, touchesInbound);\n  const latestEmail = pickLatest(\n    interactions,\n    (interaction) => interaction.kind === 'email',\n  );\n  const latestMeeting = pickLatest(\n    interactions,\n    (interaction) => interaction.kind === 'meeting',\n  );\n\n  if (\n    latestOutbound &&\n    isNewer(latestOutbound.occurredAt, current.lastOutboundAt)\n  ) {\n    data.lastOutboundAt = latestOutbound.occurredAt;\n  }\n  if (\n    latestInbound &&\n    isNewer(latestInbound.occurredAt, current.lastInboundAt)\n  ) {\n    data.lastInboundAt = latestInbound.occurredAt;\n  }\n  if (\n    latestEmail &&\n    isNewer(latestEmail.occurredAt, current.lastEmail?.receivedAt)\n  ) {\n    data.lastEmailId = latestEmail.itemId;\n  }\n  if (\n    latestMeeting &&\n    isNewer(latestMeeting.occurredAt, current.lastMeeting?.startsAt)\n  ) {\n    data.lastMeetingId = latestMeeting.itemId;\n  }\n\n  if (Object.keys(data).length === 0) {\n    return undefined;\n  }\n\n  return { id: personId, ...data };\n};\n", "import { type CoreApiClient } from 'twenty-client-sdk/core';\n\nimport { chunk } from 'src/utils/chunk';\nimport { executeWithRetry } from 'src/utils/execute-with-retry';\n\nconst QUERY_MAX_RECORDS = 200;\n\nexport type UpsertMutationName =\n  | 'createPeople'\n  | 'createCompanies'\n  | 'createOpportunities';\n\nexport type RecordUpsert = { id: string } & Record<string, string | null>;\n\nexport const upsertRecordsInBatches = async (\n  client: CoreApiClient,\n  mutationName: UpsertMutationName,\n  records: RecordUpsert[],\n): Promise<void> => {\n  for (const batch of chunk(records, QUERY_MAX_RECORDS)) {\n    await executeWithRetry(() =>\n      client.mutation({\n        [mutationName]: {\n          __args: { data: batch, upsert: true },\n          id: true,\n        },\n      }),\n    );\n  }\n};\n", "import { type CoreApiClient } from 'twenty-client-sdk/core';\n\nimport { chunk } from 'src/utils/chunk';\nimport { executeWithRetry } from 'src/utils/execute-with-retry';\nimport { type InteractionKind } from 'src/utils/update-person-last-contact';\nimport {\n  type RecordUpsert,\n  upsertRecordsInBatches,\n} from 'src/utils/upsert-records-in-batches';\n\nconst PAGE_SIZE = 200;\n\nexport type RelatedInteraction = {\n  occurredAt: string;\n  itemId: string;\n  kind: InteractionKind;\n};\n\ntype OpportunityLink = {\n  opportunityId: string;\n  pointOfContactId: string;\n  lastContactAt: string | null;\n};\n\nconst isNewer = (\n  candidate: string,\n  current: string | null | undefined,\n): boolean => !current || current < candidate;\n\nconst buildData = ({\n  occurredAt,\n  itemId,\n  kind,\n}: RelatedInteraction): Record<string, string | null> => ({\n  lastContactAt: occurredAt,\n  lastContactItemMessageId: kind === 'email' ? itemId : null,\n  lastContactItemCalendarEventId: kind === 'meeting' ? itemId : null,\n});\n\nconst collectCompanyIdByPersonId = async (\n  client: CoreApiClient,\n  personIds: string[],\n): Promise<Map<string, string>> => {\n  const companyIdByPersonId = new Map<string, string>();\n\n  for (const ids of chunk(personIds, PAGE_SIZE)) {\n    let after: string | undefined;\n\n    do {\n      const { people } = await executeWithRetry(() =>\n        client.query({\n          people: {\n            __args: { filter: { id: { in: ids } }, first: PAGE_SIZE, after },\n            edges: { node: { id: true, companyId: true } },\n            pageInfo: { hasNextPage: true, endCursor: true },\n          },\n        }),\n      );\n\n      for (const edge of people?.edges ?? []) {\n        const { id, companyId } = edge.node;\n\n        if (id && companyId) {\n          companyIdByPersonId.set(id, companyId);\n        }\n      }\n\n      after = people?.pageInfo.hasNextPage\n        ? (people.pageInfo.endCursor ?? undefined)\n        : undefined;\n    } while (after);\n  }\n\n  return companyIdByPersonId;\n};\n\nconst collectCompanyLastContactAt = async (\n  client: CoreApiClient,\n  companyIds: string[],\n): Promise<Map<string, string | null>> => {\n  const lastContactAtByCompanyId = new Map<string, string | null>();\n\n  for (const ids of chunk(companyIds, PAGE_SIZE)) {\n    let after: string | undefined;\n\n    do {\n      const { companies } = await executeWithRetry(() =>\n        client.query({\n          companies: {\n            __args: { filter: { id: { in: ids } }, first: PAGE_SIZE, after },\n            edges: { node: { id: true, lastContactAt: true } },\n            pageInfo: { hasNextPage: true, endCursor: true },\n          },\n        }),\n      );\n\n      for (const edge of companies?.edges ?? []) {\n        const { id, lastContactAt } = edge.node;\n\n        if (id) {\n          lastContactAtByCompanyId.set(id, lastContactAt ?? null);\n        }\n      }\n\n      after = companies?.pageInfo.hasNextPage\n        ? (companies.pageInfo.endCursor ?? undefined)\n        : undefined;\n    } while (after);\n  }\n\n  return lastContactAtByCompanyId;\n};\n\nconst collectOpportunityLinks = async (\n  client: CoreApiClient,\n  personIds: string[],\n): Promise<OpportunityLink[]> => {\n  const links: OpportunityLink[] = [];\n\n  for (const ids of chunk(personIds, PAGE_SIZE)) {\n    let after: string | undefined;\n\n    do {\n      const { opportunities } = await executeWithRetry(() =>\n        client.query({\n          opportunities: {\n            __args: {\n              filter: { pointOfContactId: { in: ids } },\n              first: PAGE_SIZE,\n              after,\n            },\n            edges: {\n              node: {\n                id: true,\n                pointOfContactId: true,\n                lastContactAt: true,\n              },\n            },\n            pageInfo: { hasNextPage: true, endCursor: true },\n          },\n        }),\n      );\n\n      for (const edge of opportunities?.edges ?? []) {\n        const { id, pointOfContactId, lastContactAt } = edge.node;\n\n        if (id && pointOfContactId) {\n          links.push({\n            opportunityId: id,\n            pointOfContactId,\n            lastContactAt: lastContactAt ?? null,\n          });\n        }\n      }\n\n      after = opportunities?.pageInfo.hasNextPage\n        ? (opportunities.pageInfo.endCursor ?? undefined)\n        : undefined;\n    } while (after);\n  }\n\n  return links;\n};\n\n// Companies and opportunities surface emails and meetings from their related\n// people, so their last contact mirrors the most recent contact of any person\n// connected to them.\nexport const updateRelatedLastContactForPeople = async (\n  client: CoreApiClient,\n  contactByPersonId: Map<string, RelatedInteraction>,\n): Promise<void> => {\n  const personIds = [...contactByPersonId.keys()];\n\n  if (personIds.length === 0) {\n    return;\n  }\n\n  const companyIdByPersonId = await collectCompanyIdByPersonId(\n    client,\n    personIds,\n  );\n  const contactByCompanyId = new Map<string, RelatedInteraction>();\n\n  for (const [personId, contact] of contactByPersonId) {\n    const companyId = companyIdByPersonId.get(personId);\n\n    if (!companyId) {\n      continue;\n    }\n\n    const current = contactByCompanyId.get(companyId);\n\n    if (!current || contact.occurredAt > current.occurredAt) {\n      contactByCompanyId.set(companyId, contact);\n    }\n  }\n\n  const lastContactAtByCompanyId = await collectCompanyLastContactAt(\n    client,\n    [...contactByCompanyId.keys()],\n  );\n  const companyUpserts: RecordUpsert[] = [];\n\n  for (const [companyId, contact] of contactByCompanyId) {\n    if (!lastContactAtByCompanyId.has(companyId)) {\n      continue;\n    }\n\n    if (isNewer(contact.occurredAt, lastContactAtByCompanyId.get(companyId))) {\n      companyUpserts.push({ id: companyId, ...buildData(contact) });\n    }\n  }\n\n  await upsertRecordsInBatches(client, 'createCompanies', companyUpserts);\n\n  const opportunityLinks = await collectOpportunityLinks(client, personIds);\n  const opportunityUpserts: RecordUpsert[] = [];\n\n  for (const { opportunityId, pointOfContactId, lastContactAt } of opportunityLinks) {\n    const contact = contactByPersonId.get(pointOfContactId);\n\n    if (!contact || !isNewer(contact.occurredAt, lastContactAt)) {\n      continue;\n    }\n\n    opportunityUpserts.push({ id: opportunityId, ...buildData(contact) });\n  }\n\n  await upsertRecordsInBatches(\n    client,\n    'createOpportunities',\n    opportunityUpserts,\n  );\n};\n", "import { type CoreApiClient } from 'twenty-client-sdk/core';\n\nimport {\n  buildPersonLastContactUpdate,\n  collectPersonLastContactState,\n  type Interaction,\n  pickLatestInteraction,\n} from 'src/utils/update-person-last-contact';\nimport {\n  type RelatedInteraction,\n  updateRelatedLastContactForPeople,\n} from 'src/utils/update-related-last-contact';\nimport {\n  type RecordUpsert,\n  upsertRecordsInBatches,\n} from 'src/utils/upsert-records-in-batches';\n\nexport const applyPersonInteractions = async (\n  client: CoreApiClient,\n  interactionsByPersonId: Map<string, Interaction[]>,\n): Promise<void> => {\n  const personIds = [...interactionsByPersonId.keys()];\n\n  if (personIds.length === 0) {\n    return;\n  }\n\n  const stateByPersonId = await collectPersonLastContactState(\n    client,\n    personIds,\n  );\n  const updates: RecordUpsert[] = [];\n  const contactByPersonId = new Map<string, RelatedInteraction>();\n\n  for (const [personId, interactions] of interactionsByPersonId) {\n    const current = stateByPersonId.get(personId);\n\n    if (!current) {\n      continue;\n    }\n\n    const update = buildPersonLastContactUpdate(\n      personId,\n      current,\n      interactions,\n    );\n\n    if (update) {\n      updates.push(update);\n    }\n\n    const latest = pickLatestInteraction(interactions);\n\n    if (latest) {\n      contactByPersonId.set(personId, {\n        occurredAt: latest.occurredAt,\n        itemId: latest.itemId,\n        kind: latest.kind,\n      });\n    }\n  }\n\n  await upsertRecordsInBatches(client, 'createPeople', updates);\n  await updateRelatedLastContactForPeople(client, contactByPersonId);\n};\n", "export type Participant = {\n  workspaceMemberId?: string | null;\n  role?: string | null;\n  isOrganizer?: boolean | null;\n};\n\nexport const pickContactTeamMemberId = (\n  participants: Participant[],\n  prefer: { role: 'FROM' } | { isOrganizer: true },\n): string | null => {\n  const members = participants.filter((participant) =>\n    Boolean(participant.workspaceMemberId),\n  );\n\n  if (members.length === 0) {\n    return null;\n  }\n\n  const preferred = members.find((participant) =>\n    'role' in prefer\n      ? participant.role === prefer.role\n      : participant.isOrganizer === true,\n  );\n\n  return (preferred ?? members[0]).workspaceMemberId ?? null;\n};\n", "import { type CoreApiClient } from 'twenty-client-sdk/core';\n\nimport { chunk } from 'src/utils/chunk';\nimport { executeWithRetry } from 'src/utils/execute-with-retry';\nimport {\n  pickContactTeamMemberId,\n  type Participant,\n} from 'src/utils/pick-contact-team-member';\nimport { type InteractionDirection } from 'src/utils/update-person-last-contact';\n\nconst PAGE_SIZE = 200;\n\nexport type MessageInteraction = {\n  receivedAt: string;\n  workspaceMemberId: string | null;\n  direction: InteractionDirection;\n};\n\ntype MessageParticipantNode = Participant & {\n  messageId?: string | null;\n  message?: { receivedAt: string | null } | null;\n};\n\nexport const collectMessageInteractions = async (\n  client: CoreApiClient,\n  messageIds: string[],\n): Promise<Map<string, MessageInteraction>> => {\n  const participantsByMessageId = new Map<string, MessageParticipantNode[]>();\n\n  for (const ids of chunk(messageIds, PAGE_SIZE)) {\n    let after: string | undefined;\n\n    do {\n      const { messageParticipants } = await executeWithRetry(() =>\n        client.query({\n          messageParticipants: {\n            __args: {\n              filter: { messageId: { in: ids } },\n              first: PAGE_SIZE,\n              after,\n            },\n            edges: {\n              node: {\n                messageId: true,\n                role: true,\n                workspaceMemberId: true,\n                message: { receivedAt: true },\n              },\n            },\n            pageInfo: { hasNextPage: true, endCursor: true },\n          },\n        }),\n      );\n\n      for (const edge of messageParticipants?.edges ?? []) {\n        const node = edge.node as MessageParticipantNode;\n\n        if (!node.messageId) {\n          continue;\n        }\n\n        const participants = participantsByMessageId.get(node.messageId);\n\n        if (participants) {\n          participants.push(node);\n        } else {\n          participantsByMessageId.set(node.messageId, [node]);\n        }\n      }\n\n      after = messageParticipants?.pageInfo.hasNextPage\n        ? (messageParticipants.pageInfo.endCursor ?? undefined)\n        : undefined;\n    } while (after);\n  }\n\n  const interactionByMessageId = new Map<string, MessageInteraction>();\n\n  for (const [messageId, participants] of participantsByMessageId) {\n    const receivedAt = participants[0]?.message?.receivedAt ?? null;\n\n    if (!receivedAt) {\n      continue;\n    }\n\n    const fromParticipant = participants.find(\n      (participant) => participant.role === 'FROM',\n    );\n\n    interactionByMessageId.set(messageId, {\n      receivedAt,\n      workspaceMemberId: pickContactTeamMemberId(participants, {\n        role: 'FROM',\n      }),\n      direction: fromParticipant?.workspaceMemberId ? 'outbound' : 'inbound',\n    });\n  }\n\n  return interactionByMessageId;\n};\n", "import { type CoreApiClient } from 'twenty-client-sdk/core';\n\nimport { applyPersonInteractions } from 'src/utils/apply-person-interactions';\nimport { collectMessageInteractions } from 'src/utils/collect-message-interactions';\nimport { type Interaction } from 'src/utils/update-person-last-contact';\n\nexport type MessageParticipantLink = {\n  personId: string;\n  messageId: string;\n};\n\nexport const applyEmailInteractions = async (\n  client: CoreApiClient,\n  links: MessageParticipantLink[],\n): Promise<void> => {\n  const messageIds = [...new Set(links.map((link) => link.messageId))];\n\n  if (messageIds.length === 0) {\n    return;\n  }\n\n  const interactionByMessageId = await collectMessageInteractions(\n    client,\n    messageIds,\n  );\n  const interactionsByPersonId = new Map<string, Interaction[]>();\n\n  for (const { personId, messageId } of links) {\n    const message = interactionByMessageId.get(messageId);\n\n    if (!message) {\n      continue;\n    }\n\n    const interaction: Interaction = {\n      kind: 'email',\n      occurredAt: message.receivedAt,\n      itemId: messageId,\n      workspaceMemberId: message.workspaceMemberId,\n      direction: message.direction,\n    };\n    const interactions = interactionsByPersonId.get(personId);\n\n    if (interactions) {\n      interactions.push(interaction);\n    } else {\n      interactionsByPersonId.set(personId, [interaction]);\n    }\n  }\n\n  await applyPersonInteractions(client, interactionsByPersonId);\n};\n"],
  "mappings": ";;;;AAIA,IAAM,sBAAsB,CAAC,Y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