@happyvertical/smrt-products

中文文档
0.62.1发布于 2026/11/17TypeScriptES Module近 30 天下载 1.7万

SMRT products module: triple-purpose microservice template for standalone apps, federated modules, and NPM libraries

原始使用文档
文档目录13 节
  1. Installation
  2. Usage
  3. Import as npm library
  4. Three consumption modes
  5. API
  6. Top-Level Exports
  7. Models (from lib/models )
  8. Collections (from lib/collections )
  9. Components (from lib/components )
  10. Stores (from lib/stores )
  11. Utilities (from lib/utils )
  12. Virtual Modules (Vite plugin)
  13. Dependencies

@happyvertical/smrt-products

Product catalog reference template demonstrating triple-consumption: npm package library, module federation, and standalone REST API server.

Installation

pnpm add @happyvertical/smrt-products

Usage

Import as npm library

import { Product, ProductCollection, Category } from '@happyvertical/smrt-products';
import { startServer } from '@happyvertical/smrt-products';
import { generateMCPServer } from '@happyvertical/smrt-products';
import { AssetCollection } from '@happyvertical/smrt-assets';

// Start standalone REST API server
const { shutdown } = await startServer();

const products = await ProductCollection.create();
const assets = await AssetCollection.create();
const product = await products.create({
  name: 'Demo Product',
  price: 29.99,
});
const hero = await assets.create({
  name: 'demo-product-hero.jpg',
  sourceUri: 'file:///tmp/demo-product-hero.jpg',
  mimeType: 'image/jpeg',
});

await product.addAsset(hero, 'hero');
await products.addAsset(product.id!, hero, 'gallery', 1);

Three consumption modes

  1. NPM library -- import classes, components, and stores directly
  2. Module federation -- runtime component sharing (experimental)
  3. Standalone API -- startServer() launches Express with auto-generated routes

API

Top-Level Exports

ExportDescription
startServerLaunch standalone REST API server
generateMCPServerGenerate MCP server for AI tool integration
demonstrateClientDemo of auto-generated TypeScript client
startAllStart all services (REST + MCP)

Models (from lib/models)

ExportDescription
ProductSTI-enabled product with specs and tags
CategoryHierarchical category (parentId, level, productCount), STI enabled
ProductAssetDedicated owned-asset join stored in product_assets with relationship and sortOrder; intentionally not tenant-scoped because Product is not tenant-scoped

Collections (from lib/collections)

ExportDescription
ProductCollectionCRUD plus findByManufacturer(), findInStock(), and owned asset wrappers
ProductAssetCollectionDirect access to product_assets rows plus asset helper wrappers

Components (from lib/components)

ExportDescription
ProductCardSvelte 5 product display component
ProductFormSvelte 5 product edit form

Stores (from lib/stores)

ExportDescription
ProductStoreClassSvelte 5 rune-based state management class
productStoreSingleton store instance

Utilities (from lib/utils)

ExportDescription
formatPriceFormat number as USD currency string
formatDateFormat date as human-readable string
slugifyConvert text to URL-friendly slug
generateIdGenerate random ID string

Virtual Modules (Vite plugin)

ExportDescription
createClientAuto-generated TypeScript API client
setupRoutesAuto-generated Express routes
createMCPServerAuto-generated MCP server
manifests-m-r-t object metadata

Owned asset helpers are available on both Product and ProductCollection via getAssets(), addAsset(), and removeAsset(). Common relationships include hero, gallery, attachment, and thumbnail.

Dependencies

PackagePurpose
@happyvertical/smrt-coreSmrtObject/SmrtCollection base classes, REST server, MCP generator
@happyvertical/smrt-assetsShared Asset / AssetCollection types used by product-owned asset helpers
@happyvertical/sqlDatabase operations
@happyvertical/aiAI integration

版本与发布记录

@happyvertical/smrt-products 共发布 365 个版本,首次发布于 2026/06/23;过去 12 个月发布了 365 个版本。

版本发布日期距今
0.62.1latest2026/11/17今天
0.62.02026/11/17今天
0.61.62026/11/161 天前
0.61.52026/11/161 天前
0.61.42026/11/161 天前
0.61.32026/11/152 天前

关于 @happyvertical/smrt-products 的常见问题

@happyvertical/smrt-products 是什么?

SMRT products module: triple-purpose microservice template for standalone apps, federated modules, and NPM libraries

如何安装 @happyvertical/smrt-products?

在项目目录运行 npm install @happyvertical/smrt-products,或使用 pnpm add / yarn add / bun add。

@happyvertical/smrt-products 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@happyvertical/smrt-products 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@happyvertical/smrt-products 可以商用吗?

@happyvertical/smrt-products 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@happyvertical/smrt-products 的下载量有多少?

根据 npm 官方下载统计,@happyvertical/smrt-products 在 2026/10/17 – 2026/11/15 这 30 天内被下载 16,931 次,日均约 564 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@happyvertical/smrt-products 还在维护吗?

最新版本 0.62.1 发布于 2026/11/17(今天);至今共发布 365 个版本,其中过去 12 个月发布了 365 个;首次发布于 2026/06/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。