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

@thezelijah/majik-product

v1.0.3

Published

Majik Product is a fully-featured class representing a product in the Majik system, designed for financial, inventory, and supply management. It provides utilities for computing revenue, COGS, profits, margins, and net revenue/profit on a per-month basis.

Readme

Majik Product

Majik Product is a fully-featured class representing a product in the Majik system, designed for financial, inventory, and supply management. It provides utilities for computing revenue, COGS, profits, margins, and net revenue/profit on a per-month basis. Its chainable setter methods make it easy to construct and update products fluently.


Live Demo

Majik Runway Thumbnail

Click the image to try Majik Product inside Majik Runway's revenue stream.

Price Genie Thumbnail

Click the image to try Majik Product inside Price Genie.


Table of Contents


✨ Overview

MajikProduct manages:

  • Metadata: name, category, type, description, SRP, inventory.
  • Settings: status, visibility, system flags.
  • Finance: grossRevenue, grossCost, grossProfit, netRevenue, netProfit.
  • Supply Plan: Monthly capacities, adjustments, generation, recomputation.
  • COGS: Full cost breakdown per unit.
  • Inventory: Stock tracking and unit calculations.
  • Serialization/Deserialization: Convert to/from JSON with full monetary support MajikMoney.

Full API Docs


📦 Installation

npm i @thezelijah/majik-product @thezelijah/majik-money@latest

Usage

Create a Product Instance

import { MajikProduct } from "@thezelijah/majik-product";
import { MajikMoney } from "@/SDK/tools/finance/majik-money/majik-money";

const product = MajikProduct.initialize(
  "Coffee Mug",
  ProductType.PHYSICAL,
  MajikMoney.fromMajor(10, "PHP"),
  100,
  "Drinkware",
  "Premium ceramic mug",
  "SKU123"
);

Defaults: status → ACTIVE visibility → PRIVATE Empty COGS, empty supply plan

Example Usage

import { MajikProduct } from "@/SDK/tools/business/majik-product";
import { MajikMoney } from "@/SDK/tools/finance/majik-money";
import { ProductType } from "@/SDK/tools/business/majik-product/enums";

// Initialize
const mug = MajikProduct.initialize(
  "Coffee Mug",
  ProductType.PHYSICAL,
  MajikMoney.fromMajor(12, "USD"),
  100,
  "Drinkware"
)
  .setDescriptionText("Premium ceramic mug")
  .setDescriptionHTML("<p>Premium ceramic mug for coffee lovers</p>")
  .addCOGS("Ceramic", MajikMoney.fromMajor(3, "USD"))
  .generateCapacityPlan(12, 100, 0.05);

// Monthly revenue
console.log(mug.getRevenue("2025-12"));

// Update stock
mug.reduceStock(10);

// Serialize
const json = mug.toJSON();

// Deserialize
const restored = MajikProduct.parseFromJSON(json);

Metadata Helpers

Chainable methods to update product metadata:

| Method | Description | | ---------------------------------- | ------------------------------ | | setName(name: string) | Updates name and slug | | setCategory(category: string) | Updates category | | setType(type: ProductType) | Updates product type | | setSRP(srp: MajikMoney) | Updates suggested retail price | | setDescriptionHTML(html: string) | Updates HTML description | | setDescriptionText(text: string) | Updates plain text description | | setDescriptionSEO(text: string) | Updates SEO text |

COGS Management

Manage the Cost of Goods Sold per unit:

| Method | Description | | ------------------------------------------- | ---------------------------------------- | | addCOGS(name, unitCost, quantity?, unit?) | Add a new COGS item | | pushCOGS(item: COGSItem) | Push an externally constructed COGS item | | updateCOGS(id, updates) | Update an existing COGS item | | removeCOGS(id) | Remove COGS item by ID | | setCOGS(items: COGSItem[]) | Replace entire COGS array | | clearCostBreakdown() | Remove all COGS items |

Supply Management

Manage monthly capacity and supply plan:

| Method | Description | | --------------------------------------------------------------- | -------------------------------------- | | addCapacity(month: YYYYMM, capacity, adjustment?) | Add a monthly capacity entry | | updateCapacityUnits(month, units) | Update units for a month | | updateCapacityAdjustment(month, adjustment?) | Update adjustment | | removeCapacity(month) | Remove a month from the plan | | clearCapacity() | Remove all capacity entries | | generateCapacityPlan(months, amount, growthRate?, startDate?) | Auto-generate a monthly plan | | normalizeCapacityUnits(amount) | Normalize all months to the same units | | recomputeCapacityPeriod(start, end, mode?) | Resize or redistribute capacity plan |

