{
  "version": 3,
  "sources": ["twenty-sdk-define-stub:__twenty-sdk-define-stub__", "../../../../src/logic-functions/on-company-created.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/collect-existing-record-ids.ts", "../../../../src/utils/upsert-records-in-batches.ts", "../../../../src/utils/recompute-company-last-contact.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 ObjectRecordCreateEvent,\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 { COMPANY_CREATED_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER } from 'src/constants/universal-identifiers';\nimport { recomputeCompaniesLastContact } from 'src/utils/recompute-company-last-contact';\n\ntype CompanyCreate = { id?: string | null };\n\nconst handler = async (\n  batch: DatabaseEventBatchPayload<ObjectRecordCreateEvent<CompanyCreate>>,\n): Promise<void> => {\n  const companyIds = new Set<string>();\n\n  for (const event of batch.events) {\n    const companyId = event.properties.after.id ?? event.recordId;\n\n    if (companyId) {\n      companyIds.add(companyId);\n    }\n  }\n\n  if (companyIds.size === 0) {\n    return;\n  }\n\n  await recomputeCompaniesLastContact(new CoreApiClient(), [...companyIds]);\n};\n\nexport default defineLogicFunction({\n  universalIdentifier: COMPANY_CREATED_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER,\n  name: 'on-company-created',\n  description:\n    \"Computes a company's last contact from its people when the company is created.\",\n  timeoutSeconds: BATCH_HANDLER_TIMEOUT_SECONDS,\n  databaseEventTriggerSettings: {\n    eventName: 'company.created',\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';\n\nconst PAGE_SIZE = 200;\n\nexport type RecordQueryField = 'people' | 'companies' | 'opportunities';\n\nexport const collectExistingRecordIds = async (\n  client: CoreApiClient,\n  queryField: RecordQueryField,\n  recordIds: string[],\n): Promise<Set<string>> => {\n  const existingRecordIds = new Set<string>();\n\n  for (const ids of chunk(recordIds, PAGE_SIZE)) {\n    let after: string | undefined;\n\n    do {\n      const result = await executeWithRetry(() =>\n        client.query({\n          [queryField]: {\n            __args: { filter: { id: { in: ids } }, first: PAGE_SIZE, after },\n            edges: { node: { id: true } },\n            pageInfo: { hasNextPage: true, endCursor: true },\n          },\n        }),\n      );\n      const connection = result?.[queryField];\n\n      for (const edge of connection?.edges ?? []) {\n        if (edge.node.id) {\n          existingRecordIds.add(edge.node.id);\n        }\n      }\n\n      after = connection?.pageInfo.hasNextPage\n        ? (connection.pageInfo.endCursor ?? undefined)\n        : undefined;\n    } while (after);\n  }\n\n  return existingRecordIds;\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 { collectExistingRecordIds } from 'src/utils/collect-existing-record-ids';\nimport { executeWithRetry } from 'src/utils/execute-with-retry';\nimport {\n  type RecordUpsert,\n  upsertRecordsInBatches,\n} from 'src/utils/upsert-records-in-batches';\n\nconst PAGE_SIZE = 200;\nconst MAX_SCAN_PAGES = 5;\n\nconst EMPTY_LAST_CONTACT: Record<string, string | null> = {\n  lastContactAt: null,\n  lastContactItemMessageId: null,\n  lastContactItemCalendarEventId: null,\n};\n\ntype PersonNode = {\n  companyId?: string | null;\n  lastContactAt?: string | null;\n  lastContactItemMessage?: { id: string } | null;\n  lastContactItemCalendarEvent?: { id: string } | null;\n};\n\nconst PERSON_LAST_CONTACT_SELECTION = {\n  companyId: true,\n  lastContactAt: true,\n  lastContactItemMessage: { id: true },\n  lastContactItemCalendarEvent: { id: true },\n};\n\nconst buildLastContactData = (\n  person: PersonNode,\n): Record<string, string | null> => ({\n  lastContactAt: person.lastContactAt ?? null,\n  lastContactItemMessageId: person.lastContactItemMessage?.id ?? null,\n  lastContactItemCalendarEventId:\n    person.lastContactItemCalendarEvent?.id ?? null,\n});\n\nconst fetchTopPersonForCompany = async (\n  client: CoreApiClient,\n  companyId: string,\n): Promise<PersonNode | undefined> => {\n  const { people } = await executeWithRetry(() =>\n    client.query({\n      people: {\n        __args: {\n          filter: {\n            companyId: { eq: companyId },\n            lastContactAt: { is: 'NOT_NULL' },\n          },\n          orderBy: [{ lastContactAt: 'DescNullsLast' }],\n          first: 1,\n        },\n        edges: { node: PERSON_LAST_CONTACT_SELECTION },\n      },\n    }),\n  );\n\n  return people?.edges?.[0]?.node as PersonNode | undefined;\n};\n\nconst collectTopPersonByCompanyId = async (\n  client: CoreApiClient,\n  companyIds: string[],\n): Promise<Map<string, PersonNode>> => {\n  const topPersonByCompanyId = new Map<string, PersonNode>();\n  const unresolvedCompanyIds = new Set(companyIds);\n\n  let after: string | undefined;\n  let scannedPages = 0;\n  let hasNextPage = false;\n\n  do {\n    const { people } = await executeWithRetry(() =>\n      client.query({\n        people: {\n          __args: {\n            filter: {\n              companyId: { in: companyIds },\n              lastContactAt: { is: 'NOT_NULL' },\n            },\n            orderBy: [{ lastContactAt: 'DescNullsLast' }],\n            first: PAGE_SIZE,\n            after,\n          },\n          edges: { node: PERSON_LAST_CONTACT_SELECTION },\n          pageInfo: { hasNextPage: true, endCursor: true },\n        },\n      }),\n    );\n\n    for (const edge of people?.edges ?? []) {\n      const person = edge.node as PersonNode;\n      const companyId = person.companyId;\n\n      if (companyId && unresolvedCompanyIds.has(companyId)) {\n        topPersonByCompanyId.set(companyId, person);\n        unresolvedCompanyIds.delete(companyId);\n      }\n    }\n\n    scannedPages += 1;\n    hasNextPage = people?.pageInfo.hasNextPage ?? false;\n    after = hasNextPage ? (people?.pageInfo.endCursor ?? undefined) : undefined;\n  } while (\n    after &&\n    unresolvedCompanyIds.size > 0 &&\n    scannedPages < MAX_SCAN_PAGES\n  );\n\n  if (hasNextPage) {\n    for (const companyId of unresolvedCompanyIds) {\n      const topPerson = await fetchTopPersonForCompany(client, companyId);\n\n      if (topPerson) {\n        topPersonByCompanyId.set(companyId, topPerson);\n      }\n    }\n  }\n\n  return topPersonByCompanyId;\n};\n\nexport const recomputeCompaniesLastContact = async (\n  client: CoreApiClient,\n  companyIds: string[],\n): Promise<void> => {\n  if (companyIds.length === 0) {\n    return;\n  }\n\n  const [topPersonByCompanyId, existingCompanyIds] = await Promise.all([\n    collectTopPersonByCompanyId(client, companyIds),\n    collectExistingRecordIds(client, 'companies', companyIds),\n  ]);\n\n  const upserts: RecordUpsert[] = companyIds\n    .filter((companyId) => existingCompanyIds.has(companyId))\n    .map((companyId) => {\n      const topPerson = topPersonByCompanyId.get(companyId);\n\n      return {\n        id: companyId,\n        ...(topPerson ? buildLastContactData(topPerson) : EMPTY_LAST_CONTACT),\n      };\n    });\n\n  await upsertRecordsInBatches(client, 'createCompanies', upserts);\n};\n"],
  "mappings": ";;;;AAIA,IAAM,sBAAsB,CAAC,YAAY;AAAA,EACvC,SAAS;AAAA,EACT;AAAA,EACA,QAAQ,CAAC;AACX;AAEA,IAAM,eAAe;AAAA,EACnB,IAAI,SAAS,MAAM;AACjB,QAAI,SAAS,aAAc,QAAO;AAClC,QAAI,SAAS,OAAO,YAAa,QAAO,MAAM;AAC9C,QAAI,OAAO,SAAS,SAAU,QAAO;AACrC,WAAO,IAAI,MAAM,MAAM,QAAW,YAAY;AAAA,EAChD;AAAA,EACA,QAAQ;AACN,WAAO,IAAI,MAAM,MAAM,QAAW,YAAY;AAAA,EAChD;AACF;AACA,IAAM,YAAY,IAAI,MAAM,MAAM,QAAW,YAAY;AAWlD,IAAM,sBAAsB;;;AC3B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