npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@pinelab/vendure-plugin-stock-monitoring

v1.4.1

Published

Vendure plugin for monitoring stock levels through a widget or by email

Downloads

76

Readme

Vendure stock monitoring plugin

Official documentation here

This plugin helps you monitor the stock levels in two ways:

  1. A dashboard widget that displays variants who's stocklevel is below a given threshold
  2. An email handler that sends an email when stocklevels of a variant dropped below a given threshold

Getting started

  1. Add the plugin to your vendure-config.ts to expose a productVariantsWithLowStock query in the admin API.
import { StockMonitoringPlugin } from '@pinelab/vendure-plugin-stock-monitoring';
import { AdminUiPlugin } from '@vendure/admin-ui-plugin';

plugins: [
  StockMonitoringPlugin.init({
    threshold: 10,
  }),
  // Add the widget to the admin ui
  AdminUiPlugin.init({
    port: 3002,
    route: 'admin',
    app: compileUiExtensions({
      outputPath: path.join(__dirname, '__admin-ui'),
      extensions: [StockMonitoringPlugin.ui],
    }),
  }),
];

For more configuration options regarding the admin ui, check the docs.

When you start the server and login, you can find stock-levels under the add widgets button.

Low stock email handler

The email handler will send an email when the stocklevel of a variant drops below the given threshold. To activate the handler, you can add the following handlers to your vendure-config.ts:

import { createLowStockEmailHandler } from "@pinelab/vendure-plugin-stock-monitoring";

EmailPlugin.init({
  handlers: [
    // Dynamically get email recipients based on the event
    // and send an email when stock drops below 10
    createLowStockEmailHandler({
      threshold: 10,
      subject: "Stock of variants belo 10",
      emailRecipients: async (injector, event) => {
        // Dynamically resolve email recipients with the injector and event
        const recipients = await injector.get(MyService).getAdminsForChannel(event.ctx);
        return recipients;
      }
    }),
    // Send emails to two static addresses when stock drops below 99
    createLowStockEmailHandler({
      threshold: 99,
      subject: "Stock of variants below 99",
      emailRecipients: ["[email protected]", "[email protected]"]
    })
  ],
  ...

Create a template file for the low stock email in static/email/templates/low-stock/body.hbs with the following content:

<mjml>
  <mj-body>
    <mj-section>
      <mj-column>
        <mj-text font-size='30px'>Low stocknotification</mj-text>
        <mj-divider border-color='#343434'></mj-divider>

        <mj-text>
          These products are low on stock:
          <br />
          <br />
          {{#each lines}}
            <a href='http://localhost:3050/admin/products/'>
              {{productVariant.name}}
              -
              {{productVariant.stockOnHand}}
              pc.
            </a>
            <br />
          {{/each}}
        </mj-text>

      </mj-column>
    </mj-section>

  </mj-body>
</mjml>