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

@trebired/e-shop

v0.7.0

Published

E-shop for Bun apps: catalog, stock, cart, checkout, orders, payments, a storefront structure for @trebired/frontend and a signed admin API.

Readme

@trebired/e-shop

Postgres-backed e-shop for Bun apps: catalog with variants and stock, cart, checkout, orders with a status history, Czech bank transfer payments with a QR code, card payments through Stripe, GoPay and Comgate, Bitcoin through BTCPay Server, Packeta pickup points with packet creation and labels, Czech invoices and credit notes as PDF, customer accounts, order email, a complete storefront for @trebired/frontend with every shop page, and a signed admin API that is always on.

The package owns the shop schema, the order rules, the storefront and admin HTTP routes and the storefront components. The app owns its @trebired/store runtime, which owns the database connection, its pages and their layout, its SMTP account, its public address, the admin token and its payment gateway accounts and credentials. The package does not own product photography storage, accounting, a customer marketing system or the admin interface itself; an admin application drives it through the admin API.

Install

Runtime support: Bun 1+.

bun i @trebired/e-shop

Quick Start

import http from "node:http";
import { createStoreApplicationRuntime } from "@trebired/store";
import { loadConfig } from "@trebired/e-shop/config";
import { createEshop } from "@trebired/e-shop/server";

const { config } = await loadConfig();
const store = createStoreApplicationRuntime({ entities: {} });
const eshop = createEshop({
  adminToken: process.env.ESHOP_ADMIN_TOKEN!,
  config,
  publicUrl: "https://shop.example",
  smtpUrl: process.env.SMTP_URL,
  sql: store.sql,
  gateways: {
    stripe: { secretKey: process.env.STRIPE_SECRET_KEY!, webhookSecret: process.env.STRIPE_WEBHOOK_SECRET! },
  },
});
await eshop.migrate();

http.createServer((req, res) => eshop.handle(req, res)).listen(3000);

In an Express app, mount eshop.handle before any body parser: app.use(eshop.handle). The handler reads request bodies itself, because the admin API signs the exact bytes.

Concepts

Money and VAT

Every amount is a whole number of minor units: 25000 is 250 Kč. Prices include VAT. An order's totals.vat lists the base and the VAT per rate, shipping counted at the default rate.

Stock

A variant's stock is a number or null for unlimited. Checkout takes the stock in the same transaction that creates the order, with a conditional update, so two buyers racing for the last item never both get it. Cancelling an order that has not shipped returns its stock.

Orders

An order moves pending_payment to paid, processing, shipped and delivered; it can be cancelled before it ships and refunded once paid. Every change is recorded with the actor in the order history. Order numbers are the year followed by a six-digit counter, and the number doubles as the bank variable symbol.

Payments

Bank transfer shows the account, the variable symbol and a QR payment code; the operator marks the order paid. Stripe, GoPay and Comgate share one payment interface. Checkout creates the order, then starts the payment and returns payment.redirectUrl, where the customer pays. The gateway's notification and the customer's return are both checked by asking the gateway for the payment status, so a forged or repeated notification changes nothing and a paid order is marked paid once. A failed or abandoned payment leaves the order waiting, and POST /orders/:token/pay starts a new one. Refunding, or cancelling a paid card order, returns the money through the same gateway before the order changes. Bitcoin runs through the shop's own BTCPay Server: the customer pays an invoice there, the settled invoice marks the order paid, and a refund creates a BTCPay refund whose claim link the order page shows, because a Bitcoin refund is sent to an address the customer gives.

Packeta

A packeta shipping method makes checkout ask for a pickup point. The storefront opens the Packeta widget with the public packeta.apiKey and sends the chosen point with the order; a point run by another carrier keeps its carrier id. Shipping the order creates the Packeta packet first, once, with the order number, the customer, the order total and the weight of the variants, and uses the packet barcode as the tracking number. The admin API also creates the packet on its own and returns the label PDF.

Invoices