Supply plan queries:

  • totalCapacity → total units across all months
  • averageMonthlyCapacity → average supply per month
  • maxSupplyMonth / minSupplyMonth → highest/lowest monthly supply

Finance Computation

| Method | Description | | -------------------- | --------------------------------------------- | | getRevenue(month) | Returns gross revenue for the specified month | | getProfit(month) | Returns profit for the specified month | | reduceStock(units) | Reduces inventory stock safely | | isOutOfStock | Boolean flag if stock ≤ 0 |

Calculates revenue, costs, and profits per month or across all months.

  • grossRevenue, grossCost, grossProfit → totals across supply plan
  • netRevenue(month, discounts?, returns?, allowances?) → net per month
  • netProfit(month, operatingExpenses?, taxes?, discounts?, returns?, allowances?) → net profit per month
  • getRevenue(month), getCOGS(month), getProfit(month), getMargin(month) → month-specific
  • averageMonthlyRevenue, averageMonthlyProfit → averages

All computations use MajikMoney and respect currency.


Inventory Management

  • metadata.inventory.stock → current stock
  • reduceStock(units) → reduces stock safely
  • isOutOfStock → boolean flag

Unit-level computations:

  • unitCost, unitProfit, unitMargin, price

Utilities

  • validateSelf(throwError?: boolean) → validates all required fields
  • finalize() → converts to JSON with auto-generated ID
  • toJSON() → serialize with proper MajikMoney handling
  • parseFromJSON(json: string | object) → reconstruct a MajikProduct instance

Use Cases

MajikProduct is designed for applications that require structured, financial-aware product management. Typical use cases include:

  1. E-commerce Platforms
  • Track inventory, product pricing, and margins.
  • Calculate revenue and profit per month for forecasting.
  • Automatically generate supply plans and adjust capacity.
  1. Financial Analysis & Reporting
  • Compute gross/net revenue, COGS, and profits with full monthly breakdowns.
  • Generate monthly snapshots for dashboards or reports.
  • Integrate with accounting modules to track net profit, taxes, and allowances.
  1. Manufacturing & Production Planning
  • Manage supply plans with monthly capacity and adjustments.
  • Calculate per-unit cost and margin for cost optimization.
  • Recompute and redistribute capacity when production schedules change.
  1. Inventory & Stock Management
  • Track real-time stock availability and unit reduction.
  • Prevent over-selling by monitoring isOutOfStock.
  • Plan production based on stock trends and forecasted demand.
  1. Data Serialization & Integration
  • Export products to JSON for database storage or API integration.
  • Deserialize JSON to fully functional MajikProduct instances.
  • Maintain currency consistency using MajikMoney.

Best Practices

To maximize reliability, maintainability, and performance:

  1. Use Chainable Setters
  • Always modify products via setter methods (setSRP, addCOGS, setCapacity) to ensure timestamps and finance recalculations are handled automatically.
  1. Validate Before Finalization
  • Call validateSelf(true) before exporting or persisting the product to ensure all required fields are properly set.
  1. Maintain Currency Consistency
  • All monetary operations use MajikMoney. Avoid mixing currencies; setter methods validate against product SRP currency.
  1. Leverage Supply Plan Utilities
  • Use generateCapacityPlan, normalizeCapacityUnits, or recomputeCapacityPeriod to programmatically manage monthly supply rather than manually modifying arrays.
  1. Keep COGS Accurate
  • Always ensure unitCost and subtotal calculations are correct. Prefer addCOGS or pushCOGS instead of direct array mutation.
  1. Minimize Finance Recomputations for Bulk Updates
  • When performing bulk updates to COGS or supply, consider batching changes and calling recomputeFinance once at the end to avoid repeated expensive calculations.
  1. Use Snapshots for Reporting
  • Use getMonthlySnapshot(month) for consistent monthly financial reporting and dashboards.
  1. Error Handling
  • All setters throw on invalid input. Wrap critical updates in try/catch to handle edge cases gracefully.
  1. Serialization & Deserialization
  • Use toJSON / finalize for exporting, and parseFromJSON for reconstruction. Avoid manually modifying the serialized object to prevent integrity issues.

Conclusion

MajikProduct provides a robust, chainable, financial-first approach to product management, suitable for enterprise-grade applications with detailed revenue, COGS, and supply planning needs.

Contributing

Contributions, bug reports, and suggestions are welcome! Feel free to fork and open a pull request.


License

ISC — free for personal and commercial use.


Author

Made with 💙 by @thezelijah

About the Developer


Contact