The product to key.
A stable dedupe key, or undefined when no identity is available.
getProductDedupeKey({ supplier: "Carolina Chemical", cacheKey: "6981" }); // "3f9c2a…"
getProductDedupeKey({ supplier: "ACME" }); // undefined (no identity)
export function getProductDedupeKey(product: Product): string | undefined {
const identity =
product.cacheKey ??
(product.id != null ? String(product.id) : undefined) ??
(product.uuid != null ? String(product.uuid) : undefined) ??
product.url;
if (!identity) return undefined;
return getProductIdentityKey(identity, product.supplier ?? '');
}
Derive a supplier-scoped dedupe key for a product, used to drop the same product appearing more than once in a single search's result set. Prefers the supplier-stable
cacheKey, thenid,uuid, and finallyurl, all mixed with the supplier name so two suppliers that share an identity string (e.g. a numericidlike6981) never collide. Returnsundefinedwhen the product carries no usable identity, so callers keep it rather than merging unknowns.