import type { ProductRecommendationsResponse } from 'brainerce'; /** * Reads of SDK fields that exist only in newer `brainerce` releases than the floor this template is scaffolded with. * * Why not just `item.brands`: a scaffold resolves the newest `brainerce` that satisfies the floor, which may be older than the * release that added a field. A direct property access then fails `next build` type-check on that SDK, for a feature that is meant * to render NOTHING when the data is absent. Reading through these helpers type-checks against every SDK and gives the same * result at run time: the value when the server sent it, `undefined` otherwise. Once the floor passes the release that added a * field, its helper can be deleted and the field read directly. */ type Group = NonNullable; /** `recommendations.customersAlsoBought` (SDK 3.21.0 and newer). */ export function customersAlsoBoughtOf( recommendations: ProductRecommendationsResponse | null | undefined ): Group | undefined { return (recommendations as { customersAlsoBought?: Group } | null | undefined) ?.customersAlsoBought; } /** `OrderItem.brands`, the brands frozen at the sale (SDK 3.21.0 and newer). */ export function orderLineBrands(item: object): Array<{ id: string; name: string }> | undefined { return (item as { brands?: Array<{ id: string; name: string }> }).brands; }