With invoices.supplier configured, paying an order issues its invoice and attaches the PDF to the paid email. Refunding it, or cancelling it after payment, issues a credit note that reverses it. Invoices and credit notes are numbered per year in their own series (2026000001, D2026000001), and each keeps a frozen copy of the supplier, the customer, the lines and the VAT, so later changes to products or settings never alter an issued document. A VAT payer's invoice is a tax document with the date of taxable supply and a VAT summary; otherwise it states that the supplier is not a VAT payer. The PDF is rendered on request with an embedded Noto Sans subset under the SIL Open Font License, shipped in assets/fonts.

Customer Accounts

With accounts configured, customers can register, sign in and reset a forgotten password by email. Passwords are at least 10 characters and stored as Bun.password hashes. A session is a random token in an HttpOnly cookie, stored only as a hash, valid for 30 days and ended by signing out or by setting a new password. Five failed sign-ins for an email from one address within 15 minutes block that address until the window passes or the password is reset; the count is kept in memory per process. A reset link is valid for one hour and works once, and asking for one answers the same for any email. An order placed while signed in belongs to the account, and checkout without an account keeps working.

Storefront Preset

With storefront in the config, the package owns the whole storefront: the catalog with category filters and paging, product pages, the cart, checkout, order pages with payment and invoices, the customer account and password reset. eshopStorefront(config) from @trebired/e-shop/react returns:

  • pages(route): the page for a storefront address, ready for createSitePages from @trebired/frontend; any other address returns undefined and stays the app's.
  • paths: every storefront page to build, with _ in place of a product slug or order token.
  • Provider: one cart and copy for the whole site, so a header and a page share the cart.
  • CartLink: a link to the cart with the number of items.
  • href(page, param): a link to any storefront page.

createEshop({ storefrontDir }) serves the built page for every storefront address, so a product or order page works at its own address without app code. Routes, the catalog page size and the category filter are set in storefront; slots adds the app's own content before or after any page.

const storefront = eshopStorefront(eshopConfig, { slots: { checkout: { before: ShippingNote } } });
const sitePages = createSitePages({ error: ErrorPage, pages: (route) => storefront.pages(route) ?? appPages(route) });

Storefront

@trebired/e-shop/react gives the pieces a shop page is built from: EshopProvider, ProductGrid, ProductCard, ProductDetail, CartView, CheckoutForm, OrderStatus, AccountView, LoginForm, RegisterForm, ForgotPasswordForm and ResetPasswordForm, plus useCatalog, useProduct, useOrder and useAccount. They render @trebired/frontend primitives and namespace classes, ship Czech and English text, and leave layout and routing to the app.

Admin API

/eshop/admin/api/v1 covers statistics, products, variants, stock, categories, orders, customers, invoices and Packeta packets and labels. GET /products/:id accepts a product slug in place of its id. Every request carries x-eshop-timestamp and x-eshop-signature, an HMAC-SHA256 over the timestamp, method, path and body hash with the admin token. A request older than five minutes, signed with another token, or replayed is refused. The API is mounted whenever the shop is, and no option turns it off. createEshopAdminClient from @trebired/e-shop/client signs requests for an admin application.

Configuration

Config File

.trebired/e-shop/config.ts:

import { defineConfig } from "@trebired/e-shop/config";

export default defineConfig({
  forVersion: "0.7.0",
  shop: { name: "Example", currency: "CZK", locales: ["cs", "en"] },
  vat: { defaultRate: 21 },
  shipping: [
    { id: "pickup", kind: "pickup", label: { cs: "Osobní odběr", en: "Pickup" }, priceMinor: 0 },
    { id: "courier", kind: "courier", label: { cs: "Kurýr", en: "Courier" }, priceMinor: 12900, freeFromMinor: 200000 },
    { id: "packeta", kind: "packeta", label: { cs: "Zásilkovna", en: "Packeta" }, priceMinor: 7900 },
  ],
  packeta: { apiKey: "public widget key", sender: "example-eshop" },
  accounts: {},
  storefront: { catalog: { pageSize: 24 }, routes: { product: "/products/{slug}" } },
  invoices: {
    supplier: {
      name: "Example s.r.o.", street: "Údolní 1", postalCode: "602 00", city: "Brno", country: "Česká republika",
      companyId: "12345678", vatId: "CZ12345678", vatPayer: true,
      registration: "Zapsáno v obchodním rejstříku vedeném Krajským soudem v Brně, oddíl C, vložka 1",
    },
  },
  payments: {
    bankTransfer: { iban: "CZ6508000000192000145399", accountName: "Example s.r.o.", dueDays: 7 },
    stripe: { enabled: true },
    gopay: { goid: "8123456789", sandbox: true },
    comgate: { merchant: "123456", test: true },
    btcpay: { serverUrl: "https://btcpay.example", storeId: "store id" },
  },
  mail: { from: "[email protected]", operator: "[email protected]" },
  orders: { statusPath: "/order/{token}" },
});

