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

@devx-retailos/invoice

v0.0.2

Published

GST-compliant PDF invoice generation for retailOS POS backends.

Readme

@devx-retailos/invoice

GST-compliant PDF invoice generation for Medusa v2 POS backends: assembles invoice data from a POS order, computes CGST/SGST/IGST breakdowns, and renders an A4 PDF (or HTML) via a pluggable renderer.

Part of retailOS, a Medusa v2 SDK for offline-store POS systems. Each @devx-retailos/* package is an independently installable Medusa plugin; a brand backend composes the ones it needs in medusa-config.ts.

Installation

npm install @devx-retailos/invoice

Peer dependencies: @medusajs/framework, @medusajs/medusa, and @medusajs/admin-shared ^2.15.0. puppeteer (^22.0.0) is an optional peer — the default PDF renderer requires it; skip it if you register a custom renderer or only serve HTML.

Requires @devx-retailos/order in the same backend (invoices are assembled from its orders). @devx-retailos/store-details is optional but recommended — it supplies the seller block (address, GSTIN, state code); without it those fields render empty.

Setup

// medusa-config.ts
module.exports = defineConfig({
  plugins: [
    { resolve: "@devx-retailos/order", options: {} },
    { resolve: "@devx-retailos/store-details", options: {} },
    { resolve: "@devx-retailos/invoice", options: {} },
  ],
})

The module registers under the key retailos_invoice (exported as INVOICE_MODULE).

Usage

import { INVOICE_MODULE } from "@devx-retailos/invoice"

const invoices = container.resolve(INVOICE_MODULE)

// Render a PDF for an order
const pdf: Buffer = await invoices.renderInvoice("order_01...", {
  organization_id: "org_...",
  store_id: "store_...",
  customer_state_code: "27",   // optional — drives intra/interstate GST split
  employee_name: "Cashier name", // optional — printed on the invoice
})

// Or get the structured data without rendering
const data = await invoices.assembleInvoiceData("order_01...", { organization_id: "org_..." })

GST notes

  • Per-line GST rate and HSN code are read from the order line item's metadata.gst_rate and metadata.hsn_code.
  • computeGstBreakdown(taxableAmount, gstRate, isIntrastate) splits tax into CGST + SGST (intrastate) or IGST (interstate). The sale is treated as intrastate when the customer state code is unknown or equals the store's state code.
  • formatInvoiceNumber(orderId, createdAt, override?) prefers order.metadata.invoice_number, falling back to INV-{YYYYMMDD}-{last 8 of order id}.
  • amountToWords(1250.5)"One Thousand Two Hundred Fifty Rupees and Fifty Paise Only" (Indian numbering: Lakh/Crore).

These helpers, plus renderInvoiceHtml(data), are exported for direct use.

Extension points

The default PuppeteerInvoiceRenderer launches headless Chromium and prints the HTML template to A4. To use a different PDF engine (or a hosted rendering service), implement InvoiceRenderer and register it at bootstrap:

import type { InvoiceRenderer, InvoiceData } from "@devx-retailos/invoice"

const myRenderer: InvoiceRenderer = {
  async render(data: InvoiceData): Promise<Buffer> {
    // produce a PDF buffer however you like
    return buffer
  },
}

invoices.setRenderer(myRenderer)

Permissions

Exported as INVOICE_PERMISSIONS from @devx-retailos/invoice/permissions:

| Key | Description | | --- | --- | | order.invoice | Generate and download GST-compliant PDF invoices for orders |

API routes

| Method | Path | Purpose | Permission | | --- | --- | --- | --- | | GET | /admin/retailos/orders/:id/invoice | Download the invoice. Query: organization_id (required), store_id, customer_state_code, employee_name, format=pdf\|html (default pdf). | order.invoice |

Returns 404 if the order doesn't exist and 503 if no PDF renderer is available (puppeteer missing and no custom renderer registered).

Errors

All extend RetailOSError from @devx-retailos/core (also importable from @devx-retailos/invoice/errors); switch on err.code:

  • RETAILOS_INVOICE_NOT_FOUND — no order found for the given id.
  • RETAILOS_INVOICE_RENDERER_NOT_AVAILABLE — puppeteer not installed and no custom renderer registered.
  • RETAILOS_INVOICE_RENDER_FAILED — the renderer threw; original error on cause.

Related packages

  • @devx-retailos/core — shared types, RetailOSError, Logger, permission registry.
  • @devx-retailos/order — the POS orders invoices are generated from.
  • @devx-retailos/store-details — store address/GST metadata printed on the invoice.
  • @devx-retailos/rbac — roles and permission checks enforced by the invoice route.

License

MIT