# Low-stock warnings trigger at configured thresholds

- **Pattern:** `ab-001128` (`ecommerce-catalog.inventory.low-stock-warning`)
- **Severity:** low
- **Lifecycle:** active
- **Last modified:** 2026-04-18
- **Canonical URL:** https://auditbuffet.com/patterns/ab-001128
- **License:** CC-BY-4.0 — attribute to AuditBuffet Pattern Catalog (https://auditbuffet.com/patterns/ab-001128)

## Why it matters

With no low-stock signal, shoppers who would convert under urgency keep browsing and abandon, while a hardcoded threshold of 1 fires too late to move units before the SKU goes dark. The inverse failure — fabricated urgency with no real threshold — draws FTC scrutiny under scarcity-claim rules. Either way, a missing or non-configurable threshold hands revenue back to competitors and blocks the merchandising team from tuning behavior per category.

## Severity rationale

Low because the impact is conversion-rate loss and merchandising inflexibility, not a security or data-integrity failure.

## Remediation

Read the threshold from an environment variable so ops can tune it per deployment, then gate the warning on positive stock to avoid rendering 'Only 0 left' messages. Put the logic in `src/lib/inventory.ts` and consume it from every product card:

```ts
const LOW_STOCK_THRESHOLD = parseInt(process.env.LOW_STOCK_THRESHOLD ?? '5', 10)

if (product.stock > 0 && product.stock <= LOW_STOCK_THRESHOLD) {
  return { ...product, lowStockWarning: `Only ${product.stock} left in stock` }
}
```

## Detection

- **ID:** `low-stock-warning`
- **Severity:** `low`
- **What to look for:** Count all references to low-stock thresholds in the codebase: search for "low stock", "LOW_STOCK", "lowStock", "only.*left", "few remaining" in `src/`, `app/`, and config files. Enumerate any threshold values found (hardcoded numbers, environment variables, or config settings). Check whether the threshold is configurable (environment variable or admin setting) or hardcoded.
- **Pass criteria:** A low-stock warning threshold is defined (at least 1 threshold value found) and implemented in at least 1 product display component. When stock <= threshold, a warning is displayed. Count all threshold references and report: "X low-stock threshold references found, threshold value: Y, configurable: [yes/no]."
- **Fail criteria:** No low-stock warning logic exists anywhere in the codebase (0 threshold references found), or the threshold is hardcoded to 1 with no way to configure.
- **Skip (N/A) when:** The project explicitly chooses not to display low-stock warnings — confirmed by a code comment or documentation stating this is an intentional design decision.
- **Cross-reference:** For urgency messaging compliance, the FTC Consumer Protection audit covers scarcity claims and truthful advertising.
- **Cross-reference:** For environment variable configuration patterns, the Environment Security audit covers config management best practices.
- **Cross-reference:** For real-time stock display performance, the Performance Core audit covers data freshness and caching strategies.
- **Detail on fail:** `"No low-stock warning found in the codebase — 0 references to stock thresholds"` or `"Low-stock threshold is hardcoded to 1 in src/components/product/ProductCard.tsx with no way to configure"`
- **Remediation:** Add a low-stock warning with a configurable threshold in `src/lib/inventory.ts`:

  ```ts
  const LOW_STOCK_THRESHOLD = parseInt(process.env.LOW_STOCK_THRESHOLD ?? '5', 10)

  if (product.stock > 0 && product.stock <= LOW_STOCK_THRESHOLD) {
    return {
      ...product,
      lowStockWarning: `Only ${product.stock} left in stock`,
    }
  }
  ```

---

Taxons: user-experience

HTML version: https://auditbuffet.com/patterns/ab-001128
