Poseidonas

payload stock alerts

by Poseidonas
Stores & catalogs
v3
>=3.88 <4
MIT

Overview

Summary generated from the README

Adds per-item low stock thresholds and backorder settings to products and variants, and sends one email through payload.sendEmail when stock falls from above the threshold to at or below it. It works with the official ecommerce plugin or any collection with an inventory field, and adds admin-only endpoints for reporting and checking low stock. Requires Payload 3.88 or newer.

Features

  • Emails the shop once when inventory crosses down to the threshold, then re-arms when stock recovers
  • Watches product and variant changes as well as new orders, since checkout decrements bypass hooks
  • Adds threshold, backorder checkbox, notified date and a virtual stockStatus field to products and variants
  • Endpoints to list low stock items and to run a check that notifies for unflagged items
  • Rejects negative inventory on writes through Payload when backorder is not allowed
  • Customizable email content, field names, collection slugs and admin access check

Use cases

  • Notify a shop owner when a product or variant runs low after a sale
  • Show an on-backorder status on a storefront from the stockStatus field
  • Audit existing catalogue stock after install by running a one-off check

From the author

Low stock thresholds, admin notification on the downward crossing and backorder handling for Payload ecommerce.

Installation

npm i payload-stock-alerts

1

Stars

0

Forks

0

Open Issues

2 weeks ago

Last Updated

25

Weekly Downloads

v1.0.1

npm Version

34.9 KB

Unpacked Size

0

Dependencies

GitHub stars

10 since Sep 7

Show data
GitHub stars by day (UTC)
DateStars
Dec 6, 20261
Dec 5, 20261
Dec 4, 20261
Dec 3, 20261
Dec 2, 20261
Dec 1, 20261
Nov 30, 20261
Nov 29, 20261
Nov 28, 20261
Nov 27, 20261
Nov 26, 20261
Nov 25, 20261
Nov 24, 20261
Nov 23, 20261
Nov 22, 20261
Nov 21, 20261
Nov 20, 20261
Nov 19, 20261
Nov 18, 20261
Nov 17, 20261
Nov 16, 20261
Nov 15, 20261
Nov 14, 20261
Nov 13, 20261
Nov 12, 20261
Nov 11, 20261
Nov 10, 20261
Nov 9, 20261
Nov 8, 20261
Nov 7, 20261
Nov 6, 20261
Nov 5, 20261
Nov 4, 20261
Nov 3, 20261
Nov 2, 20261
Nov 1, 20261
Oct 31, 20261
Oct 30, 20261
Oct 29, 20261
Oct 28, 20261
Oct 27, 20261
Oct 26, 20261
Oct 25, 20261
Oct 24, 20261
Oct 23, 20261
Oct 22, 20261
Oct 21, 20261
Oct 20, 20261
Oct 19, 20261
Oct 18, 20261
Oct 17, 20261
Oct 16, 20261
Oct 15, 20261
Oct 14, 20261
Oct 13, 20261
Oct 12, 20261
Oct 11, 20261
Oct 10, 20261
Oct 9, 20261
Oct 8, 20261
Oct 7, 20261
Oct 6, 20261
Oct 5, 20261
Oct 4, 20261
Oct 3, 20261
Oct 2, 20261
Oct 1, 20261
Sep 30, 20261
Sep 29, 20261
Sep 28, 20261
Sep 27, 20261
Sep 26, 20261
Sep 25, 20261
Sep 24, 20261
Sep 23, 20261
Sep 22, 20261
Sep 21, 20261
Sep 20, 20261
Sep 19, 20261
Sep 18, 20261
Sep 17, 20261
Sep 16, 20261
Sep 15, 20261
Sep 14, 20261
Sep 13, 20261
Sep 12, 20261
Sep 11, 20261
Sep 10, 20261
Sep 9, 20261
Sep 8, 20261
Sep 7, 20261
npm weekly downloads

