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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@lionrockjs/worker-cms-plugin-decorator-credits

v0.1.0

Published

Optional credit and diamond client APIs for 0xCMS Worker plugins

Downloads

98

Readme

worker-cms-plugin-credits

Optional credit and diamond support for 0xCMS Worker plugins.

This package decorates any CMS client implementing the small request() transport contract. It has no runtime or peer dependency on @lionrockjs/worker-cms-plugin, so the base client and this feature package can be upgraded independently.

npm install @lionrockjs/worker-cms-plugin @lionrockjs/worker-cms-plugin-credits
import { CmsClient } from '@lionrockjs/worker-cms-plugin';
import { creditShortfall, withCredits } from '@lionrockjs/worker-cms-plugin-credits';

const cms = withCredits(new CmsClient(env, 'messaging'));

// Base methods are preserved by the decorator.
const message = await cms.create({
  page_type: 'message',
  name: 'Delivery',
});

// Credit methods are added by this package.
const quote = await cms.creditQuote('send_sms', recipients.length, userId);
if (!quote.affordable) return outOfBalance(quote.currency);

try {
  await cms.chargeCredits('send_sms', recipients.length, {
    actingUserId: userId,
    entityType: 'message',
    entityId: message.id,
  });
} catch (error) {
  const shortfall = creditShortfall(error);
  if (shortfall) return topUpPrompt(shortfall.currency);
  throw error;
}

withCredits() returns a non-mutating proxy: base methods still execute on the wrapped client, while the four credit methods execute on a CmsCredits decorator. Code that prefers explicit composition can use const credits = new CmsCredits(cms) instead.

The official @lionrockjs/worker-cms-plugin client needs version 0.3.3 or newer because that release introduces the stable request() transport. This package does not declare or pin it, so later base-client releases do not require a corresponding credits-package release.

Manifest costs

The CMS meters chargeable actions in two independent currencies. credit is the ordinary wallet; diamond is the premium wallet for actions for which the operator pays real money, such as SMS and WhatsApp delivery. The wallets never convert into each other.

A cost chooses its wallet in the plugin manifest. Omitting currency means ordinary credits.

{
  "credits": [
    {
      "key": "send_sms",
      "label": "Send SMS",
      "charge": "metered",
      "unit": "message",
      "currency": "diamond",
      "default": 3
    },
    {
      "key": "send_edm",
      "label": "Send EDM",
      "charge": "metered",
      "unit": "recipient",
      "default": 2
    }
  ]
}

The host owns pricing and charging. A plugin may request a quote or charge a manifest-declared cost, but it cannot set a price or write a balance.

API

  • credits(actingUserId?) returns this plugin's declared costs and balances.
  • creditQuote(key, quantity, actingUserId?) checks affordability without deducting anything.
  • chargeCredits(key, quantity, options?) charges a metered cost.
  • reportCreditUsage(key, quantity, userId) reports current usage for a recurring cost; the host bills it during its recurring sweep.
  • creditShortfall(error) extracts the wallet and required balances from an insufficient_credits HTTP 402 response.

balance and shared_balance remain aliases for the ordinary credit wallet. balances and shared_balances expose every wallet by currency.

Host requirement

These methods call /__cms/credits, /__cms/credits/quote, /__cms/credits/charge, and /__cms/credits/usage. A Worker CMS deployment without the credits feature returns 404 for those routes. Base page and tenant functionality remains on the independently installed base client.