Supplier shipping/country metadata (from SupplierFactory.supplierShippingMeta).
The active shippingType and country selections.
The set of supplier class names no result could satisfy under the filters.
suppliersExcludedBySearchFilters(
{ A: { country: 'US', shipping: 'worldwide' }, B: { country: 'US', shipping: 'domestic' } },
{ shippingType: ['worldwide'], country: [] },
); // => Set { 'B' } (domestic can't fulfill a worldwide request)
export function suppliersExcludedBySearchFilters(
meta: SupplierMetaMap,
filters: { shippingType: readonly string[]; country: readonly string[] },
): Set<string> {
const excluded = new Set<string>();
const requestedScopes = filters.shippingType.filter(isShippingRange);
const byShipping = requestedScopes.length > 0;
const byCountry = filters.country.length > 0;
if (!byShipping && !byCountry) return excluded;
for (const [key, { country, shipping }] of Object.entries(meta)) {
if (byShipping && !requestedScopes.some((requested) => shippingCovers(shipping, requested))) {
excluded.add(key);
} else if (byCountry && !filters.country.includes(country)) {
excluded.add(key);
}
}
return excluded;
}
The supplier class names ruled out by the active shipping-type and/or country filters. A supplier is excluded when a non-empty shipping filter names no scope its own scope can fulfill (per the shippingCovers hierarchy), or a non-empty country filter doesn't list its country. An empty filter constrains nothing.