25+6 since Sep 7

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 6, 202625
Dec 5, 202621
Dec 4, 202623
Dec 3, 202618
Dec 2, 202620
Dec 1, 202621
Nov 30, 202621
Nov 29, 202624
Nov 28, 202633
Nov 27, 202638
Nov 26, 2026210
Nov 25, 2026207
Nov 24, 2026201
Nov 23, 2026200
Nov 22, 2026194
Nov 21, 2026185
Nov 20, 2026177
Nov 19, 20262
Nov 18, 20262
Nov 17, 20264
Nov 16, 20264
Nov 15, 20264
Nov 14, 20264
Nov 13, 20264
Nov 12, 20264
Nov 11, 20264
Nov 10, 20262
Nov 9, 20268
Nov 8, 202610
Nov 7, 202611
Nov 6, 202611
Nov 5, 202613
Nov 4, 202614
Nov 3, 202614
Nov 2, 20268
Nov 1, 20265
Oct 31, 20265
Oct 30, 20267
Oct 29, 20264
Oct 28, 20263
Oct 27, 20263
Oct 26, 20264
Oct 25, 20264
Oct 24, 20263
Oct 23, 20261
Oct 22, 20263
Oct 21, 20263
Oct 20, 20263
Oct 19, 20263
Oct 18, 20263
Oct 17, 20263
Oct 16, 20263
Oct 15, 20263
Oct 14, 20263
Oct 13, 20263
Oct 12, 20262
Oct 11, 20263
Oct 10, 20263
Oct 9, 20264
Oct 8, 20263
Oct 7, 20263
Oct 6, 20264
Oct 5, 20264
Oct 4, 20264
Oct 3, 20265
Oct 2, 20266
Oct 1, 20266
Sep 30, 20266
Sep 29, 20266
Sep 28, 20267
Sep 27, 20266
Sep 26, 20269
Sep 25, 20267
Sep 24, 20266
Sep 23, 20268
Sep 22, 20268
Sep 21, 20267
Sep 20, 20268
Sep 19, 20264
Sep 18, 20265
Sep 17, 20268
Sep 16, 202611
Sep 15, 202611
Sep 14, 202614
Sep 13, 202614
Sep 12, 202618
Sep 11, 202619
Sep 10, 202616
Sep 9, 202615
Sep 8, 202618
Sep 7, 202619

Each point is npm's rolling 7-day download count.

Health Score

