* Resolve a brand reference (domain + optional brand_id) to a ResolvedBrand. * For single-brand domains (no brand_id), delegates to resolveBrand(domain). * For multi-brand domains (with brand_id), resolves the house portfolio and * finds the specific brand by id.
(
ref: { domain: string; brand_id?: string },
options: { skipCache?: boolean } = {}
)
| 752 | * finds the specific brand by id. |
| 753 | */ |
| 754 | async resolveBrandRef( |
| 755 | ref: { domain: string; brand_id?: string }, |
| 756 | options: { skipCache?: boolean } = {} |
| 757 | ): Promise<ResolvedBrand | null> { |
| 758 | const resolved = await this.resolveBrand(ref.domain, options); |
| 759 | if (!resolved || !ref.brand_id) { |
| 760 | return resolved; |
| 761 | } |
| 762 | |
| 763 | // If the resolved brand already matches the requested brand_id, return it |
| 764 | if (resolved.canonical_id === ref.brand_id || resolved.canonical_domain === ref.brand_id) { |
| 765 | return resolved; |
| 766 | } |
| 767 | |
| 768 | // For house portfolios, look up the specific brand by id |
| 769 | const validationResult = await this.validateDomain(ref.domain, { skipCache: options.skipCache }); |
| 770 | if (validationResult.variant === 'house_portfolio' && validationResult.raw_data) { |
| 771 | const portfolio = validationResult.raw_data as HousePortfolioVariant; |
| 772 | const brand = portfolio.brands.find((b) => b.id === ref.brand_id); |
| 773 | if (brand) { |
| 774 | const primaryName = this.getPrimaryName(brand.names); |
| 775 | return { |
| 776 | canonical_id: brand.parent_brand ? `${brand.parent_brand}#${brand.id}` : brand.id, |
| 777 | canonical_domain: brand.id, |
| 778 | brand_name: primaryName || brand.id, |
| 779 | names: brand.names, |
| 780 | keller_type: brand.keller_type, |
| 781 | parent_brand: brand.parent_brand, |
| 782 | house_domain: portfolio.house.domain, |
| 783 | house_name: portfolio.house.name, |
| 784 | brand_manifest: brand.brand_manifest as Record<string, unknown> | undefined, |
| 785 | source: 'brand_json', |
| 786 | }; |
| 787 | } |
| 788 | } |
| 789 | |
| 790 | return null; |
| 791 | } |
| 792 | |
| 793 | /** |
| 794 | * Find a brand in a portfolio by property identifier |
nothing calls this directly
no test coverage detected