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AA,OAAO;AAAA,MACN,GAAG,UAAA;AAAA,MACH,WAAA;AAAA,MACA;AAAA,KACD;AAAA,EACD,CAAA,CAAA,MAAQ;AACP,IAAA,OAAO,IAAA;AAAA,EACR;AACD;AAKA,eAAsB,oBAAA,CACrB,KACA,SAAA,EACmB;AACnB,EAAA,MAAM,IAAA,GAAO,SAAA,CAAU,IAAA,CAAK,GAAG,CAAA;AAC/B,EAAA,MAAM,WAAW,MAAM,GAAA,CAAI,GAAA,CAAI,CAAA,4BAAA,EAA+B,IAAI,CAAA,CAAE,CAAA;AACpE,EAAA,OAAO,QAAA,CAAS,IAAA;AACjB","file":"index.cjs","sourcesContent":["/**\n * FamilySearch Tree/Pedigree API Module\n *\n * Provides helpers for fetching and managing family tree data\n * including pedigree, ancestry, and relationship information.\n */\n\nimport type { FamilySearchSDK } from \"../client\";\nimport type {\n\tEnhancedPedigreeData,\n\tEnhancedPerson,\n\tFamilySearchUser,\n\tPedigreeData,\n\tProgressCallback,\n\tRelationship,\n} from \"../types\";\n\n/**\n * Fetch pedigree/ancestry data with enhanced details\n *\n * @param sdk - FamilySearch SDK instance\n * @param personId - Optional person ID to start from. If not provided, uses current user.\n * @param options - Fetch options\n * @returns Promise with enhanced pedigree data\n *\n * @example\n * ```typescript\n * const pedigree = await fetchPedigree(sdk, \"XXXX-YYY\", {\n *   generations: 5,\n *   onProgress: (p) => console.log(`${p.percent}% complete`)\n * });\n * ```\n */\nexport async function fetchPedigree(\n\tsdk: FamilySearchSDK,\n\tpersonId?: string,\n\toptions: {\n\t\tgenerations?: number;\n\t\tonProgress?: ProgressCallback;\n\t\tincludeDetails?: boolean;\n\t\tincludeNotes?: boolean;\n\t\tincludeRelationshipDetails?: boolean;\n\t} = {}\n): Promise<EnhancedPedigreeData> {\n\tconst {\n\t\tgenerations = 4,\n\t\tonProgress,\n\t\tincludeDetails = true,\n\t\tincludeNotes = true,\n\t\tincludeRelationshipDetails = true,\n\t} = options;\n\n\t// Get current user's person ID if not provided\n\tlet targetPersonId = personId;\n\tif (!targetPersonId) {\n\t\tonProgress?.({\n\t\t\tstage: \"getting_current_user\",\n\t\t\tcurrent: 0,\n\t\t\ttotal: 1,\n\t\t\tpercent: 0,\n\t\t});\n\n\t\tconst currentUser = await sdk.getCurrentUser();\n\t\ttargetPersonId =\n\t\t\tcurrentUser?.personId ||\n\t\t\tcurrentUser?.treeUserId ||\n\t\t\tcurrentUser?.id;\n\n\t\tif (!targetPersonId) {\n\t\t\tthrow new Error(\"Could not determine person ID for current user\");\n\t\t}\n\t}\n\n\t// Step 1: Fetch ancestry structure\n\tonProgress?.({\n\t\tstage: \"fetching_ancestry_structure\",\n\t\tcurrent: 1,\n\t\ttotal: 3,\n\t\tpercent: 10,\n\t});\n\n\tconst ancestryResponse = await sdk.getAncestry(targetPersonId, generations);\n\tconst ancestry = ancestryResponse.data as PedigreeData;\n\n\tif (!ancestry.persons || ancestry.persons.length === 0) {\n\t\tthrow new Error(\"No persons found in ancestry\");\n\t}\n\n\t// Step 2: Enhance each person with detailed data\n\tonProgress?.({\n\t\tstage: \"fetching_person_details\",\n\t\tcurrent: 0,\n\t\ttotal: ancestry.persons.length,\n\t\tpercent: 20,\n\t});\n\n\tconst personsWithDetails: EnhancedPerson[] = [];\n\tfor (let i = 0; i < ancestry.persons.length; i++) {\n\t\tconst person = ancestry.persons[i];\n\n\t\tonProgress?.({\n\t\t\tstage: \"fetching_person_details\",\n\t\t\tcurrent: i + 1,\n\t\t\ttotal: ancestry.persons.length,\n\t\t\tpercent: 20 + Math.floor(((i + 1) / ancestry.persons.length) * 45),\n\t\t});\n\n\t\ttry {\n\t\t\tconst enhanced: EnhancedPerson = { ...person };\n\n\t\t\t// Fetch full person details with sources\n\t\t\tif (includeDetails) {\n\t\t\t\tenhanced.fullDetails = (await sdk.getPersonWithDetails(\n\t\t\t\t\tperson.id\n\t\t\t\t)) as EnhancedPerson[\"fullDetails\"];\n\t\t\t}\n\n\t\t\t// Fetch notes\n\t\t\tif (includeNotes) {\n\t\t\t\tenhanced.notes = (await sdk.getPersonNotes(\n\t\t\t\t\tperson.id\n\t\t\t\t)) as EnhancedPerson[\"notes\"];\n\t\t\t}\n\n\t\t\tpersonsWithDetails.push(enhanced);\n\t\t} catch {\n\t\t\t// Fallback to basic person data\n\t\t\tpersonsWithDetails.push(person as EnhancedPerson);\n\t\t}\n\t}\n\n\t// Step 3: Enhance couple relationships with marriage details\n\tonProgress?.({\n\t\tstage: \"fetching_relationship_details\",\n\t\tcurrent: 0,\n\t\ttotal: ancestry.relationships?.length || 0,\n\t\tpercent: 65,\n\t});\n\n\tconst relationshipsWithDetails: Relationship[] = [];\n\tif (ancestry.relationships && includeRelationshipDetails) {\n\t\tfor (let i = 0; i < ancestry.relationships.length; i++) {\n\t\t\tconst rel = ancestry.relationships[i];\n\n\t\t\tonProgress?.({\n\t\t\t\tstage: \"fetching_relationship_details\",\n\t\t\t\tcurrent: i + 1,\n\t\t\t\ttotal: ancestry.relationships.length,\n\t\t\t\tpercent:\n\t\t\t\t\t65 +\n\t\t\t\t\tMath.floor(((i + 1) / ancestry.relationships.length) * 25),\n\t\t\t});\n\n\t\t\ttry {\n\t\t\t\t// Only fetch details for couple relationships\n\t\t\t\tif (rel.type?.includes?.(\"Couple\")) {\n\t\t\t\t\tconst relDetails = await sdk.getCoupleRelationship(rel.id);\n\t\t\t\t\trelationshipsWithDetails.push({\n\t\t\t\t\t\t...rel,\n\t\t\t\t\t\tdetails: relDetails as Relationship[\"details\"],\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\trelationshipsWithDetails.push(rel);\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\trelationshipsWithDetails.push(rel);\n\t\t\t}\n\t\t}\n\t} else if (ancestry.relationships) {\n\t\trelationshipsWithDetails.push(...ancestry.relationships);\n\t}\n\n\t// Step 4: Extract additional relationships from person details\n\tonProgress?.({\n\t\tstage: \"extracting_additional_relationships\",\n\t\tcurrent: 0,\n\t\ttotal: 1,\n\t\tpercent: 90,\n\t});\n\n\tconst allRelationships = [...relationshipsWithDetails];\n\tconst relationshipIds = new Set(relationshipsWithDetails.map((r) => r.id));\n\n\tpersonsWithDetails.forEach((person) => {\n\t\t// Extract child-parent relationships from person details\n\t\tconst childAndParentsRels =\n\t\t\tperson.fullDetails?.childAndParentsRelationships;\n\t\tif (childAndParentsRels && Array.isArray(childAndParentsRels)) {\n\t\t\tchildAndParentsRels.forEach((rel) => {\n\t\t\t\tif (!relationshipIds.has(rel.id)) {\n\t\t\t\t\trelationshipIds.add(rel.id);\n\t\t\t\t\tallRelationships.push({\n\t\t\t\t\t\tid: rel.id,\n\t\t\t\t\t\ttype: \"http://gedcomx.org/ParentChild\",\n\t\t\t\t\t\tperson1: rel.parent1,\n\t\t\t\t\t\tperson2: rel.child,\n\t\t\t\t\t\tparent2: rel.parent2,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\n\t\t// Extract couple relationships from person details\n\t\tconst relationships = person.fullDetails?.relationships;\n\t\tif (relationships && Array.isArray(relationships)) {\n\t\t\trelationships.forEach((rel) => {\n\t\t\t\tif (rel.type?.includes?.(\"Couple\") && !relationshipIds.has(rel.id)) {\n\t\t\t\t\trelationshipIds.add(rel.id);\n\t\t\t\t\tallRelationships.push({\n\t\t\t\t\t\tid: rel.id,\n\t\t\t\t\t\ttype: rel.type,\n\t\t\t\t\t\tperson1: rel.person1,\n\t\t\t\t\t\tperson2: rel.person2,\n\t\t\t\t\t\tfacts: rel.facts,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t});\n\n\tonProgress?.({\n\t\tstage: \"completing_data_fetch\",\n\t\tcurrent: 1,\n\t\ttotal: 1,\n\t\tpercent: 98,\n\t});\n\n\treturn {\n\t\tpersons: personsWithDetails,\n\t\trelationships: allRelationships,\n\t\tenvironment: sdk.getEnvironment(),\n\t};\n}\n\n/**\n * Get current user information\n */\nexport async function getCurrentUser(\n\tsdk: FamilySearchSDK\n): Promise<FamilySearchUser | null> {\n\treturn sdk.getCurrentUser();\n}\n\n/**\n * Get person by ID with full details\n */\nexport async function getPersonWithDetails(\n\tsdk: FamilySearchSDK,\n\tpersonId: string\n): Promise<EnhancedPerson | null> {\n\ttry {\n\t\tconst [details, notes] = await Promise.all([\n\t\t\tsdk.getPersonWithDetails(personId),\n\t\t\tsdk.getPersonNotes(personId),\n\t\t]);\n\n\t\tif (!details) {\n\t\t\treturn null;\n\t\t}\n\n\t\t// The details response contains the person data in persons array\n\t\tconst fullDetails = details as EnhancedPerson[\"fullDetails\"];\n\t\tconst personData = fullDetails?.persons?.[0];\n\n\t\tif (!personData) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn {\n\t\t\t...personData,\n\t\t\tfullDetails: fullDetails,\n\t\t\tnotes: notes as EnhancedPerson[\"notes\"],\n\t\t};\n\t} catch {\n\t\treturn null;\n\t}\n}\n\n/**\n * Fetch multiple persons at once\n */\nexport async function fetchMultiplePersons(\n\tsdk: FamilySearchSDK,\n\tpersonIds: string[]\n): Promise<unknown> {\n\tconst pids = personIds.join(\",\");\n\tconst response = await sdk.get(`/platform/tree/persons?pids=${pids}`);\n\treturn response.data;\n}\n"]}