forVersion must match the installed major and minor version. basePath (default /eshop) moves every route; cart.cookie and cart.ttlDays set the cart cookie.

Environment

createEshop takes the admin token, SMTP URL, public URL and events URL as options; the app reads them from its own environment. The admin token must be at least 32 characters.

Gateway credentials never go in the config file. Each gateway enabled in payments needs its credentials in createEshop({ gateways }), or createEshop throws:

  • stripe: secretKey and webhookSecret. Point a Stripe webhook for checkout.session.* events at <publicUrl>/eshop/api/payments/stripe/notify.
  • gopay: clientId and clientSecret. goid and sandbox stay in the config.
  • btcpay: apiKey and webhookSecret. Create a store webhook in BTCPay Server for invoice events pointing at <publicUrl>/eshop/api/payments/btcpay/notify.
  • comgate: secret. merchant and test stay in the config. Set the push address in the Comgate portal to <publicUrl>/eshop/api/payments/comgate/notify.

A packeta shipping method needs createEshop({ packeta: { apiPassword } }), the secret Packeta API password, or createEshop throws. packeta.sender is the sender label set up in the Packeta client section.

Card payments need publicUrl, because the gateways send the customer and their notifications back to it. Each gateway also takes apiBase, which replaces the gateway's address for tests and proxies.

Runtime

Storage

migrate() creates the eshop_* tables through sql.migrate, which runs each step once under an advisory lock and records it in the store's store_migrations. A database that an earlier version migrated keeps its tables: the steps it already applied are skipped, and its eshop_schema_migrations table is dropped. pruneCarts() deletes carts idle longer than cart.ttlDays.

Email

With smtpUrl and mail.from, the shop emails the customer when an order is placed, paid, shipped or cancelled, and emails mail.operator about every new order. Mail runs after the order is saved and never fails a request.

Events

With eventsUrl, every order change is posted there as JSON, signed the same way as admin requests, so an admin application can refresh without polling.

Public API

Entrypoints

  • @trebired/e-shop: types, formatMoney, vatLines, localized, the order actions per status (orderActionsFor) and the API constants. Browser safe.
  • @trebired/e-shop/config: defineConfig, loadConfig, normalizeConfig.
  • @trebired/e-shop/server: createEshop, migrateEshop, the catalog and order functions, signRequest, verifySignature, spaydString.
  • @trebired/e-shop/client: createEshopAdminClient, EshopAdminError.
  • @trebired/e-shop/react: the storefront provider, components and hooks.

Storefront Routes

  • GET /eshop/api/catalog, GET /eshop/api/products/:slug
  • GET /eshop/api/cart, POST /eshop/api/cart/items
  • GET /eshop/api/checkout/options, POST /eshop/api/checkout
  • GET /eshop/api/orders/:token/invoices/:number returns the invoice or credit note PDF
  • GET /eshop/api/account, POST /eshop/api/account/register, /login, /logout, /password/forgot, /password/reset
  • GET /eshop/api/orders/:token, POST /eshop/api/orders/:token/pay, POST /eshop/api/orders/:token/refresh
  • POST and GET /eshop/api/payments/:gateway/notify, GET /eshop/api/payments/:gateway/return

POST routes accept only application/json, except the gateway notifications, which accept what each gateway sends.

What It Does Not Do

This package does not:

  • sign customers in through other identity providers;
  • send invoices to accounting software or report them to the tax office;
  • ship Packeta home delivery; Packeta covers pickup points and Z-BOXes;
  • store or resize product images; products refer to image URLs the app serves;
  • compute taxes other than VAT included in the price, or handle more than one currency per shop;
  • provide an admin interface; it provides the admin API one is built on.