{
  "version": 3,
  "sources": ["../../../../src/logic-functions/backfill-people-last-contact.ts", "twenty-sdk-define-stub:__twenty-sdk-define-stub__", "../../../../src/constants/universal-identifiers.ts", "../../../../src/utils/backfill-batch-args.ts", "../../../../src/constants/backfill.ts", "../../../../src/utils/backfill-settings.ts", "../../../../src/utils/execute-with-retry.ts", "../../../../src/utils/chunk.ts", "../../../../src/utils/person-last-contact-aggregation.ts", "../../../../src/utils/upsert-records-in-batches.ts"],
  "sourcesContent": ["import { CoreApiClient } from 'twenty-client-sdk/core';\nimport { defineLogicFunction } from 'twenty-sdk/define';\n\nimport { type BackfillBatchPayload } from 'src/constants/backfill';\nimport { BACKFILL_PEOPLE_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER } from 'src/constants/universal-identifiers';\nimport { buildBackfillBatchArgs } from 'src/utils/backfill-batch-args';\nimport { getBackfillBatchSize } from 'src/utils/backfill-settings';\nimport { executeWithRetry } from 'src/utils/execute-with-retry';\nimport {\n  buildPersonAggregates,\n  buildPersonUpdateData,\n} from 'src/utils/person-last-contact-aggregation';\nimport {\n  type RecordUpsert,\n  upsertRecordsInBatches,\n} from 'src/utils/upsert-records-in-batches';\n\nconst handler = async ({ batchId }: BackfillBatchPayload): Promise<object> => {\n  const client = new CoreApiClient();\n\n  const { people } = await executeWithRetry(() =>\n    client.query({\n      people: {\n        __args: buildBackfillBatchArgs(batchId, getBackfillBatchSize()),\n        edges: { node: { id: true } },\n      },\n    }),\n  );\n\n  const personIds = (people?.edges ?? [])\n    .map((edge: { node: { id: string } }) => edge.node.id)\n    .filter(Boolean);\n\n  if (personIds.length === 0) {\n    return { batchId, count: 0 };\n  }\n\n  const aggByPersonId = await buildPersonAggregates(client, personIds);\n  const upserts: RecordUpsert[] = [];\n\n  for (const personId of personIds) {\n    const agg = aggByPersonId.get(personId);\n    const data = agg ? buildPersonUpdateData(agg) : {};\n\n    if (Object.keys(data).length === 0) {\n      continue;\n    }\n\n    upserts.push({ id: personId, ...data });\n  }\n\n  await upsertRecordsInBatches(client, 'createPeople', upserts);\n\n  return { batchId, count: personIds.length };\n};\n\nexport default defineLogicFunction({\n  universalIdentifier: BACKFILL_PEOPLE_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER,\n  name: 'backfill-people-last-contact',\n  description:\n    'Backfills last-contact fields for one batch of people, resolved from the batch id in its payload.',\n  timeoutSeconds: 120,\n  handler,\n});\n", "\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", "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", "// A total order over createdAt then id keeps offset windows stable while the\n// backfill runs: newly created records sort to the tail, so the batch each job\n// owns does not shift under it.\nconst BACKFILL_ORDER_BY = [\n  { createdAt: 'AscNullsFirst' },\n  { id: 'AscNullsFirst' },\n];\n\n// Query args selecting the record window a batch job owns.\nexport const buildBackfillBatchArgs = (\n  batchId: number,\n  batchSize: number,\n): { first: number; offset: number; orderBy: typeof BACKFILL_ORDER_BY } => ({\n  first: batchSize,\n  offset: batchId * batchSize,\n  orderBy: BACKFILL_ORDER_BY,\n});\n", "import {\n  BACKFILL_COMPANIES_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER,\n  BACKFILL_OPPORTUNITIES_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER,\n  BACKFILL_PEOPLE_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER,\n} from 'src/constants/universal-identifiers';\n\nexport type BackfillPhase = 'people' | 'opportunities' | 'companies';\n\nexport const BACKFILL_PHASE_ORDER: BackfillPhase[] = [\n  'people',\n  'opportunities',\n  'companies',\n];\n\n// GraphQL query field exposing the record connection for each phase.\nexport const BACKFILL_PHASE_QUERY_FIELD: Record<BackfillPhase, string> = {\n  people: 'people',\n  opportunities: 'opportunities',\n  companies: 'companies',\n};\n\n// Logic function each phase's batch jobs are enqueued against.\nexport const BACKFILL_PHASE_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIERS: Record<\n  BackfillPhase,\n  string\n> = {\n  people: BACKFILL_PEOPLE_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER,\n  opportunities: BACKFILL_OPPORTUNITIES_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER,\n  companies: BACKFILL_COMPANIES_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER,\n};\n\n// A batch job resolves the records it owns from this index and the batch size.\nexport type BackfillBatchPayload = { batchId: number };\n\n// Server variables, injected into process.env on every execution.\nexport const BACKFILL_BATCH_SIZE_ENV_VAR_NAME =\n  'LAST_CONTACT_BACKFILL_BATCH_SIZE';\nexport const BACKFILL_SLEEP_MS_ENV_VAR_NAME = 'LAST_CONTACT_BACKFILL_SLEEP_MS';\n\nexport const DEFAULT_BACKFILL_BATCH_SIZE = 200;\nexport const DEFAULT_BACKFILL_SLEEP_MS = 1_000;\n", "import {\n  BACKFILL_BATCH_SIZE_ENV_VAR_NAME,\n  BACKFILL_SLEEP_MS_ENV_VAR_NAME,\n  DEFAULT_BACKFILL_BATCH_SIZE,\n  DEFAULT_BACKFILL_SLEEP_MS,\n} from 'src/constants/backfill';\n\n// Application and server variables are injected into process.env on every\n// execution.\nconst readPositiveInteger = (\n  envVarName: string,\n  fallback: number,\n): number => {\n  const rawValue = process.env[envVarName];\n\n  if (rawValue === undefined || rawValue.trim().length === 0) {\n    return fallback;\n  }\n\n  const parsedValue = Number(rawValue);\n\n  return Number.isInteger(parsedValue) && parsedValue > 0\n    ? parsedValue\n    : fallback;\n};\n\nexport const getBackfillBatchSize = (): number =>\n  readPositiveInteger(BACKFILL_BATCH_SIZE_ENV_VAR_NAME, DEFAULT_BACKFILL_BATCH_SIZE);\n\nexport const getBackfillSleepMs = (): number =>\n  readPositiveInteger(BACKFILL_SLEEP_MS_ENV_VAR_NAME, DEFAULT_BACKFILL_SLEEP_MS);\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", "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", "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 PAGE_SIZE = 200;\n\ntype EmailInteraction = {\n  personId: string;\n  messageId: string;\n  receivedAt: string;\n};\ntype MeetingInteraction = {\n  personId: string;\n  calendarEventId: string;\n  startsAt: string;\n};\ntype MessageMemberInfo = { ownerId: string; fromIsMember: boolean };\ntype ContactItem = { kind: 'email' | 'meeting'; id: string };\n\nexport type LastContact = { at: string; item: ContactItem };\nexport type PersonUpdateData = Record<string, string | null>;\n\nexport type PersonAgg = {\n  lastContactAt?: string;\n  lastContactById?: string | null;\n  item?: ContactItem;\n  lastOutboundAt?: string;\n  lastInboundAt?: string;\n  lastEmail?: { at: string; id: string };\n  lastMeeting?: { at: string; id: string };\n};\n\nconst collectEmailInteractions = async (\n  client: CoreApiClient,\n  personIds: string[],\n): Promise<EmailInteraction[]> => {\n  const interactions: EmailInteraction[] = [];\n\n  for (const ids of chunk(personIds, PAGE_SIZE)) {\n    let after: string | undefined;\n\n    do {\n      const { messageParticipants } = await executeWithRetry(() =>\n        client.query({\n          messageParticipants: {\n            __args: {\n              filter: { personId: { in: ids } },\n              first: PAGE_SIZE,\n              after,\n            },\n            edges: {\n              node: {\n                id: true,\n                personId: true,\n                message: { id: true, receivedAt: true },\n              },\n            },\n            pageInfo: { hasNextPage: true, endCursor: true },\n          },\n        }),\n      );\n\n      for (const edge of messageParticipants?.edges ?? []) {\n        const { personId, message } = edge.node;\n        if (personId && message?.id && message?.receivedAt) {\n          interactions.push({\n            personId,\n            messageId: message.id,\n            receivedAt: message.receivedAt,\n          });\n        }\n      }\n\n      after = messageParticipants?.pageInfo.hasNextPage\n        ? (messageParticipants.pageInfo.endCursor ?? undefined)\n        : undefined;\n    } while (after);\n  }\n\n  return interactions;\n};\n\nconst collectMeetingInteractions = async (\n  client: CoreApiClient,\n  personIds: string[],\n): Promise<MeetingInteraction[]> => {\n  const now = new Date().toISOString();\n  const interactions: MeetingInteraction[] = [];\n\n  for (const ids of chunk(personIds, PAGE_SIZE)) {\n    let after: string | undefined;\n\n    do {\n      const { calendarEventParticipants } = await executeWithRetry(() =>\n        client.query({\n          calendarEventParticipants: {\n            __args: {\n              filter: { personId: { in: ids } },\n              first: PAGE_SIZE,\n              after,\n            },\n            edges: {\n              node: {\n                id: true,\n                personId: true,\n                calendarEvent: { id: true, startsAt: true, isCanceled: true },\n              },\n            },\n            pageInfo: { hasNextPage: true, endCursor: true },\n          },\n        }),\n      );\n\n      for (const edge of calendarEventParticipants?.edges ?? []) {\n        const { personId, calendarEvent } = edge.node;\n        if (\n          personId &&\n          calendarEvent?.id &&\n          calendarEvent?.startsAt &&\n          !calendarEvent.isCanceled &&\n          calendarEvent.startsAt <= now\n        ) {\n          interactions.push({\n            personId,\n            calendarEventId: calendarEvent.id,\n            startsAt: calendarEvent.startsAt,\n          });\n        }\n      }\n\n      after = calendarEventParticipants?.pageInfo.hasNextPage\n        ? (calendarEventParticipants.pageInfo.endCursor ?? undefined)\n        : undefined;\n    } while (after);\n  }\n\n  return interactions;\n};\n\nconst collectMessageMemberInfo = async (\n  client: CoreApiClient,\n  messageIds: string[],\n): Promise<Map<string, MessageMemberInfo>> => {\n  const infoByMessageId = new Map<string, MessageMemberInfo>();\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: {\n                messageId: { in: ids },\n                workspaceMemberId: { is: 'NOT_NULL' },\n              },\n              first: PAGE_SIZE,\n              after,\n            },\n            edges: {\n              node: { messageId: true, role: true, workspaceMemberId: true },\n            },\n            pageInfo: { hasNextPage: true, endCursor: true },\n          },\n        }),\n      );\n\n      for (const edge of messageParticipants?.edges ?? []) {\n        const { messageId, role, workspaceMemberId } = edge.node;\n        if (!messageId || !workspaceMemberId) {\n          continue;\n        }\n        const info = infoByMessageId.get(messageId) ?? {\n          ownerId: workspaceMemberId,\n          fromIsMember: false,\n        };\n        if (role === 'FROM') {\n          info.ownerId = workspaceMemberId;\n          info.fromIsMember = true;\n        }\n        infoByMessageId.set(messageId, info);\n      }\n\n      after = messageParticipants?.pageInfo.hasNextPage\n        ? (messageParticipants.pageInfo.endCursor ?? undefined)\n        : undefined;\n    } while (after);\n  }\n\n  return infoByMessageId;\n};\n\nconst collectCalendarOwners = async (\n  client: CoreApiClient,\n  calendarEventIds: string[],\n): Promise<Map<string, string>> => {\n  const ownerByCalendarEventId = new Map<string, string>();\n\n  for (const ids of chunk(calendarEventIds, PAGE_SIZE)) {\n    let after: string | undefined;\n\n    do {\n      const { calendarEventParticipants } = await executeWithRetry(() =>\n        client.query({\n          calendarEventParticipants: {\n            __args: {\n              filter: {\n                calendarEventId: { in: ids },\n                workspaceMemberId: { is: 'NOT_NULL' },\n              },\n              first: PAGE_SIZE,\n              after,\n            },\n            edges: {\n              node: {\n                calendarEventId: true,\n                isOrganizer: true,\n                workspaceMemberId: true,\n              },\n            },\n            pageInfo: { hasNextPage: true, endCursor: true },\n          },\n        }),\n      );\n\n      for (const edge of calendarEventParticipants?.edges ?? []) {\n        const { calendarEventId, isOrganizer, workspaceMemberId } = edge.node;\n        if (\n          calendarEventId &&\n          workspaceMemberId &&\n          (!ownerByCalendarEventId.has(calendarEventId) || isOrganizer === true)\n        ) {\n          ownerByCalendarEventId.set(calendarEventId, workspaceMemberId);\n        }\n      }\n\n      after = calendarEventParticipants?.pageInfo.hasNextPage\n        ? (calendarEventParticipants.pageInfo.endCursor ?? undefined)\n        : undefined;\n    } while (after);\n  }\n\n  return ownerByCalendarEventId;\n};\n\nconst foldEmail = (\n  agg: PersonAgg,\n  receivedAt: string,\n  messageId: string,\n  info: MessageMemberInfo | undefined,\n): void => {\n  if (!agg.lastEmail || receivedAt > agg.lastEmail.at) {\n    agg.lastEmail = { at: receivedAt, id: messageId };\n  }\n  if (info?.fromIsMember) {\n    if (!agg.lastOutboundAt || receivedAt > agg.lastOutboundAt) {\n      agg.lastOutboundAt = receivedAt;\n    }\n  } else if (!agg.lastInboundAt || receivedAt > agg.lastInboundAt) {\n    agg.lastInboundAt = receivedAt;\n  }\n  if (!agg.lastContactAt || receivedAt > agg.lastContactAt) {\n    agg.lastContactAt = receivedAt;\n    agg.lastContactById = info?.ownerId ?? null;\n    agg.item = { kind: 'email', id: messageId };\n  }\n};\n\nconst foldMeeting = (\n  agg: PersonAgg,\n  startsAt: string,\n  calendarEventId: string,\n  ownerId: string | null,\n): void => {\n  if (!agg.lastMeeting || startsAt > agg.lastMeeting.at) {\n    agg.lastMeeting = { at: startsAt, id: calendarEventId };\n  }\n  if (!agg.lastOutboundAt || startsAt > agg.lastOutboundAt) {\n    agg.lastOutboundAt = startsAt;\n  }\n  if (!agg.lastInboundAt || startsAt > agg.lastInboundAt) {\n    agg.lastInboundAt = startsAt;\n  }\n  if (!agg.lastContactAt || startsAt > agg.lastContactAt) {\n    agg.lastContactAt = startsAt;\n    agg.lastContactById = ownerId;\n    agg.item = { kind: 'meeting', id: calendarEventId };\n  }\n};\n\n// Aggregates every email and meeting interaction of the given people into one\n// last-contact snapshot per person, resolving the owning team member and the\n// inbound/outbound direction from the message and calendar participants.\nexport const buildPersonAggregates = async (\n  client: CoreApiClient,\n  personIds: string[],\n): Promise<Map<string, PersonAgg>> => {\n  const aggByPersonId = new Map<string, PersonAgg>();\n\n  if (personIds.length === 0) {\n    return aggByPersonId;\n  }\n\n  const [emails, meetings] = await Promise.all([\n    collectEmailInteractions(client, personIds),\n    collectMeetingInteractions(client, personIds),\n  ]);\n\n  const messageIds = [...new Set(emails.map((email) => email.messageId))];\n  const calendarEventIds = [\n    ...new Set(meetings.map((meeting) => meeting.calendarEventId)),\n  ];\n\n  const [messageMemberInfo, calendarOwners] = await Promise.all([\n    collectMessageMemberInfo(client, messageIds),\n    collectCalendarOwners(client, calendarEventIds),\n  ]);\n\n  const aggFor = (personId: string): PersonAgg => {\n    const existing = aggByPersonId.get(personId);\n    if (existing) {\n      return existing;\n    }\n    const created: PersonAgg = {};\n    aggByPersonId.set(personId, created);\n    return created;\n  };\n\n  for (const email of emails) {\n    foldEmail(\n      aggFor(email.personId),\n      email.receivedAt,\n      email.messageId,\n      messageMemberInfo.get(email.messageId),\n    );\n  }\n  for (const meeting of meetings) {\n    foldMeeting(\n      aggFor(meeting.personId),\n      meeting.startsAt,\n      meeting.calendarEventId,\n      calendarOwners.get(meeting.calendarEventId) ?? null,\n    );\n  }\n\n  return aggByPersonId;\n};\n\nexport const pickPersonLastContact = (\n  agg: PersonAgg | undefined,\n): LastContact | undefined =>\n  agg?.lastContactAt && agg.item\n    ? { at: agg.lastContactAt, item: agg.item }\n    : undefined;\n\nexport const pickLatestLastContact = (\n  contacts: LastContact[],\n): LastContact | undefined =>\n  contacts.reduce<LastContact | undefined>(\n    (latest, contact) =>\n      !latest || contact.at > latest.at ? contact : latest,\n    undefined,\n  );\n\nexport const buildPersonUpdateData = (agg: PersonAgg): PersonUpdateData => ({\n  ...(agg.lastContactAt\n    ? {\n        lastContactAt: agg.lastContactAt,\n        lastContactById: agg.lastContactById ?? null,\n      }\n    : {}),\n  ...(agg.lastOutboundAt ? { lastOutboundAt: agg.lastOutboundAt } : {}),\n  ...(agg.lastInboundAt ? { lastInboundAt: agg.lastInboundAt } : {}),\n  ...(agg.lastEmail ? { lastEmailId: agg.lastEmail.id } : {}),\n  ...(agg.lastMeeting ? { lastMeetingId: agg.lastMeeting.id } : {}),\n  ...(agg.item?.kind === 'email'\n    ? {\n        lastContactItemMessageId: agg.item.id,\n        lastContactItemCalendarEventId: null,\n      }\n    : agg.item?.kind === 'meeting'\n      ? {\n          lastContactItemCalendarEventId: agg.item.id,\n          lastContactItemMessageId: null,\n        }\n      : {}),\n});\n\nexport const buildRelatedUpdateData = ({\n  at,\n  item,\n}: LastContact): PersonUpdateData => ({\n  lastContactAt: at,\n  lastContactItemMessageId: item.kind === 'email' ? item.id : null,\n  lastContactItemCalendarEventId: item.kind === 'meeting' ? item.id : 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';\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"],
  "mappings": ";;;;AAA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