ChemPal Documentation - v1.6.0
    Preparing search index...

    Function getProductDedupeKey

    • 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, then id, uuid, and finally url, all mixed with the supplier name so two suppliers that share an identity string (e.g. a numeric id like 6981) never collide. Returns undefined when the product carries no usable identity, so callers keep it rather than merging unknowns.

      Parameters

      • product: Product

        The product to key.

      Returns undefined | string

      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 ?? '');
      }