@hyperse-hub/hps-plugin-stock-monitor
Vendure plugin for low-stock monitoring, Admin API listing, and email alerts when inventory crosses your threshold (on order placement and optional daily digest). Part of the Hub Store group — see Platform.md.
Features
- Admin GraphQL — Paginated query
productVariantsWithLowStock lists variants whose summed on-hand stock for the current channel is below a configurable threshold (same rules as alerts).
- Order-based alerts — After an order is placed, the plugin detects variants whose available stock crossed from at/above the threshold to at/below it because of that order, then raises a low-stock alert for those lines only (avoids noise when stock was already low).
- Scheduled digest — Optional daily task (09:00 server time) runs per channel and publishes a single alert per channel when any variants are below threshold (full channel scan, not threshold-cross detection).
- Email integration — Registers a
low-stock template with @hyperse-hub/hps-plugin-email (React Email), with product links built from adminProductUrl.
- Filtering options — Optionally exclude disabled or soft-deleted products, and optionally skip “fully out of stock” variants so only partial low stock is reported.
Prerequisites
- Vendure
>=3.3.0 (as declared by the plugin compatibility).
@hyperse-hub/hps-plugin-email must be loaded and configured so transactional email and templates work. Register it in your VendureConfig.plugins (typically before this plugin) with valid SMTP or provider settings.
Installation
Configuration
| Option | Type | Default | Description |
|---|
threshold | number | 10 | Stock level below which a variant is considered low (per channel, summed stock locations linked to the channel). |
subject | string | 'Stock of variants below {threshold}' | Email subject line. You can keep the literal {threshold} for your template or replace it; template vars also expose threshold for the body. |
adminProductUrl | string | '/admin/catalog/products/' | Base path used in the email template to link to products in the Admin UI (combined with product id as your template expects). |
emailRecipients |
Admin GraphQL
Requires ReadCatalog permission.
threshold — Optional; defaults to the plugin threshold option.
options — Standard Vendure list options (pagination, sort, filter) applied to the variant query.
Stock is evaluated using summed stockOnHand for stock locations assigned to the current channel, consistent with the scheduled check and email line collection.
Events
The plugin publishes LowStockAlertEvent (exported from the package) when:
source | When |
|---|
'order' | At least one order line caused stock to cross into the low band (from at/above threshold to at/below). |
'scheduled' | The daily job found one or more low-stock variants in that channel. |
Payload includes ctx, lines (LowStockLine: name, ids, stockOnHand), optional order when source === 'order'.
Email template
On bootstrap, the plugin registers the low-stock handler with the email plugin. Template variables typically include:
lines — Rows for the email body.
adminProductUrl — For building Admin links.
threshold — Configured threshold.
Ensure the email package can resolve the bundled template path (templates/dist in the published package).
Scheduler
Task id: daily-low-stock-check. Runs every day at 09:00 (server timezone). Iterates all channels, builds a request context per channel, collects low-stock lines, and publishes LowStockAlertEvent with source: 'scheduled' when the list is non-empty. Disable with enableDailyStockCheck: false.
Development
From this package directory:
License
MIT — see repository root.