72/100Good

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1340410667-root.svg)](https://payloaddirectory.dev/plugins/1340410667-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1340410667-root"><img src="https://payloaddirectory.dev/badge/1340410667-root.svg" alt="Payload Directory"></a>
Updated Nov 17, 2026Created Aug 20, 2026Published Nov 17, 2026

README

payload-stock-alerts

npm node license payload

Tells the shop once, by email, when a product or variant falls to its low stock threshold, decides whether inventory may go below zero, and exposes both as data a storefront can read.

  • Works with @payloadcms/plugin-ecommerce and with any collection that has an inventory field
  • Sends through payload.sendEmail, so it uses whatever email adapter the project already has
  • No runtime dependencies and no mail library. The only import in the built file is APIError from payload itself, which is already a peer dependency
  • No admin components, so it survives minor releases

Install

Requires Payload 3.88 or newer and @payloadcms/plugin-ecommerce 3.88 or newer. Verified against Payload 3.88.0 with the official plugin installed.

pnpm add payload-stock-alerts
import { stockAlertsPlugin } from 'payload-stock-alerts'

export default buildConfig({
  plugins: [
    stockAlertsPlugin({
      threshold: 5,
      to: '[email protected]',
    }),
  ],
})

Everything currently low, as data:

import { findLowStock } from 'payload-stock-alerts'

const { alerts, scanned, truncated } = await findLowStock({ req })

or over HTTP, GET /api/stock-alerts/low-stock:

{
  "alerts": [
    {
      "allowBackorder": false,
      "collection": "variants",
      "id": "12",
      "inventory": 2,
      "status": "low-stock",
      "threshold": 5,
      "title": "Blue mug, large"
    }
  ],
  "scanned": 148,
  "truncated": false
}

What was measured

Why a product hook is not enough

Read from @payloadcms/[email protected], endpoints/confirmOrder.ts. After a payment settles, inventory is decremented like this:

await payload.db.updateOne({
  id,
  collection: variantsSlug,
  data: { inventory: { $inc: item.quantity * -1 } },
})

payload.db.updateOne goes straight to the database adapter. It runs no collection hooks and no field validation. A plugin that only watches products and variants would never see a single sale.

So this plugin watches two places:

TriggerSeesHow the level after the change is known
afterChange on products and variantsadmin edits, imports, your own payload.update callsread from the document
afterChange on an order being createdsales through the official checkoutthe current level of each item minus the quantity on the order

The order path runs before the decrement, because the order is written first and the $inc loop runs after confirmOrder returns. The level after the sale is therefore calculated from the order, not observed on the item. Turn it off with checkOnOrder: false if your stock moves some other way.

Notifying once, not on every save

The crossing, not the level, decides. A save that leaves stock at 3 with a threshold of 5 sends nothing if the previous level was already at or below 5; only a fall from above the threshold to at or below it does. A date is then written to lowStockNotifiedAt, and it is cleared the first time stock returns above the threshold, which arms the next crossing. Both rules are covered by the test suite.

Options

OptionDefaultMeaning
allowBackorderfalseWhether inventory may go below zero when an item does not say
backorderFieldName'allowBackorder'Per item backorder checkbox
checkOnOrdertrueAlso check the items of an order when the order is created
disabledfalseStops checking and notifying but keeps the fields, so the database keeps its shape
enableVariantstrueAdds the fields and hooks to the variants collection
endpointPath'/stock-alerts'Path below the Payload API route
inventoryFieldName'inventory'Field the level is read from
isAdmin'admin' in req.user.rolesWho may call the endpoints
maxItems5000Items one scan reads in total before stopping and reporting truncated
notifiedFieldName'lowStockNotifiedAt'Date field recording that the crossing was notified
notifytrueSends the email. Off keeps the fields, the flag and the endpoints
ordersSlug'orders'Slug of the orders collection
pageSize100Items one scan reads at a time
productsSlug'products'Slug of the products collection
renderEmailplain text listBuilds the subject and body from the alerts
statusFieldName'stockStatus'Read only virtual field carrying the status
threshold5Threshold used when an item does not carry its own
thresholdFieldName'lowStockThreshold'Per item threshold field
tononeAddress or addresses the notification goes to
variantsSlug'variants'Slug of the variants collection

A value that cannot be used is replaced by its default rather than being applied. A negative threshold becomes 5 and 4.9 becomes 4. An entry in to without an @ is dropped. Nothing is silently reinterpreted: -5 never becomes 5.

What it adds to your database

CollectionFieldTypeNotes
your products collectionlowStockThresholdnumberempty means the store default
your products collectionallowBackordercheckboxdefaults to the store setting
your products collectionlowStockNotifiedAtdatehidden, written by the plugin
your products collectionstockStatustext, virtualin-stock, low-stock, out-of-stock or backorder. Computed on read, never stored
your variants collectionthe same fouromitted when enableVariants is false

Nothing else is created. No collection is added.

Two endpoints are added: GET /api/stock-alerts/low-stock, which only reports, and POST /api/stock-alerts/check, which reports and notifies for everything not yet flagged. Both are guarded by isAdmin.

Exported for server side use: stockAlertsPlugin, findLowStock, checkStock, stockStatus, crossedDown, decideNotification, defaultRenderEmail, resolveConfig.

stockStatus is what a storefront reads to show "on backorder": it is on every product and variant document returned by the API, and it already accounts for the per item allowBackorder setting.

Honest limits

Backorder cannot be refused on the checkout path. allowBackorder: false is enforced by a beforeValidate hook, so it refuses a negative level on every write that goes through Payload. It cannot refuse the official plugin's payload.db.updateOne, which bypasses hooks and validation entirely, so a sale can still drive inventory negative. The plugin reports that as out-of-stock; holding stock at checkout time is a different job and belongs in payload-stock-reservation.

The order path predicts, it does not observe. It calculates current level - quantity ordered. If the sale later fails to decrement, or something else changed the level in between, the number in the email is wrong by that difference. The level in GET /api/stock-alerts/low-stock is always read fresh and is never predicted.

Two simultaneous crossings can send two emails. Two concurrent writes both reading a pre-crossing level both decide to notify. The lowStockNotifiedAt flag narrows the window but does not close it, because the flag is read before it is written. The cost is a duplicate email, never a missed one.

Stock that is already low when you install stays quiet. There is no crossing to observe. Run POST /api/stock-alerts/check once after installing; it notifies for everything below threshold that carries no flag, and flags it.

A scan reads two indexes, not the whole catalogue. It asks for items whose inventory is at or below the store threshold, plus every item carrying its own threshold field, then filters each against its own value. A catalogue where most items carry a custom threshold is read almost in full. Pages are pageSize at a time and the scan stops at maxItems, reporting truncated: true.

Notification failure never breaks a save. Every send and every flag write is wrapped; failures are logged through payload.logger and the document is returned unchanged. Without to nothing is sent and a warning is logged instead.

stockStatus is virtual. It is computed by an afterRead hook and no column or property is created for it. It cannot be sorted or filtered on in a query.

License

MIT. Copyright George Vasiliades, https://github.com/Poseidonas

Similar plugins